From 741444d07e1e9bb51a1ca0b80daf6177876a9a6e Mon Sep 17 00:00:00 2001 From: Conduitry Date: Sat, 4 Jan 2020 22:50:40 -0500 Subject: [PATCH] fix when LHS of a reactive assignment is a member expression (#4212) --- CHANGELOG.md | 1 + src/compiler/compile/Component.ts | 1 + .../reactive-values-no-implicit-member-expression/_config.js | 5 +++++ .../main.svelte | 3 +++ 4 files changed, 10 insertions(+) create mode 100644 test/runtime/samples/reactive-values-no-implicit-member-expression/_config.js create mode 100644 test/runtime/samples/reactive-values-no-implicit-member-expression/main.svelte diff --git a/CHANGELOG.md b/CHANGELOG.md index 4cf25421f6..054dd17f64 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * Prevent text input cursor jumping in Safari with one-way binding ([#3449](https://github.com/sveltejs/svelte/issues/3449)) * Expose compiler version in dev events ([#4047](https://github.com/sveltejs/svelte/issues/4047)) +* Do not automatically declare variables in reactive declarations when assigning to a member expression ([#4212](https://github.com/sveltejs/svelte/issues/4212)) ## 3.16.7 diff --git a/src/compiler/compile/Component.ts b/src/compiler/compile/Component.ts index 1a5d39ab28..baa327f4a6 100644 --- a/src/compiler/compile/Component.ts +++ b/src/compiler/compile/Component.ts @@ -603,6 +603,7 @@ export default class Component { const { expression } = node.body; if (expression.type !== 'AssignmentExpression') return; + if (expression.left.type === 'MemberExpression') return; extract_names(expression.left).forEach(name => { if (!this.var_lookup.has(name) && name[0] !== '$') { diff --git a/test/runtime/samples/reactive-values-no-implicit-member-expression/_config.js b/test/runtime/samples/reactive-values-no-implicit-member-expression/_config.js new file mode 100644 index 0000000000..05a8159589 --- /dev/null +++ b/test/runtime/samples/reactive-values-no-implicit-member-expression/_config.js @@ -0,0 +1,5 @@ +export default { + test({ assert, window }) { + assert.equal(window.document.title, 'foo'); + } +}; diff --git a/test/runtime/samples/reactive-values-no-implicit-member-expression/main.svelte b/test/runtime/samples/reactive-values-no-implicit-member-expression/main.svelte new file mode 100644 index 0000000000..a631d4d9f8 --- /dev/null +++ b/test/runtime/samples/reactive-values-no-implicit-member-expression/main.svelte @@ -0,0 +1,3 @@ +