getNearestAncestor.js 203 B

12345678910
  1. module.exports = function getNearestAncestor(node, type) {
  2. let temp = node.parent;
  3. while (temp) {
  4. if (temp.type === type) {
  5. return temp;
  6. }
  7. temp = temp.parent;
  8. }
  9. return temp;
  10. };