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';
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;
@ -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,

@ -14,6 +14,12 @@
</div>
</Comp>
<Comp>
<div slot="new">
reserved keyword
</div>
</Comp>
<Comp>
<div slot="stuff">
cool

@ -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 >

Loading…
Cancel
Save