File tree Expand file tree Collapse file tree
src/core/change_detection/parser
test/core/change_detection Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -216,6 +216,14 @@ export class _ParseAST {
216216 return n . toString ( ) ;
217217 }
218218
219+ parseSimpleBinding ( ) : AST {
220+ var ast = this . parseChain ( ) ;
221+ if ( ! SimpleExpressionChecker . check ( ast ) ) {
222+ this . error ( `Simple binding expression can only contain field access and constants'` ) ;
223+ }
224+ return ast ;
225+ }
226+
219227 parseChain ( ) : AST {
220228 var exprs = [ ] ;
221229 while ( this . index < this . tokens . length ) {
@@ -237,14 +245,6 @@ export class _ParseAST {
237245 return new Chain ( exprs ) ;
238246 }
239247
240- parseSimpleBinding ( ) : AST {
241- var ast = this . parseChain ( ) ;
242- if ( ! SimpleExpressionChecker . check ( ast ) ) {
243- this . error ( `Simple binding expression can only contain field access and constants'` ) ;
244- }
245- return ast ;
246- }
247-
248248 parsePipe ( ) : AST {
249249 var result = this . parseExpression ( ) ;
250250 if ( this . optionalOperator ( "|" ) ) {
@@ -256,7 +256,7 @@ export class _ParseAST {
256256 var name = this . expectIdentifierOrKeyword ( ) ;
257257 var args = [ ] ;
258258 while ( this . optionalCharacter ( $COLON ) ) {
259- args . push ( this . parsePipe ( ) ) ;
259+ args . push ( this . parseExpression ( ) ) ;
260260 }
261261 result = new BindingPipe ( result , name , args ) ;
262262 } while ( this . optionalOperator ( "|" ) ) ;
Original file line number Diff line number Diff line change @@ -408,6 +408,7 @@ var _availableDefinitions = [
408408 'name | pipe' ,
409409 '(name | pipe).length' ,
410410 "name | pipe:'one':address.city" ,
411+ "name | pipe:'a':'b' | pipe:0:1:2" ,
411412 'value' ,
412413 'a' ,
413414 'address.city' ,
Original file line number Diff line number Diff line change @@ -354,6 +354,14 @@ export function main() {
354354 expect ( val . dispatcher . loggedValues ) . toEqual ( [ 'value one two default' ] ) ;
355355 } ) ;
356356
357+ it ( 'should associate pipes right-to-left' , ( ) => {
358+ var registry = new FakePipes ( 'pipe' , ( ) => new MultiArgPipe ( ) ) ;
359+ var person = new Person ( 'value' ) ;
360+ var val = _createChangeDetector ( "name | pipe:'a':'b' | pipe:0:1:2" , person , registry ) ;
361+ val . changeDetector . detectChanges ( ) ;
362+ expect ( val . dispatcher . loggedValues ) . toEqual ( [ 'value a b default 0 1 2' ] ) ;
363+ } ) ;
364+
357365 it ( 'should not reevaluate pure pipes unless its context or arg changes' , ( ) => {
358366 var pipe = new CountingPipe ( ) ;
359367 var registry = new FakePipes ( 'pipe' , ( ) => pipe , { pure : true } ) ;
Original file line number Diff line number Diff line change @@ -6,14 +6,6 @@ import {Unparser} from './unparser';
66import { Lexer } from 'angular2/src/core/change_detection/parser/lexer' ;
77import { BindingPipe , LiteralPrimitive , AST } from 'angular2/src/core/change_detection/parser/ast' ;
88
9- class TestData {
10- constructor ( public a ?: any , public b ?: any , public fnReturnValue ?: any ) { }
11-
12- fn ( ) { return this . fnReturnValue ; }
13-
14- add ( a , b ) { return a + b ; }
15- }
16-
179export function main ( ) {
1810 function createParser ( ) { return new Parser ( new Lexer ( ) , reflector ) ; }
1911
@@ -229,8 +221,8 @@ export function main() {
229221 checkBinding ( 'a[b] | c' , '(a[b] | c)' ) ;
230222 checkBinding ( 'a?.b | c' , '(a?.b | c)' ) ;
231223 checkBinding ( 'true | a' , '(true | a)' ) ;
232- checkBinding ( 'a | b:c | d' , '(a | b:(c | d) )' ) ;
233- checkBinding ( '( a | b:c) | d' , '(( a | b:c) | d)' ) ;
224+ checkBinding ( 'a | b:c | d' , '(( a | b:c) | d)' ) ;
225+ checkBinding ( 'a | b:(c | d) ' , '(a | b:(c | d) )' ) ;
234226 } ) ;
235227
236228 it ( 'should only allow identifier or keyword as formatter names' , ( ) => {
You can’t perform that action at this time.
0 commit comments