feat(change_detector): add support for negate

This commit is contained in:
vsavkin 2014-11-11 17:02:59 -08:00
parent 4e38e3a96c
commit f38b94067a
3 changed files with 11 additions and 4 deletions

View File

@ -262,7 +262,6 @@ export class Binary extends AST {
} }
export class PrefixNot extends AST { export class PrefixNot extends AST {
@FIELD('final operation:string')
@FIELD('final expression:AST') @FIELD('final expression:AST')
constructor(expression:AST) { constructor(expression:AST) {
this.expression = expression; this.expression = expression;

View File

@ -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 {FIELD, IMPLEMENTS, isBlank, isPresent, int, toBool, autoConvertAdd, BaseException} from 'facade/lang';
import {ListWrapper} from 'facade/collection'; import {ListWrapper} from 'facade/collection';
import {AST, AccessMember, ImplicitReceiver, AstVisitor, LiteralPrimitive, import {AST, AccessMember, ImplicitReceiver, AstVisitor, LiteralPrimitive,
Binary, Formatter, MethodCall, FunctionCall} from './parser/ast'; Binary, Formatter, MethodCall, FunctionCall, PrefixNot} from './parser/ast';
export class ProtoWatchGroup { export class ProtoWatchGroup {
@FIELD('headRecord:ProtoRecord') @FIELD('headRecord:ProtoRecord')
@ -170,10 +170,14 @@ class ProtoRecordCreator {
visitBinary(ast:Binary, dest) { visitBinary(ast:Binary, dest) {
var record = this.construct(PROTO_RECORD_PURE_FUNCTION, _operationToFunction(ast.operation), 2, dest); var record = this.construct(PROTO_RECORD_PURE_FUNCTION, _operationToFunction(ast.operation), 2, dest);
ast.left.visit(this, new Destination(record, 0)); ast.left.visit(this, new Destination(record, 0));
ast.right.visit(this, new Destination(record, 1)); 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); this.add(record);
} }
@ -232,7 +236,6 @@ class ProtoRecordCreator {
function _operationToFunction(operation:string):Function { function _operationToFunction(operation:string):Function {
switch(operation) { switch(operation) {
case '!' : return _operation_negate;
case '+' : return _operation_add; case '+' : return _operation_add;
case '-' : return _operation_subtract; case '-' : return _operation_subtract;
case '*' : return _operation_multiply; case '*' : return _operation_multiply;

View File

@ -121,6 +121,11 @@ export function main() {
expect(executeWatch('exp', 'false || false')).toEqual(['exp=false']); 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", () => { it("should support formatters", () => {
var formatters = { var formatters = {
"uppercase" : (v) => v.toUpperCase(), "uppercase" : (v) => v.toUpperCase(),