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}