diff --git a/modules/change_detection/src/parser/ast.js b/modules/change_detection/src/parser/ast.js index bbeb606cea..645899becc 100644 --- a/modules/change_detection/src/parser/ast.js +++ b/modules/change_detection/src/parser/ast.js @@ -18,6 +18,16 @@ export class AST { } } +export class EmptyExpr extends AST { + eval(context) { + return null; + } + + visit(visitor, args) { + //do nothing + } +} + export class ImplicitReceiver extends AST { eval(context) { return context; diff --git a/modules/change_detection/src/parser/parser.js b/modules/change_detection/src/parser/parser.js index de07e154ec..475fe0e2dc 100644 --- a/modules/change_detection/src/parser/parser.js +++ b/modules/change_detection/src/parser/parser.js @@ -5,6 +5,7 @@ import {Lexer, EOF, Token, $PERIOD, $COLON, $SEMICOLON, $LBRACKET, $RBRACKET, import {reflector, Reflector} from 'reflection/reflection'; import { AST, + EmptyExpr, ImplicitReceiver, AccessMember, LiteralPrimitive, @@ -146,7 +147,9 @@ class _ParseAST { this.error(`Unexpected token '${this.next}'`); } } - return exprs.length == 1 ? exprs[0] : new Chain(exprs); + if (exprs.length == 0) return new EmptyExpr(); + if (exprs.length == 1) return exprs[0]; + return new Chain(exprs); } parseFormatter() { diff --git a/modules/change_detection/test/parser/parser_spec.js b/modules/change_detection/test/parser/parser_spec.js index eb0f202505..38ed12e4a1 100644 --- a/modules/change_detection/test/parser/parser_spec.js +++ b/modules/change_detection/test/parser/parser_spec.js @@ -150,6 +150,10 @@ export function main() { expectEvalError("null + null").toThrowError(); expectEvalError("null - null").toThrowError(); }); + + it('should parse an empty string', () => { + expectEval('').toBeNull(); + }); }); describe("literals", () => { @@ -376,7 +380,7 @@ export function main() { } it('should parse an empty string', () => { - var bindings = parseTemplateBindings(""); + var bindings = parseTemplateBindings(''); expect(bindings).toEqual([]); });