项目原始demo,不改动
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
此仓库已存档。您可以查看文件和克隆,但不能推送或创建工单/合并请求。

123456789101112131415161718192021222324252627282930313233
  1. # babel-traverse
  2. > babel-traverse maintains the overall tree state, and is responsible for replacing, removing, and adding nodes.
  3. ## Install
  4. ```sh
  5. $ npm install --save babel-traverse
  6. ```
  7. ## Usage
  8. We can use it alongside Babylon to traverse and update nodes:
  9. ```js
  10. import * as babylon from "babylon";
  11. import traverse from "babel-traverse";
  12. const code = `function square(n) {
  13. return n * n;
  14. }`;
  15. const ast = babylon.parse(code);
  16. traverse(ast, {
  17. enter(path) {
  18. if (path.isIdentifier({ name: "n" })) {
  19. path.node.name = "x";
  20. }
  21. }
  22. });
  23. ```
  24. [:book: **Read the full docs here**](https://github.com/thejameskyle/babel-handbook/blob/master/translations/en/plugin-handbook.md#babel-traverse)