@@ -888,17 +888,20 @@ function get_element_parent(node) {
888888function get_possible_element_siblings ( element , adjacent_only ) {
889889 /** @type {Map<Compiler.AST.RegularElement | Compiler.AST.SvelteElement | Compiler.AST.SlotElement | Compiler.AST.RenderTag, NodeExistsValue> } */
890890 const result = new Map ( ) ;
891+ const path = element . metadata . path ;
891892
892893 /** @type {Compiler.SvelteNode } */
893- let node = element ;
894- let path = element . metadata . path ;
894+ let current = element ;
895+
895896 let i = path . length ;
896897
897898 while ( i -- ) {
898- let fragment = /** @type {Compiler.AST.Fragment } */ ( path [ i -- ] ) ;
899+ const fragment = /** @type {Compiler.AST.Fragment } */ ( path [ i -- ] ) ;
900+ let j = fragment . nodes . indexOf ( current ) ;
901+
902+ while ( j -- ) {
903+ const node = fragment . nodes [ j ] ;
899904
900- // @ts -expect-error
901- while ( ( node = node . prev ) ) {
902905 if ( node . type === 'RegularElement' ) {
903906 const has_slot_attribute = node . attributes . some (
904907 ( attr ) => attr . type === 'Attribute' && attr . name . toLowerCase ( ) === 'slot'
@@ -928,13 +931,13 @@ function get_possible_element_siblings(element, adjacent_only) {
928931 }
929932 }
930933
931- node = path [ i ] ;
934+ current = path [ i ] ;
932935
933- if ( ! node || ! is_block ( node ) ) break ;
936+ if ( ! current || ! is_block ( current ) ) break ;
934937
935- if ( node . type === 'EachBlock' && fragment === node . body ) {
938+ if ( current . type === 'EachBlock' && fragment === current . body ) {
936939 // `{#each ...}<a /><b />{/each}` — `<b>` can be previous sibling of `<a />`
937- add_to_map ( get_possible_last_child ( node , adjacent_only ) , result ) ;
940+ add_to_map ( get_possible_last_child ( current , adjacent_only ) , result ) ;
938941 }
939942 }
940943
0 commit comments