eslint-plugin-sonarjs
Version:
SonarJS rules for ESLint
21 lines (20 loc) • 677 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ancestorsChain = exports.findFirstMatchingAncestor = void 0;
function findFirstMatchingAncestor(node, predicate) {
return ancestorsChain(node, new Set()).find(predicate);
}
exports.findFirstMatchingAncestor = findFirstMatchingAncestor;
function ancestorsChain(node, boundaryTypes) {
const chain = [];
let currentNode = node.parent;
while (currentNode) {
chain.push(currentNode);
if (boundaryTypes.has(currentNode.type)) {
break;
}
currentNode = currentNode.parent;
}
return chain;
}
exports.ancestorsChain = ancestorsChain;