diff --git a/.changeset/good-kings-try.md b/.changeset/good-kings-try.md new file mode 100644 index 0000000000..b2239f91a2 --- /dev/null +++ b/.changeset/good-kings-try.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +feat: add `migration-task` for impossible to migrate slots diff --git a/packages/svelte/src/compiler/migrate/index.js b/packages/svelte/src/compiler/migrate/index.js index 2ca590ac69..a554d0f0bb 100644 --- a/packages/svelte/src/compiler/migrate/index.js +++ b/packages/svelte/src/compiler/migrate/index.js @@ -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 = /(]+>)([\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, + `\n${state.indent}` + ); + return; + } state.str.remove(attribute.start, attribute.end); } if (attribute.type === 'LetDirective') { diff --git a/packages/svelte/tests/migrate/samples/slot-non-identifier/input.svelte b/packages/svelte/tests/migrate/samples/slot-non-identifier/input.svelte new file mode 100644 index 0000000000..a5dfd1aad1 --- /dev/null +++ b/packages/svelte/tests/migrate/samples/slot-non-identifier/input.svelte @@ -0,0 +1,39 @@ + + + +
+ cool +
+
+ + +
+ cool +
+
+ + +
+ cool +
+
+ + + + cool + + + + + + cool + + + + + + cool + + \ No newline at end of file diff --git a/packages/svelte/tests/migrate/samples/slot-non-identifier/output.svelte b/packages/svelte/tests/migrate/samples/slot-non-identifier/output.svelte new file mode 100644 index 0000000000..6ea49817d1 --- /dev/null +++ b/packages/svelte/tests/migrate/samples/slot-non-identifier/output.svelte @@ -0,0 +1,47 @@ + + + + +
+ cool +
+
+ + + +
+ cool +
+
+ + + {#snippet stuff()} +
+ cool +
+ {/snippet} +
+ + + + + cool + + + + + + + cool + + + + + {#snippet stuff()} + + cool + + {/snippet} + \ No newline at end of file