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: add self-closing-tags migration #12128

Merged
merged 2 commits into from
Apr 16, 2024
Merged

Conversation

dummdidumm
Copy link
Member

Companion to sveltejs/svelte#11114. This adds an npx svelte-migrate self-closing-tags migration that replaces all the self-closing non-void elements in your .svelte files.

Alternative to #12102 with the following adjustments:

  • doesn't migrate slots that are not real custom element slots (will make diff much less noisy)
  • doesn't migrate when namespace is foreign
  • leaves tag-like strings inside scripts/styles etc alone

Please don't delete this checklist! 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
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

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

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Edits

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

Companion to sveltejs/svelte#11114. This adds an npx svelte-migrate self-closing-tags migration that replaces all the self-closing non-void elements in your .svelte files.
Copy link

changeset-bot bot commented Apr 15, 2024

🦋 Changeset detected

Latest commit: 4a5b9ec

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte-migrate Minor

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

'<svelte:options namespace="foreign" /><foo />': '<svelte:options namespace="foreign" /><foo />',
'<script>console.log("<div />")</script>': '<script>console.log("<div />")</script>',
'<script lang="ts">let a: string = ""</script><div />':
'<script lang="ts">let a: string = ""</script><div></div>'
Copy link
Member

Choose a reason for hiding this comment

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

ideally this would work on Svelte 5 codebases too (which means having svelte@next as a dependency, and using walk from either estree-walker or zimmerframe instead of svelte/compiler)

Suggested change
'<script lang="ts">let a: string = ""</script><div></div>'
'<script lang="ts">let a: string = ""</script><div></div>',
'{#snippet foo()}<div />{/snippet}': '{#snippet foo()}<div></div>{/snippet}'

Copy link
Member Author

@dummdidumm dummdidumm Apr 15, 2024

Choose a reason for hiding this comment

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

This should work in Svelte 5 code bases, too, because when you do npx .. aren't you storing the whole dependenies in a isolated folder somewhere on your computer? If not then yes we can switch to zimmerframe.

Oh wait I see what you mean. Mhhhhm how does npx work in general in these situations? Can it pick up dependencies from the environment it's run in? If so then we can do await import('svelte') and use that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Using the local Svelte installation now, tested it successfully on the Svelte 5 repo

@Rich-Harris Rich-Harris merged commit bd54aa1 into main Apr 16, 2024
13 checks passed
@Rich-Harris Rich-Harris deleted the migrate-self-closing-tags-v2 branch April 16, 2024 20:45
@github-actions github-actions bot mentioned this pull request Apr 16, 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.

2 participants