diff --git a/src/language-css/utils/index.js b/src/language-css/utils/index.js index 40dfae2cf..aca98c0ce 100644 --- a/src/language-css/utils/index.js +++ b/src/language-css/utils/index.js @@ -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,