| | |
| | | path.get("body.body.0.argument.callee.arguments.0").unwrapFunctionEnvironment(); |
| | | } |
| | | |
| | | function plainFunction(path, callId, noNewArrows) { |
| | | function plainFunction(path, callId, noNewArrows, ignoreFunctionLength) { |
| | | const node = path.node; |
| | | const isDeclaration = path.isFunctionDeclaration(); |
| | | const functionId = node.id; |
| | |
| | | } |
| | | |
| | | const built = callExpression(callId, [node]); |
| | | const params = []; |
| | | |
| | | for (const param of node.params) { |
| | | if (isAssignmentPattern(param) || isRestElement(param)) { |
| | | break; |
| | | } |
| | | |
| | | params.push(path.scope.generateUidIdentifier("x")); |
| | | } |
| | | |
| | | const container = wrapper({ |
| | | NAME: functionId || null, |
| | | REF: path.scope.generateUidIdentifier(functionId ? functionId.name : "ref"), |
| | | FUNCTION: built, |
| | | PARAMS: node.params.reduce((acc, param) => { |
| | | acc.done = acc.done || isAssignmentPattern(param) || isRestElement(param); |
| | | |
| | | if (!acc.done) { |
| | | acc.params.push(path.scope.generateUidIdentifier("x")); |
| | | } |
| | | |
| | | return acc; |
| | | }, { |
| | | params: [], |
| | | done: false |
| | | }).params |
| | | PARAMS: params |
| | | }); |
| | | |
| | | if (isDeclaration) { |
| | |
| | | }); |
| | | } |
| | | |
| | | if (!retFunction || retFunction.id || node.params.length) { |
| | | if (!retFunction || retFunction.id || !ignoreFunctionLength && params.length) { |
| | | path.replaceWith(container); |
| | | } else { |
| | | path.replaceWith(built); |
| | |
| | | } |
| | | } |
| | | |
| | | function wrapFunction(path, callId, noNewArrows = true) { |
| | | function wrapFunction(path, callId, noNewArrows = true, ignoreFunctionLength = false) { |
| | | if (path.isMethod()) { |
| | | classOrObjectMethod(path, callId); |
| | | } else { |
| | | plainFunction(path, callId, noNewArrows); |
| | | plainFunction(path, callId, noNewArrows, ignoreFunctionLength); |
| | | } |
| | | } |