eslint-codemod-utils
Version:
A collection of AST helper functions for more complex ESLint rule fixes.
19 lines (18 loc) • 566 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.closestOfType = void 0;
const is_node_of_type_1 = require("./is-node-of-type");
/**
* Traverses the node's parents until the specified `type` is found. If no `type` is found
* in the traversal it will return `null`.
*/
function closestOfType(node, type) {
if ((0, is_node_of_type_1.isNodeOfType)(node, type)) {
return node;
}
if (node.parent) {
return closestOfType(node.parent, type);
}
return null;
}
exports.closestOfType = closestOfType;