diff --git a/.changeset/mean-worms-fetch.md b/.changeset/mean-worms-fetch.md new file mode 100644 index 000000000000..d573a631ded2 --- /dev/null +++ b/.changeset/mean-worms-fetch.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: bail on named slots with that have reserved keywords during migration diff --git a/packages/svelte/src/compiler/migrate/index.js b/packages/svelte/src/compiler/migrate/index.js index 4942dd7db279..9db09158a12c 100644 --- a/packages/svelte/src/compiler/migrate/index.js +++ b/packages/svelte/src/compiler/migrate/index.js @@ -17,7 +17,7 @@ import { } from '../utils/ast.js'; 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 { is_reserved, is_svg, is_void } from '../../utils.js'; import { regex_is_valid_identifier } from '../phases/patterns.js'; const regex_style_tags = /(]+>)([\S\s]*?)(<\/style>)/g; @@ -1440,7 +1440,7 @@ function migrate_slot_usage(node, path, state) { if (snippet_name === 'default') { snippet_name = 'children'; } - if (!regex_is_valid_identifier.test(snippet_name)) { + if (!regex_is_valid_identifier.test(snippet_name) || is_reserved(snippet_name)) { has_migration_task = true; state.str.appendLeft( node.start, diff --git a/packages/svelte/tests/migrate/samples/slot-non-identifier/input.svelte b/packages/svelte/tests/migrate/samples/slot-non-identifier/input.svelte index a62eff1b7468..7cf7dd86bbc8 100644 --- a/packages/svelte/tests/migrate/samples/slot-non-identifier/input.svelte +++ b/packages/svelte/tests/migrate/samples/slot-non-identifier/input.svelte @@ -14,6 +14,12 @@ + +
+ reserved keyword +
+
+
cool @@ -63,4 +69,4 @@ 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 index 85913264b475..fb262e8c2532 100644 --- a/packages/svelte/tests/migrate/samples/slot-non-identifier/output.svelte +++ b/packages/svelte/tests/migrate/samples/slot-non-identifier/output.svelte @@ -16,6 +16,13 @@
+ + +
+ reserved keyword +
+
+ {#snippet stuff()}
@@ -75,4 +82,4 @@ cool - \ No newline at end of file +