utils-parent.js 717 B

123456789101112131415161718192021
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.ancestorsChain = exports.findFirstMatchingAncestor = void 0;
  4. function findFirstMatchingAncestor(node, predicate) {
  5. return ancestorsChain(node, new Set()).find(predicate);
  6. }
  7. exports.findFirstMatchingAncestor = findFirstMatchingAncestor;
  8. function ancestorsChain(node, boundaryTypes) {
  9. const chain = [];
  10. let currentNode = node.parent;
  11. while (currentNode) {
  12. chain.push(currentNode);
  13. if (boundaryTypes.has(currentNode.type)) {
  14. break;
  15. }
  16. currentNode = currentNode.parent;
  17. }
  18. return chain;
  19. }
  20. exports.ancestorsChain = ancestorsChain;
  21. //# sourceMappingURL=utils-parent.js.map