sveltejs / svelte

Cybernetically enhanced web apps
https://svelte.dev
MIT License
78.19k stars 4.09k forks source link

Autosubscribed stores no longer listed as referenced in `vars` #4081

Closed Conduitry closed 4 years ago

Conduitry commented 4 years ago

Describe the bug Since #3945, autosubscribing to a store within the template no longer causes the store to be marked as referenced: true in the vars response from the compiler.

Logs n/a

To Reproduce

<script>
    let store;
</script>
{$store}

Compile this, and look at the vars value in the response. store has referenced: false.

Expected behavior store should have referenced: true.

Stacktraces n/a

Information about your Svelte project: Svelte 3.16.0, 3.16.1

Severity Moderate. Causing new incorrect warnings in the ESLint plugin - https://github.com/sveltejs/eslint-plugin-svelte3/issues/49

Additional context Unlike the above, this seems to be working correctly:

<script>
    let store;
    $store;
</script>
ghost commented 4 years ago

Another interesting thing is that $store has referenced: true in the first case but not the second. Looking at the debugger, the first case only calls add_reference on the $store variable name.

There's code in that method here to check for an auto-subscribe so we should probably just also tag it with referenced = true.

PR on the way... just running CI tests now.

ghost commented 4 years ago

Bah... marking the store as referenced creates a codegen test failure.... image

ghost commented 4 years ago

Actually, I think the change to the expected output is OK since it used to be there before @Rich-Harris made his changes (though in a different order).

anlexN commented 4 years ago

@Conduitry why do you have to use this syntax?

Conduitry commented 4 years ago

What syntax? I'm not sure what you're asking.

anlexN commented 4 years ago
let store;
$store;