walk and transform ASTs with references to parent nodes
JavaScript
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
test
.travis.yml
LICENSE
README.md
index.js
package.json

README.md

visitor

walk and transform ASTs with references to parent nodes

browser support

build status

This module is heavily inspired by astw, falafel and acorn. It allows to walk and update ASTs providing references to parent nodes.

examples

var visit = require("visitor");
var assert = require("assert");

visit("var xs = [1, 2, 3];", {
  ArrayExpression: function (node) {
    assert.equal(node.source(), "[1, 2, 3]");
    assert.equal(node.parent.type, "VariableDeclarator");
    assert.equal(node.parent.parent.type, "VariableDeclaration");
  }
});
var visit = require("visitor");
var assert = require("assert");

var result = visit("1 + 2", {
  BinaryExpression: function (node) {
    if (node.operator === "+" &&
        node.left.type === "Literal" &&
        node.right.type === "Literal") {
      node.update(node.left.value + node.right.value);
    }
  }
});

assert(result === "3", "combined both sides of the expression");

install

With npm do:

npm install visitor

license

MIT