Skip to content

Commit fd8c588

Browse files
[fix] create AST node of empty string for empty attribute values (#6539)
Co-authored-by: Conduitry <[email protected]>
1 parent 923088f commit fd8c588

File tree

5 files changed

+141
-0
lines changed

5 files changed

+141
-0
lines changed

src/compiler/parse/state/tag.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,15 @@ function get_directive_type(name: string): DirectiveType {
422422

423423
function read_attribute_value(parser: Parser) {
424424
const quote_mark = parser.eat("'") ? "'" : parser.eat('"') ? '"' : null;
425+
if (quote_mark && parser.eat(quote_mark)) {
426+
return [{
427+
start: parser.index - 1,
428+
end: parser.index - 1,
429+
type: 'Text',
430+
raw: '',
431+
data: ''
432+
}];
433+
}
425434

426435
const regex = (
427436
quote_mark === "'" ? /'/ :
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<span attr=""></span>
2+
<span attr=''></span>
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"html": {
3+
"start": 0,
4+
"end": 43,
5+
"type": "Fragment",
6+
"children": [
7+
{
8+
"start": 0,
9+
"end": 21,
10+
"type": "Element",
11+
"name": "span",
12+
"attributes": [
13+
{
14+
"start": 6,
15+
"end": 13,
16+
"type": "Attribute",
17+
"name": "attr",
18+
"value": [
19+
{
20+
"start": 12,
21+
"end": 12,
22+
"type": "Text",
23+
"raw": "",
24+
"data": ""
25+
}
26+
]
27+
}
28+
],
29+
"children": []
30+
},
31+
{
32+
"start": 21,
33+
"end": 22,
34+
"type": "Text",
35+
"raw": "\n",
36+
"data": "\n"
37+
},
38+
{
39+
"start": 22,
40+
"end": 43,
41+
"type": "Element",
42+
"name": "span",
43+
"attributes": [
44+
{
45+
"start": 28,
46+
"end": 35,
47+
"type": "Attribute",
48+
"name": "attr",
49+
"value": [
50+
{
51+
"start": 34,
52+
"end": 34,
53+
"type": "Text",
54+
"raw": "",
55+
"data": ""
56+
}
57+
]
58+
}
59+
],
60+
"children": []
61+
}
62+
]
63+
}
64+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<span attr="foo"></span>
2+
<span attr='bar'></span>
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"html": {
3+
"start": 0,
4+
"end": 49,
5+
"type": "Fragment",
6+
"children": [
7+
{
8+
"start": 0,
9+
"end": 24,
10+
"type": "Element",
11+
"name": "span",
12+
"attributes": [
13+
{
14+
"start": 6,
15+
"end": 16,
16+
"type": "Attribute",
17+
"name": "attr",
18+
"value": [
19+
{
20+
"start": 12,
21+
"end": 15,
22+
"type": "Text",
23+
"raw": "foo",
24+
"data": "foo"
25+
}
26+
]
27+
}
28+
],
29+
"children": []
30+
},
31+
{
32+
"start": 24,
33+
"end": 25,
34+
"type": "Text",
35+
"raw": "\n",
36+
"data": "\n"
37+
},
38+
{
39+
"start": 25,
40+
"end": 49,
41+
"type": "Element",
42+
"name": "span",
43+
"attributes": [
44+
{
45+
"start": 31,
46+
"end": 41,
47+
"type": "Attribute",
48+
"name": "attr",
49+
"value": [
50+
{
51+
"start": 37,
52+
"end": 40,
53+
"type": "Text",
54+
"raw": "bar",
55+
"data": "bar"
56+
}
57+
]
58+
}
59+
],
60+
"children": []
61+
}
62+
]
63+
}
64+
}

0 commit comments

Comments
 (0)