[fix] create AST node of empty string for empty attribute values (#6539)

Co-authored-by: Conduitry <git@chor.date>
pull/6563/head
Yuichiro Yamashita 3 years ago committed by GitHub
parent 923088f5f8
commit fd8c5885c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -422,6 +422,15 @@ function get_directive_type(name: string): DirectiveType {
function read_attribute_value(parser: Parser) { function read_attribute_value(parser: Parser) {
const quote_mark = parser.eat("'") ? "'" : parser.eat('"') ? '"' : null; const quote_mark = parser.eat("'") ? "'" : parser.eat('"') ? '"' : null;
if (quote_mark && parser.eat(quote_mark)) {
return [{
start: parser.index - 1,
end: parser.index - 1,
type: 'Text',
raw: '',
data: ''
}];
}
const regex = ( const regex = (
quote_mark === "'" ? /'/ : quote_mark === "'" ? /'/ :

@ -0,0 +1,2 @@
<span attr=""></span>
<span attr=''></span>

@ -0,0 +1,64 @@
{
"html": {
"start": 0,
"end": 43,
"type": "Fragment",
"children": [
{
"start": 0,
"end": 21,
"type": "Element",
"name": "span",
"attributes": [
{
"start": 6,
"end": 13,
"type": "Attribute",
"name": "attr",
"value": [
{
"start": 12,
"end": 12,
"type": "Text",
"raw": "",
"data": ""
}
]
}
],
"children": []
},
{
"start": 21,
"end": 22,
"type": "Text",
"raw": "\n",
"data": "\n"
},
{
"start": 22,
"end": 43,
"type": "Element",
"name": "span",
"attributes": [
{
"start": 28,
"end": 35,
"type": "Attribute",
"name": "attr",
"value": [
{
"start": 34,
"end": 34,
"type": "Text",
"raw": "",
"data": ""
}
]
}
],
"children": []
}
]
}
}

@ -0,0 +1,2 @@
<span attr="foo"></span>
<span attr='bar'></span>

@ -0,0 +1,64 @@
{
"html": {
"start": 0,
"end": 49,
"type": "Fragment",
"children": [
{
"start": 0,
"end": 24,
"type": "Element",
"name": "span",
"attributes": [
{
"start": 6,
"end": 16,
"type": "Attribute",
"name": "attr",
"value": [
{
"start": 12,
"end": 15,
"type": "Text",
"raw": "foo",
"data": "foo"
}
]
}
],
"children": []
},
{
"start": 24,
"end": 25,
"type": "Text",
"raw": "\n",
"data": "\n"
},
{
"start": 25,
"end": 49,
"type": "Element",
"name": "span",
"attributes": [
{
"start": 31,
"end": 41,
"type": "Attribute",
"name": "attr",
"value": [
{
"start": 37,
"end": 40,
"type": "Text",
"raw": "bar",
"data": "bar"
}
]
}
],
"children": []
}
]
}
}
Loading…
Cancel
Save