JSPM

  • Created
  • Published
  • Downloads 3439661
  • Score
    100M100P100Q239667F
  • License MIT

The Babel Traverse module maintains the overall tree state, and is responsible for replacing, removing, and adding nodes

Package Exports

  • babel-traverse
  • babel-traverse/lib/scope/binding

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 (babel-traverse) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

babel-traverse

babel-traverse maintains the overall tree state, and is responsible for replacing, removing, and adding nodes.

Install

$ npm install --save babel-traverse

Usage

We can use it alongside Babylon to traverse and update nodes:

import * as babylon from "babylon";
import traverse from "babel-traverse";

const code = `function square(n) {
  return n * n;
}`;

const ast = babylon.parse(code);

traverse(ast, {
  enter(path) {
    if (path.isIdentifier({ name: "n" })) {
      path.node.name = "x";
    }
  }
});

📖 Read the full docs here