Skip to content

Commit

Permalink
feat: add migration-task for impossible to migrate slots (#13658)
Browse files Browse the repository at this point in the history
* feat: add `migration-task` for impossible to migrate slots

* Update packages/svelte/src/compiler/migrate/index.js

Co-authored-by: Paolo Ricciuti <ricciutipaolo@gmail.com>

* Update packages/svelte/tests/migrate/samples/slot-non-identifier/output.svelte

Co-authored-by: Paolo Ricciuti <ricciutipaolo@gmail.com>

* Update packages/svelte/tests/migrate/samples/slot-non-identifier/output.svelte

Co-authored-by: Paolo Ricciuti <ricciutipaolo@gmail.com>

* Update packages/svelte/tests/migrate/samples/slot-non-identifier/output.svelte

Co-authored-by: Paolo Ricciuti <ricciutipaolo@gmail.com>

* Update packages/svelte/tests/migrate/samples/slot-non-identifier/output.svelte

Co-authored-by: Paolo Ricciuti <ricciutipaolo@gmail.com>

---------

Co-authored-by: Dominic Gannaway <trueadm@users.noreply.github.com>
  • Loading branch information
paoloricciuti and trueadm authored Oct 18, 2024
1 parent 0dcd4f6 commit 969e6aa
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/good-kings-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

feat: add `migration-task` for impossible to migrate slots
8 changes: 8 additions & 0 deletions packages/svelte/src/compiler/migrate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import { migrate_svelte_ignore } from '../utils/extract_svelte_ignore.js';
import { validate_component_options } from '../validate-options.js';
import { is_svg, is_void } from '../../utils.js';
import { regex_is_valid_identifier } from '../phases/patterns.js';

const regex_style_tags = /(<style[^>]+>)([\S\s]*?)(<\/style>)/g;
const style_placeholder = '/*$$__STYLE_CONTENT__$$*/';
Expand Down Expand Up @@ -1082,6 +1083,13 @@ function migrate_slot_usage(node, path, state) {
is_text_attribute(attribute)
) {
snippet_name = attribute.value[0].data;
if (!regex_is_valid_identifier.test(snippet_name)) {
state.str.appendLeft(
node.start,
`<!-- @migration-task: migrate this slot by hand, \`${snippet_name}\` is an invalid identifier -->\n${state.indent}`
);
return;
}
state.str.remove(attribute.start, attribute.end);
}
if (attribute.type === 'LetDirective') {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<script>
import Comp from "./Component.svelte";
</script>

<Comp>
<div slot="cool:stuff">
cool
</div>
</Comp>

<Comp>
<div slot="cool stuff">
cool
</div>
</Comp>

<Comp>
<div slot="stuff">
cool
</div>
</Comp>

<Comp>
<svelte:fragment slot="cool:stuff">
cool
</svelte:fragment>
</Comp>

<Comp>
<svelte:fragment slot="cool stuff">
cool
</svelte:fragment>
</Comp>

<Comp>
<svelte:fragment slot="stuff">
cool
</svelte:fragment>
</Comp>
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<script>
import Comp from "./Component.svelte";
</script>

<Comp>
<!-- @migration-task: migrate this slot by hand, `cool:stuff` is an invalid identifier -->
<div slot="cool:stuff">
cool
</div>
</Comp>

<Comp>
<!-- @migration-task: migrate this slot by hand, `cool stuff` is an invalid identifier -->
<div slot="cool stuff">
cool
</div>
</Comp>

<Comp>
{#snippet stuff()}
<div >
cool
</div>
{/snippet}
</Comp>

<Comp>
<!-- @migration-task: migrate this slot by hand, `cool:stuff` is an invalid identifier -->
<svelte:fragment slot="cool:stuff">
cool
</svelte:fragment>
</Comp>

<Comp>
<!-- @migration-task: migrate this slot by hand, `cool stuff` is an invalid identifier -->
<svelte:fragment slot="cool stuff">
cool
</svelte:fragment>
</Comp>

<Comp>
{#snippet stuff()}

cool

{/snippet}
</Comp>

0 comments on commit 969e6aa

Please sign in to comment.