From 0a940211d500b1403b7a14795b1202b57188bde7 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Thu, 8 Oct 2015 12:17:56 -0700 Subject: [PATCH] feat(change detection): remove support for "if" BREAKING CHANGE: Remove if statement support from actions. Closes #4616 --- .../src/core/change_detection/parser/ast.ts | 20 +------------- .../src/core/change_detection/parser/lexer.ts | 4 --- .../core/change_detection/parser/parser.ts | 26 ------------------- .../change_detection/proto_change_detector.ts | 3 --- .../change_detection/parser/parser_spec.ts | 7 ----- .../core/change_detection/parser/unparser.ts | 19 -------------- 6 files changed, 1 insertion(+), 78 deletions(-) diff --git a/modules/angular2/src/core/change_detection/parser/ast.ts b/modules/angular2/src/core/change_detection/parser/ast.ts index ad61b9a749..b3bea7e967 100644 --- a/modules/angular2/src/core/change_detection/parser/ast.ts +++ b/modules/angular2/src/core/change_detection/parser/ast.ts @@ -1,5 +1,4 @@ -import {isBlank, isPresent, FunctionWrapper} from "angular2/src/core/facade/lang"; -import {Map, ListWrapper, StringMapWrapper} from "angular2/src/core/facade/collection"; +import {ListWrapper} from "angular2/src/core/facade/collection"; export class AST { visit(visitor: AstVisitor): any { return null; } @@ -29,11 +28,6 @@ export class Conditional extends AST { visit(visitor: AstVisitor): any { return visitor.visitConditional(this); } } -export class If extends AST { - constructor(public condition: AST, public trueExp: AST, public falseExp?: AST) { super(); } - visit(visitor: AstVisitor): any { return visitor.visitIf(this); } -} - export class PropertyRead extends AST { constructor(public receiver: AST, public name: string, public getter: Function) { super(); } visit(visitor: AstVisitor): any { return visitor.visitPropertyRead(this); } @@ -133,7 +127,6 @@ export interface AstVisitor { visitChain(ast: Chain): any; visitConditional(ast: Conditional): any; visitFunctionCall(ast: FunctionCall): any; - visitIf(ast: If): any; visitImplicitReceiver(ast: ImplicitReceiver): any; visitInterpolation(ast: Interpolation): any; visitKeyedRead(ast: KeyedRead): any; @@ -163,12 +156,6 @@ export class RecursiveAstVisitor implements AstVisitor { ast.falseExp.visit(this); return null; } - visitIf(ast: If): any { - ast.condition.visit(this); - ast.trueExp.visit(this); - ast.falseExp.visit(this); - return null; - } visitPipe(ast: BindingPipe): any { ast.exp.visit(this); this.visitAll(ast.args); @@ -301,9 +288,4 @@ export class AstTransformer implements AstVisitor { } visitChain(ast: Chain): Chain { return new Chain(this.visitAll(ast.expressions)); } - - visitIf(ast: If): If { - let falseExp = isPresent(ast.falseExp) ? ast.falseExp.visit(this) : null; - return new If(ast.condition.visit(this), ast.trueExp.visit(this), falseExp); - } } diff --git a/modules/angular2/src/core/change_detection/parser/lexer.ts b/modules/angular2/src/core/change_detection/parser/lexer.ts index b41261177b..7013d16393 100644 --- a/modules/angular2/src/core/change_detection/parser/lexer.ts +++ b/modules/angular2/src/core/change_detection/parser/lexer.ts @@ -56,10 +56,6 @@ export class Token { isKeywordTrue(): boolean { return (this.type == TokenType.Keyword && this.strValue == "true"); } - isKeywordIf(): boolean { return (this.type == TokenType.Keyword && this.strValue == "if"); } - - isKeywordElse(): boolean { return (this.type == TokenType.Keyword && this.strValue == "else"); } - isKeywordFalse(): boolean { return (this.type == TokenType.Keyword && this.strValue == "false"); } toNumber(): number { diff --git a/modules/angular2/src/core/change_detection/parser/parser.ts b/modules/angular2/src/core/change_detection/parser/parser.ts index be8fcc3cea..3503cfff04 100644 --- a/modules/angular2/src/core/change_detection/parser/parser.ts +++ b/modules/angular2/src/core/change_detection/parser/parser.ts @@ -29,7 +29,6 @@ import { Binary, PrefixNot, Conditional, - If, BindingPipe, Chain, KeyedRead, @@ -429,19 +428,6 @@ export class _ParseAST { this.advance(); return new LiteralPrimitive(false); - } else if (this.parseAction && this.next.isKeywordIf()) { - this.advance(); - this.expectCharacter($LPAREN); - let condition = this.parseExpression(); - this.expectCharacter($RPAREN); - let ifExp = this.parseExpressionOrBlock(); - let elseExp; - if (this.next.isKeywordElse()) { - this.advance(); - elseExp = this.parseExpressionOrBlock(); - } - return new If(condition, ifExp, elseExp); - } else if (this.optionalCharacter($LBRACKET)) { var elements = this.parseExpressionList($RBRACKET); this.expectCharacter($RBRACKET); @@ -542,16 +528,6 @@ export class _ParseAST { return positionals; } - parseExpressionOrBlock(): AST { - if (this.optionalCharacter($LBRACE)) { - let block = this.parseBlockContent(); - this.expectCharacter($RBRACE); - return block; - } - - return this.parseExpression(); - } - parseBlockContent(): AST { if (!this.parseAction) { this.error("Binding expression cannot contain chained expression"); @@ -688,6 +664,4 @@ class SimpleExpressionChecker implements AstVisitor { } visitChain(ast: Chain) { this.simple = false; } - - visitIf(ast: If) { this.simple = false; } } diff --git a/modules/angular2/src/core/change_detection/proto_change_detector.ts b/modules/angular2/src/core/change_detection/proto_change_detector.ts index 787e42ab23..ad9a5c94e1 100644 --- a/modules/angular2/src/core/change_detection/proto_change_detector.ts +++ b/modules/angular2/src/core/change_detection/proto_change_detector.ts @@ -12,7 +12,6 @@ import { Binary, Chain, Conditional, - If, BindingPipe, FunctionCall, ImplicitReceiver, @@ -266,8 +265,6 @@ class _ConvertAstIntoProtoRecords implements AstVisitor { return this._addRecord(RecordType.Chain, "chain", null, args, null, 0); } - visitIf(ast: If) { throw new BaseException('Not supported'); } - _visitAll(asts: any[]) { var res = ListWrapper.createFixedSize(asts.length); for (var i = 0; i < asts.length; ++i) { diff --git a/modules/angular2/test/core/change_detection/parser/parser_spec.ts b/modules/angular2/test/core/change_detection/parser/parser_spec.ts index dce5dad7a5..c3ed640874 100644 --- a/modules/angular2/test/core/change_detection/parser/parser_spec.ts +++ b/modules/angular2/test/core/change_detection/parser/parser_spec.ts @@ -173,13 +173,6 @@ export function main() { }); }); - describe("if", () => { - it('should parse if statements', () => { - checkAction("if (true) a = 0"); - checkAction("if (true) {a = 0;}", "if (true) a = 0"); - }); - }); - describe("assignment", () => { it("should support field assignments", () => { checkAction("a = 12"); diff --git a/modules/angular2/test/core/change_detection/parser/unparser.ts b/modules/angular2/test/core/change_detection/parser/unparser.ts index eff3183757..70983a6282 100644 --- a/modules/angular2/test/core/change_detection/parser/unparser.ts +++ b/modules/angular2/test/core/change_detection/parser/unparser.ts @@ -7,7 +7,6 @@ import { Chain, Conditional, EmptyExpr, - If, BindingPipe, FunctionCall, ImplicitReceiver, @@ -70,17 +69,6 @@ export class Unparser implements AstVisitor { this._visit(ast.falseExp); } - visitIf(ast: If) { - this._expression += 'if ('; - this._visit(ast.condition); - this._expression += ') '; - this._visitExpOrBlock(ast.trueExp); - if (isPresent(ast.falseExp)) { - this._expression += ' else '; - this._visitExpOrBlock(ast.falseExp); - } - } - visitPipe(ast: BindingPipe) { this._expression += '('; this._visit(ast.exp); @@ -200,11 +188,4 @@ export class Unparser implements AstVisitor { } private _visit(ast: AST) { ast.visit(this); } - - private _visitExpOrBlock(ast: AST) { - var isBlock = ast instanceof Chain || ast instanceof EmptyExpr; - if (isBlock) this._expression += '{ '; - this._visit(ast); - if (isBlock) this._expression += ' }'; - } }