feat(change_detection): add support for pipes in the template

This commit is contained in:
vsavkin
2015-02-20 10:59:14 -08:00
parent 29f5ee0c29
commit 987a5fdf56
12 changed files with 138 additions and 134 deletions

View File

@ -170,31 +170,15 @@ export class KeyedAccess extends AST {
}
}
export class Formatter extends AST {
export class Pipe extends AST {
exp:AST;
name:string;
args:List<AST>;
allArgs:List<AST>;
constructor(exp:AST, name:string, args:List) {
super();
this.exp = exp;
this.name = name;
this.args = args;
this.allArgs = ListWrapper.concat([exp], args);
}
visit(visitor) {
return visitor.visitFormatter(this);
}
}
export class Pipe extends AST {
exp:AST;
name:string;
constructor(exp:AST, name:string) {
super();
this.exp = exp;
this.name = name;
}
visit(visitor) {
@ -459,7 +443,6 @@ export class AstVisitor {
visitBinary(ast:Binary) {}
visitChain(ast:Chain){}
visitConditional(ast:Conditional) {}
visitFormatter(ast:Formatter) {}
visitPipe(ast:Pipe) {}
visitFunctionCall(ast:FunctionCall) {}
visitImplicitReceiver(ast:ImplicitReceiver) {}

View File

@ -13,7 +13,6 @@ import {
Binary,
PrefixNot,
Conditional,
Formatter,
Pipe,
Assignment,
Chain,
@ -57,7 +56,7 @@ export class Parser {
if (ListWrapper.isEmpty(pipes)) return bindingAst;
var res = ListWrapper.reduce(pipes,
(result, currentPipeName) => new Pipe(result, currentPipeName),
(result, currentPipeName) => new Pipe(result, currentPipeName, []),
bindingAst.ast);
return new ASTWithSource(res, bindingAst.source, bindingAst.location);
}
@ -191,7 +190,7 @@ class _ParseAST {
parseChain():AST {
var exprs = [];
while (this.index < this.tokens.length) {
var expr = this.parseFormatter();
var expr = this.parsePipe();
ListWrapper.push(exprs, expr);
if (this.optionalCharacter($SEMICOLON)) {
@ -208,18 +207,18 @@ class _ParseAST {
return new Chain(exprs);
}
parseFormatter() {
parsePipe() {
var result = this.parseExpression();
while (this.optionalOperator("|")) {
if (this.parseAction) {
this.error("Cannot have a formatter in an action expression");
this.error("Cannot have a pipe in an action expression");
}
var name = this.expectIdentifierOrKeyword();
var args = ListWrapper.create();
while (this.optionalCharacter($COLON)) {
ListWrapper.push(args, this.parseExpression());
}
result = new Formatter(result, name, args);
result = new Pipe(result, name, args);
}
return result;
}
@ -380,7 +379,7 @@ class _ParseAST {
parsePrimary() {
if (this.optionalCharacter($LPAREN)) {
var result = this.parseFormatter();
var result = this.parsePipe();
this.expectCharacter($RPAREN);
return result;