How to use the VariableDeclaration function from @babel/types

Find comprehensive JavaScript @babel/types.VariableDeclaration code examples handpicked from public code repositorys.

31
32
33
34
35
36
37
38
39
40
 *   variableDeclarationMethod('isWeex', true)
 *
 *   const isWeex = true;
 */
function variableDeclarationMethod(name, value) {
  return types.VariableDeclaration(
    'const', [
      types.variableDeclarator(
        types.Identifier(name),
        types.BooleanLiteral(value),
fork icon69
star icon100
watch icon15

+ 5 other calls in file

32
33
34
35
36
37
38
39
40
41
if(paramsList.length>0){
    paramsList.map(function (letname){
        if(t.isIdentifier(letname)){
            //定义一个变量,并添加到结构体中
            let varDec = t.VariableDeclarator(t.identifier(letname.name))//
            let localAST = t.VariableDeclaration('var', [varDec]);//
            node_exp.callee.body.body.unshift(localAST);//添加
        }
    })
}
fork icon40
star icon57
watch icon4

837
838
839
840
841
842
843
844
845
846

        var toInsert = opts.varNode;
        var node = toInsert.node;
        var index = toInsert.index;

        node.body.splice(index, 0, t.VariableDeclaration('var', varArray));
      }
    }
  }
},
fork icon27
star icon77
watch icon14

164
165
166
167
168
169
170
171
172
173
  return
}
const params = node.params ? node.params : node.value.params
if (node.value && node.value.type === 'ArrowFunctionExpression') {
  this.componentBody.push(
    t.VariableDeclaration('const', [
      t.VariableDeclarator(node.key, node.value)
    ])
  )
  return
fork icon8
star icon53
watch icon1

+ 5 other calls in file

73
74
75
76
77
78
79
80
81
82
let new_array = [];  // 创建用来存放node节点的数组
// 取出原本在列表中的node节点(splice会默认删除取出的内容)
let new_var = node.declarations.splice(1)
new_var.map(v => {
    // 创建节点
    let create_node = t.VariableDeclaration('var', [v])
    // 将节点添加到数组中去
    new_array.push(create_node)
})
// 将取出来的节点添加到指定位置
fork icon5
star icon14
watch icon1

+ 2 other calls in file

99
100
101
102
103
104
105
106
107
108

let newNodes = [];

for (const varNode of declarations)
{
   let newDeclartionNode = types.VariableDeclaration(kind,[varNode]);
   newNodes.push(newDeclartionNode);
}

path.replaceWithMultiple(newNodes);
fork icon0
star icon0
watch icon1

+ 74 other calls in file

Other functions in @babel/types

Sorted by popularity

function icon

@babel/types.identifier is the most popular function in @babel/types (20936 examples)