From ea74bfec554a9fba50d5d5ab803f96bd63fe83ba Mon Sep 17 00:00:00 2001 From: Mikhail Korepanov Date: Sun, 16 Jun 2019 13:37:28 +0300 Subject: [PATCH] Allow whitespace after = in attributes (#3026) --- src/compiler/parse/state/tag.ts | 1 + .../attribute-with-whitespace/input.svelte | 1 + .../attribute-with-whitespace/output.json | 39 +++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 test/parser/samples/attribute-with-whitespace/input.svelte create mode 100644 test/parser/samples/attribute-with-whitespace/output.json diff --git a/src/compiler/parse/state/tag.ts b/src/compiler/parse/state/tag.ts index 2fb82b4d2e..907233fdc7 100644 --- a/src/compiler/parse/state/tag.ts +++ b/src/compiler/parse/state/tag.ts @@ -385,6 +385,7 @@ function read_attribute(parser: Parser, unique_names: Set) { let value: any[] | true = true; if (parser.eat('=')) { + parser.allow_whitespace(); value = read_attribute_value(parser); end = parser.index; } else if (parser.match_regex(/["']/)) { diff --git a/test/parser/samples/attribute-with-whitespace/input.svelte b/test/parser/samples/attribute-with-whitespace/input.svelte new file mode 100644 index 0000000000..2743a89ed0 --- /dev/null +++ b/test/parser/samples/attribute-with-whitespace/input.svelte @@ -0,0 +1 @@ + diff --git a/test/parser/samples/attribute-with-whitespace/output.json b/test/parser/samples/attribute-with-whitespace/output.json new file mode 100644 index 0000000000..eab6054f2a --- /dev/null +++ b/test/parser/samples/attribute-with-whitespace/output.json @@ -0,0 +1,39 @@ +{ + "html": { + "start": 0, + "end": 38, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 38, + "type": "Element", + "name": "button", + "attributes": [ + { + "start": 8, + "end": 23, + "type": "EventHandler", + "name": "click", + "modifiers": [], + "expression": { + "type": "Identifier", + "start": 19, + "end": 22, + "name": "foo" + } + } + ], + "children": [ + { + "start": 24, + "end": 29, + "type": "Text", + "raw": "Click", + "data": "Click" + } + ] + } + ] + } +}