-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
vars not reported as reassigned/mutated when directly done in template #3793
Comments
It renders correctly with However, if <script>
let bar = 0;
</script>
<h1>{bar = 1}</h1>
<h2>{bar}</h2>
<button on:click={() => {bar }}>bar </button> |
The runtime error mentioned above is no longer happening as of 3.13.0, but there's another issue - the inline update in the template is only affecting the component's |
was revisiting this, and realise that @Rich-Harris wrote a comment on this svelte/src/compiler/compile/nodes/shared/Expression.ts Lines 224 to 226 in 3a37de3
we can mark it as {bar = 1} and regarding the impact on compiled output, i tried, it seems that the only difference is that, it will try to be reactive in the if (dirty & /*bar*/ 4 && t4_value !== (t4_value = (/*bar*/ ctx[2] = 1) "")) set_data_dev(t4, t4_value); yet, as you said, the changes made here may / may not make its way back to the |
Writing something like <script>
let y;
</script>
{#each [1, 2, 3, 4, 5] as x}
{(y = x * x, '')}
<div>
{y}
</div>
{/each} This is something we probably want to discourage, but at this point, depending on how many people are using it, it might not be something I feel comfortable making stop working. A few months ago, something else I had suggested in chat was to make assignments from the template not trigger reactivity. That would let something like I suppose on the whole, I'm a little worried about doing something like #4492 and calling it a bugfix, because it seems to start to make a decision about some of this stuff that would be a bit hard to walk back later. I feel like I want to have at least some answers for how all this stuff should work before proceeding, and I don't think I do currently. |
Closing as this behaves correctly in Svelte 5 |
The
vars
in the compiler output reportsfoo
as reassigned, but does not reportbar
as ever reassigned. I don't know what effects this might have on the compiled output, but for the ESLint plugin withprefer-const
enabled, it does result inbar
being erroneously turned into aconst
.The text was updated successfully, but these errors were encountered: