Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/goto-bus-stop/dash-ast
walk an AST, quickly
https://github.com/goto-bus-stop/dash-ast
ast estree javascript tree-walker
Last synced: 13 days ago
JSON representation
walk an AST, quickly
- Host: GitHub
- URL: https://github.com/goto-bus-stop/dash-ast
- Owner: goto-bus-stop
- License: other
- Created: 2018-05-30T13:40:25.000Z (over 6 years ago)
- Default Branch: default
- Last Pushed: 2024-10-17T04:59:47.000Z (27 days ago)
- Last Synced: 2024-10-24T16:23:02.534Z (20 days ago)
- Topics: ast, estree, javascript, tree-walker
- Language: JavaScript
- Size: 33.2 KB
- Stars: 12
- Watchers: 2
- Forks: 2
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# dash-ast
walk an AST, quickly
[![npm][npm-image]][npm-url]
[![travis][travis-image]][travis-url]
[![standard][standard-image]][standard-url][npm-image]: https://img.shields.io/npm/v/dash-ast.svg?style=flat-square
[npm-url]: https://www.npmjs.com/package/dash-ast
[travis-image]: https://img.shields.io/travis/goto-bus-stop/dash-ast.svg?style=flat-square
[travis-url]: https://travis-ci.org/goto-bus-stop/dash-ast
[standard-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square
[standard-url]: http://npm.im/standard## Install
```
npm install dash-ast
```## Usage
```js
var dashAst = require('dash-ast')
var isIdentifier = require('estree-is-identifier')var deps = []
dashAst(ast, function (node, parent) {
if (node.type === 'CallExpression' && isIdentifier(node.callee, 'require')) {
deps.push(node.arguments[0])
}
})
```## API
### `dashAst(ast, callback)`
Call `callback(node, parent)` on each node in `ast`. This does a preorder traversal, i.e. `callback` receives child nodes _after_ the parent node.
### `dashAst(ast, { enter, leave })`
Call `enter(node, parent)` on each node in `ast` before traversing its children, and call `leave(enter, parent)` on each node _after_ traversing its children. If a node does not have children, `enter()` and `leave()` are called immediately after each other.
## License
[Apache-2.0](LICENSE.md)