From a0be1aaf6d98fcf8767a72b9f850581026d817ac Mon Sep 17 00:00:00 2001 From: Jeremiasz Major Date: Mon, 29 Apr 2024 16:49:38 +0200 Subject: [PATCH] require whitespace after `@const` tag --- .changeset/six-boats-shave.md | 5 +++++ packages/svelte/src/compiler/phases/1-parse/state/tag.js | 2 +- .../samples/const-tag-whitespace/_config.js | 9 +++++++++ .../samples/const-tag-whitespace/main.svelte | 3 +++ 4 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 .changeset/six-boats-shave.md create mode 100644 packages/svelte/tests/compiler-errors/samples/const-tag-whitespace/_config.js create mode 100644 packages/svelte/tests/compiler-errors/samples/const-tag-whitespace/main.svelte diff --git a/.changeset/six-boats-shave.md b/.changeset/six-boats-shave.md new file mode 100644 index 000000000000..6dc8c9628f97 --- /dev/null +++ b/.changeset/six-boats-shave.md @@ -0,0 +1,5 @@ +--- +"svelte": patch +--- + +fix: require whitespace after `@const` tag diff --git a/packages/svelte/src/compiler/phases/1-parse/state/tag.js b/packages/svelte/src/compiler/phases/1-parse/state/tag.js index bf6adccccfcf..a41c5d09a012 100644 --- a/packages/svelte/src/compiler/phases/1-parse/state/tag.js +++ b/packages/svelte/src/compiler/phases/1-parse/state/tag.js @@ -543,7 +543,7 @@ function special(parser) { } if (parser.eat('const')) { - parser.allow_whitespace(); + parser.require_whitespace(); const id = read_pattern(parser); parser.allow_whitespace(); diff --git a/packages/svelte/tests/compiler-errors/samples/const-tag-whitespace/_config.js b/packages/svelte/tests/compiler-errors/samples/const-tag-whitespace/_config.js new file mode 100644 index 000000000000..45c6e5da4d45 --- /dev/null +++ b/packages/svelte/tests/compiler-errors/samples/const-tag-whitespace/_config.js @@ -0,0 +1,9 @@ +import { test } from '../../test'; + +export default test({ + error: { + code: 'expected_whitespace', + message: 'Expected whitespace', + position: [19, 19] + } +}); diff --git a/packages/svelte/tests/compiler-errors/samples/const-tag-whitespace/main.svelte b/packages/svelte/tests/compiler-errors/samples/const-tag-whitespace/main.svelte new file mode 100644 index 000000000000..9794dd92276f --- /dev/null +++ b/packages/svelte/tests/compiler-errors/samples/const-tag-whitespace/main.svelte @@ -0,0 +1,3 @@ +{#if true} + {@constfoo = 'bar'} +{/if}