diff --git a/.changeset/fair-crabs-check.md b/.changeset/fair-crabs-check.md new file mode 100644 index 0000000000..fa51ebf2d5 --- /dev/null +++ b/.changeset/fair-crabs-check.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: prevent false positives when detecting runes mode diff --git a/packages/svelte/src/compiler/phases/2-analyze/index.js b/packages/svelte/src/compiler/phases/2-analyze/index.js index c0c8906acc..2920a92610 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/index.js +++ b/packages/svelte/src/compiler/phases/2-analyze/index.js @@ -284,7 +284,11 @@ export function analyze_component(root, options) { if (declaration === null && /[a-z]/.test(store_name[0])) { error(references[0].node, 'illegal-global', name); } else if (declaration !== null && Runes.includes(name)) { - warn(warnings, declaration.node, [], 'store-with-rune-name', store_name); + for (const { node, path } of references) { + if (path.at(-1)?.type === 'CallExpression') { + warn(warnings, node, [], 'store-with-rune-name', store_name); + } + } } } @@ -302,6 +306,8 @@ export function analyze_component(root, options) { const binding = instance.scope.declare(b.id(name), 'store_sub', 'synthetic'); binding.references = references; + instance.scope.references.set(name, references); + module.scope.references.delete(name); } } diff --git a/packages/svelte/tests/validator/samples/store-looking-like-rune/input.svelte b/packages/svelte/tests/validator/samples/store-looking-like-rune/input.svelte new file mode 100644 index 0000000000..d5d0f76942 --- /dev/null +++ b/packages/svelte/tests/validator/samples/store-looking-like-rune/input.svelte @@ -0,0 +1,8 @@ + + +