From 5035a2995f234d5c807eaf59c1bd999055b0affe Mon Sep 17 00:00:00 2001 From: Bassam Ismail Date: Wed, 24 Jun 2020 01:47:42 +0530 Subject: [PATCH] fix hoisting of imported, mutated stores (#5022) --- src/compiler/compile/Component.ts | 4 +++- test/runtime/samples/store-imports-hoisted/_config.js | 7 +++++++ test/runtime/samples/store-imports-hoisted/foo.js | 3 +++ test/runtime/samples/store-imports-hoisted/main.svelte | 7 +++++++ 4 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 test/runtime/samples/store-imports-hoisted/_config.js create mode 100644 test/runtime/samples/store-imports-hoisted/foo.js create mode 100644 test/runtime/samples/store-imports-hoisted/main.svelte diff --git a/src/compiler/compile/Component.ts b/src/compiler/compile/Component.ts index a5a31c8070..5f06de8e21 100644 --- a/src/compiler/compile/Component.ts +++ b/src/compiler/compile/Component.ts @@ -1152,7 +1152,9 @@ export default class Component { for (const specifier of specifiers) { const variable = var_lookup.get(specifier.local.name); - if (!variable.mutated) variable.hoistable = true; + if (!variable.mutated || variable.subscribable) { + variable.hoistable = true; + } } } } diff --git a/test/runtime/samples/store-imports-hoisted/_config.js b/test/runtime/samples/store-imports-hoisted/_config.js new file mode 100644 index 0000000000..251866e5ba --- /dev/null +++ b/test/runtime/samples/store-imports-hoisted/_config.js @@ -0,0 +1,7 @@ +export default { + compileOptions: { dev: true }, // tests `@validate_store` code generation + + html: ` +

42

+ ` +}; \ No newline at end of file diff --git a/test/runtime/samples/store-imports-hoisted/foo.js b/test/runtime/samples/store-imports-hoisted/foo.js new file mode 100644 index 0000000000..5d15213c3a --- /dev/null +++ b/test/runtime/samples/store-imports-hoisted/foo.js @@ -0,0 +1,3 @@ +import { writable } from '../../../../store'; + +export default writable(42); \ No newline at end of file diff --git a/test/runtime/samples/store-imports-hoisted/main.svelte b/test/runtime/samples/store-imports-hoisted/main.svelte new file mode 100644 index 0000000000..223572962e --- /dev/null +++ b/test/runtime/samples/store-imports-hoisted/main.svelte @@ -0,0 +1,7 @@ + + +

{answer}