Big update!Introducing GitHub Bot Commands. Learn more
Socket
Log inBook a demo

estree-walker

Package Overview
Dependencies
0
Maintainers
1
Versions
25
Issues
File Explorer

Advanced tools

estree-walker

Traverse an ESTree-compliant AST

    3.0.1latest

Version published
Maintainers
1
Weekly downloads
13,805,718
decreased by-12.15%

Weekly downloads

Changelog

Source

3.0.1

  • Add package.json to exports

Readme

Source

estree-walker

Simple utility for walking an ESTree-compliant AST, such as one generated by acorn.

Installation

npm i estree-walker

Usage

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.

Why not use estraverse?

The ESTree spec is evolving to accommodate ES6/7. I've had a couple of experiences where estraverse was unable to handle an AST generated by recent versions of acorn, because it hard-codes visitor keys.

estree-walker, by contrast, simply enumerates a node's properties to find child nodes (and child lists of nodes), and is therefore resistant to spec changes. It's also much smaller. (The performance, if you're wondering, is basically identical.)

None of which should be taken as criticism of estraverse, which has more features and has been battle-tested in many more situations, and for which I'm very grateful.

License

MIT

FAQs

What is estree-walker?

Traverse an ESTree-compliant AST

Is estree-walker popular?

The npm package estree-walker receives a total of 11,048,891 weekly downloads. As such, estree-walker popularity was classified as popular.

Is estree-walker well maintained?

We found that estree-walker demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.It has 1 open source maintainer collaborating on the project.

Last updated on 20 Dec 2021

Did you know?

Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install Socket
Socket

Product

Subscribe to our newsletter

Get open source security insights delivered straight into your inbox. Be the first to learn about new features and product updates.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc