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: correctly parse each with loose parser #14887

Merged
merged 5 commits into from
Jan 6, 2025
Merged

Conversation

paoloricciuti
Copy link
Member

@paoloricciuti paoloricciuti commented Jan 3, 2025

Closes #14766

This was a wild chase: initially i thought it was a problem with the language-tools but then i realised that the ast for each was incorrectly generated when in loose mode...the reason is because in the each we are relying on acorn throwing the error on parse_expression to then backtrack for situations like as { x = y }...the loose parser made this impossible and returned an incorrect identifier which in turn was screwing the language server.

This fixes it even tho I'm not a huge fun of the solution because it means we need to handle the error differently if we are in an each but i don't think there's another way.

I've added a test only in parser-modern...should i add one in legacy too?

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.
  • If this PR changes code within packages/svelte/src, add a changeset (npx changeset).

Tests and linting

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

Copy link

changeset-bot bot commented Jan 3, 2025

🦋 Changeset detected

Latest commit: ee00946

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
Contributor

github-actions bot commented Jan 3, 2025

Playground

pnpm add https://pkg.pr.new/svelte@14887

@jasonlyu123
Copy link
Member

Does this also fix sveltejs/language-tools#2636? I haven't figured out if it's a compiler or a svelte2tsx issue. For some odd reason, I can only see it in some projects. But the problem is the context is null in the AST.

@paoloricciuti
Copy link
Member Author

Does this also fix sveltejs/language-tools#2636? I haven't figured out if it's a compiler or a svelte2tsx issue. For some odd reason, I can only see it in some projects. But the problem is the context is null in the AST.

I suspect yes...you probably can only see it for projects that uses svelte version after the loose parser

@jasonlyu123
Copy link
Member

jasonlyu123 commented Jan 3, 2025

The weird thing is that I can't reproduce it in the svelte test or the svelte2tsx test and all the version is 5.16.0. But it does seem to be fixed if I install the pkg.new version in the project where I can reproduce the problem. Hopely it is really fixed and not just another situation where it doesn't show up 😅

@paoloricciuti
Copy link
Member Author

The weird thing is that I can't reproduce it in the svelte test or the svelte2tsx test and all the version is 5.16.0. But it does seem to be fixed if I install the pkg.new version in the project I can reproduce the problem. Hopely it is really fixed and not just another situation where it doesn't show up 😅

Yeah I think we need to add a test suite for the loose parser: svelte2tsx tests and repl run without the loose parser while the extension run with it. I had the same problem while trying to understand this bug

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.

destructuring {#each} with fallback has type inference error
3 participants