Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(5019): imported stores can be identified as reactive store subscr… #5022

Merged
merged 4 commits into from
Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>