simplify parent loop

pull/5427/head
Tan Li Hau 5 years ago
parent cd6a9b3281
commit 66201c2fd8

@ -434,21 +434,20 @@ function get_possible_element_siblings(node: INode, adjacent_only: boolean): Ele
if (!prev || !adjacent_only) { if (!prev || !adjacent_only) {
let parent: INode = node; 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')) { 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); const possible_siblings = get_possible_element_siblings(parent, adjacent_only);
result.push(...possible_siblings); result.push(...possible_siblings);
if (parent.type === 'EachBlock') { if (parent.type === 'EachBlock') {
if (else_block) { // first child of each block can select the last child of each block as previous sibling
else_block = false; for (const each_parent_last_child of get_possible_last_child(parent, adjacent_only)) {
} else { result.push(each_parent_last_child);
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 if (parent.type === 'ElseBlock') {
else_block = true; parent = parent.parent;
} }
if (adjacent_only && possible_siblings.find(sibling => sibling.exist === NodeExist.Definitely)) { if (adjacent_only && possible_siblings.find(sibling => sibling.exist === NodeExist.Definitely)) {

Loading…
Cancel
Save