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
pull/14274/head
Torsten Dittmann 1 month ago committed by GitHub
parent 36ece1c381
commit 033061842d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: bail on named slots with that have reserved keywords during migration

@ -17,7 +17,7 @@ import {
} from '../utils/ast.js'; } from '../utils/ast.js';
import { migrate_svelte_ignore } from '../utils/extract_svelte_ignore.js'; import { migrate_svelte_ignore } from '../utils/extract_svelte_ignore.js';
import { validate_component_options } from '../validate-options.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'; import { regex_is_valid_identifier } from '../phases/patterns.js';
const regex_style_tags = /(<style[^>]+>)([\S\s]*?)(<\/style>)/g; const regex_style_tags = /(<style[^>]+>)([\S\s]*?)(<\/style>)/g;
@ -1440,7 +1440,7 @@ function migrate_slot_usage(node, path, state) {
if (snippet_name === 'default') { if (snippet_name === 'default') {
snippet_name = 'children'; 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; has_migration_task = true;
state.str.appendLeft( state.str.appendLeft(
node.start, node.start,

@ -14,6 +14,12 @@
</div> </div>
</Comp> </Comp>
<Comp>
<div slot="new">
reserved keyword
</div>
</Comp>
<Comp> <Comp>
<div slot="stuff"> <div slot="stuff">
cool cool
@ -63,4 +69,4 @@
<svelte:fragment let:should_stay slot="cool stuff"> <svelte:fragment let:should_stay slot="cool stuff">
cool cool
</svelte:fragment> </svelte:fragment>
</Comp> </Comp>

@ -16,6 +16,13 @@
</div> </div>
</Comp> </Comp>
<Comp>
<!-- @migration-task: migrate this slot by hand, `new` is an invalid identifier -->
<div slot="new">
reserved keyword
</div>
</Comp>
<Comp> <Comp>
{#snippet stuff()} {#snippet stuff()}
<div > <div >
@ -75,4 +82,4 @@
<svelte:fragment let:should_stay slot="cool stuff"> <svelte:fragment let:should_stay slot="cool stuff">
cool cool
</svelte:fragment> </svelte:fragment>
</Comp> </Comp>

Loading…
Cancel
Save