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

Svelte 5: $state declared with var in *.svelte.js broken #12900

Closed
Black1358 opened this issue Aug 18, 2024 · 2 comments · Fixed by #12949
Closed

Svelte 5: $state declared with var in *.svelte.js broken #12900

Black1358 opened this issue Aug 18, 2024 · 2 comments · Fixed by #12949
Labels
Milestone

Comments

@Black1358
Copy link
Contributor

Describe the bug

I like to declare states using "var", because they become more noticeable when reading the code. But using this syntax in .svelte.ts files, sometimes the states are "true" when I'm sure they're false. When I output them using console.log, I was very surprised - instead of false, I got the object of the state itself. It definitely wasn't meant to be that way.

Reproduction

https://svelte-5-preview.vercel.app/#H4sIAAAAAAAACmVSy07EMAz8FSvi0IpVF67d7Up8ACeOFKHSdSFLmlSJuwJV-Xfy6mOFeqhsz9iecSbWcYGGla8Tk02PrGRPw8B2jH4HH5grCkIXGzXq1meOptV8oFMta-L9oDTBBEo-q1GShU6rHupEq5kH3QAJDb2Q0ggLttiHRBE5xcXU7DDzBBK0vjNUcGeoIcwecl91tW6ULXElgctWY4-SshymwKTIua_gMbSykZG2zByuOq1QaZTAQqjPbNmu-ETXLY_kvJbH_apaHj9Gcr2c6Fbw9rualgVscCVkTQlT2MJ6dmScnI-9OvOO45mVpEe0u8X2rQmr_xez9X6RbJyhAgMl45ITb0TSfm00vF8bMeJq2YxIxmmkUctZv1dqZDOYL-Vd7hphcPHRXa6DpZxDosa-xZzP4sBol_8SLKZT1u7i3_h5nr4ZsiwcCjcE66JwPvxJT2ijHexhU_KXpM0Lq25sisIc_v8R3uwf-J-cIQcDAAA=

See dev-console

Logs

Object {
  f: 0,
  v: false,
  reactions: null,
  equals: equals(value),
  version: 0,
}

System Info

Svelte version 5.0.0-next.225

Severity

annoyance

@Conduitry
Copy link
Member

Adjacent: #12807. I don't know whether they'd be solved as part of the same work.

@dummdidumm
Copy link
Member

The $.get calls are missing the generated code

@dummdidumm dummdidumm added the bug label Aug 21, 2024
dummdidumm added a commit that referenced this issue Aug 21, 2024
- fixes #12807: state declared with var is now retrieved using a new `safe_get` function, which works like `get` but checks for undefined
- fixes #12900: ensure we're not creating another new scope for block statements of function declarations, which resulted in var declarations getting "swallowed" (because they were hoisted to the function declaration scope and never seen by our logic)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants