Skip to content

Commit

Permalink
fix: named slots with reserved keywords during migration (#14278)
Browse files Browse the repository at this point in the history
Fixes named slots with a reserved keyword not working anymore after migration. Re-uses the @migration-task logic for invalid identifiers.

Fixes #14277
  • Loading branch information
TorstenDittmann authored Nov 12, 2024
1 parent 36ece1c commit 0330618
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/mean-worms-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: bail on named slots with that have reserved keywords during migration
4 changes: 2 additions & 2 deletions packages/svelte/src/compiler/migrate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = /(<style[^>]+>)([\S\s]*?)(<\/style>)/g;
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
</div>
</Comp>

<Comp>
<div slot="new">
reserved keyword
</div>
</Comp>

<Comp>
<div slot="stuff">
cool
Expand Down Expand Up @@ -63,4 +69,4 @@
<svelte:fragment let:should_stay slot="cool stuff">
cool
</svelte:fragment>
</Comp>
</Comp>
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
</div>
</Comp>

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

<Comp>
{#snippet stuff()}
<div >
Expand Down Expand Up @@ -75,4 +82,4 @@
<svelte:fragment let:should_stay slot="cool stuff">
cool
</svelte:fragment>
</Comp>
</Comp>

0 comments on commit 0330618

Please sign in to comment.