diff --git a/.changeset/polite-dolphins-care.md b/.changeset/polite-dolphins-care.md new file mode 100644 index 0000000000..409b7e66d6 --- /dev/null +++ b/.changeset/polite-dolphins-care.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: improve non state referenced warning diff --git a/packages/svelte/src/compiler/phases/2-analyze/index.js b/packages/svelte/src/compiler/phases/2-analyze/index.js index be66f41d27..8d7d9a5906 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/index.js +++ b/packages/svelte/src/compiler/phases/2-analyze/index.js @@ -409,10 +409,10 @@ export function analyze_component(root, options) { analysis.reactive_statements = order_reactive_statements(analysis.reactive_statements); } - // warn on any nonstate declarations that are a) mutated and b) referenced in the template + // warn on any nonstate declarations that are a) reassigned and mutated and b) referenced in the template for (const scope of [module.scope, instance.scope]) { outer: for (const [name, binding] of scope.declarations) { - if (binding.kind === 'normal' && binding.mutated) { + if (binding.kind === 'normal' && binding.reassigned && binding.mutated) { for (const { path } of binding.references) { if (path[0].type !== 'Fragment') continue; for (let i = 1; i < path.length; i += 1) { diff --git a/packages/svelte/tests/validator/samples/runes-referenced-nonstate-2/_config.js b/packages/svelte/tests/validator/samples/runes-referenced-nonstate-2/_config.js new file mode 100644 index 0000000000..f47bee71df --- /dev/null +++ b/packages/svelte/tests/validator/samples/runes-referenced-nonstate-2/_config.js @@ -0,0 +1,3 @@ +import { test } from '../../test'; + +export default test({}); diff --git a/packages/svelte/tests/validator/samples/runes-referenced-nonstate-2/input.svelte b/packages/svelte/tests/validator/samples/runes-referenced-nonstate-2/input.svelte new file mode 100644 index 0000000000..42f1b675de --- /dev/null +++ b/packages/svelte/tests/validator/samples/runes-referenced-nonstate-2/input.svelte @@ -0,0 +1,6 @@ + + + +
{JSON.stringify(a)} + {a.b}
diff --git a/packages/svelte/tests/validator/samples/runes-referenced-nonstate-2/warnings.json b/packages/svelte/tests/validator/samples/runes-referenced-nonstate-2/warnings.json new file mode 100644 index 0000000000..fe51488c70 --- /dev/null +++ b/packages/svelte/tests/validator/samples/runes-referenced-nonstate-2/warnings.json @@ -0,0 +1 @@ +[]