-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
fix: correctly migrate sequence expressions #13291
Conversation
🦋 Changeset detectedLatest commit: 213247d The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@@ -0,0 +1,14 @@ | |||
<script> | |||
let count = ($state((void 0, 0))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this output doesn't seem right
let count = ($state((void 0, 0))); | |
let count = $state((void 0, 0)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The migration simply append $state(
and )
to the left and right of the init
(it was already like this before).
This keeps the code very simple but if you have multiple parentheses spit out some weird code. Eg.
let count = (((0)));
converts to
let count = ((($state(0))));
Because parentheses are basically counted nowhere in the ast.
We can probably fix this with some more complex code to migrate state but I'm not sure is worth it just for the esthetic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So basically the point is: the last tells us where the expression is but the expression does not include the parentheses and we can't really be sure of how many parentheses, whitespace, code that the ast doesn't consider are there so the code will be probably much more complex (and even worse for handling the derived)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i fixed it 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh I need to remember that doing such things is fine...whenever I'm working with some AST i tend to avoid touching strings as much as possible but it's actually totally fine. Thanks and sorry 😉
Svelte 5 rewrite
Closes #13278
While working on this i noticed that the sequence expression was a problem for
$state
too. Also while the migration correctly migrate thisthe resulting code will actually error at runtime because a derived is accessing himself. This however is a bit harder to migrate effectively because either we should move it to state+effect (kinda 🤮) or we should have an external non stateful variable. Regardless i think we should do this in a separate PR.
Please note that the Svelte codebase is currently being rewritten for Svelte 5. Changes should target Svelte 5, which lives on the default branch (
main
).If your PR concerns Svelte 4 (including updates to svelte.dev.docs), please ensure the base branch is
svelte-4
and notmain
.Before submitting the PR, please make sure you do the following
feat:
,fix:
,chore:
, ordocs:
.Tests and linting
pnpm test
and lint the project withpnpm lint