Skip to main content

ASTWalker

ASTWalker - Provides a simple AST traversal utility that traverses all nodes / children regardless of type.

A callback object is provided in traverse which may contain two methods enterNode and exitNode which are invoked with the current node and the parent node respectively when entering and exiting a given node.

enterNode may return a array of strings which provide a set of children keys to ignore.

enterNode may also return null to skip traversing children keys entirely.

Index

Constructors

Methods

Constructors

constructor

Methods

traverse

  • traverse(ast: any, callbacks: any): void
  • Traverses the ast tree provided and invokes callbacks.enterNode / callbacks.exitNode


    Parameters

    • ast: any

      An AST Tree object hash or an array of nodes.

    • callbacks: any

      An object hash containing a function for enterNode and / or exitNode keys.

    Returns void