feat: add `migration-task` for impossible to migrate slots (#13658)

* 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>
pull/13668/head
Paolo Ricciuti 2 months ago committed by GitHub
parent 0dcd4f6c6e
commit 969e6aa750
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
feat: add `migration-task` for impossible to migrate slots

@ -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__$$*/';
@ -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') {

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

@ -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>
Loading…
Cancel
Save