Simplify getAncestorNode in css (#13497)
This commit is contained in:
1 parent
398f8f0cc9
commit
6d551ab0ed
1 file changed
+2
-19
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user