babel-traverse
The Babel Traverse module maintains the overall tree state, and is responsible for replacing, removing, and adding nodes
Last updated 8 years ago by hzoo .
MIT · Repository · Original npm
$ cnpm install babel-traverse 
SYNC missed versions from official npm registry.

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";
    }
  }
});

:book: Read the full docs here

Current Tags

  • 6.26.0                                ...           latest (8 years ago)
  • 7.0.0-beta.3                                ...           next (8 years ago)

5 Versions

  • 7.0.0-beta.1                                ...           8 years ago
  • 7.0.0-alpha.16                                ...           8 years ago
  • 7.0.0-beta.3                                ...           8 years ago
  • 6.10.4                                ...           9 years ago
  • 6.26.0                                ...           8 years ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (9)
Dev Dependencies (1)
Dependents (0)
None

Copyright 2013 - present © cnpmjs.org