How to use the VariableDeclaration function from @babel/types
Find comprehensive JavaScript @babel/types.VariableDeclaration code examples handpicked from public code repositorys.
GitHub: raxjs/rax-app
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),
69
100
15
+ 5 other calls in file
GitHub: lk-li/spider_reverse
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);//添加 } }) }
40
57
4
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)); } } } },
27
77
14
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
8
53
1
+ 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) }) // 将取出来的节点添加到指定位置
5
14
1
+ 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);
0
0
1
+ 74 other calls in file
@babel/types.identifier is the most popular function in @babel/types (20936 examples)