File tree Expand file tree Collapse file tree 2 files changed +41
-2
lines changed Expand file tree Collapse file tree 2 files changed +41
-2
lines changed Original file line number Diff line number Diff line change @@ -268,12 +268,16 @@ export class Parser {
268
268
const expressionNodes : AST [ ] = [ ] ;
269
269
270
270
for ( let i = 0 ; i < expressions . length ; ++ i ) {
271
+ // If we have a token for the specific expression, it's preferrable to use it because it
272
+ // allows us to produce more accurate error messages. The expressions are always at the odd
273
+ // indexes inside the tokens.
274
+ const expressionSpan = interpolatedTokens ?. [ i * 2 + 1 ] ?. sourceSpan ;
271
275
const expressionText = expressions [ i ] . text ;
272
276
const sourceToLex = this . _stripComments ( expressionText ) ;
273
277
const tokens = this . _lexer . tokenize ( sourceToLex ) ;
274
278
const ast = new _ParseAST (
275
- input ,
276
- parseSourceSpan ,
279
+ expressionSpan ? expressionText : input ,
280
+ expressionSpan || parseSourceSpan ,
277
281
absoluteOffset ,
278
282
tokens ,
279
283
ParseFlags . None ,
Original file line number Diff line number Diff line change @@ -784,6 +784,41 @@ describe('R3 template transform', () => {
784
784
expect ( errors [ 1 ] . msg ) . toContain ( 'Invalid character [#]' ) ;
785
785
expect ( errors [ 2 ] . msg ) . toContain ( `Unexpected token ')'` ) ;
786
786
} ) ;
787
+
788
+ it ( 'should report parsing errors on the specific interpolated expressions' , ( ) => {
789
+ const errors = parse (
790
+ `
791
+ bunch of text bunch of text bunch of text bunch of text bunch of text bunch of text
792
+ bunch of text bunch of text bunch of text bunch of text
793
+
794
+ {{foo[0}} bunch of text bunch of text bunch of text bunch of text {{.bar}}
795
+
796
+ bunch of text
797
+ bunch of text
798
+ bunch of text
799
+ bunch of text
800
+ bunch of text {{one + #two + baz}}
801
+ ` ,
802
+ {
803
+ ignoreError : true ,
804
+ } ,
805
+ ) . errors ;
806
+
807
+ expect ( errors . map ( ( e ) => e . span . toString ( ) ) ) . toEqual ( [
808
+ '{{foo[0}}' ,
809
+ '{{.bar}}' ,
810
+ '{{one + #two + baz}}' ,
811
+ ] ) ;
812
+
813
+ expect ( errors . map ( ( e ) => e . msg ) ) . toEqual ( [
814
+ jasmine . stringContaining ( 'Missing expected ] at the end of the expression [foo[0]' ) ,
815
+ jasmine . stringContaining ( 'Unexpected token . at column 1 in [.bar]' ) ,
816
+ jasmine . stringContaining (
817
+ 'Private identifiers are not supported. Unexpected private identifier: ' +
818
+ '#two at column 7 in [one + #two + baz]' ,
819
+ ) ,
820
+ ] ) ;
821
+ } ) ;
787
822
} ) ;
788
823
789
824
describe ( 'Ignored elements' , ( ) => {
You can’t perform that action at this time.
0 commit comments