diff --git a/packages/compiler/src/ml_parser/lexer.ts b/packages/compiler/src/ml_parser/lexer.ts
index 6864d5a550..75da6732e5 100644
--- a/packages/compiler/src/ml_parser/lexer.ts
+++ b/packages/compiler/src/ml_parser/lexer.ts
@@ -713,6 +713,10 @@ class _Tokenizer {
}
} while (!this._isTextEnd());
+ // It is possible that an interpolation was started but not ended inside this text token.
+ // Make sure that we reset the state of the lexer correctly.
+ this._inInterpolation = false;
+
this._endToken([this._processCarriageReturns(parts.join(''))]);
}
diff --git a/packages/compiler/test/ml_parser/lexer_spec.ts b/packages/compiler/test/ml_parser/lexer_spec.ts
index 7d451b52ea..00c19418ee 100644
--- a/packages/compiler/test/ml_parser/lexer_spec.ts
+++ b/packages/compiler/test/ml_parser/lexer_spec.ts
@@ -1208,6 +1208,18 @@ import {ParseLocation, ParseSourceFile, ParseSourceSpan} from '../../src/parse_u
]]);
});
+ it('should report unescaped "{" as an error, even after a prematurely terminated interpolation',
+ () => {
+ expect(tokenizeAndHumanizeErrors(
+ `{{b}}
import {a} from 'a';`,
+ {tokenizeExpansionForms: true}))
+ .toEqual([[
+ lex.TokenType.RAW_TEXT,
+ `Unexpected character "EOF" (Do you have an unescaped "{" in your template? Use "{{ '{' }}") to escape it.)`,
+ '0:56',
+ ]]);
+ });
+
it('should include 2 lines of context in message', () => {
const src = '111\n222\n333\nE\n444\n555\n666\n';
const file = new ParseSourceFile(src, 'file://');