# @kristoferbaxter/estree-walker

> Traverse an ESTree-compliant AST

Latest version **2.0.2** (published 2020-04-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install @kristoferbaxter/estree-walker
pnpm add @kristoferbaxter/estree-walker
yarn add @kristoferbaxter/estree-walker
bun add @kristoferbaxter/estree-walker
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.2 |
| Published | 2020-04-21 |
| First published | 2020-01-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 28.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Rich Harris |
| Maintainers | kristoferbaxter |

## Links

- npm: https://www.npmjs.com/package/@kristoferbaxter/estree-walker
- Repository: https://github.com/kristoferbaxter/estree-walker
- npm.io page: https://npm.io/package/@kristoferbaxter/estree-walker

## Recent versions

- 2.0.2 (latest) — 2020-04-21
- 2.0.0 — 2020-01-28
- 1.1.0 — 2020-01-27
- 1.0.2 — 2020-01-24

## README

# 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.

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](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

---
_Source: https://npm.io/package/@kristoferbaxter/estree-walker · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
