Skip to content

feat: support migration of svelte:component #13437

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

Merged
merged 6 commits into from
Sep 30, 2024

Conversation

paoloricciuti
Copy link
Member

Svelte 5 rewrite

Closes #13418

As usual this kinda opened a can of wormsedge cases so i had to go through multiple hops for something and there might be better ways to do it but it should work decently (you can see the transform from the output of the test)

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 Sep 29, 2024

🦋 Changeset detected

Latest commit: d492dc8

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

Judging from the tests it's impressive how many cases it handles (honestly more than I think we need to), but I'm a bit surprised about all the additional code for Component and SvelteComponent - why do we need to account for slots, comments, the last const binding, etc etc? My (maybe too simplistic) first thought was that we'd call context.next() in the (Svelte)Component visitor first, then remove the this attribute, then replace the svelte:component tags with whatever replacement they need and potentially prepend a @const directly before it. What's the reason this isn't enough?

@paoloricciuti
Copy link
Member Author

Judging from the tests it's impressive how many cases it handles (honestly more than I think we need to), but I'm a bit surprised about all the additional code for Component and SvelteComponent - why do we need to account for slots, comments, the last const binding, etc etc? My (maybe too simplistic) first thought was that we'd call context.next() in the (Svelte)Component visitor first, then remove the this attribute, then replace the svelte:component tags with whatever replacement they need and potentially prepend a @const directly before it. What's the reason this isn't enough?

I was honestly surprised too, the walk was initially just needed to properly replace $$props and $$restProps and most of the complexity came from the LetDirective and the ConstTag...the idea behind last_const_binding was to put the new {@const} tag after the last {@const} tag that was used inside the expression because that's how i would write that code but you are probably right and just writing it right before the svelte:component should solve a lot of headaches. And doing this should also solve the let problem because the whole code in Component was there just to be able to have the correct scope in svelte:component.

I'll try with your suggestion and i'm pretty sure it's simplify-able (that will result in probably a tad uglier code in some cases but i think it's perfectly reasonable).

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.

Yeah this looks a lot better already!

@paoloricciuti paoloricciuti changed the title feat: allow migration of svelte:component feat: support migration of svelte:component Sep 30, 2024
@paoloricciuti paoloricciuti merged commit b665425 into main Sep 30, 2024
9 checks passed
This was referenced Sep 30, 2024
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 migration script: migrate svelte:component
2 participants