feat(change detection): remove support for "if"
BREAKING CHANGE: Remove if statement support from actions. Closes #4616
This commit is contained in:
parent
fd0ba37734
commit
0a940211d5
@ -1,5 +1,4 @@
|
|||||||
import {isBlank, isPresent, FunctionWrapper} from "angular2/src/core/facade/lang";
|
import {ListWrapper} from "angular2/src/core/facade/collection";
|
||||||
import {Map, ListWrapper, StringMapWrapper} from "angular2/src/core/facade/collection";
|
|
||||||
|
|
||||||
export class AST {
|
export class AST {
|
||||||
visit(visitor: AstVisitor): any { return null; }
|
visit(visitor: AstVisitor): any { return null; }
|
||||||
@ -29,11 +28,6 @@ export class Conditional extends AST {
|
|||||||
visit(visitor: AstVisitor): any { return visitor.visitConditional(this); }
|
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 {
|
export class PropertyRead extends AST {
|
||||||
constructor(public receiver: AST, public name: string, public getter: Function) { super(); }
|
constructor(public receiver: AST, public name: string, public getter: Function) { super(); }
|
||||||
visit(visitor: AstVisitor): any { return visitor.visitPropertyRead(this); }
|
visit(visitor: AstVisitor): any { return visitor.visitPropertyRead(this); }
|
||||||
@ -133,7 +127,6 @@ export interface AstVisitor {
|
|||||||
visitChain(ast: Chain): any;
|
visitChain(ast: Chain): any;
|
||||||
visitConditional(ast: Conditional): any;
|
visitConditional(ast: Conditional): any;
|
||||||
visitFunctionCall(ast: FunctionCall): any;
|
visitFunctionCall(ast: FunctionCall): any;
|
||||||
visitIf(ast: If): any;
|
|
||||||
visitImplicitReceiver(ast: ImplicitReceiver): any;
|
visitImplicitReceiver(ast: ImplicitReceiver): any;
|
||||||
visitInterpolation(ast: Interpolation): any;
|
visitInterpolation(ast: Interpolation): any;
|
||||||
visitKeyedRead(ast: KeyedRead): any;
|
visitKeyedRead(ast: KeyedRead): any;
|
||||||
@ -163,12 +156,6 @@ export class RecursiveAstVisitor implements AstVisitor {
|
|||||||
ast.falseExp.visit(this);
|
ast.falseExp.visit(this);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
visitIf(ast: If): any {
|
|
||||||
ast.condition.visit(this);
|
|
||||||
ast.trueExp.visit(this);
|
|
||||||
ast.falseExp.visit(this);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
visitPipe(ast: BindingPipe): any {
|
visitPipe(ast: BindingPipe): any {
|
||||||
ast.exp.visit(this);
|
ast.exp.visit(this);
|
||||||
this.visitAll(ast.args);
|
this.visitAll(ast.args);
|
||||||
@ -301,9 +288,4 @@ export class AstTransformer implements AstVisitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
visitChain(ast: Chain): Chain { return new Chain(this.visitAll(ast.expressions)); }
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -56,10 +56,6 @@ export class Token {
|
|||||||
|
|
||||||
isKeywordTrue(): boolean { return (this.type == TokenType.Keyword && this.strValue == "true"); }
|
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"); }
|
isKeywordFalse(): boolean { return (this.type == TokenType.Keyword && this.strValue == "false"); }
|
||||||
|
|
||||||
toNumber(): number {
|
toNumber(): number {
|
||||||
|
@ -29,7 +29,6 @@ import {
|
|||||||
Binary,
|
Binary,
|
||||||
PrefixNot,
|
PrefixNot,
|
||||||
Conditional,
|
Conditional,
|
||||||
If,
|
|
||||||
BindingPipe,
|
BindingPipe,
|
||||||
Chain,
|
Chain,
|
||||||
KeyedRead,
|
KeyedRead,
|
||||||
@ -429,19 +428,6 @@ export class _ParseAST {
|
|||||||
this.advance();
|
this.advance();
|
||||||
return new LiteralPrimitive(false);
|
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)) {
|
} else if (this.optionalCharacter($LBRACKET)) {
|
||||||
var elements = this.parseExpressionList($RBRACKET);
|
var elements = this.parseExpressionList($RBRACKET);
|
||||||
this.expectCharacter($RBRACKET);
|
this.expectCharacter($RBRACKET);
|
||||||
@ -542,16 +528,6 @@ export class _ParseAST {
|
|||||||
return positionals;
|
return positionals;
|
||||||
}
|
}
|
||||||
|
|
||||||
parseExpressionOrBlock(): AST {
|
|
||||||
if (this.optionalCharacter($LBRACE)) {
|
|
||||||
let block = this.parseBlockContent();
|
|
||||||
this.expectCharacter($RBRACE);
|
|
||||||
return block;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.parseExpression();
|
|
||||||
}
|
|
||||||
|
|
||||||
parseBlockContent(): AST {
|
parseBlockContent(): AST {
|
||||||
if (!this.parseAction) {
|
if (!this.parseAction) {
|
||||||
this.error("Binding expression cannot contain chained expression");
|
this.error("Binding expression cannot contain chained expression");
|
||||||
@ -688,6 +664,4 @@ class SimpleExpressionChecker implements AstVisitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
visitChain(ast: Chain) { this.simple = false; }
|
visitChain(ast: Chain) { this.simple = false; }
|
||||||
|
|
||||||
visitIf(ast: If) { this.simple = false; }
|
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@ import {
|
|||||||
Binary,
|
Binary,
|
||||||
Chain,
|
Chain,
|
||||||
Conditional,
|
Conditional,
|
||||||
If,
|
|
||||||
BindingPipe,
|
BindingPipe,
|
||||||
FunctionCall,
|
FunctionCall,
|
||||||
ImplicitReceiver,
|
ImplicitReceiver,
|
||||||
@ -266,8 +265,6 @@ class _ConvertAstIntoProtoRecords implements AstVisitor {
|
|||||||
return this._addRecord(RecordType.Chain, "chain", null, args, null, 0);
|
return this._addRecord(RecordType.Chain, "chain", null, args, null, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
visitIf(ast: If) { throw new BaseException('Not supported'); }
|
|
||||||
|
|
||||||
_visitAll(asts: any[]) {
|
_visitAll(asts: any[]) {
|
||||||
var res = ListWrapper.createFixedSize(asts.length);
|
var res = ListWrapper.createFixedSize(asts.length);
|
||||||
for (var i = 0; i < asts.length; ++i) {
|
for (var i = 0; i < asts.length; ++i) {
|
||||||
|
@ -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", () => {
|
describe("assignment", () => {
|
||||||
it("should support field assignments", () => {
|
it("should support field assignments", () => {
|
||||||
checkAction("a = 12");
|
checkAction("a = 12");
|
||||||
|
@ -7,7 +7,6 @@ import {
|
|||||||
Chain,
|
Chain,
|
||||||
Conditional,
|
Conditional,
|
||||||
EmptyExpr,
|
EmptyExpr,
|
||||||
If,
|
|
||||||
BindingPipe,
|
BindingPipe,
|
||||||
FunctionCall,
|
FunctionCall,
|
||||||
ImplicitReceiver,
|
ImplicitReceiver,
|
||||||
@ -70,17 +69,6 @@ export class Unparser implements AstVisitor {
|
|||||||
this._visit(ast.falseExp);
|
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) {
|
visitPipe(ast: BindingPipe) {
|
||||||
this._expression += '(';
|
this._expression += '(';
|
||||||
this._visit(ast.exp);
|
this._visit(ast.exp);
|
||||||
@ -200,11 +188,4 @@ export class Unparser implements AstVisitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _visit(ast: AST) { ast.visit(this); }
|
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 += ' }';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user