fix: don't error on slot prop inside block inside other component (#15148)

`slot` is treated as a regular prop if it is not used directly inside another component, but we were running validations on such regular props that should only be run on real slots.

Fixes #15125
pull/15156/head
Simon H 7 months ago committed by GitHub
parent b8607f8765
commit 83f00ebbd6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: don't error on slot prop inside block inside other component

@ -80,18 +80,19 @@ export function validate_slot_attribute(context, attribute, is_component = false
}
if (owner) {
if (!is_text_attribute(attribute)) {
e.slot_attribute_invalid(attribute);
}
if (
owner.type === 'Component' ||
owner.type === 'SvelteComponent' ||
owner.type === 'SvelteSelf'
) {
if (owner !== parent) {
if (!is_component) {
e.slot_attribute_invalid_placement(attribute);
}
} else {
if (!is_text_attribute(attribute)) {
e.slot_attribute_invalid(attribute);
}
const name = attribute.value[0].data;
@ -117,6 +118,7 @@ export function validate_slot_attribute(context, attribute, is_component = false
}
}
}
}
} else if (!is_component) {
e.slot_attribute_invalid_placement(attribute);
}

@ -1,2 +1,8 @@
<Foo slot="foo">valid</Foo>
<Foo slot={foo}>valid</Foo>
<Foo>
{#if true}
<Foo slot="foo">valid</Foo>
<Foo slot={foo}>valid</Foo>
{/if}
</Foo>
Loading…
Cancel
Save