-
-
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: fix issue where variable declarations with var or in switch blocks without brackets don't work #8442
Conversation
@ngtr6788 is attempting to deploy a commit to the Svelte Team on Vercel. A member of the Team first needs to authorize it. |
@Conduitry in #6794 you said you wanted to explicitly disallow usage of |
8f7b1dc
to
04d20a0
Compare
65d4b5c
to
879cb1c
Compare
For the uninitiated, this PR fixes the original bug, and then it goes on to fix another bug not mentioned in the issue, but as a consequence of my first attempted fix (see below), and thus, this post is a bit long, and I try to make sure I get my point across as clearly as possible, so my most sincere apologies. 😞 My first attempted fix is inspired by the implementation in the version prior to the regression in the issue (v3.40.3 IIRC), which assumes that all variable declarations are part of a list of statements, e.g.
and we can simply splice subscriptions and
and things break when variables declared with
Therefore, as a preventative measure, I added test cases where variable declarations with You may ask: wait, aren't stores supposed to be declared at the top-level scope in order to be auto-subscribable? Well, stores declared with
Let me know if there are anything you want to add, any opinions you may have, any suggestions, any questions, etc. Thank you, and hope you have a wonderful day! |
9f83acf
to
defb2f1
Compare
Thank you for the PR (and all your other PRs lately, they are great)! Sadly, we won't be merging this PR for Svelte 4, as with Svelte 5 we might want to drastically change the compiler output and we're not quite sure yet how hard it would be to also support Also a heads up that we're now starting the repository restructuring so if you want to contribute best wait until we're done with that (should be sometime next week) and then do contributions against the |
That's all right 🙂. However, I was wondering whether to either close this, or just reset this branch to just before I deal with autosubscribable |
I'd prefer to hold off completely from fixing this for now. As I said, we don't yet know how hard it would be to also support this in Svelte 5 so it's best not to fix something which becomes a burden to implement for the new iteration of the compiler. |
👍 Well, I guess I'll close this for now. Maybe when Svelte 5 comes around, I might get a go at this again. |
Fixes #6706 hopefully
(edit: Some rewording)
One of the comments mentioned in the ticket said that there is an invalid cast from
Node
toNode[]
, which is correct. One big reason why there isNot implemented undefined
is because we somehow have one variable declaration node wrapped in an array, so it tries to read the AST type of the array which doesn't exist. What I have done instead is that instead of replacing aNode
with aNode[]
, I put the props and inserts to the right of the current node, as siblings in an array and get rid of the current node if necessary, like what thethis.replace
did but flattened on the same array. If the variable declaration is not a node in an array (ie, a standalone statement), a 'dummy' variable is created for the sole purpose of calling inserts.Hopefully this does not break things too much. Any feedback, whether on the code, or this comment, is appreciated! 😊
Before submitting the PR, please make sure you do the following
feat:
,fix:
,chore:
, ordocs:
.Tests
npm test
and lint the project withnpm run lint