@@ -45,7 +45,8 @@ import {
4545 SafeMethodCall ,
4646 FunctionCall ,
4747 TemplateBinding ,
48- ASTWithSource
48+ ASTWithSource ,
49+ AstVisitor
4950} from './ast' ;
5051
5152
@@ -73,6 +74,12 @@ export class Parser {
7374 return new ASTWithSource ( ast , input , location ) ;
7475 }
7576
77+ parseSimpleBinding ( input : string , location : string ) : ASTWithSource {
78+ var tokens = this . _lexer . tokenize ( input ) ;
79+ var ast = new _ParseAST ( input , location , tokens , this . _reflector , false ) . parseSimpleBinding ( ) ;
80+ return new ASTWithSource ( ast , input , location ) ;
81+ }
82+
7683 parseTemplateBindings ( input : string , location : any ) : List < TemplateBinding > {
7784 var tokens = this . _lexer . tokenize ( input ) ;
7885 return new _ParseAST ( input , location , tokens , this . _reflector , false ) . parseTemplateBindings ( ) ;
@@ -202,6 +209,14 @@ class _ParseAST {
202209 return new Chain ( exprs ) ;
203210 }
204211
212+ parseSimpleBinding ( ) : AST {
213+ var ast = this . parseChain ( ) ;
214+ if ( ! SimpleExpressionChecker . check ( ast ) ) {
215+ this . error ( `Simple binding expression can only contain field access and constants'` ) ;
216+ }
217+ return ast ;
218+ }
219+
205220 parsePipe ( ) {
206221 var result = this . parseExpression ( ) ;
207222 if ( this . optionalOperator ( "|" ) ) {
@@ -590,3 +605,57 @@ class _ParseAST {
590605 `Parser Error: ${ message } ${ location } [${ this . input } ] in ${ this . location } ` ) ;
591606 }
592607}
608+
609+ class SimpleExpressionChecker implements AstVisitor {
610+ static check ( ast : AST ) {
611+ var s = new SimpleExpressionChecker ( ) ;
612+ ast . visit ( s ) ;
613+ return s . simple ;
614+ }
615+
616+ simple = true ;
617+
618+ visitImplicitReceiver ( ast : ImplicitReceiver ) { }
619+
620+ visitInterpolation ( ast : Interpolation ) { this . simple = false ; }
621+
622+ visitLiteralPrimitive ( ast : LiteralPrimitive ) { }
623+
624+ visitAccessMember ( ast : AccessMember ) { }
625+
626+ visitSafeAccessMember ( ast : SafeAccessMember ) { this . simple = false ; }
627+
628+ visitMethodCall ( ast : MethodCall ) { this . simple = false ; }
629+
630+ visitSafeMethodCall ( ast : SafeMethodCall ) { this . simple = false ; }
631+
632+ visitFunctionCall ( ast : FunctionCall ) { this . simple = false ; }
633+
634+ visitLiteralArray ( ast : LiteralArray ) { this . visitAll ( ast . expressions ) ; }
635+
636+ visitLiteralMap ( ast : LiteralMap ) { this . visitAll ( ast . values ) ; }
637+
638+ visitBinary ( ast : Binary ) { this . simple = false ; }
639+
640+ visitPrefixNot ( ast : PrefixNot ) { this . simple = false ; }
641+
642+ visitConditional ( ast : Conditional ) { this . simple = false ; }
643+
644+ visitPipe ( ast : BindingPipe ) { this . simple = false ; }
645+
646+ visitKeyedAccess ( ast : KeyedAccess ) { this . simple = false ; }
647+
648+ visitAll ( asts : List < any > ) {
649+ var res = ListWrapper . createFixedSize ( asts . length ) ;
650+ for ( var i = 0 ; i < asts . length ; ++ i ) {
651+ res [ i ] = asts [ i ] . visit ( this ) ;
652+ }
653+ return res ;
654+ }
655+
656+ visitChain ( ast : Chain ) { this . simple = false ; }
657+
658+ visitAssignment ( ast : Assignment ) { this . simple = false ; }
659+
660+ visitIf ( ast : If ) { this . simple = false ; }
661+ }
0 commit comments