Skip to content

Commit 4117836

Browse files
committed
feat(HtmlLexer): better hint on unclosed ICU message errors
fixes #10227
1 parent 54f2edb commit 4117836

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

modules/@angular/compiler/src/html_lexer.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ class _HtmlTokenizer {
202202
}
203203

204204
private _createError(msg: string, span: ParseSourceSpan): _ControlFlowError {
205+
if (this._isInExpansionForm()) {
206+
msg += ' (Do you have an unescaped "{" in your template?).';
207+
}
205208
const error = new HtmlTokenError(msg, this._currentTokenType, span);
206209
this._currentTokenStart = null;
207210
this._currentTokenType = null;
@@ -523,6 +526,8 @@ class _HtmlTokenizer {
523526
this._requireCharCode(chars.$LBRACE);
524527
this._endToken([]);
525528

529+
this._expansionCaseStack.push(HtmlTokenType.EXPANSION_FORM_START);
530+
526531
this._beginToken(HtmlTokenType.RAW_TEXT, this._getLocation());
527532
const condition = this._readUntil(chars.$COMMA);
528533
this._endToken([condition], this._getLocation());
@@ -534,8 +539,6 @@ class _HtmlTokenizer {
534539
this._endToken([type], this._getLocation());
535540
this._requireCharCode(chars.$COMMA);
536541
this._attemptCharCodeUntilFn(isNotWhitespace);
537-
538-
this._expansionCaseStack.push(HtmlTokenType.EXPANSION_FORM_START);
539542
}
540543

541544
private _consumeExpansionCaseStart() {

modules/@angular/compiler/test/html_lexer_spec.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,14 @@ export function main() {
728728
});
729729

730730
describe('errors', () => {
731+
it('should parse nested expansion forms', () => {
732+
expect(tokenizeAndHumanizeErrors(`<p>before { after</p>`, true)).toEqual([[
733+
HtmlTokenType.RAW_TEXT,
734+
'Unexpected character "EOF" (Do you have an unescaped "{" in your template?).',
735+
'0:21',
736+
]]);
737+
});
738+
731739
it('should include 2 lines of context in message', () => {
732740
let src = '111\n222\n333\nE\n444\n555\n666\n';
733741
let file = new ParseSourceFile(src, 'file://');
@@ -787,7 +795,7 @@ function tokenizeAndHumanizeLineColumn(input: string): any[] {
787795
token => [<any>token.type, humanizeLineColumn(token.sourceSpan.start)]);
788796
}
789797

790-
function tokenizeAndHumanizeErrors(input: string): any[] {
791-
return tokenizeHtml(input, 'someUrl')
798+
function tokenizeAndHumanizeErrors(input: string, tokenizeExpansionForms: boolean = false): any[] {
799+
return tokenizeHtml(input, 'someUrl', tokenizeExpansionForms)
792800
.errors.map(e => [<any>e.tokenType, e.msg, humanizeLineColumn(e.span.start)]);
793801
}

0 commit comments

Comments
 (0)