diff --git a/.changeset/quiet-crabs-nail.md b/.changeset/quiet-crabs-nail.md new file mode 100644 index 0000000000..78ea5ba14e --- /dev/null +++ b/.changeset/quiet-crabs-nail.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: take into account member expressions when determining legacy reactive dependencies diff --git a/packages/svelte/src/compiler/phases/2-analyze/index.js b/packages/svelte/src/compiler/phases/2-analyze/index.js index dc98fb31e6..781ccdfc60 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/index.js +++ b/packages/svelte/src/compiler/phases/2-analyze/index.js @@ -500,7 +500,15 @@ const legacy_scope_tweaker = { node.body.type === 'ExpressionStatement' && node.body.expression.type === 'AssignmentExpression' ) { - for (const id of extract_identifiers(node.body.expression.left)) { + let ids = extract_identifiers(node.body.expression.left); + if (node.body.expression.left.type === 'MemberExpression') { + const id = object(node.body.expression.left); + if (id !== null) { + ids = [id]; + } + } + + for (const id of ids) { const binding = state.scope.get(id.name); if (binding?.kind === 'legacy_reactive') { // TODO does this include `let double; $: double = x * 2`? @@ -511,8 +519,15 @@ const legacy_scope_tweaker = { }, AssignmentExpression(node, { state, next }) { if (state.reactive_statement && node.operator === '=') { - for (const id of extract_identifiers(node.left)) { - state.reactive_statement.assignments.add(id); + if (node.left.type === 'MemberExpression') { + const id = object(node.left); + if (id !== null) { + state.reactive_statement.assignments.add(id); + } + } else { + for (const id of extract_identifiers(node.left)) { + state.reactive_statement.assignments.add(id); + } } } diff --git a/packages/svelte/tests/runtime-legacy/samples/reactive-value-assign-properties/_config.js b/packages/svelte/tests/runtime-legacy/samples/reactive-value-assign-properties/_config.js new file mode 100644 index 0000000000..9c66e2e6db --- /dev/null +++ b/packages/svelte/tests/runtime-legacy/samples/reactive-value-assign-properties/_config.js @@ -0,0 +1,5 @@ +import { test } from '../../test'; + +export default test({ + html: `1 1` +}); diff --git a/packages/svelte/tests/runtime-legacy/samples/reactive-value-assign-properties/main.svelte b/packages/svelte/tests/runtime-legacy/samples/reactive-value-assign-properties/main.svelte new file mode 100644 index 0000000000..6dabf61707 --- /dev/null +++ b/packages/svelte/tests/runtime-legacy/samples/reactive-value-assign-properties/main.svelte @@ -0,0 +1,12 @@ + + +{button.title} {button.label}