Traverse an ESTree-compliant AST
npm install @timeax/estree-walkerbash
npm i estree-walker
`
Usage
`js
var walk = require('estree-walker').walk;
var acorn = require('acorn');
ast = acorn.parse(sourceCode, options); // https://github.com/acornjs/acorn
walk(ast, {
enter(node, parent, prop, index) {
// some code happens
},
leave(node, parent, prop, index) {
// some code happens
}
});
`
Inside the enter function, calling this.skip() will prevent the node's children being walked, or the leave function (which is optional) being called.
Call this.replace(new_node) in either enter or leave to replace the current node with a new one.
Call this.remove() in either enter or leave` to remove the current node.