@@ -704,6 +704,14 @@ describe('parser', () => {
704
704
] ) ;
705
705
} ) ;
706
706
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
+
707
715
it ( 'should map variable declaration via "as"' , ( ) => {
708
716
const attr =
709
717
'*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
951
959
}
952
960
953
961
function 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 ) {
954
974
const match = attribute . match ( / ^ \* ( .+ ) = " ( .* ) " $ / ) ;
955
975
expect ( match ) . toBeTruthy ( `failed to extract key and value from ${ attribute } ` ) ;
956
976
const [ _ , key , value ] = match ;
957
977
const absKeyOffset = 1 ; // skip the * prefix
958
978
const absValueOffset = attribute . indexOf ( '=' ) + '="' . length ;
959
979
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 ) ;
965
981
}
966
982
967
983
function parseInterpolation ( text : string , location : any = null , offset : number = 0 ) : ASTWithSource |
0 commit comments