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: allow ts casts in bindings #10181

Merged
merged 6 commits into from
Jan 19, 2024
Merged

fix: allow ts casts in bindings #10181

merged 6 commits into from
Jan 19, 2024

Conversation

gtm-nayan
Copy link
Contributor

fix #10179

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 Jan 14, 2024

🦋 Changeset detected

Latest commit: 1a50e1f

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 Jan 14, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
svelte-5-preview ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 14, 2024 3:59am

@dummdidumm
Copy link
Member

dummdidumm commented Jan 15, 2024

There's an object method in the utils.js which I think should also get this treatment?
In general I'm wondering if we should unpack the expressions in acorn.js where we traverse the TS AST to clean up a few thing. Maybe we can also unpack/remove those AST types from the AST.

@gtm-nayan
Copy link
Contributor Author

#10179

turns out the place that marks the binding as reassigned and mutated

for (const [scope, node] of updates) {

would also need to be updated,

I think it makes sense to unwrap everything right after parse then

@@ -270,6 +272,9 @@ function _extract_paths(assignments = [], param, expression, update_expression)
* The Acorn TS plugin defines `foo!` as a `TSNonNullExpression` node, and
* `foo as Bar` as a `TSAsExpression` node. This function unwraps those.
*
* We can't just remove the typescript AST nodes in the parser stage because subsequent
* parsing would fail, since AST start/end nodes would point at the wrong positions.
Copy link
Member

Choose a reason for hiding this comment

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

I tried removing all AST nodes right after parsing in a post-process step, but it failed because of this - if you have an idea how to solve this, I'm all ears

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's for removing it during parsing right? We could do one pass after the whole file is parsed.

Copy link
Member

Choose a reason for hiding this comment

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

Mhm maybe. I removed it after an expression/the script tag was parsed, but doing it after the whole thing is parsed could maybe work.. would you mind trying it out?

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: Typescript type assertion when binding cause syntax error
3 participants