How to use the functionExpression function from babel-types
Find comprehensive JavaScript babel-types.functionExpression code examples handpicked from public code repositorys.
40 41 42 43 44 45 46 47 48 49
}else{ // 替他情况就是原型上的方法 let protoObj = t.memberExpression(className,t.identifier('prototype')); let left = t.memberExpression(protoObj,t.identifier(item.key.name)); let right = t.functionExpression(null,[],body,false,false); let assign = t.assignmentExpression('=',left,right); // 多个原型上的方法 es5Func.push(assign); }
57
56
4
+ 3 other calls in file
24 25 26 27 28 29 30 31 32 33
if(!t.isBlockStatement(body)){ // 不是代码块 let returnStatement = t.returnStatement(body); body = t.blockStatement([returnStatement]); } let funcs = t.functionExpression(null,params,body,false,false); path.replaceWith(funcs); } } }
57
56
4
+ 9 other calls in file
GitHub: mpvue/mpvue-loader
91 92 93 94 95 96 97 98 99 100
if (path.node.declarations && t.isVariableDeclarator(path.node.declarations[0]) && t.isNewExpression(path.node.declarations[0].init) && t.isIdentifier(path.node.declarations[0].init.callee, { name: 'Vue' }) ) { const fnExpression = t.functionExpression( null, [], t.blockStatement( [
49
47
12
+ 43 other calls in file
GitHub: liangklfangl/webpack-core-usage
176 177 178 179 180 181 182 183 184 185
const astProgramBody = codeAst.program.body; const codeBlock = types.BlockStatement(astProgramBody); if (renderReturn) { astProgramBody.push(renderReturn); } const coceFunction = types.functionExpression( types.Identifier('jsonmlReactLoader'), [], ); path.replaceWith(coceFunction);
11
102
3
+ 19 other calls in file
9 10 11 12 13 14 15 16 17 18
let { node } = path; let body = node.body; let params = node.params; let r = t.functionExpression(null, params, body, false, false); path.replaceWith(r); } } }
12
27
1
+ 11 other calls in file
273 274 275 276 277 278 279 280 281
let func = null; // 区分是函数申明还是函数表达式 if (types.isFunctionDeclaration(node)) { func = types.functionDeclaration(node.id, node.params, types.BlockStatement([tryStatement]), node.generator, node.async); } else { func = types.functionExpression(node.id, node.params, types.BlockStatement([tryStatement]), node.generator, node.async); } path.replaceWith(func); ```
6
14
2
+ 23 other calls in file
7 8 9 10 11 12 13 14 15
ArrowFunctionExpression(path){ let params = path.node.params; let blockStatement = types.blockStatement([ types.returnStatement(path.node.body) ]); let func = types.functionExpression(null, params, blockStatement, false, false); path.replaceWith(func); } }
6
12
2
272 273 274 275 276 277 278 279 280 281
if (method.kind == 'constructor') { constructorFunction = t.functionDeclaration(id,method.params,method.body,false,false); functions.push(constructorFunction); } else { let memberObj=t.memberExpression(t.memberExpression(id,t.identifier('prototype')),method.key); let memberFunction = t.functionExpression(id,method.params,method.body,false,false); let assignment = t.assignmentExpression('=',memberObj,memberFunction); functions.push(assignment); } });
6
12
2
+ 35 other calls in file
20 21 22 23 24 25 26 27 28 29
'var', [ t.variableDeclarator( t.identifier(className), t.callExpression( t.functionExpression( null, [], body ),
0
45
2
+ 8 other calls in file
181 182 183 184 185 186 187 188 189 190
ArrowFunctionExpression(path) { // 在visitor中拦截箭头函数 let params = path.node.params // 获取函数参数 const returnStatement = types.returnStatement(path.node.body) //构建一个return表达式 const blockStatement = types.blockStatement([returnStatement]) // 构建一个blockStatement // babel-types的functionExpression构造成一个新的ES function语法的函数 let func = types.functionExpression(null, params, blockStatement, false, false) //替换当前箭头函数节点 path.replaceWith(func) }, VariableDeclaration(path) { // 在visitor中变量声明
4
12
0
+ 21 other calls in file
GitHub: Zenquan/babel-plugin-import
249 250 251 252 253 254 255 256 257 258
funs = t.functionDeclaration(className, [params], body, false, false); path.replaceWith(funs); }else { let protoObj = t.memberExpression(className, t.identifier('prototype')); let left = t.memberExpression(protoObj, t.identifier(item.key.name)); let right = t.functionExpression(null, [], body, false, false); let assign = t.assignmentExpression('=', left, right); es5func.push(assign); }
1
9
1
+ 65 other calls in file
GitHub: liangklfangl/wcf
76 77 78 79 80 81 82 83 84 85
// ReactDOM.render always at the last of preview method if (renderReturn) { astProgramBody.push(renderReturn); } //program.body is an array, so we can push returnStatement to the end of array var coceFunction = types.functionExpression(types.Identifier('jsonmlReactLoader'), //here is an Identifier of function [], codeBlock //Even though `import` or 'ReactDOM.render' are removed, but // <program><codeBlock></codeBlock><returnStatement><returnStatement/></program>
8
15
2
+ 5 other calls in file
43 44 45 46 47 48 49 50 51 52
body = node.body, container; node.async = false; container = t.functionExpression(null, [], t.blockStatement(body.body), true); container.shadow = true; body.body = [t.returnStatement(t.callExpression(t.callExpression(callId, [container]), []))]; }
0
2
1
+ 11 other calls in file
204 205 206 207 208 209 210 211 212 213
// Examples const intoExampleFunction = (source, ast, options) => { const body = ast.program.body; return new Raw(withMeta({ OBJECT: t.functionExpression( null, // id [], // params t.blockStatement(body), false, // generator
111
0
2
+ 11 other calls in file
149 150 151 152 153 154 155 156 157 158
const key = c.KEY_I(branch.iterSuffix); const iter = t.callExpression(c.ITER, [ Guard(branch.subject.path), t.functionExpression(c.EACH, [ key, c.INDEX, c.LENGTH, ], t.blockStatement([
17
0
5
GitHub: corner1990/dream
20 21 22 23 24 25 26 27 28 29
// console.log(path) let params = path.node.params let body = types.blockStatement([ types.returnStatement(path.node.body) ]) let fn = types.functionExpression(null, params, body, false, false) path.replaceWith(fn) } } let arrayPlugin = { visitor }
7
6
3
83 84 85 86 87 88 89 90 91 92
// ReactDOM.render always at the last of preview method if (renderReturn) { astProgramBody.push(renderReturn); } const coceFunction = types.functionExpression(null, [], codeBlock); path.replaceWith(coceFunction); } }, });
6
0
2
+ 4 other calls in file
GitHub: JX-Zhuang/architect
21 22 23 24 25 26 27 28 29 30
// console.log(body) // const statement = types.returnStatement(body.body); // console.log(statement) const block = types.BlockStatement([body.body]); // console.log(block) func = types.functionExpression(id, body.params, block, false, false); } }); path.replaceWith(func); }
2
6
2
+ 3 other calls in file
GitHub: krasimir/cssx
162 163 164 165 166 167 168 169 170 171
} createSelfInvoke = function (expr) { return t.parenthesizedExpression(expr); }; // wrapping up the self-invoke function funcExpr = t.functionExpression(null, [], t.blockStatement(funcLines)); funcCallExpr = t.callExpression( t.memberExpression(funcExpr, t.identifier('apply')), [t.thisExpression()] );
47
0
36
23 24 25 26 27 28 29 30 31 32
// 不是代码块,兼容箭头函数的问题 简写模式 let returnStatement =t.returnStatement(body) // 创造return代码块 body = t.blockStatement([returnStatement]) // } // 生成一个普通函数表达式 let funcs = t.functionExpression(null,params,body,false,false) path.replaceWith(funcs) } } }
4
2
0
babel-types.identifier is the most popular function in babel-types (4076 examples)