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

feat: migrate svelte:self #13504

Merged
merged 13 commits into from
Oct 5, 2024
Merged

feat: migrate svelte:self #13504

merged 13 commits into from
Oct 5, 2024

Conversation

paoloricciuti
Copy link
Member

Svelte 5 rewrite

This adds the ability to migrate svelte:self which is deprecated. We need the filename to be able to auto-import so i've added it to the signature of the migrate function. If the user is using an older version of the cli which doesn't pass the filename in i've added a @migration-task as a comment.

Don't know if we want to do it but i'd say if we want to do it better do it now than later. I'll prepare a PR for kit too to pass the filename during the migration script.

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 Oct 4, 2024

🦋 Changeset detected

Latest commit: d1ffa69

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

* @returns {{ code: string; }}
*/
export function migrate(source) {
export function migrate(source, filename) {
Copy link
Member

Choose a reason for hiding this comment

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

let's play it save and make this an options argument, so we can enhance this in the future of needed

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea, will do 😉

packages/svelte/src/compiler/migrate/index.js Outdated Show resolved Hide resolved
// by default we overwrite until the end of the node - 1
let end = node.end - 1;
// if it has some children we need to overwrite from start to start of the fragment
if (node.fragment.nodes.length > 0) {
Copy link
Member

Choose a reason for hiding this comment

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

This seems a bit complicated, can you elaborate why? AFAIK we can just str.update(node.start + 1, node.start + 1 + 'svelte:self'.length). For the end tag it needs a few more checks, that's true

Copy link
Member Author

Choose a reason for hiding this comment

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

Duh... I'll add a post it on my screen with "check if there's a simpler way you idiot" 😁


{#if false}
<!-- @migration-task: migrate this by hand or call the migrate function with the filename of this file -->
<svelte:self />
Copy link
Member

Choose a reason for hiding this comment

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

I think it's fine to just have this as a single test, no need to check all variants for a successful addition of a comment

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.

One small suggestion; and needs a changeset, other than that good to go

packages/svelte/src/compiler/migrate/index.js Outdated Show resolved Hide resolved
@paoloricciuti
Copy link
Member Author

One small suggestion; and needs a changeset, other than that good to go

Want to take a look at the sveltekit PR too?

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.

2 participants