Skip to content

Commit

Permalink
fix hoisting of imported, mutated stores (#5022)
Browse files Browse the repository at this point in the history
  • Loading branch information
skippednote authored Jun 23, 2020
1 parent 9257870 commit 0e2bc35
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/compiler/compile/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions test/runtime/samples/store-imports-hoisted/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default {
compileOptions: { dev: true }, // tests `@validate_store` code generation

html: `
<p>42</p>
`
};
3 changes: 3 additions & 0 deletions test/runtime/samples/store-imports-hoisted/foo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { writable } from '../../../../store';

export default writable(42);
7 changes: 7 additions & 0 deletions test/runtime/samples/store-imports-hoisted/main.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script>
import foo from './foo.js';
foo.bar = 'baz';
const answer = $foo;
</script>

<p>{answer}</p>

0 comments on commit 0e2bc35

Please sign in to comment.