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

compiler: tag auto-subscribe stores as referenced in vars #4089

Merged
merged 3 commits into from Dec 11, 2019
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
5 changes: 4 additions & 1 deletion src/compiler/compile/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,10 @@ export default class Component {
const subscribable_name = name.slice(1);

const variable = this.var_lookup.get(subscribable_name);
if (variable) variable.subscribable = true;
if (variable) {
variable.referenced = true;
variable.subscribable = true;
}
} else {
this.used_names.add(name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function instance($$self, $$props, $$invalidate) {
let $foo;
const foo = writable(0);
component_subscribe($$self, foo, value => $$invalidate(0, $foo = value));
return [$foo];
return [$foo, foo];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it'll cause any incorrect behavior, but it would be nice if this weren't added. Presumably the bitmask changes co-opted referenced to mean 'needed in the context array', which is also what caused this bug in the first place when that started being false for stores that are only accessed via autosubscription in the template. That may not be worth it to fix at this point though.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's something interesting though...
If you add another normal variable that can't be hoisted, it gets put in the context list anyway.
This occurs in both current master as well as my branch.
https://svelte.dev/repl/e61b08c7da904ba7af9d005ebac0d2d2?version=3.16.3

So, yeah, it probably isn't a big enough issue to worry about.

}

class Component extends SvelteComponent {
Expand Down
2 changes: 1 addition & 1 deletion test/vars/samples/store-referenced/_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default {
module: false,
mutated: false,
reassigned: false,
referenced: false,
referenced: true,
referenced_from_script: false,
writable: true
},
Expand Down