Skip to content

Commit da52137

Browse files
hawkgsmattrbeck
authored andcommitted
fix(compiler): parsing of an empty template literal interpolation
Even if we have an `EmptyExpr`, add that expression to the expressions array when a literal is parsed. The lack of the expression results in a discrepancy in the sizes of the `elements` and the `expressions` arrays of a `TemplateLiteral`, that result in an error when we visit that same literal due to the missing expression. Fixes #69699
1 parent 5de0ea5 commit da52137

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

packages/compiler/src/expression_parser/parser.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,9 +1646,8 @@ class _ParseAST {
16461646
const expression = this.parsePipe();
16471647
if (expression instanceof EmptyExpr) {
16481648
this.error('Template literal interpolation cannot be empty');
1649-
} else {
1650-
expressions.push(expression);
16511649
}
1650+
expressions.push(expression);
16521651
this.rbracesExpected--;
16531652
} else {
16541653
this.advance();

packages/compiler/test/expression_parser/parser_spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,9 @@ describe('parser', () => {
529529
});
530530

531531
it('should report error if interpolation is empty', () => {
532+
// Even though an empty interpolation should result in an error,
533+
// we should retain the expression.
534+
checkBinding('`hello ${}`');
532535
expectBindingError('`hello ${}`', 'Template literal interpolation cannot be empty');
533536
});
534537

0 commit comments

Comments
 (0)