From 66201c2fd8730fddd9158cdcc543807d668bee54 Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Sat, 19 Sep 2020 23:36:09 +0800 Subject: [PATCH] simplify parent loop --- src/compiler/compile/css/Selector.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/compiler/compile/css/Selector.ts b/src/compiler/compile/css/Selector.ts index d8ffbd6d12..c60bd1d443 100644 --- a/src/compiler/compile/css/Selector.ts +++ b/src/compiler/compile/css/Selector.ts @@ -434,21 +434,20 @@ function get_possible_element_siblings(node: INode, adjacent_only: boolean): Ele if (!prev || !adjacent_only) { let parent: INode = node; - let else_block = node.type === 'ElseBlock'; + if (node.type === 'ElseBlock') { + parent = parent.parent; + } while ((parent = parent.parent) && (parent.type === 'EachBlock' || parent.type === 'IfBlock' || parent.type === 'ElseBlock' || parent.type === 'AwaitBlock')) { const possible_siblings = get_possible_element_siblings(parent, adjacent_only); result.push(...possible_siblings); if (parent.type === 'EachBlock') { - if (else_block) { - else_block = false; - } else { - for (const each_parent_last_child of get_possible_last_child(parent, adjacent_only)) { - result.push(each_parent_last_child); - } + // first child of each block can select the last child of each block as previous sibling + for (const each_parent_last_child of get_possible_last_child(parent, adjacent_only)) { + result.push(each_parent_last_child); } } else if (parent.type === 'ElseBlock') { - else_block = true; + parent = parent.parent; } if (adjacent_only && possible_siblings.find(sibling => sibling.exist === NodeExist.Definitely)) {