sensordb2 e64a8defe5 3.17 1 year ago
..
bench e64a8defe5 3.17 1 year ago
test e64a8defe5 3.17 1 year ago
.travis.yml e64a8defe5 3.17 1 year ago
CHANGELOG.md e64a8defe5 3.17 1 year ago
LICENSE.md e64a8defe5 3.17 1 year ago
README.md e64a8defe5 3.17 1 year ago
index.js e64a8defe5 3.17 1 year ago
package.json e64a8defe5 3.17 1 year ago

README.md

dash-ast

walk an AST, quickly

npm travis standard

Install

npm install dash-ast

Usage

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.

dashAst.withParent(ast, callback)

Call callback(node) on each node in ast. This does a preorder traversal, i.e. callback receives child nodes after the parent node. Each node has an additional property node.parent referring to the parent node.

dashAst.withParent(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. Each node has an additional property node.parent referring to the parent node.

License

Apache-2.0