From 8d7d0ff7dd7b248ca6d9b6b4cac098430c6e6ffa Mon Sep 17 00:00:00 2001 From: Conduitry Date: Sat, 19 Oct 2019 08:51:59 -0400 Subject: [PATCH] fix `bind:this` binding to a store (#3591) --- CHANGELOG.md | 1 + src/compiler/compile/Component.ts | 2 +- test/runtime/samples/binding-this-store/_config.js | 4 ++++ test/runtime/samples/binding-this-store/main.svelte | 6 ++++++ 4 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 test/runtime/samples/binding-this-store/_config.js create mode 100644 test/runtime/samples/binding-this-store/main.svelte diff --git a/CHANGELOG.md b/CHANGELOG.md index e357e58acdc8..c2611da704bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * Allow exiting a reactive block early with `break $` ([#2828](https://github.com/sveltejs/svelte/issues/2828)) * Check attributes have changed before setting them to avoid image flicker ([#3579](https://github.com/sveltejs/svelte/pull/3579)) * Fix generating malformed code for `{@debug}` tags with no dependencies ([#3588](https://github.com/sveltejs/svelte/issue/3588)) +* Fix `bind:this` binding to a store ([#3591](https://github.com/sveltejs/svelte/issue/3591)) * Use safer `HTMLElement` check before extending class ([#3608](https://github.com/sveltejs/svelte/issue/3608)) * Add `location` as a known global ([#3619](https://github.com/sveltejs/svelte/pull/3619)) * Support `{#await}` with `{:catch}` but no `{:then}` ([#3623](https://github.com/sveltejs/svelte/issues/3623)) diff --git a/src/compiler/compile/Component.ts b/src/compiler/compile/Component.ts index 20c0d09e2472..8d1384e7a1d7 100644 --- a/src/compiler/compile/Component.ts +++ b/src/compiler/compile/Component.ts @@ -764,7 +764,7 @@ export default class Component { } if (name[0] === '$' && name[1] !== '$') { - return x`${name.slice(1)}.set(${name})`; + return x`${name.slice(1)}.set(${value || name})`; } if ( diff --git a/test/runtime/samples/binding-this-store/_config.js b/test/runtime/samples/binding-this-store/_config.js new file mode 100644 index 000000000000..f818c2e31e4b --- /dev/null +++ b/test/runtime/samples/binding-this-store/_config.js @@ -0,0 +1,4 @@ +export default { + skip_if_ssr: true, + html: `
object
` +}; diff --git a/test/runtime/samples/binding-this-store/main.svelte b/test/runtime/samples/binding-this-store/main.svelte new file mode 100644 index 000000000000..7958dfa2d817 --- /dev/null +++ b/test/runtime/samples/binding-this-store/main.svelte @@ -0,0 +1,6 @@ + + +
{typeof $foo}