From 8e3128b12e9005d194d8ccb643ffa4d0ab675119 Mon Sep 17 00:00:00 2001 From: Simon Holthausen Date: Mon, 20 Nov 2023 10:01:03 +0100 Subject: [PATCH] fix: adjust static attribute regex a `+` was missing Fixes https://github.com/sveltejs/vite-plugin-svelte/issues/804 --- .changeset/khaki-turkeys-hunt.md | 5 + .../svelte/src/compiler/parse/state/tag.js | 2 +- .../input.svelte | 7 + .../output.json | 178 ++++++++++++++++++ 4 files changed, 191 insertions(+), 1 deletion(-) create mode 100644 .changeset/khaki-turkeys-hunt.md create mode 100644 packages/svelte/test/parser/samples/script-context-module-unquoted/input.svelte create mode 100644 packages/svelte/test/parser/samples/script-context-module-unquoted/output.json diff --git a/.changeset/khaki-turkeys-hunt.md b/.changeset/khaki-turkeys-hunt.md new file mode 100644 index 0000000000..76a45519bf --- /dev/null +++ b/.changeset/khaki-turkeys-hunt.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: adjust static attribute regex diff --git a/packages/svelte/src/compiler/parse/state/tag.js b/packages/svelte/src/compiler/parse/state/tag.js index 37281c5156..e04d9abc73 100644 --- a/packages/svelte/src/compiler/parse/state/tag.js +++ b/packages/svelte/src/compiler/parse/state/tag.js @@ -437,7 +437,7 @@ function get_directive_type(name) { if (name === 'in' || name === 'out' || name === 'transition') return 'Transition'; } -const regex_attribute_value = /^(?:"([^"]*)"|'([^'])*'|([^>\s]))/; +const regex_attribute_value = /^(?:"([^"]*)"|'([^'])*'|([^>\s]+))/; /** * @param {import('../index.js').Parser} parser diff --git a/packages/svelte/test/parser/samples/script-context-module-unquoted/input.svelte b/packages/svelte/test/parser/samples/script-context-module-unquoted/input.svelte new file mode 100644 index 0000000000..b88dae2a65 --- /dev/null +++ b/packages/svelte/test/parser/samples/script-context-module-unquoted/input.svelte @@ -0,0 +1,7 @@ + + + diff --git a/packages/svelte/test/parser/samples/script-context-module-unquoted/output.json b/packages/svelte/test/parser/samples/script-context-module-unquoted/output.json new file mode 100644 index 0000000000..072e101782 --- /dev/null +++ b/packages/svelte/test/parser/samples/script-context-module-unquoted/output.json @@ -0,0 +1,178 @@ +{ + "html": { + "start": 62, + "end": 60, + "type": "Fragment", + "children": [ + { + "start": 60, + "end": 62, + "type": "Text", + "raw": "\n\n", + "data": "\n\n" + } + ] + }, + "instance": { + "type": "Script", + "start": 62, + "end": 86, + "context": "default", + "content": { + "type": "Program", + "start": 70, + "end": 77, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 72, + "end": 76, + "loc": { + "start": { + "line": 6, + "column": 1 + }, + "end": { + "line": 6, + "column": 5 + } + }, + "expression": { + "type": "Identifier", + "start": 72, + "end": 75, + "loc": { + "start": { + "line": 6, + "column": 1 + }, + "end": { + "line": 6, + "column": 4 + } + }, + "name": "foo" + } + } + ], + "sourceType": "module" + } + }, + "module": { + "type": "Script", + "start": 0, + "end": 60, + "context": "module", + "content": { + "type": "Program", + "start": 23, + "end": 51, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 0 + } + }, + "body": [ + { + "type": "ExportNamedDeclaration", + "start": 25, + "end": 50, + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 26 + } + }, + "declaration": { + "type": "VariableDeclaration", + "start": 32, + "end": 50, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 26 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 38, + "end": 49, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "id": { + "type": "Identifier", + "start": 38, + "end": 41, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "name": "foo" + }, + "init": { + "type": "Literal", + "start": 44, + "end": 49, + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "value": "bar", + "raw": "'bar'" + } + } + ], + "kind": "const" + }, + "specifiers": [], + "source": null + } + ], + "sourceType": "module" + } + } +}