Skip to content

Commit 9b69e29

Browse files
JeanMechemattrbeck
authored andcommitted
refactor(compiler): Add info about unclosed element.
We chose to throw 2 errors here because we can't assume the intention of the developer and the span we target are different. fixes #57032
1 parent 6245333 commit 9b69e29

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

packages/compiler/src/ml_parser/parser.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,13 +753,30 @@ class _TreeBuilder {
753753
}
754754

755755
private _consumeBlockClose(token: BlockCloseToken) {
756+
const initialStackLength = this._containerStack.length;
757+
const topNode = this._containerStack[initialStackLength - 1];
756758
if (!this._popContainer(null, html.Block, token.sourceSpan)) {
759+
if (this._containerStack.length < initialStackLength) {
760+
const nodeName = topNode instanceof html.Component ? topNode.fullName : topNode.name;
761+
this.errors.push(
762+
TreeError.create(
763+
null,
764+
token.sourceSpan,
765+
`Unexpected closing block. The block may have been closed earlier. ` +
766+
`Did you forget to close the <${nodeName}> element? ` +
767+
`If you meant to write the \`}\` character, you should use the "&#125;" ` +
768+
`HTML entity instead.`,
769+
),
770+
);
771+
return;
772+
}
773+
757774
this.errors.push(
758775
TreeError.create(
759776
null,
760777
token.sourceSpan,
761778
`Unexpected closing block. The block may have been closed earlier. ` +
762-
`If you meant to write the } character, you should use the "&#125;" ` +
779+
`If you meant to write the \`}\` character, you should use the "&#125;" ` +
763780
`HTML entity instead.`,
764781
),
765782
);

packages/compiler/test/ml_parser/html_parser_spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,7 @@ describe('HtmlParser', () => {
11081108
expect(humanizeErrors(errors)).toEqual([
11091109
[
11101110
null,
1111-
'Unexpected closing block. The block may have been closed earlier. If you meant to write the } character, you should use the "&#125;" HTML entity instead.',
1111+
'Unexpected closing block. The block may have been closed earlier. If you meant to write the `}` character, you should use the "&#125;" HTML entity instead.',
11121112
'0:5',
11131113
],
11141114
]);
@@ -1120,7 +1120,7 @@ describe('HtmlParser', () => {
11201120
expect(humanizeErrors(errors)).toEqual([
11211121
[
11221122
null,
1123-
'Unexpected closing block. The block may have been closed earlier. If you meant to write the } character, you should use the "&#125;" HTML entity instead.',
1123+
'Unexpected closing block. The block may have been closed earlier. Did you forget to close the <strong> element? If you meant to write the `}` character, you should use the "&#125;" HTML entity instead.',
11241124
'0:21',
11251125
],
11261126
]);
@@ -1137,7 +1137,7 @@ describe('HtmlParser', () => {
11371137
],
11381138
[
11391139
null,
1140-
'Unexpected closing block. The block may have been closed earlier. If you meant to write the } character, you should use the "&#125;" HTML entity instead.',
1140+
'Unexpected closing block. The block may have been closed earlier. If you meant to write the `}` character, you should use the "&#125;" HTML entity instead.',
11411141
'0:28',
11421142
],
11431143
]);

0 commit comments

Comments
 (0)