You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An error that occurs with (as far as I can tell) lambda functions inside curly braces in the markup, that reference an {@const} named func. This causes a conflict between generating a function for the lambda (internally called func), and the variable func. It then (I assume) incorrectly thinks the lambda function is the same as the @const. It does not apply to regular variables named func, only {@const} variables.
Reproduction
I'll save you the painful process of cutting everything down: here's the simplest scenario I could find that showcases the weird error.
{#iftrue}
{@constfunc= [12, 13, 14]}
{(() =>JSON.stringify(func))()} <!-- Error: ctx[0] is not a function -->
{/if}
It's specifically {@const func = _} that causes the error, every other identifier i tried worked AOK. Which was very fun to figure out. I think this is because when I look at the generated javascript:
ctx[0] shows up twice, once for the "const variable", and once for the function being referenced. So yes, ctx[0] is not a function its a variable. That makes sense I guess.
So to recap:
You need an @const variable named func
You need to reference it inside a lambda in the markup
The generated code will confuse the lambda and the @const variable, replacing the lambda with a call to the @const.
Things finally make sense you do not know how weird this error was when I first discovered it.
This error probably shouldn't be terribly high priority but it also should be pretty easy to fix I think.
Logs
No response
System Info
As far as I can tell it's completely platform independent, tested it on my machine and the online REPL, buuuut... System: OS: Linux 6.3 Fedora Linux 37 (KDE Plasma) CPU: (16) x64 12th Gen Intel(R) Core(TM) i7-1260P Memory: 4.90 GB / 15.32 GB Container: Yes Shell: 3.6.1 - /usr/bin/fish Binaries: Node: 18.16.0 - /usr/bin/node npm: 9.5.1 - /usr/local/bin/npm Browsers: Chromium: 114.0.5735.106 Firefox: 114.0 npmPackages: svelte: ^3.55.1 => 3.59.1
### Severity
annoyance
The text was updated successfully, but these errors were encountered:
aspiringLich
changed the title
ctx[_] is undefined error with @const's named func referenced inside lambda expressionsctx[_] is not a function error with @const's named func referenced inside lambda expressions
Jun 18, 2023
Describe the bug
An error that occurs with (as far as I can tell) lambda functions inside curly braces in the markup, that reference an
{@const}
namedfunc
. This causes a conflict between generating a function for the lambda (internally calledfunc
), and the variablefunc
. It then (I assume) incorrectly thinks the lambda function is the same as the@const
. It does not apply to regular variables namedfunc
, only{@const}
variables.Reproduction
I'll save you the painful process of cutting everything down: here's the simplest scenario I could find that showcases the weird error.
It's specifically
{@const func = _}
that causes the error, every other identifier i tried worked AOK. Which was very fun to figure out. I think this is because when I look at the generated javascript:ctx[0]
shows up twice, once for the "const variable", and once for the function being referenced. So yes,ctx[0]
is not a function its a variable. That makes sense I guess.So to recap:
@const
variable namedfunc
@const
variable, replacing the lambda with a call to the@const
.Things finally make sense you do not know how weird this error was when I first discovered it.
This error probably shouldn't be terribly high priority but it also should be pretty easy to fix I think.
Logs
No response
System Info
The text was updated successfully, but these errors were encountered: