ast-parents
Walks a JavaScript AST and adds a "parent" property to each node
Last updated 13 years ago by hughsk .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install ast-parents 
SYNC missed versions from official npm registry.

ast-parents Flattr this!experimental

Walks a JavaScript AST, such as one supplied via 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

require('ast-parents')(ast)

Where ast is an AST object. For example:

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 for details.

Current Tags

  • 0.0.1                                ...           latest (13 years ago)

2 Versions

  • 0.0.1                                ...           13 years ago
  • 0.0.0                                ...           13 years ago
Maintainers (1)
Downloads
Total 13
Today 0
This Week 7
This Month 11
Last Day 0
Last Week 0
Last Month 1
Dependencies (0)
None
Dev Dependencies (0)
None
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE