Skip to content

Commit c005c08

Browse files
committed
remove a node.parent usage
1 parent 67b2c8c commit c005c08

File tree

1 file changed

+12
-9
lines changed
  • packages/svelte/src/compiler/phases/2-analyze/css

1 file changed

+12
-9
lines changed

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -867,15 +867,18 @@ function unquote(str) {
867867
* @returns {Compiler.AST.RegularElement | Compiler.AST.SvelteElement | null}
868868
*/
869869
function get_element_parent(node) {
870-
/** @type {Compiler.SvelteNode | null} */
871-
let parent = node;
872-
while (
873-
// @ts-expect-error TODO figure out a more elegant solution
874-
(parent = parent.parent) &&
875-
parent.type !== 'RegularElement' &&
876-
parent.type !== 'SvelteElement'
877-
);
878-
return parent ?? null;
870+
let path = node.metadata.path;
871+
let i = path.length;
872+
873+
while (i--) {
874+
const parent = path[i];
875+
876+
if (parent.type === 'RegularElement' || parent.type === 'SvelteElement') {
877+
return parent;
878+
}
879+
}
880+
881+
return null;
879882
}
880883

881884
/**

0 commit comments

Comments
 (0)