How to use the traverse function from @babel/core

Find comprehensive JavaScript @babel/core.traverse code examples handpicked from public code repositorys.

204
205
206
207
208
209
210
211
212
213
  // presets: ['@babel/preset-env', '@babel/preset-react'],
  // parserOpts: {
  // }
});

traverse(ast, updateVariable, undefined, [
  {
    ...ctx,
    path: null,
  },
fork icon6
star icon19
watch icon36

+ 11 other calls in file

97
98
99
100
101
102
103
104
105
106

if (!nodeHadRemoveTS.ast) {
  return;
}

babel.traverse(nodeHadRemoveTS.ast, {
  enter(p) {
    let value = "";

    if (p.isImportDeclaration()) {
fork icon3
star icon20
watch icon2

+ 5 other calls in file

12
13
14
15
16
17
18
19
20
21
22
23
24


    let returnState = ''




//输出所有定义的变量和对应的类型
    babel.traverse(ast, {
        enter(path) {
            if (path.node.type === "FunctionDeclaration" && path.node.id.name === "fuzzopt") {
                //方法内部
                let funcbody = path.node.body.body
fork icon0
star icon1
watch icon1

+ 11 other calls in file

115
116
117
118
119
120
121
122
123
124
125
126
127
      path.skipKey("body");
    }


  });


  const nestedVisitor = _core.traverse.visitors.merge([Object.assign({}, visitor), _helperEnvironmentVisitor.default]);


  return privateNameVisitor;
}

fork icon0
star icon0
watch icon1

+ 7 other calls in file

67
68
69
70
71
72
73
74
75

const setState = newState => {
  Object.assign(classState, newState);
};

const findThisesVisitor = _core.traverse.visitors.merge([_helperReplaceSupers.environmentVisitor, {
  ThisExpression(path) {
    classState.superThises.push(path);
  }
fork icon0
star icon0
watch icon1

+ 3 other calls in file