Skip to content

Commit 8a5e6dc

Browse files
committed
helperise/robustify
1 parent 1b30e7f commit 8a5e6dc

File tree

1 file changed

+16
-15
lines changed
  • packages/svelte/src/compiler/phases/2-analyze/css

1 file changed

+16
-15
lines changed

packages/svelte/src/compiler/phases/2-analyze/css/css-prune.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -955,12 +955,7 @@ function get_possible_element_siblings(node, adjacent_only) {
955955
if (adjacent_only) {
956956
break;
957957
}
958-
} else if (
959-
prev.type === 'EachBlock' ||
960-
prev.type === 'IfBlock' ||
961-
prev.type === 'AwaitBlock' ||
962-
prev.type === 'KeyBlock'
963-
) {
958+
} else if (is_block(prev)) {
964959
const possible_last_child = get_possible_last_child(prev, adjacent_only);
965960
add_to_map(possible_last_child, result);
966961
if (adjacent_only && has_definite_elements(possible_last_child)) {
@@ -984,10 +979,7 @@ function get_possible_element_siblings(node, adjacent_only) {
984979
while (
985980
// @ts-expect-error TODO
986981
(parent = parent?.parent) &&
987-
(parent.type === 'EachBlock' ||
988-
parent.type === 'IfBlock' ||
989-
parent.type === 'AwaitBlock' ||
990-
parent.type === 'KeyBlock')
982+
is_block(parent)
991983
) {
992984
const possible_siblings = get_possible_element_siblings(parent, adjacent_only);
993985
add_to_map(possible_siblings, result);
@@ -1117,11 +1109,7 @@ function loop_child(children, adjacent_only) {
11171109
if (adjacent_only) {
11181110
break;
11191111
}
1120-
} else if (
1121-
child.type === 'EachBlock' ||
1122-
child.type === 'IfBlock' ||
1123-
child.type === 'AwaitBlock'
1124-
) {
1112+
} else if (is_block(child)) {
11251113
const child_result = get_possible_last_child(child, adjacent_only);
11261114
add_to_map(child_result, result);
11271115
if (adjacent_only && has_definite_elements(child_result)) {
@@ -1132,3 +1120,16 @@ function loop_child(children, adjacent_only) {
11321120

11331121
return result;
11341122
}
1123+
1124+
/**
1125+
* @param {Compiler.SvelteNode} node
1126+
* @returns {node is Compiler.AST.IfBlock | Compiler.AST.EachBlock | Compiler.AST.AwaitBlock | Compiler.AST.KeyBlock}
1127+
*/
1128+
function is_block(node) {
1129+
return (
1130+
node.type === 'IfBlock' ||
1131+
node.type === 'EachBlock' ||
1132+
node.type === 'AwaitBlock' ||
1133+
node.type === 'KeyBlock'
1134+
);
1135+
}

0 commit comments

Comments
 (0)