diff --git a/src/compiler/parse/state/tag.ts b/src/compiler/parse/state/tag.ts index 7999c34f84..28821edb01 100644 --- a/src/compiler/parse/state/tag.ts +++ b/src/compiler/parse/state/tag.ts @@ -422,6 +422,15 @@ function get_directive_type(name: string): DirectiveType { function read_attribute_value(parser: Parser) { 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 = ( quote_mark === "'" ? /'/ : diff --git a/test/parser/samples/element-with-attribute-empty-string/input.svelte b/test/parser/samples/element-with-attribute-empty-string/input.svelte new file mode 100644 index 0000000000..685c0995d5 --- /dev/null +++ b/test/parser/samples/element-with-attribute-empty-string/input.svelte @@ -0,0 +1,2 @@ + + diff --git a/test/parser/samples/element-with-attribute-empty-string/output.json b/test/parser/samples/element-with-attribute-empty-string/output.json new file mode 100644 index 0000000000..8e8768eb62 --- /dev/null +++ b/test/parser/samples/element-with-attribute-empty-string/output.json @@ -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": [] + } + ] + } +} diff --git a/test/parser/samples/element-with-attribute/input.svelte b/test/parser/samples/element-with-attribute/input.svelte new file mode 100644 index 0000000000..f564fd0541 --- /dev/null +++ b/test/parser/samples/element-with-attribute/input.svelte @@ -0,0 +1,2 @@ + + diff --git a/test/parser/samples/element-with-attribute/output.json b/test/parser/samples/element-with-attribute/output.json new file mode 100644 index 0000000000..a80344101e --- /dev/null +++ b/test/parser/samples/element-with-attribute/output.json @@ -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": [] + } + ] + } +}