diff --git a/modules/angular2/src/change_detection/parser/parser.js b/modules/angular2/src/change_detection/parser/parser.js index 463593f80e..58b803f47a 100644 --- a/modules/angular2/src/change_detection/parser/parser.js +++ b/modules/angular2/src/change_detection/parser/parser.js @@ -211,18 +211,11 @@ class _ParseAST { parsePipe() { var result = this.parseExpression(); - while (this.optionalOperator("|")) { - if (this.parseAction) { - 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 Pipe(result, name, args, true); + if (this.optionalOperator("|")) { + return this.parseInlinedPipe(result); + } else { + return result; } - return result; } parseExpression() { @@ -464,10 +457,32 @@ class _ParseAST { } else { var getter = this.reflector.getter(id); var setter = this.reflector.setter(id); - return new AccessMember(receiver, id, getter, setter); + var am = new AccessMember(receiver, id, getter, setter); + + if (this.optionalOperator("|")) { + return this.parseInlinedPipe(am); + } else { + return am; + } } } + parseInlinedPipe(result) { + do { + if (this.parseAction) { + 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 Pipe(result, name, args, true); + } while(this.optionalOperator("|")); + + return result; + } + parseCallArguments() { if (this.next.isCharacter($RPAREN)) return []; var positionals = []; diff --git a/modules/angular2/test/change_detection/parser/parser_spec.js b/modules/angular2/test/change_detection/parser/parser_spec.js index 8b4ca5a76c..7533c79a50 100644 --- a/modules/angular2/test/change_detection/parser/parser_spec.js +++ b/modules/angular2/test/change_detection/parser/parser_spec.js @@ -381,11 +381,29 @@ export function main() { expect(exp.name).toEqual("uppercase"); }); + it("should parse pipes in the middle of a binding", () => { + var exp = parseBinding("user|a|b.name").ast; + + expect(exp.name).toEqual("name"); + expect(exp.receiver).toBeAnInstanceOf(Pipe); + expect(exp.receiver.name).toEqual("b"); + + expect(exp.receiver.exp).toBeAnInstanceOf(Pipe); + expect(exp.receiver.exp.name).toEqual("a"); + }); + it("should parse pipes with args", () => { - var exp = parseBinding("1|increment:2").ast; + var exp = parseBinding("(1|a:2)|b:3").ast; + expect(exp).toBeAnInstanceOf(Pipe); - expect(exp.name).toEqual("increment"); + expect(exp.name).toEqual("b"); expect(exp.args[0]).toBeAnInstanceOf(LiteralPrimitive); + + expect(exp.exp).toBeAnInstanceOf(Pipe); + expect(exp.exp.name).toEqual("a"); + expect(exp.exp.args[0]).toBeAnInstanceOf(LiteralPrimitive); + + expect(exp.exp.exp).toBeAnInstanceOf(LiteralPrimitive); }); it('should only allow identifier or keyword as formatter names', () => {