How to use the functionExpression function from @babel/types
Find comprehensive JavaScript @babel/types.functionExpression code examples handpicked from public code repositorys.
GitHub: qooxdoo/qooxdoo
1557 1558 1559 1560 1561 1562 1563 1564 1565
).program.body; inject.push(tmp[0]); let block = types.blockStatement(inject); let rootFn = types.expressionStatement( types.callExpression( types.functionExpression(null, [], block), [] ) );
257
758
0
+ 21 other calls in file
GitHub: egoist/styled-vue
179 180 181 182 183 184 185 186 187 188
} } if (vars.length > 0) { ref.replaceWith( t.functionExpression( null, [ t.identifier('vm'), !isGlobal && t.identifier('existing') // Global vars are handled differently
27
429
6
+ 15 other calls in file
GitHub: rickyes/node-mini
36 37 38 39 40 41 42 43 44
babelTypes.blockStatement([]))); } function wrapTryCatchInFunction(node) { const ret = wrapTryCatch(babelTypes.returnStatement(node)); const anonymousFun = babelTypes.functionExpression( null, [], babelTypes.blockStatement([ret])); return babelTypes.callExpression(anonymousFun, []); }
3
25
0
GitHub: ringcrl/cs-notes
60 61 62 63 64 65 66 67 68 69
let { body } = node; // 判断是不是 blockStatement,不是的话让他变成 blockStatement if (!t.isBlockStatement(body)) { body = t.blockStatement([body]); } const functionExpression = t.functionExpression(null, params, body); // 替换原来的函数 path.replaceWith(functionExpression); }, },
7
16
1
+ 11 other calls in file
319 320 321 322 323 324 325 326 327
let id = path.parent.id; let params = node.params; let body= types.blockStatement([ types.returnStatement(node.body) ]); let functionExpression = types.functionExpression(id,params,body,false,false); path.replaceWith(functionExpression); } })
3
14
7
+ 9 other calls in file
GitHub: tapaswenipathak/rax
54 55 56 57 58 59 60 61 62 63
if (replacer) { replacer.replaceWith( t.variableDeclaration('const', [ t.variableDeclarator( t.identifier(EXPORTED_DEF), t.functionExpression(id, params, body, generator, async) ) ]) ); }
663
0
1
+ 19 other calls in file
259 260 261 262 263 264 265 266 267 268
let body = node.body // 判断是不是 blockStatement,不是的话让他变成 blockStatement if (!t.isBlockStatement(body)) { body = t.blockStatement([body]) } const functionExpression = t.functionExpression(null, params, body) // 替换原来的函数 path.replaceWith(functionExpression) } ```
2
0
1
+ 103 other calls in file
GitHub: N0taN3rd/Emu
214 215 216 217 218 219 220 221
btypes.numericLiteral(0) ) } static setterOverride (sname, pi, rwcode) { return btypes.functionExpression( null, [pi],
1
1
2
+ 11 other calls in file
49 50 51 52 53 54 55 56 57 58
const program = t.program([ ...nodes, t.expressionStatement( t.callExpression( t.memberExpression( t.functionExpression(null, [], t.blockStatement(inner)), t.identifier("call") ), [t.identifier("module.exports")] )
0
1
1
+ 58 other calls in file
GitHub: haojy/weact
216 217 218 219 220 221
} else if (/created|attached|ready|moved|detached/.test(methodName)) { // Component life cycle fn. if (!isComponent()) return const fn = t.objectProperty( t.identifier(methodName), t.functionExpression(null, path.node.params, path.node.body, path.node.generator, path.node.async)
12
84
1
658 659 660 661 662 663 664 665 666 667 668
* @param {*} path * @returns */ function objectMethod2FunctionExpression (path) { if (!path) global.log("objectMethod2FunctionExpression 参数错误") return t.functionExpression(path.id, path.params, path.body) } /** * 获取components ast里面的props列表
221
0
0
+ 5 other calls in file
127 128 129 130 131 132 133 134 135 136
}) var me = t.memberExpression(t.thisExpression(), t.identifier(newFunName)) var callExp = t.callExpression(me, args) var expStatement = t.expressionStatement(callExp) var blockStatement = t.blockStatement([expStatement]) var funExp = t.functionExpression(null, args, blockStatement) onLoadFunNode.value = funExp } else if (t.isObjectMethod(onLoadFunNode)) { //onLoad(a){} var args = onLoadFunNode.params
221
0
0
GitHub: DWL716/plugin-all
51 52 53 54 55 56 57 58 59 60
} } }, MemberExpression: function (path, state) { if (isConsoleLog(path) && path.parentKey === 'init') { var myFun = t.functionExpression(null, [], t.blockStatement([])); path.replaceWith(myFun); } }, };
0
1
1
+ 35 other calls in file
64 65 66 67 68 69 70 71 72 73 74
function functionFromProgram( program, parameters) { return t.functionExpression( t.identifier(''), parameters.map(makeIdentifier), t.blockStatement(program.body, program.directives));
1
0
1
161 162 163 164 165 166 167 168 169 170
params[0] = t.identifier(p0.name); } const isArrow = t.isArrowFunctionExpression(fn); const fnExp = isArrow ? t.arrowFunctionExpression(params, fn.body, fn.async) : t.functionExpression(undefined, params, fn.body, fn.generator, fn.async); // fnExp.end = fn.end; fnExp.extra = fn.extra; fnExp.generator = fn.generator; // fnExp.innerComments = fn.innerComments;
0
0
1
+ 25 other calls in file
GitHub: saltires/saltire-lerna
133 134 135 136 137 138 139 140 141 142
); nodes.push(constructorFn); } else if (item.kind === 'method') { let prototypeMem = t.memberExpression(className, t.identifier('prototype')); let methodMem = t.memberExpression(prototypeMem, item.key); let memberFunction = t.functionExpression( item.key, item.params, item.body, item.generator,
0
0
1
44 45 46 47 48 49 50 51 52 53 54
`); function classOrObjectMethod(path, callId) { const node = path.node; const body = node.body; const container = t.functionExpression(null, [], t.blockStatement(body.body), true); body.body = [t.returnStatement(t.callExpression(t.callExpression(callId, [container]), []))]; node.async = false; node.generator = false; path.get("body.body.0.argument.callee.arguments.0").unwrapFunctionEnvironment();
0
0
0
15 16 17 18 19 20 21 22 23 24
let retSta2 = t.returnStatement(t.binaryExpression("+", binExpr2, t.numericLiteral(1000))); let retSta3 = t.returnStatement(t.binaryExpression("+", binExpr3, t.numericLiteral(1000))); let bloSta2 = t.blockStatement([retSta2]); let bloSta3 = t.blockStatement([retSta3]); let funcExpr2 = t.functionExpression(null, [a, b], bloSta2); let funcExpr3 = t.functionExpression(null, [a, b], bloSta3); let objProp1 = t.objectProperty(t.identifier('name'), t.stringLiteral('xiaojianbang')); let objProp2 = t.objectProperty(t.identifier('add'), funcExpr2); let objProp3 = t.objectProperty(t.identifier('mul'), funcExpr3); let objExpr = t.objectExpression([objProp1, objProp2, objProp3]);
0
0
0
GitHub: charoenlap/af1app
61 62 63 64 65 66 67 68 69 70
} if (t.isProperty(node)) { value = node.value; } else if (t.isObjectMethod(node) || t.isClassMethod(node)) { value = t.functionExpression(null, node.params, node.body, node.generator, node.async); value.returnType = node.returnType; } const inheritedKind = toKind(node);
0
0
0
@babel/types.identifier is the most popular function in @babel/types (20936 examples)