fix: skip certain slot validations for custom elements (#10207)

fixes #10196
pull/10202/head
Simon H 12 months ago committed by GitHub
parent e398047f8f
commit 9f87f059d2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
"svelte": patch
---
fix: skip certain slot validations for custom elements

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

@ -2,6 +2,12 @@
import Nested from './irrelevant';
</script>
<!-- allowed in custom elements -->
<c-e>
<c-e-item slot="allowed"></c-e-item>
<c-e-item slot="allowed"></c-e-item>
</c-e>
<Nested>
<p slot="foo">{value}</p>
<p slot="foo">{value}</p>

Loading…
Cancel
Save