export function findNodeAtLocation()

in src/utils/astUtilityFunctions.ts [82:96]


export function findNodeAtLocation(rootNode: ASTNode, loc: number): ASTNode | undefined {
  if (isLocationInNodeRange(rootNode, loc)) {
    const { children } = rootNode

    if (children?.length) {
      const nodeInRange = children.find((node) => isLocationInNodeRange(node, loc))

      if (nodeInRange) {
        return findNodeAtLocation(nodeInRange, loc)
      }
    }

    return rootNode
  }
}