mirror of
https://github.com/sveltejs/svelte.git
synced 2024-12-01 17:30:59 +01:00
fix hoisting of imported, mutated stores (#5022)
This commit is contained in:
parent
92578706b0
commit
0e2bc352df
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
7
test/runtime/samples/store-imports-hoisted/_config.js
Normal file
7
test/runtime/samples/store-imports-hoisted/_config.js
Normal file
@ -0,0 +1,7 @@
|
||||
export default {
|
||||
compileOptions: { dev: true }, // tests `@validate_store` code generation
|
||||
|
||||
html: `
|
||||
<p>42</p>
|
||||
`
|
||||
};
|
3
test/runtime/samples/store-imports-hoisted/foo.js
Normal file
3
test/runtime/samples/store-imports-hoisted/foo.js
Normal file
@ -0,0 +1,3 @@
|
||||
import { writable } from '../../../../store';
|
||||
|
||||
export default writable(42);
|
7
test/runtime/samples/store-imports-hoisted/main.svelte
Normal file
7
test/runtime/samples/store-imports-hoisted/main.svelte
Normal file
@ -0,0 +1,7 @@
|
||||
<script>
|
||||
import foo from './foo.js';
|
||||
foo.bar = 'baz';
|
||||
const answer = $foo;
|
||||
</script>
|
||||
|
||||
<p>{answer}</p>
|
Loading…
Reference in New Issue
Block a user