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

fix: Fixes destructuring signal with await bug #9962

Merged
merged 26 commits into from
Jan 9, 2024

Conversation

ngtr6788
Copy link
Contributor

@ngtr6788 ngtr6788 commented Dec 19, 2023

Fixes #9686 and #9312 and #9982. Because I can't find a place to determine if an expression is asynchronous, and I can't find a builder for async/await, I ended up building it. Hopefully it's good enough, but comments and feedback and advice is most certainly welcome, because I could be wrong :)

Svelte 5 rewrite

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 not main.

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests and linting

  • Run the tests with pnpm test and lint the project with pnpm lint

Copy link

changeset-bot bot commented Dec 19, 2023

🦋 Changeset detected

Latest commit: 3ab71cf

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Patch

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

Copy link

vercel bot commented Dec 19, 2023

@ngtr6788 is attempting to deploy a commit to the Svelte Team on Vercel.

A member of the Team first needs to authorize it.

@ngtr6788 ngtr6788 marked this pull request as ready for review December 20, 2023 02:37
@ngtr6788 ngtr6788 marked this pull request as draft December 21, 2023 00:46
@ngtr6788 ngtr6788 marked this pull request as ready for review December 22, 2023 04:20
Copy link
Member

@dummdidumm dummdidumm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you briefly explain why there are multiple test cases for this? Can't they be handled in one test case?

Apart from that, I think this is the most sensible solution, can't think of other good approaches. One thing we possibly could do as a performance optimization is to traverse upwards to the closest function boundary first and check whether or not it's async. Not sure if the additional code is worth the possibly tiny savings we get from it.

@ngtr6788
Copy link
Contributor Author

ngtr6788 commented Jan 2, 2024

Could you briefly explain why there are multiple test cases for this? Can't they be handled in one test case?

Come to think of it now, you're right. I can just put it in one test case

One thing we possibly could do as a performance optimization is to traverse upwards to the closest function boundary first and check whether or not it's async. Not sure if the additional code is worth the possibly tiny savings we get from it.

Can you elaborate on what you mean by "closest function boundary"? I didn't quite get it :(

@dummdidumm
Copy link
Member

dummdidumm commented Jan 2, 2024

Can you elaborate on what you mean by "closest function boundary"?

await can only be used in functions marked with the async keyword, so we could first traverse upwards to the closest function boundary and check if it has the async keyword. If not, then we know that there can't be an await inside the expression.

function x() { // the closest function boundary; no async modifier -> can't have await inside expression
  let { .. } = { .. }; // the expression we're checking
}

Copy link
Member

@dummdidumm dummdidumm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

.changeset/nasty-yaks-peel.md Outdated Show resolved Hide resolved
@dummdidumm dummdidumm merged commit 1ff9c0f into sveltejs:main Jan 9, 2024
6 of 8 checks passed
trueadm pushed a commit that referenced this pull request Jan 9, 2024
Adds a traversion mechanism to found out if destructured expressions contain await
Fixes #9686
Fixes #9312
Fixes #9982
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Svelte 5: Destructuring Assignment to a Signal Produces a Compiled Output that Interferes with Await Keyword
2 participants