@@ -175,7 +175,13 @@ function apply_selector(relative_selectors, rule, element, stylesheet) {
175
175
let sibling_matched = false ;
176
176
177
177
for ( const possible_sibling of siblings . keys ( ) ) {
178
- if ( apply_selector ( parent_selectors , rule , possible_sibling , stylesheet ) ) {
178
+ if ( possible_sibling . type === 'RenderTag' || possible_sibling . type === 'SlotElement' ) {
179
+ // `{@render foo()}<p>foo</p>` with `:global(.x) + p` is a match
180
+ if ( parent_selectors . length === 1 && parent_selectors [ 0 ] . metadata . is_global ) {
181
+ mark ( relative_selector , element ) ;
182
+ sibling_matched = true ;
183
+ }
184
+ } else if ( apply_selector ( parent_selectors , rule , possible_sibling , stylesheet ) ) {
179
185
mark ( relative_selector , element ) ;
180
186
sibling_matched = true ;
181
187
}
@@ -564,38 +570,39 @@ function get_element_parent(node) {
564
570
function find_previous_sibling ( node ) {
565
571
/** @type {import('#compiler').SvelteNode } */
566
572
let current_node = node ;
567
- do {
568
- if ( current_node . type === 'SlotElement' ) {
569
- const slot_children = current_node . fragment . nodes ;
570
- if ( slot_children . length > 0 ) {
571
- current_node = slot_children . slice ( - 1 ) [ 0 ] ; // go to its last child first
572
- continue ;
573
- }
574
- }
575
- while (
576
- // @ts -expect-error TODO
577
- ! current_node . prev &&
578
- // @ts -expect-error TODO
579
- current_node . parent &&
580
- // @ts -expect-error TODO
581
- current_node . parent . type === 'SlotElement'
582
- ) {
583
- // @ts -expect-error TODO
584
- current_node = current_node . parent ;
573
+
574
+ while (
575
+ // @ts -expect-error TODO
576
+ ! current_node . prev &&
577
+ // @ts -expect-error TODO
578
+ current_node . parent ?. type === 'SlotElement'
579
+ ) {
580
+ // @ts -expect-error TODO
581
+ current_node = current_node . parent ;
582
+ }
583
+
584
+ // @ts -expect-error
585
+ current_node = current_node . prev ;
586
+
587
+ while ( current_node ?. type === 'SlotElement' ) {
588
+ const slot_children = current_node . fragment . nodes ;
589
+ if ( slot_children . length > 0 ) {
590
+ current_node = slot_children . slice ( - 1 ) [ 0 ] ;
591
+ } else {
592
+ break ;
585
593
}
586
- // @ts -expect-error
587
- current_node = current_node . prev ;
588
- } while ( current_node && current_node . type === 'SlotElement' ) ;
594
+ }
595
+
589
596
return current_node ;
590
597
}
591
598
592
599
/**
593
600
* @param {import('#compiler').SvelteNode } node
594
601
* @param {boolean } adjacent_only
595
- * @returns {Map<import('#compiler').RegularElement, NodeExistsValue> }
602
+ * @returns {Map<import('#compiler').RegularElement | import('#compiler').SvelteElement | import('#compiler').SlotElement | import('#compiler').RenderTag , NodeExistsValue> }
596
603
*/
597
604
function get_possible_element_siblings ( node , adjacent_only ) {
598
- /** @type {Map<import('#compiler').RegularElement, NodeExistsValue> } */
605
+ /** @type {Map<import('#compiler').RegularElement | import('#compiler').SvelteElement | import('#compiler').SlotElement | import('#compiler').RenderTag , NodeExistsValue> } */
599
606
const result = new Map ( ) ;
600
607
601
608
/** @type {import('#compiler').SvelteNode } */
@@ -618,6 +625,14 @@ function get_possible_element_siblings(node, adjacent_only) {
618
625
if ( adjacent_only && has_definite_elements ( possible_last_child ) ) {
619
626
return result ;
620
627
}
628
+ } else if (
629
+ prev . type === 'SlotElement' ||
630
+ prev . type === 'RenderTag' ||
631
+ prev . type === 'SvelteElement'
632
+ ) {
633
+ result . set ( prev , NODE_PROBABLY_EXISTS ) ;
634
+ // Special case: slots, render tags and svelte:element tags could resolve to no siblings,
635
+ // so we want to continue until we find a definite sibling even with the adjacent-only combinator
621
636
}
622
637
}
623
638
@@ -720,7 +735,7 @@ function get_possible_last_child(relative_selector, adjacent_only) {
720
735
}
721
736
722
737
/**
723
- * @param {Map<import('#compiler').RegularElement , NodeExistsValue> } result
738
+ * @param {Map<unknown , NodeExistsValue> } result
724
739
* @returns {boolean }
725
740
*/
726
741
function has_definite_elements ( result ) {
@@ -734,8 +749,9 @@ function has_definite_elements(result) {
734
749
}
735
750
736
751
/**
737
- * @param {Map<import('#compiler').RegularElement, NodeExistsValue> } from
738
- * @param {Map<import('#compiler').RegularElement, NodeExistsValue> } to
752
+ * @template T
753
+ * @param {Map<T, NodeExistsValue> } from
754
+ * @param {Map<T, NodeExistsValue> } to
739
755
* @returns {void }
740
756
*/
741
757
function add_to_map ( from , to ) {
0 commit comments