diff --git a/.changeset/blue-timers-film.md b/.changeset/blue-timers-film.md new file mode 100644 index 0000000000..4a7e421700 --- /dev/null +++ b/.changeset/blue-timers-film.md @@ -0,0 +1,5 @@ +--- +"svelte": patch +--- + +fix: skip certain slot validations for custom elements diff --git a/packages/svelte/src/compiler/phases/2-analyze/validation.js b/packages/svelte/src/compiler/phases/2-analyze/validation.js index e4e6275b46..49aea8c195 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/validation.js +++ b/packages/svelte/src/compiler/phases/2-analyze/validation.js @@ -172,31 +172,37 @@ function validate_slot_attribute(context, attribute) { error(attribute, 'invalid-slot-attribute'); } - if (owner.type === 'Component' || owner.type === 'SvelteComponent') { + if ( + owner.type === 'Component' || + owner.type === 'SvelteComponent' || + owner.type === 'SvelteSelf' + ) { if (owner !== context.path.at(-2)) { error(attribute, 'invalid-slot-placement'); } - } - const name = attribute.value[0].data; - if (context.state.component_slots.has(name)) { - error(attribute, 'duplicate-slot-name', name, owner.name); - } - context.state.component_slots.add(name); + const name = attribute.value[0].data; - if (name === 'default') { - for (const node of owner.fragment.nodes) { - if (node.type === 'Text' && regex_only_whitespaces.test(node.data)) { - continue; - } + if (context.state.component_slots.has(name)) { + error(attribute, 'duplicate-slot-name', name, owner.name); + } - if (node.type === 'RegularElement' || node.type === 'SvelteFragment') { - if (node.attributes.some((a) => a.type === 'Attribute' && a.name === 'slot')) { + context.state.component_slots.add(name); + + if (name === 'default') { + for (const node of owner.fragment.nodes) { + if (node.type === 'Text' && regex_only_whitespaces.test(node.data)) { continue; } - } - error(node, 'invalid-default-slot-content'); + if (node.type === 'RegularElement' || node.type === 'SvelteFragment') { + if (node.attributes.some((a) => a.type === 'Attribute' && a.name === 'slot')) { + continue; + } + } + + error(node, 'invalid-default-slot-content'); + } } } } else { diff --git a/packages/svelte/tests/compiler-errors/samples/component-slot-duplicate-error/main.svelte b/packages/svelte/tests/compiler-errors/samples/component-slot-duplicate-error/main.svelte index 05475a3bf2..bbaf69118b 100644 --- a/packages/svelte/tests/compiler-errors/samples/component-slot-duplicate-error/main.svelte +++ b/packages/svelte/tests/compiler-errors/samples/component-slot-duplicate-error/main.svelte @@ -2,6 +2,12 @@ import Nested from './irrelevant'; + + + + + +

{value}

{value}