Skip to content

fix(migration): named slots with reserved keywords #14278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
Loading