JSPM

ast-parents

0.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 149546
  • Score
    100M100P100Q165997F
  • License MIT

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

Package Exports

  • ast-parents

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ast-parents) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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.