Simplify getAncestorNode in css (#13497)

This commit is contained in:
fisker Cheung authored and GitHub committed 2022-09-20 18:57:07 +08:00
1 parent 398f8f0cc9
commit 6d551ab0ed
1 file changed
+2 -19
+2 -19
View File
@@ -26,24 +26,8 @@ const colorAdjusterFunctions = new Set([
"hwba",
]);
function getAncestorCounter(path, typeOrTypes) {
const types = Array.isArray(typeOrTypes) ? typeOrTypes : [typeOrTypes];
let counter = -1;
let ancestorNode;
while ((ancestorNode = path.getParentNode(++counter))) {
if (types.includes(ancestorNode.type)) {
return counter;
}
}
return -1;
}
function getAncestorNode(path, typeOrTypes) {
const counter = getAncestorCounter(path, typeOrTypes);
return counter === -1 ? null : path.getParentNode(counter);
function getAncestorNode(path, type) {
return path.findAncestor((node) => node.type === type);
}
function getPropOfDeclNode(path) {
@@ -400,7 +384,6 @@ function isParenGroupNode(node) {
}
export {
getAncestorCounter,
getAncestorNode,
getPropOfDeclNode,
maybeToLowerCase,