@@ -704,6 +704,14 @@ describe('parser', () => {
704704 ] ) ;
705705 } ) ;
706706
707+ it ( 'should report unexpected token when encountering interpolation' , ( ) => {
708+ const attr = '*ngIf="name && {{name}}"' ;
709+
710+ expectParseTemplateBindingsError (
711+ attr ,
712+ 'Parser Error: Unexpected token {, expected identifier, keyword, or string at column 10 in [name && {{name}}] in foo.html' ) ;
713+ } ) ;
714+
707715 it ( 'should map variable declaration via "as"' , ( ) => {
708716 const attr =
709717 '*ngFor="let item; of items | slice:0:1 as collection, trackBy: func; index as i"' ;
@@ -951,17 +959,25 @@ function parseBinding(text: string, location: any = null, offset: number = 0): A
951959}
952960
953961function parseTemplateBindings ( attribute : string , templateUrl = 'foo.html' ) : TemplateBinding [ ] {
962+ const result = _parseTemplateBindings ( attribute , templateUrl ) ;
963+ expect ( result . errors ) . toEqual ( [ ] ) ;
964+ expect ( result . warnings ) . toEqual ( [ ] ) ;
965+ return result . templateBindings ;
966+ }
967+
968+ function expectParseTemplateBindingsError ( attribute : string , error : string ) {
969+ const result = _parseTemplateBindings ( attribute , 'foo.html' ) ;
970+ expect ( result . errors [ 0 ] . message ) . toEqual ( error ) ;
971+ }
972+
973+ function _parseTemplateBindings ( attribute : string , templateUrl : string ) {
954974 const match = attribute . match ( / ^ \* ( .+ ) = " ( .* ) " $ / ) ;
955975 expect ( match ) . toBeTruthy ( `failed to extract key and value from ${ attribute } ` ) ;
956976 const [ _ , key , value ] = match ;
957977 const absKeyOffset = 1 ; // skip the * prefix
958978 const absValueOffset = attribute . indexOf ( '=' ) + '="' . length ;
959979 const parser = createParser ( ) ;
960- const result =
961- parser . parseTemplateBindings ( key , value , templateUrl , absKeyOffset , absValueOffset ) ;
962- expect ( result . errors ) . toEqual ( [ ] ) ;
963- expect ( result . warnings ) . toEqual ( [ ] ) ;
964- return result . templateBindings ;
980+ return parser . parseTemplateBindings ( key , value , templateUrl , absKeyOffset , absValueOffset ) ;
965981}
966982
967983function parseInterpolation ( text : string , location : any = null , offset : number = 0 ) : ASTWithSource |
0 commit comments