From 033061842d463c1db9a0ebed3b27a2ab5b7fddb7 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Tue, 12 Nov 2024 18:13:05 +0100 Subject: [PATCH] fix: named slots with reserved keywords during migration (#14278) Fixes named slots with a reserved keyword not working anymore after migration. Re-uses the @migration-task logic for invalid identifiers. Fixes #14277 --- .changeset/mean-worms-fetch.md | 5 +++++ packages/svelte/src/compiler/migrate/index.js | 4 ++-- .../migrate/samples/slot-non-identifier/input.svelte | 8 +++++++- .../migrate/samples/slot-non-identifier/output.svelte | 9 ++++++++- 4 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 .changeset/mean-worms-fetch.md diff --git a/.changeset/mean-worms-fetch.md b/.changeset/mean-worms-fetch.md new file mode 100644 index 0000000000..d573a631de --- /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 4942dd7db2..9db09158a1 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 a62eff1b74..7cf7dd86bb 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 85913264b4..fb262e8c25 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 +