@ -260,12 +260,15 @@ function apply_combinator(combinator, relative_selector, parent_selectors, rule,
switch ( name ) {
switch ( name ) {
case ' ' :
case ' ' :
case '>' : {
case '>' : {
let parent = /** @type {Compiler.TemplateNode | null} */ ( element . parent ) ;
let parent _matched = false ;
let parent _matched = false ;
let crossed _component _boundary = false ;
let crossed _component _boundary = false ;
while ( parent ) {
const path = element . metadata . path ;
let i = path . length ;
while ( i -- ) {
const parent = path [ i ] ;
if ( parent . type === 'Component' || parent . type === 'SvelteComponent' ) {
if ( parent . type === 'Component' || parent . type === 'SvelteComponent' ) {
crossed _component _boundary = true ;
crossed _component _boundary = true ;
}
}
@ -289,8 +292,6 @@ function apply_combinator(combinator, relative_selector, parent_selectors, rule,
if ( name === '>' ) return parent _matched ;
if ( name === '>' ) return parent _matched ;
}
}
parent = /** @type {Compiler.TemplateNode | null} */ ( parent . parent ) ;
}
}
return parent _matched || parent _selectors . every ( ( selector ) => is _global ( selector , rule ) ) ;
return parent _matched || parent _selectors . every ( ( selector ) => is _global ( selector , rule ) ) ;
@ -679,51 +680,50 @@ function relative_selector_might_apply_to_node(relative_selector, rule, element,
* @ param { boolean } include _self
* @ param { boolean } include _self
* /
* /
function get _following _sibling _elements ( element , include _self ) {
function get _following _sibling _elements ( element , include _self ) {
/** @type {Compiler.AST.RegularElement | Compiler.AST.SvelteElement | Compiler.AST.Root | null} */
const path = element . metadata . path ;
let parent = get _element _parent ( element ) ;
let i = path . length ;
/** @type {Compiler.SvelteNode} */
let start = element ;
let nodes = /** @type {Compiler.SvelteNode[]} */ (
/** @type {Compiler.AST.Fragment} */ ( path [ 0 ] ) . nodes
) ;
// find the set of nodes to walk...
while ( i -- ) {
const node = path [ i ] ;
if ( node . type === 'RegularElement' || node . type === 'SvelteElement' ) {
nodes = node . fragment . nodes ;
break ;
}
if ( ! parent ) {
if ( node . type !== 'Fragment' ) {
parent = element ;
start = node ;
while ( parent ? . type !== 'Root' ) {
parent = /** @type {any} */ ( parent ) . parent ;
}
}
}
}
/** @type {Array<Compiler.AST.RegularElement | Compiler.AST.SvelteElement>} */
/** @type {Array<Compiler.AST.RegularElement | Compiler.AST.SvelteElement>} */
const sibling _elements = [ ] ;
const siblings = [ ] ;
let found _parent = false ;
for ( const el of parent . fragment . nodes ) {
// ...then walk them, starting from the node after the one
if ( found _parent ) {
// containing the element in question
walk (
for ( const node of nodes . slice ( nodes . indexOf ( start ) + 1 ) ) {
el ,
walk ( node , null , {
{ } ,
{
RegularElement ( node ) {
RegularElement ( node ) {
sibling _element s. push ( node ) ;
siblings . push ( node ) ;
} ,
} ,
SvelteElement ( node ) {
SvelteElement ( node ) {
sibling _elements . push ( node ) ;
siblings . push ( node ) ;
}
}
) ;
} else {
/** @type {any} */
let child = element ;
while ( child !== el && child !== parent ) {
child = child . parent ;
}
if ( child === el ) {
found _parent = true ;
}
}
}
} ) ;
}
}
if ( include _self ) {
if ( include _self ) {
sibling _element s. push ( element ) ;
siblings . push ( element ) ;
}
}
return sibling _element s;
return siblings ;
}
}
/ * *
/ * *
@ -867,15 +867,18 @@ function unquote(str) {
* @ returns { Compiler . AST . RegularElement | Compiler . AST . SvelteElement | null }
* @ returns { Compiler . AST . RegularElement | Compiler . AST . SvelteElement | null }
* /
* /
function get _element _parent ( node ) {
function get _element _parent ( node ) {
/** @type {Compiler.SvelteNode | null} */
let path = node . metadata . path ;
let parent = node ;
let i = path . length ;
while (
// @ts-expect-error TODO figure out a more elegant solution
while ( i -- ) {
( parent = parent . parent ) &&
const parent = path [ i ] ;
parent . type !== 'RegularElement' &&
parent . type !== 'SvelteElement'
if ( parent . type === 'RegularElement' || parent . type === 'SvelteElement' ) {
) ;
return parent ;
return parent ? ? null ;
}
}
return null ;
}
}
/ * *
/ * *
@ -920,7 +923,7 @@ function find_previous_sibling(node) {
while ( current _node ? . type === 'SlotElement' ) {
while ( current _node ? . type === 'SlotElement' ) {
const slot _children = current _node . fragment . nodes ;
const slot _children = current _node . fragment . nodes ;
if ( slot _children . length > 0 ) {
if ( slot _children . length > 0 ) {
current _node = slot _children .slice ( - 1 ) [ 0 ] ;
current _node = slot _children [slot _children . length - 1 ] ;
} else {
} else {
break ;
break ;
}
}
@ -1118,8 +1121,12 @@ function mark_as_probably(result) {
function loop _child ( children , adjacent _only ) {
function loop _child ( children , adjacent _only ) {
/** @type {Map<Compiler.AST.RegularElement, NodeExistsValue>} */
/** @type {Map<Compiler.AST.RegularElement, NodeExistsValue>} */
const result = new Map ( ) ;
const result = new Map ( ) ;
for ( let i = children . length - 1 ; i >= 0 ; i -- ) {
let i = children . length ;
while ( i -- ) {
const child = children [ i ] ;
const child = children [ i ] ;
if ( child . type === 'RegularElement' ) {
if ( child . type === 'RegularElement' ) {
result . set ( child , NODE _DEFINITELY _EXISTS ) ;
result . set ( child , NODE _DEFINITELY _EXISTS ) ;
if ( adjacent _only ) {
if ( adjacent _only ) {
@ -1137,5 +1144,6 @@ function loop_child(children, adjacent_only) {
}
}
}
}
}
}
return result ;
return result ;
}
}