JSPM

@babel/traverse

7.0.0-beta.43
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 65760667
  • Score
    100M100P100Q299200F
  • 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/path

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