Skip to content

Commit f38b940

Browse files
committed
feat(change_detector): add support for negate
1 parent 4e38e3a commit f38b940

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

modules/change_detection/src/parser/ast.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@ export class Binary extends AST {
262262
}
263263

264264
export class PrefixNot extends AST {
265-
@FIELD('final operation:string')
266265
@FIELD('final expression:AST')
267266
constructor(expression:AST) {
268267
this.expression = expression;

modules/change_detection/src/watch_group.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {ProtoRecord, Record, PROTO_RECORD_CONST, PROTO_RECORD_PURE_FUNCTION,
33
import {FIELD, IMPLEMENTS, isBlank, isPresent, int, toBool, autoConvertAdd, BaseException} from 'facade/lang';
44
import {ListWrapper} from 'facade/collection';
55
import {AST, AccessMember, ImplicitReceiver, AstVisitor, LiteralPrimitive,
6-
Binary, Formatter, MethodCall, FunctionCall} from './parser/ast';
6+
Binary, Formatter, MethodCall, FunctionCall, PrefixNot} from './parser/ast';
77

88
export class ProtoWatchGroup {
99
@FIELD('headRecord:ProtoRecord')
@@ -170,10 +170,14 @@ class ProtoRecordCreator {
170170

171171
visitBinary(ast:Binary, dest) {
172172
var record = this.construct(PROTO_RECORD_PURE_FUNCTION, _operationToFunction(ast.operation), 2, dest);
173-
174173
ast.left.visit(this, new Destination(record, 0));
175174
ast.right.visit(this, new Destination(record, 1));
175+
this.add(record);
176+
}
176177

178+
visitPrefixNot(ast:PrefixNot, dest) {
179+
var record = this.construct(PROTO_RECORD_PURE_FUNCTION, _operation_negate, 1, dest);
180+
ast.expression.visit(this, new Destination(record, 0));
177181
this.add(record);
178182
}
179183

@@ -232,7 +236,6 @@ class ProtoRecordCreator {
232236

233237
function _operationToFunction(operation:string):Function {
234238
switch(operation) {
235-
case '!' : return _operation_negate;
236239
case '+' : return _operation_add;
237240
case '-' : return _operation_subtract;
238241
case '*' : return _operation_multiply;

modules/change_detection/test/change_detector_spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ export function main() {
121121
expect(executeWatch('exp', 'false || false')).toEqual(['exp=false']);
122122
});
123123

124+
it("should support negate", () => {
125+
expect(executeWatch('exp', '!true')).toEqual(['exp=false']);
126+
expect(executeWatch('exp', '!!true')).toEqual(['exp=true']);
127+
});
128+
124129
it("should support formatters", () => {
125130
var formatters = {
126131
"uppercase" : (v) => v.toUpperCase(),

0 commit comments

Comments
 (0)