Walks a JavaScript AST and adds a "parent" property to each node


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.


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)
ast.body[0].parent === ast.body

MIT. See for details.