@babel/helper-wrap-function
Advanced tools
Comparing version 7.18.9 to 7.18.10
@@ -19,2 +19,3 @@ "use strict"; | ||
isAssignmentPattern, | ||
isFunctionDeclaration, | ||
isRestElement, | ||
@@ -62,19 +63,18 @@ returnStatement | ||
function plainFunction(path, callId, noNewArrows, ignoreFunctionLength) { | ||
const node = path.node; | ||
const isDeclaration = path.isFunctionDeclaration(); | ||
const functionId = node.id; | ||
const wrapper = isDeclaration ? buildDeclarationWrapper : functionId ? buildNamedExpressionWrapper : buildAnonymousExpressionWrapper; | ||
let functionId = null; | ||
let node; | ||
if (path.isArrowFunctionExpression()) { | ||
path.arrowFunctionToExpression({ | ||
path = path.arrowFunctionToExpression({ | ||
noNewArrows | ||
}); | ||
node = path.node; | ||
} else { | ||
node = path.node; | ||
} | ||
const isDeclaration = isFunctionDeclaration(node); | ||
functionId = node.id; | ||
node.id = null; | ||
if (isDeclaration) { | ||
node.type = "FunctionExpression"; | ||
} | ||
node.type = "FunctionExpression"; | ||
const built = callExpression(callId, [node]); | ||
@@ -91,3 +91,3 @@ const params = []; | ||
const container = wrapper({ | ||
const wrapperArgs = { | ||
NAME: functionId || null, | ||
@@ -97,19 +97,25 @@ REF: path.scope.generateUidIdentifier(functionId ? functionId.name : "ref"), | ||
PARAMS: params | ||
}); | ||
}; | ||
if (isDeclaration) { | ||
const container = buildDeclarationWrapper(wrapperArgs); | ||
path.replaceWith(container[0]); | ||
path.insertAfter(container[1]); | ||
} else { | ||
const retFunction = container.callee.body.body[1].argument; | ||
let container; | ||
if (!functionId) { | ||
if (functionId) { | ||
container = buildNamedExpressionWrapper(wrapperArgs); | ||
} else { | ||
container = buildAnonymousExpressionWrapper(wrapperArgs); | ||
const returnFn = container.callee.body.body[1].argument; | ||
(0, _helperFunctionName.default)({ | ||
node: retFunction, | ||
node: returnFn, | ||
parent: path.parent, | ||
scope: path.scope | ||
}); | ||
functionId = returnFn.id; | ||
} | ||
if (!retFunction || retFunction.id || !ignoreFunctionLength && params.length) { | ||
if (functionId || !ignoreFunctionLength && params.length) { | ||
path.replaceWith(container); | ||
@@ -116,0 +122,0 @@ } else { |
{ | ||
"name": "@babel/helper-wrap-function", | ||
"version": "7.18.9", | ||
"version": "7.18.10", | ||
"description": "Helper to wrap functions inside a function call.", | ||
@@ -18,5 +18,5 @@ "repository": { | ||
"@babel/helper-function-name": "^7.18.9", | ||
"@babel/template": "^7.18.6", | ||
"@babel/traverse": "^7.18.9", | ||
"@babel/types": "^7.18.9" | ||
"@babel/template": "^7.18.10", | ||
"@babel/traverse": "^7.18.10", | ||
"@babel/types": "^7.18.10" | ||
}, | ||
@@ -23,0 +23,0 @@ "engines": { |
5472
110
2
Updated@babel/template@^7.18.10
Updated@babel/traverse@^7.18.10
Updated@babel/types@^7.18.10