fix: relax slot prop validation on components (#11923)

If a component is not inside a slot context, having a slot property is fine and doesn't have any restrictions
pull/11928/head
Simon H 7 months ago committed by GitHub
parent 8c9d9a4a44
commit 380d4454a3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
"svelte": patch
---
fix: relax slot prop validation on components

@ -87,7 +87,7 @@ function validate_component(node, context) {
validate_attribute_name(attribute); validate_attribute_name(attribute);
if (attribute.name === 'slot') { if (attribute.name === 'slot') {
validate_slot_attribute(context, attribute); validate_slot_attribute(context, attribute, true);
} }
} }
} }
@ -253,8 +253,9 @@ function validate_attribute_name(attribute) {
/** /**
* @param {import('zimmerframe').Context<import('#compiler').SvelteNode, import('./types.js').AnalysisState>} context * @param {import('zimmerframe').Context<import('#compiler').SvelteNode, import('./types.js').AnalysisState>} context
* @param {import('#compiler').Attribute} attribute * @param {import('#compiler').Attribute} attribute
* @param {boolean} is_component
*/ */
function validate_slot_attribute(context, attribute) { function validate_slot_attribute(context, attribute, is_component = false) {
let owner = undefined; let owner = undefined;
let i = context.path.length; let i = context.path.length;
@ -310,7 +311,7 @@ function validate_slot_attribute(context, attribute) {
} }
} }
} }
} else { } else if (!is_component) {
e.slot_attribute_invalid_placement(attribute); e.slot_attribute_invalid_placement(attribute);
} }
} }

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