-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
feat: migrate svelte:self
#13504
Conversation
🦋 Changeset detectedLatest commit: d1ffa69 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, will do 😉
// 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) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 /> |
There was a problem hiding this comment.
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
Co-authored-by: Simon H <[email protected]>
There was a problem hiding this 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
Want to take a look at the sveltekit PR too? |
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 notmain
.Before submitting the PR, please make sure you do the following
feat:
,fix:
,chore:
, ordocs:
.Tests and linting
pnpm test
and lint the project withpnpm lint