X Tutup
Skip to content

Commit 0a94021

Browse files
committed
feat(change detection): remove support for "if"
BREAKING CHANGE: Remove if statement support from actions. Closes #4616
1 parent fd0ba37 commit 0a94021

File tree

6 files changed

+1
-78
lines changed

6 files changed

+1
-78
lines changed

modules/angular2/src/core/change_detection/parser/ast.ts

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import {isBlank, isPresent, FunctionWrapper} from "angular2/src/core/facade/lang";
2-
import {Map, ListWrapper, StringMapWrapper} from "angular2/src/core/facade/collection";
1+
import {ListWrapper} from "angular2/src/core/facade/collection";
32

43
export class AST {
54
visit(visitor: AstVisitor): any { return null; }
@@ -29,11 +28,6 @@ export class Conditional extends AST {
2928
visit(visitor: AstVisitor): any { return visitor.visitConditional(this); }
3029
}
3130

32-
export class If extends AST {
33-
constructor(public condition: AST, public trueExp: AST, public falseExp?: AST) { super(); }
34-
visit(visitor: AstVisitor): any { return visitor.visitIf(this); }
35-
}
36-
3731
export class PropertyRead extends AST {
3832
constructor(public receiver: AST, public name: string, public getter: Function) { super(); }
3933
visit(visitor: AstVisitor): any { return visitor.visitPropertyRead(this); }
@@ -133,7 +127,6 @@ export interface AstVisitor {
133127
visitChain(ast: Chain): any;
134128
visitConditional(ast: Conditional): any;
135129
visitFunctionCall(ast: FunctionCall): any;
136-
visitIf(ast: If): any;
137130
visitImplicitReceiver(ast: ImplicitReceiver): any;
138131
visitInterpolation(ast: Interpolation): any;
139132
visitKeyedRead(ast: KeyedRead): any;
@@ -163,12 +156,6 @@ export class RecursiveAstVisitor implements AstVisitor {
163156
ast.falseExp.visit(this);
164157
return null;
165158
}
166-
visitIf(ast: If): any {
167-
ast.condition.visit(this);
168-
ast.trueExp.visit(this);
169-
ast.falseExp.visit(this);
170-
return null;
171-
}
172159
visitPipe(ast: BindingPipe): any {
173160
ast.exp.visit(this);
174161
this.visitAll(ast.args);
@@ -301,9 +288,4 @@ export class AstTransformer implements AstVisitor {
301288
}
302289

303290
visitChain(ast: Chain): Chain { return new Chain(this.visitAll(ast.expressions)); }
304-
305-
visitIf(ast: If): If {
306-
let falseExp = isPresent(ast.falseExp) ? ast.falseExp.visit(this) : null;
307-
return new If(ast.condition.visit(this), ast.trueExp.visit(this), falseExp);
308-
}
309291
}

modules/angular2/src/core/change_detection/parser/lexer.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@ export class Token {
5656

5757
isKeywordTrue(): boolean { return (this.type == TokenType.Keyword && this.strValue == "true"); }
5858

59-
isKeywordIf(): boolean { return (this.type == TokenType.Keyword && this.strValue == "if"); }
60-
61-
isKeywordElse(): boolean { return (this.type == TokenType.Keyword && this.strValue == "else"); }
62-
6359
isKeywordFalse(): boolean { return (this.type == TokenType.Keyword && this.strValue == "false"); }
6460

6561
toNumber(): number {

modules/angular2/src/core/change_detection/parser/parser.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import {
2929
Binary,
3030
PrefixNot,
3131
Conditional,
32-
If,
3332
BindingPipe,
3433
Chain,
3534
KeyedRead,
@@ -429,19 +428,6 @@ export class _ParseAST {
429428
this.advance();
430429
return new LiteralPrimitive(false);
431430

432-
} else if (this.parseAction && this.next.isKeywordIf()) {
433-
this.advance();
434-
this.expectCharacter($LPAREN);
435-
let condition = this.parseExpression();
436-
this.expectCharacter($RPAREN);
437-
let ifExp = this.parseExpressionOrBlock();
438-
let elseExp;
439-
if (this.next.isKeywordElse()) {
440-
this.advance();
441-
elseExp = this.parseExpressionOrBlock();
442-
}
443-
return new If(condition, ifExp, elseExp);
444-
445431
} else if (this.optionalCharacter($LBRACKET)) {
446432
var elements = this.parseExpressionList($RBRACKET);
447433
this.expectCharacter($RBRACKET);
@@ -542,16 +528,6 @@ export class _ParseAST {
542528
return positionals;
543529
}
544530

545-
parseExpressionOrBlock(): AST {
546-
if (this.optionalCharacter($LBRACE)) {
547-
let block = this.parseBlockContent();
548-
this.expectCharacter($RBRACE);
549-
return block;
550-
}
551-
552-
return this.parseExpression();
553-
}
554-
555531
parseBlockContent(): AST {
556532
if (!this.parseAction) {
557533
this.error("Binding expression cannot contain chained expression");
@@ -688,6 +664,4 @@ class SimpleExpressionChecker implements AstVisitor {
688664
}
689665

690666
visitChain(ast: Chain) { this.simple = false; }
691-
692-
visitIf(ast: If) { this.simple = false; }
693667
}

modules/angular2/src/core/change_detection/proto_change_detector.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
Binary,
1313
Chain,
1414
Conditional,
15-
If,
1615
BindingPipe,
1716
FunctionCall,
1817
ImplicitReceiver,
@@ -266,8 +265,6 @@ class _ConvertAstIntoProtoRecords implements AstVisitor {
266265
return this._addRecord(RecordType.Chain, "chain", null, args, null, 0);
267266
}
268267

269-
visitIf(ast: If) { throw new BaseException('Not supported'); }
270-
271268
_visitAll(asts: any[]) {
272269
var res = ListWrapper.createFixedSize(asts.length);
273270
for (var i = 0; i < asts.length; ++i) {

modules/angular2/test/core/change_detection/parser/parser_spec.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,6 @@ export function main() {
173173
});
174174
});
175175

176-
describe("if", () => {
177-
it('should parse if statements', () => {
178-
checkAction("if (true) a = 0");
179-
checkAction("if (true) {a = 0;}", "if (true) a = 0");
180-
});
181-
});
182-
183176
describe("assignment", () => {
184177
it("should support field assignments", () => {
185178
checkAction("a = 12");

modules/angular2/test/core/change_detection/parser/unparser.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
Chain,
88
Conditional,
99
EmptyExpr,
10-
If,
1110
BindingPipe,
1211
FunctionCall,
1312
ImplicitReceiver,
@@ -70,17 +69,6 @@ export class Unparser implements AstVisitor {
7069
this._visit(ast.falseExp);
7170
}
7271

73-
visitIf(ast: If) {
74-
this._expression += 'if (';
75-
this._visit(ast.condition);
76-
this._expression += ') ';
77-
this._visitExpOrBlock(ast.trueExp);
78-
if (isPresent(ast.falseExp)) {
79-
this._expression += ' else ';
80-
this._visitExpOrBlock(ast.falseExp);
81-
}
82-
}
83-
8472
visitPipe(ast: BindingPipe) {
8573
this._expression += '(';
8674
this._visit(ast.exp);
@@ -200,11 +188,4 @@ export class Unparser implements AstVisitor {
200188
}
201189

202190
private _visit(ast: AST) { ast.visit(this); }
203-
204-
private _visitExpOrBlock(ast: AST) {
205-
var isBlock = ast instanceof Chain || ast instanceof EmptyExpr;
206-
if (isBlock) this._expression += '{ ';
207-
this._visit(ast);
208-
if (isBlock) this._expression += ' }';
209-
}
210191
}

0 commit comments

Comments
 (0)
X Tutup