Skip to content

Commit fcdc7d9

Browse files
committed
Chore: add tests about missing-end-tag-name
1 parent b14b268 commit fcdc7d9

File tree

5 files changed

+277
-9
lines changed

5 files changed

+277
-9
lines changed

src/html/parser.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -285,11 +285,6 @@ export class Parser {
285285
*/
286286
private processComment(token: Token): void {
287287
this.comments.push(token)
288-
289-
// Sepalate text nodes.
290-
if (this.currentNode.type === "VText") {
291-
this.popNodeStack()
292-
}
293288
}
294289

295290
/**
@@ -308,10 +303,17 @@ export class Parser {
308303
}
309304

310305
if (this.currentNode.type === "VText") {
311-
this.currentNode.value += token.value
312-
this.currentNode.range[1] = token.range[1]
313-
this.currentNode.loc.end = token.loc.end
314-
return
306+
if (this.currentNode.range[1] === token.range[0]) {
307+
this.currentNode.value += token.value
308+
this.currentNode.range[1] = token.range[1]
309+
this.currentNode.loc.end = token.loc.end
310+
return
311+
}
312+
313+
this.popNodeStack()
314+
if (this.currentNode.type === "VText") {
315+
throw new Error("unreachable")
316+
}
315317
}
316318

317319
const parentElement = this.currentNode

src/html/tokenizer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,7 @@ export class Tokenizer {
678678
return this.reconsumeAs("TAG_NAME")
679679
}
680680
if (cp === GREATER_THAN_SIGN) {
681+
this.endToken() // < Commit or abandon the current text token.
681682
this.reportParseError("missing-end-tag-name")
682683
return "DATA"
683684
}
Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
1+
{
2+
"type": "Program",
3+
"start": 0,
4+
"end": 0,
5+
"loc": {
6+
"start": {
7+
"line": 1,
8+
"column": 0
9+
},
10+
"end": {
11+
"line": 1,
12+
"column": 0
13+
}
14+
},
15+
"range": [
16+
0,
17+
0
18+
],
19+
"body": [],
20+
"sourceType": "script",
21+
"comments": [],
22+
"tokens": [],
23+
"templateBody": {
24+
"type": "VElement",
25+
"range": [
26+
0,
27+
30
28+
],
29+
"loc": {
30+
"start": {
31+
"line": 1,
32+
"column": 0
33+
},
34+
"end": {
35+
"line": 3,
36+
"column": 11
37+
}
38+
},
39+
"name": "template",
40+
"namespace": "http://www.w3.org/1999/xhtml",
41+
"startTag": {
42+
"type": "VStartTag",
43+
"range": [
44+
0,
45+
10
46+
],
47+
"loc": {
48+
"start": {
49+
"line": 1,
50+
"column": 0
51+
},
52+
"end": {
53+
"line": 1,
54+
"column": 10
55+
}
56+
},
57+
"attributes": []
58+
},
59+
"children": [
60+
{
61+
"type": "VText",
62+
"range": [
63+
10,
64+
15
65+
],
66+
"loc": {
67+
"start": {
68+
"line": 1,
69+
"column": 10
70+
},
71+
"end": {
72+
"line": 2,
73+
"column": 4
74+
}
75+
},
76+
"value": "\n "
77+
},
78+
{
79+
"type": "VText",
80+
"range": [
81+
18,
82+
19
83+
],
84+
"loc": {
85+
"start": {
86+
"line": 2,
87+
"column": 7
88+
},
89+
"end": {
90+
"line": 3,
91+
"column": 0
92+
}
93+
},
94+
"value": "\n"
95+
}
96+
],
97+
"endTag": {
98+
"type": "VEndTag",
99+
"range": [
100+
19,
101+
30
102+
],
103+
"loc": {
104+
"start": {
105+
"line": 3,
106+
"column": 0
107+
},
108+
"end": {
109+
"line": 3,
110+
"column": 11
111+
}
112+
}
113+
},
114+
"variables": [],
115+
"tokens": [
116+
{
117+
"type": "HTMLTagOpen",
118+
"range": [
119+
0,
120+
9
121+
],
122+
"loc": {
123+
"start": {
124+
"line": 1,
125+
"column": 0
126+
},
127+
"end": {
128+
"line": 1,
129+
"column": 9
130+
}
131+
},
132+
"value": "template"
133+
},
134+
{
135+
"type": "HTMLTagClose",
136+
"range": [
137+
9,
138+
10
139+
],
140+
"loc": {
141+
"start": {
142+
"line": 1,
143+
"column": 9
144+
},
145+
"end": {
146+
"line": 1,
147+
"column": 10
148+
}
149+
},
150+
"value": ""
151+
},
152+
{
153+
"type": "HTMLWhitespace",
154+
"range": [
155+
10,
156+
15
157+
],
158+
"loc": {
159+
"start": {
160+
"line": 1,
161+
"column": 10
162+
},
163+
"end": {
164+
"line": 2,
165+
"column": 4
166+
}
167+
},
168+
"value": "\n "
169+
},
170+
{
171+
"type": "HTMLWhitespace",
172+
"range": [
173+
18,
174+
19
175+
],
176+
"loc": {
177+
"start": {
178+
"line": 2,
179+
"column": 7
180+
},
181+
"end": {
182+
"line": 3,
183+
"column": 0
184+
}
185+
},
186+
"value": "\n"
187+
},
188+
{
189+
"type": "HTMLEndTagOpen",
190+
"range": [
191+
19,
192+
29
193+
],
194+
"loc": {
195+
"start": {
196+
"line": 3,
197+
"column": 0
198+
},
199+
"end": {
200+
"line": 3,
201+
"column": 10
202+
}
203+
},
204+
"value": "template"
205+
},
206+
{
207+
"type": "HTMLTagClose",
208+
"range": [
209+
29,
210+
30
211+
],
212+
"loc": {
213+
"start": {
214+
"line": 3,
215+
"column": 10
216+
},
217+
"end": {
218+
"line": 3,
219+
"column": 11
220+
}
221+
},
222+
"value": ""
223+
},
224+
{
225+
"type": "HTMLWhitespace",
226+
"range": [
227+
30,
228+
31
229+
],
230+
"loc": {
231+
"start": {
232+
"line": 3,
233+
"column": 11
234+
},
235+
"end": {
236+
"line": 4,
237+
"column": 0
238+
}
239+
},
240+
"value": "\n"
241+
}
242+
],
243+
"comments": [],
244+
"errors": [
245+
{
246+
"message": "missing-end-tag-name (2:6)",
247+
"index": 17,
248+
"lineNumber": 2,
249+
"column": 6
250+
}
251+
]
252+
}
253+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<template>
2+
</>
3+
</template>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[
2+
"<template",
3+
">",
4+
"\n ",
5+
"\n",
6+
"</template",
7+
">",
8+
"\n"
9+
]

0 commit comments

Comments
 (0)