@@ -278,7 +278,7 @@ export default class Element extends Node {
278278 }
279279
280280 validate_attributes ( ) {
281- const { component } = this ;
281+ const { component, parent } = this ;
282282
283283 const attribute_map = new Map ( ) ;
284284
@@ -395,26 +395,10 @@ export default class Element extends Node {
395395 component . slot_outlets . add ( name ) ;
396396 }
397397
398- let ancestor = this . parent ;
399- do {
400- if ( ancestor . type === 'InlineComponent' ) break ;
401- if ( ancestor . type === 'Element' && / - / . test ( ancestor . name ) ) break ;
402-
403- if ( ancestor . type === 'IfBlock' || ancestor . type === 'EachBlock' ) {
404- const type = ancestor . type === 'IfBlock' ? 'if' : 'each' ;
405- const message = `Cannot place slotted elements inside an ${ type } -block` ;
406-
407- component . error ( attribute , {
408- code : `invalid-slotted-content` ,
409- message
410- } ) ;
411- }
412- } while ( ancestor = ancestor . parent ) ;
413-
414- if ( ! ancestor ) {
398+ if ( ! ( parent . type === 'InlineComponent' || within_custom_element ( parent ) ) ) {
415399 component . error ( attribute , {
416400 code : `invalid-slotted-content` ,
417- message : `Element with a slot='...' attribute must be a descendant of a component or custom element`
401+ message : `Element with a slot='...' attribute must be a child of a component or a descendant of a custom element` ,
418402 } ) ;
419403 }
420404 }
@@ -776,3 +760,12 @@ function should_have_attribute(
776760 message : `A11y: <${ name } > element should have ${ article } ${ sequence } attribute`
777761 } ) ;
778762}
763+
764+ function within_custom_element ( parent : INode ) {
765+ while ( parent ) {
766+ if ( parent . type === 'InlineComponent' ) return false ;
767+ if ( parent . type === 'Element' && / - / . test ( parent . name ) ) return true ;
768+ parent = parent . parent ;
769+ }
770+ return false ;
771+ }
0 commit comments