Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hughsk/ast-parents
Walks a JavaScript AST and adds a "parent" property to each node
https://github.com/hughsk/ast-parents
Last synced: 12 days ago
JSON representation
Walks a JavaScript AST and adds a "parent" property to each node
- Host: GitHub
- URL: https://github.com/hughsk/ast-parents
- Owner: hughsk
- License: mit
- Created: 2014-02-04T09:03:47.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2014-02-04T09:16:37.000Z (almost 11 years ago)
- Last Synced: 2024-10-17T16:41:04.647Z (22 days ago)
- Language: JavaScript
- Size: 113 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# ast-parents [![Flattr this!](https://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=hughskennedy&url=http://github.com/hughsk/ast-parents&title=ast-parents&description=hughsk/ast-parents%20on%20GitHub&language=en_GB&tags=flattr,github,javascript&category=software)[![experimental](http://hughsk.github.io/stability-badges/dist/experimental.svg)](http://github.com/hughsk/stability-badges) #
Walks a JavaScript AST, such as one supplied via
[esprima](http://github.com/ariya/esprima), and adds a `parent`
property to each node.Makes it much easier to navigate the AST, and the `parent` properties
added here are non-enumerable so you can still serialize the tree to JSON
without `JSON.stringify` throwing an error.## Usage ##
[![ast-parents](https://nodei.co/npm/ast-parents.png?mini=true)](https://nodei.co/npm/ast-parents)
`require('ast-parents')(ast)`
Where `ast` is an AST object. For example:
``` javascript
var esprima = require('esprima')
var fs = require('fs')var src = fs.readFileSync(__filename, 'utf8')
var ast = esprima.parse(src)parents(ast)
ast.body[0].parent === ast.body
```## License ##
MIT. See [LICENSE.md](http://github.com/hughsk/ast-parents/blob/master/LICENSE.md) for details.