I'm running into this issue. Is this a bug?
Is using let for reactive variables not allowed?
https://stackoverflow.com/questions/56318460/cannot-access-variable-name-before-initialization
The issue I ran into was different from the stackoverflow issue.
I had a function use the same variable name as the reactive variable:
https://svelte.dev/repl/8e15e373f14a457792b3cb0fdf2be498?version=3.6.7
I'm afraid that's regular javascript behavior.
Variables in an inner scope shadow/override variables with the same name in outer scopes. There's no way to reference the shadowed outer scope variable in those cases, so name really refers to the function's variable.
On top of that, with let and const you're subject to the temporal dead zone, and that's why you get ReferenceErrors: you're trying to use the name variable in its own initialization, ie. before the variable is initialized.
I don't see anything actionable from Svelte's side on this one, unless I misunderstood your issue!
I agree. There's nothing for Svelte to do if this is normal Javascript behavior.
just linking a possible terser bug for future people googling this problem https://github.com/sveltejs/template/issues/81 - fixed my issue, could fix yours
Most helpful comment
I'm afraid that's regular javascript behavior.
Variables in an inner scope shadow/override variables with the same name in outer scopes. There's no way to reference the shadowed outer scope variable in those cases, so
namereally refers to the function's variable.On top of that, with
letandconstyou're subject to the temporal dead zone, and that's why you getReferenceErrors: you're trying to use thenamevariable in its own initialization, ie. before the variable is initialized.I don't see anything actionable from Svelte's side on this one, unless I misunderstood your issue!