Skip to content

Commit cfa3483

Browse files
committed
chore: allow test harness to support self closed void tags
1 parent 75c1daa commit cfa3483

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
1╭─ <div><img/></div>
2+
│ ││ │││ │ │ │ ╰─ closeTagEnd(div)
3+
│ ││ │││ │ │ ╰─ closeTagName "div"
4+
│ ││ │││ │ ╰─ closeTagStart "</"
5+
│ ││ │││ ╰─ openTagEnd:selfClosed "/>"
6+
│ ││ ││╰─ tagName "img"
7+
│ ││ │╰─ openTagStart
8+
│ ││ ╰─ openTagEnd
9+
│ │╰─ tagName "div"
10+
╰─ ╰─ openTagStart
11+
2╰─
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div><img/></div>

src/__tests__/main.test.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ for (const entry of fs.readdirSync(FIXTURES)) {
6868

6969
return parser.positionAt(offset);
7070
};
71-
const tagStack: Ranges.Template[] = [];
71+
const tagStack: { type: TagType; range: Ranges.Template }[] = [];
7272
const parser = createParser({
7373
onError(range) {
7474
addRange(`error(${ErrorCode[range.code]}:${range.message})`, range);
@@ -113,22 +113,24 @@ for (const entry of fs.readdirSync(FIXTURES)) {
113113
case "source":
114114
case "track":
115115
case "wbr":
116+
tagStack.push({ type: TagType.void, range });
116117
return TagType.void;
117118
case "script":
118119
case "style":
119120
case "textarea":
120121
case "html-comment":
121-
tagStack.push(range);
122+
tagStack.push({ type: TagType.text, range });
122123
return TagType.text;
123124
case "import":
124125
case "export":
125126
case "static":
126127
case "class":
128+
tagStack.push({ type: TagType.statement, range });
127129
return TagType.statement;
128130
}
129131
}
130132

131-
tagStack.push(range);
133+
tagStack.push({ type: TagType.html, range });
132134
return TagType.html;
133135
},
134136
onTagShorthandId(range) {
@@ -173,6 +175,13 @@ for (const entry of fs.readdirSync(FIXTURES)) {
173175
},
174176
onOpenTagEnd(range) {
175177
if (range.selfClosed) tagStack.pop();
178+
else
179+
switch (tagStack.at(-1)!.type) {
180+
case TagType.statement:
181+
case TagType.void:
182+
tagStack.pop();
183+
break;
184+
}
176185
addRange(`openTagEnd${range.selfClosed ? ":selfClosed" : ""}`, range);
177186
},
178187
onCloseTagStart(range) {
@@ -182,7 +191,7 @@ for (const entry of fs.readdirSync(FIXTURES)) {
182191
addRange("closeTagName", range);
183192
},
184193
onCloseTagEnd(range) {
185-
addRange(`closeTagEnd(${read(tagStack.pop()!)})`, range);
194+
addRange(`closeTagEnd(${read(tagStack.pop()!.range)})`, range);
186195
},
187196
onScriptlet(range) {
188197
addValueRange(range.block ? `scriptlet:block` : `scriptlet`, range);

0 commit comments

Comments
 (0)