UNPKG

eslint-codemod-utils

Version:

A collection of AST helper functions for more complex ESLint rule fixes.

15 lines (14 loc) 396 B
import { isNodeOfType } from './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`. */ export function closestOfType(node, type) { if (isNodeOfType(node, type)) { return node; } if (node.parent) { return closestOfType(node.parent, type); } return null; }