Fetches a node or an array of nodes from a root node or an array of root nodes by following the segments of a path. Returns null if the target could not be found.

import { walkPath, VariableName } from "estree-sentry";
// returns: { type: 'Identifier', name: 'x' }
walkPath(["left", "argument"], {
type: "LogicalExpression",
operator: "&&",
left: {
type: "UnaryExpression",
prefix: true,
operator: "!",
argument: {
type: "Identifier",
name: "x" as VariableName,
},
},
right: {
type: "Identifier",
name:"y" as VariableName,
},
});
  • Type Parameters

    • A

      Annotation type

    Parameters

    • segments: Segment[]

      An array of segments which can be produced by splitPath.

    • root: Node<A> | Node<A>[]

      The root node or an array of root nodes from which to start walking the path.

    Returns null | Node<A> | Node<A>[]

    The target node or an array of target nodes if found, otherwise null.