feat(change detection): remove support for "if"

BREAKING CHANGE: Remove if statement support from actions.

Closes #4616
This commit is contained in:
Victor Berchet 2015-10-08 12:17:56 -07:00
parent fd0ba37734
commit 0a940211d5
6 changed files with 1 additions and 78 deletions

View File

@ -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);
}
}

View File

@ -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 {

View File

@ -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; }
}

View File

@ -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) {

View File

@ -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");

View File

@ -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 += ' }';
}
}