feat(change_detector): add support for ternary
This commit is contained in:
parent
f38b94067a
commit
0e6d52306b
|
@ -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, PrefixNot} from './parser/ast';
|
||||
Binary, Formatter, MethodCall, FunctionCall, PrefixNot, Conditional} from './parser/ast';
|
||||
|
||||
export class ProtoWatchGroup {
|
||||
@FIELD('headRecord:ProtoRecord')
|
||||
|
@ -214,6 +214,14 @@ class ProtoRecordCreator {
|
|||
this.add(record);
|
||||
}
|
||||
|
||||
visitConditional(ast:Conditional, dest) {
|
||||
var record = this.construct(PROTO_RECORD_PURE_FUNCTION, _cond, 3, dest);
|
||||
ast.condition.visit(this, new Destination(record, 0));
|
||||
ast.trueExp.visit(this, new Destination(record, 1));
|
||||
ast.falseExp.visit(this, new Destination(record, 2));
|
||||
this.add(record);
|
||||
}
|
||||
|
||||
createRecordsFromAST(ast:AST, memento){
|
||||
ast.visit(this, memento);
|
||||
}
|
||||
|
@ -267,4 +275,5 @@ function _operation_less_or_equals_then(left, right) {return left <= right;}
|
|||
function _operation_greater_or_equals_then(left, right) {return left >= right;}
|
||||
function _operation_logical_and(left, right) {return left && right;}
|
||||
function _operation_logical_or(left, right) {return left || right;}
|
||||
function _cond(cond, trueVal, falseVal) {return cond ? trueVal : falseVal;}
|
||||
|
||||
|
|
|
@ -126,6 +126,11 @@ export function main() {
|
|||
expect(executeWatch('exp', '!!true')).toEqual(['exp=true']);
|
||||
});
|
||||
|
||||
it("should support conditionals", () => {
|
||||
expect(executeWatch('m', '1 < 2 ? 1 : 2')).toEqual(['m=1']);
|
||||
expect(executeWatch('m', '1 > 2 ? 1 : 2')).toEqual(['m=2']);
|
||||
});
|
||||
|
||||
it("should support formatters", () => {
|
||||
var formatters = {
|
||||
"uppercase" : (v) => v.toUpperCase(),
|
||||
|
|
Loading…
Reference in New Issue