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