feat(change_detector): add support for negate
This commit is contained in:
parent
4e38e3a96c
commit
f38b94067a
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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(),
|
||||
|
|
Loading…
Reference in New Issue