Home Manual Reference Source Repository
import ASTWalker from 'typhonjs-ast-walker/src/ASTWalker.js'
public class | source

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.

Method Summary

Public Methods
public

traverse(ast: object | Array, callbacks: object)

Traverses the ast tree provided and invokes callbacks.enterNode / callbacks.exitNode

Public Methods

public traverse(ast: object | Array, callbacks: object) source

Traverses the ast tree provided and invokes callbacks.enterNode / callbacks.exitNode

Params:

NameTypeAttributeDescription
ast object | Array

An AST Tree object hash or an array of nodes.

callbacks object

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