diff --git a/modules/change_detection/src/parser/ast.js b/modules/change_detection/src/parser/ast.js index b2c86f46e6..e98b4141b6 100644 --- a/modules/change_detection/src/parser/ast.js +++ b/modules/change_detection/src/parser/ast.js @@ -262,7 +262,6 @@ export class Binary extends AST { } export class PrefixNot extends AST { - @FIELD('final operation:string') @FIELD('final expression:AST') constructor(expression:AST) { this.expression = expression; diff --git a/modules/change_detection/src/watch_group.js b/modules/change_detection/src/watch_group.js index deacb5db46..3563852cd7 100644 --- a/modules/change_detection/src/watch_group.js +++ b/modules/change_detection/src/watch_group.js @@ -3,7 +3,7 @@ import {ProtoRecord, Record, PROTO_RECORD_CONST, PROTO_RECORD_PURE_FUNCTION, import {FIELD, IMPLEMENTS, isBlank, isPresent, int, toBool, autoConvertAdd, BaseException} from 'facade/lang'; import {ListWrapper} from 'facade/collection'; import {AST, AccessMember, ImplicitReceiver, AstVisitor, LiteralPrimitive, - Binary, Formatter, MethodCall, FunctionCall} from './parser/ast'; + Binary, Formatter, MethodCall, FunctionCall, PrefixNot} from './parser/ast'; export class ProtoWatchGroup { @FIELD('headRecord:ProtoRecord') @@ -170,10 +170,14 @@ class ProtoRecordCreator { visitBinary(ast:Binary, dest) { var record = this.construct(PROTO_RECORD_PURE_FUNCTION, _operationToFunction(ast.operation), 2, dest); - ast.left.visit(this, new Destination(record, 0)); ast.right.visit(this, new Destination(record, 1)); + this.add(record); + } + visitPrefixNot(ast:PrefixNot, dest) { + var record = this.construct(PROTO_RECORD_PURE_FUNCTION, _operation_negate, 1, dest); + ast.expression.visit(this, new Destination(record, 0)); this.add(record); } @@ -232,7 +236,6 @@ class ProtoRecordCreator { function _operationToFunction(operation:string):Function { switch(operation) { - case '!' : return _operation_negate; case '+' : return _operation_add; case '-' : return _operation_subtract; case '*' : return _operation_multiply; diff --git a/modules/change_detection/test/change_detector_spec.js b/modules/change_detection/test/change_detector_spec.js index 5961ad4b2c..b85507fc27 100644 --- a/modules/change_detection/test/change_detector_spec.js +++ b/modules/change_detection/test/change_detector_spec.js @@ -121,6 +121,11 @@ export function main() { expect(executeWatch('exp', 'false || false')).toEqual(['exp=false']); }); + it("should support negate", () => { + expect(executeWatch('exp', '!true')).toEqual(['exp=false']); + expect(executeWatch('exp', '!!true')).toEqual(['exp=true']); + }); + it("should support formatters", () => { var formatters = { "uppercase" : (v) => v.toUpperCase(),