@@ -106,7 +106,7 @@ export class Parser {
106
106
) : ASTWithSource {
107
107
const errors : ParseError [ ] = [ ] ;
108
108
this . _checkNoInterpolation ( errors , input , parseSourceSpan , interpolationConfig ) ;
109
- const sourceToLex = this . _stripComments ( input ) ;
109
+ const { stripped : sourceToLex } = this . _stripComments ( input ) ;
110
110
const tokens = this . _lexer . tokenize ( sourceToLex ) ;
111
111
const ast = new _ParseAST (
112
112
input ,
@@ -183,7 +183,7 @@ export class Parser {
183
183
errors : ParseError [ ] ,
184
184
) : AST {
185
185
this . _checkNoInterpolation ( errors , input , parseSourceSpan , interpolationConfig ) ;
186
- const sourceToLex = this . _stripComments ( input ) ;
186
+ const { stripped : sourceToLex } = this . _stripComments ( input ) ;
187
187
const tokens = this . _lexer . tokenize ( sourceToLex ) ;
188
188
return new _ParseAST (
189
189
input ,
@@ -273,8 +273,22 @@ export class Parser {
273
273
// indexes inside the tokens.
274
274
const expressionSpan = interpolatedTokens ?. [ i * 2 + 1 ] ?. sourceSpan ;
275
275
const expressionText = expressions [ i ] . text ;
276
- const sourceToLex = this . _stripComments ( expressionText ) ;
276
+ const { stripped : sourceToLex , hasComments } = this . _stripComments ( expressionText ) ;
277
277
const tokens = this . _lexer . tokenize ( sourceToLex ) ;
278
+
279
+ if ( hasComments && sourceToLex . trim ( ) . length === 0 && tokens . length === 0 ) {
280
+ // Empty expressions error are handled futher down, here we only take care of the comment case
281
+ errors . push (
282
+ getParseError (
283
+ 'Interpolation expression cannot only contain a comment' ,
284
+ input ,
285
+ `at column ${ expressions [ i ] . start } in` ,
286
+ parseSourceSpan ,
287
+ ) ,
288
+ ) ;
289
+ continue ;
290
+ }
291
+
278
292
const ast = new _ParseAST (
279
293
expressionSpan ? expressionText : input ,
280
294
expressionSpan || parseSourceSpan ,
@@ -308,7 +322,7 @@ export class Parser {
308
322
parseSourceSpan : ParseSourceSpan ,
309
323
absoluteOffset : number ,
310
324
) : ASTWithSource {
311
- const sourceToLex = this . _stripComments ( expression ) ;
325
+ const { stripped : sourceToLex } = this . _stripComments ( expression ) ;
312
326
const tokens = this . _lexer . tokenize ( sourceToLex ) ;
313
327
const errors : ParseError [ ] = [ ] ;
314
328
const ast = new _ParseAST (
@@ -450,9 +464,11 @@ export class Parser {
450
464
) ;
451
465
}
452
466
453
- private _stripComments ( input : string ) : string {
467
+ private _stripComments ( input : string ) : { stripped : string ; hasComments : boolean } {
454
468
const i = this . _commentStart ( input ) ;
455
- return i != null ? input . substring ( 0 , i ) : input ;
469
+ return i != null
470
+ ? { stripped : input . substring ( 0 , i ) , hasComments : true }
471
+ : { stripped : input , hasComments : false } ;
456
472
}
457
473
458
474
private _commentStart ( input : string ) : number | null {
0 commit comments