Sha256: 10d126161dfcbc89fd3d154e2f1f5e01220adc8886c8e29e0f02a74ac89951dd

Contents?: true

Size: 1.41 KB

Versions: 10

Compression:

Stored size: 1.41 KB

Contents

# estree-walker

Simple utility for walking an [ESTree](https://github.com/estree/estree)-compliant AST, such as one generated by [acorn](https://github.com/marijnh/acorn).


## Installation

```bash
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: function ( node, parent, prop, index ) {
    // some code happens
  },
  leave: function ( 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.


## Why not use estraverse?

The ESTree spec is evolving to accommodate ES6/7. I've had a couple of experiences where [estraverse](https://github.com/estools/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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
condenser-0.3 lib/condenser/processors/node_modules/estree-walker/README.md
condenser-0.2 lib/condenser/processors/node_modules/estree-walker/README.md
condenser-0.1 lib/condenser/processors/node_modules/estree-walker/README.md
condenser-0.0.12 lib/condenser/processors/node_modules/estree-walker/README.md
condenser-0.0.11 lib/condenser/processors/node_modules/estree-walker/README.md
condenser-0.0.10 lib/condenser/processors/node_modules/estree-walker/README.md
condenser-0.0.9 lib/condenser/processors/node_modules/estree-walker/README.md
condenser-0.0.8 lib/condenser/processors/node_modules/estree-walker/README.md
condenser-0.0.7 lib/condenser/processors/node_modules/estree-walker/README.md
condenser-0.0.5 lib/condenser/processors/node_modules/estree-walker/README.md