@babel/helper-member-expression-to-functions
Advanced tools
Comparing version 7.18.9 to 7.20.7
122
lib/index.js
@@ -33,3 +33,2 @@ 'use strict'; | ||
} = maybeWrapped; | ||
if (parentPath.isLogicalExpression()) { | ||
@@ -40,3 +39,2 @@ const { | ||
} = parentPath.node; | ||
if (operator === "&&" || operator === "||" || operator === "??" && node === right) { | ||
@@ -46,3 +44,2 @@ return willPathCastToBoolean(parentPath); | ||
} | ||
if (parentPath.isSequenceExpression()) { | ||
@@ -52,3 +49,2 @@ const { | ||
} = parentPath.node; | ||
if (expressions[expressions.length - 1] === node) { | ||
@@ -60,3 +56,2 @@ return willPathCastToBoolean(parentPath); | ||
} | ||
return parentPath.isConditional({ | ||
@@ -93,3 +88,2 @@ test: node | ||
} = _t__namespace; | ||
class AssignmentMemoiser { | ||
@@ -100,12 +94,8 @@ constructor() { | ||
} | ||
has(key) { | ||
return this._map.has(key); | ||
} | ||
get(key) { | ||
if (!this.has(key)) return; | ||
const record = this._map.get(key); | ||
const { | ||
@@ -115,10 +105,7 @@ value | ||
record.count--; | ||
if (record.count === 0) { | ||
return assignmentExpression("=", value, key); | ||
} | ||
return value; | ||
} | ||
set(key, value, count) { | ||
@@ -130,5 +117,3 @@ return this._map.set(key, { | ||
} | ||
} | ||
function toNonOptional(path, base) { | ||
@@ -138,10 +123,7 @@ const { | ||
} = path; | ||
if (isOptionalMemberExpression(node)) { | ||
return memberExpression(base, node.property, node.computed); | ||
} | ||
if (path.isOptionalCallExpression()) { | ||
const callee = path.get("callee"); | ||
if (path.node.optional && callee.isOptionalMemberExpression()) { | ||
@@ -153,6 +135,4 @@ const object = callee.node.object; | ||
} | ||
return callExpression(base, path.node.arguments); | ||
} | ||
return path.node; | ||
@@ -170,5 +150,5 @@ } | ||
const parentNode = parentPath.node; | ||
if (listKey) { | ||
if (container !== parentNode[listKey]) { | ||
if (container !== | ||
parentNode[listKey]) { | ||
return true; | ||
@@ -179,11 +159,9 @@ } | ||
} | ||
path = parentPath; | ||
} | ||
return false; | ||
} | ||
const handle = { | ||
memoise() {}, | ||
memoise() { | ||
}, | ||
@@ -197,5 +175,5 @@ handle(member, noDocumentAll) { | ||
} = member; | ||
if (member.isOptionalMemberExpression()) { | ||
if (isInDetachedTree(member)) return; | ||
const endPath = member.find(({ | ||
@@ -208,7 +186,7 @@ node, | ||
} | ||
if (isOptionalCallExpression(parent)) { | ||
return node !== member.node && parent.optional || parent.callee !== node; | ||
return ( | ||
node !== member.node && parent.optional || parent.callee !== node | ||
); | ||
} | ||
return true; | ||
@@ -218,9 +196,8 @@ }); | ||
if (scope.path.isPattern()) { | ||
endPath.replaceWith(callExpression(arrowFunctionExpression([], endPath.node), [])); | ||
endPath.replaceWith( | ||
callExpression(arrowFunctionExpression([], endPath.node), [])); | ||
return; | ||
} | ||
const willEndPathCastToBoolean = willPathCastToBoolean(endPath); | ||
const rootParentPath = endPath.parentPath; | ||
if (rootParentPath.isUpdateExpression({ | ||
@@ -233,7 +210,5 @@ argument: node | ||
} | ||
const isDeleteOperation = rootParentPath.isUnaryExpression({ | ||
operator: "delete" | ||
}); | ||
if (isDeleteOperation && endPath.isOptionalMemberExpression() && endPath.get("property").isPrivateName()) { | ||
@@ -244,3 +219,2 @@ throw member.buildCodeFrameError(`can't delete a private class element`); | ||
let startingOptional = member; | ||
for (;;) { | ||
@@ -256,15 +230,15 @@ if (startingOptional.isOptionalMemberExpression()) { | ||
} | ||
throw new Error(`Internal error: unexpected ${startingOptional.node.type}`); | ||
} | ||
const startingNode = startingOptional.isOptionalMemberExpression() ? startingOptional.node.object : startingOptional.node.callee; | ||
const startingNode = startingOptional.isOptionalMemberExpression() ? | ||
startingOptional.node.object : | ||
startingOptional.node.callee; | ||
const baseNeedsMemoised = scope.maybeGenerateMemoised(startingNode); | ||
const baseRef = baseNeedsMemoised != null ? baseNeedsMemoised : startingNode; | ||
const parentIsOptionalCall = parentPath.isOptionalCallExpression({ | ||
callee: node | ||
}); | ||
const isOptionalCall = parent => parentIsOptionalCall; | ||
const parentIsCall = parentPath.isCallExpression({ | ||
@@ -274,3 +248,2 @@ callee: node | ||
startingOptional.replaceWith(toNonOptional(startingOptional, baseRef)); | ||
if (isOptionalCall()) { | ||
@@ -284,11 +257,12 @@ if (parent.optional) { | ||
member.replaceWith(this.boundGet(member)); | ||
} else if (this.delete && parentPath.isUnaryExpression({ | ||
operator: "delete" | ||
})) { | ||
parentPath.replaceWith(this.delete(member)); | ||
} else { | ||
member.replaceWith(this.get(member)); | ||
} | ||
let regular = member.node; | ||
for (let current = member; current !== endPath;) { | ||
const parentPath = current.parentPath; | ||
if (parentPath === endPath && isOptionalCall() && parent.optional) { | ||
@@ -298,10 +272,7 @@ regular = parentPath.node; | ||
} | ||
regular = toNonOptional(parentPath, regular); | ||
current = parentPath; | ||
} | ||
let context; | ||
const endParentPath = endPath.parentPath; | ||
if (isMemberExpression(regular) && endParentPath.isOptionalCallExpression({ | ||
@@ -315,10 +286,8 @@ callee: endPath.node, | ||
context = member.scope.maybeGenerateMemoised(object); | ||
if (context) { | ||
regular.object = assignmentExpression("=", context, object); | ||
regular.object = assignmentExpression("=", context, | ||
object); | ||
} | ||
} | ||
let replacementPath = endPath; | ||
if (isDeleteOperation) { | ||
@@ -328,8 +297,6 @@ replacementPath = endParentPath; | ||
} | ||
const baseMemoised = baseNeedsMemoised ? assignmentExpression("=", cloneNode(baseRef), cloneNode(startingNode)) : cloneNode(baseRef); | ||
const baseMemoised = baseNeedsMemoised ? assignmentExpression("=", | ||
cloneNode(baseRef), cloneNode(startingNode)) : cloneNode(baseRef); | ||
if (willEndPathCastToBoolean) { | ||
let nonNullishCheck; | ||
if (noDocumentAll) { | ||
@@ -340,7 +307,5 @@ nonNullishCheck = binaryExpression("!=", baseMemoised, nullLiteral()); | ||
} | ||
replacementPath.replaceWith(logicalExpression("&&", nonNullishCheck, regular)); | ||
} else { | ||
let nullishCheck; | ||
if (noDocumentAll) { | ||
@@ -351,3 +316,2 @@ nullishCheck = binaryExpression("==", baseMemoised, nullLiteral()); | ||
} | ||
replacementPath.replaceWith(conditionalExpression(nullishCheck, isDeleteOperation ? booleanLiteral(true) : scope.buildUndefinedNode(), regular)); | ||
@@ -360,3 +324,2 @@ } | ||
} | ||
return; | ||
@@ -372,3 +335,2 @@ } | ||
} | ||
const { | ||
@@ -378,2 +340,3 @@ operator, | ||
} = parent; | ||
this.memoise(member, 2); | ||
@@ -384,6 +347,7 @@ const ref = scope.generateUidIdentifierBasedOnNode(node); | ||
}); | ||
const seq = [assignmentExpression("=", cloneNode(ref), this.get(member))]; | ||
const seq = [ | ||
assignmentExpression("=", cloneNode(ref), this.get(member))]; | ||
if (prefix) { | ||
seq.push(updateExpression(operator, cloneNode(ref), prefix)); | ||
const value = sequenceExpression(seq); | ||
@@ -398,2 +362,3 @@ parentPath.replaceWith(this.set(member, value)); | ||
seq.push(assignmentExpression("=", cloneNode(ref2), updateExpression(operator, cloneNode(ref), prefix)), cloneNode(ref)); | ||
const value = sequenceExpression(seq); | ||
@@ -412,3 +377,2 @@ parentPath.replaceWith(sequenceExpression([this.set(member, value), cloneNode(ref2)])); | ||
} | ||
const { | ||
@@ -418,3 +382,2 @@ operator, | ||
} = parentPath.node; | ||
if (operator === "=") { | ||
@@ -424,3 +387,2 @@ parentPath.replaceWith(this.set(member, value)); | ||
const operatorTrunc = operator.slice(0, -1); | ||
if (LOGICAL_OPERATORS.includes(operatorTrunc)) { | ||
@@ -434,3 +396,2 @@ this.memoise(member, 1); | ||
} | ||
return; | ||
@@ -450,6 +411,6 @@ } | ||
if (scope.path.isPattern()) { | ||
parentPath.replaceWith(callExpression(arrowFunctionExpression([], parentPath.node), [])); | ||
parentPath.replaceWith( | ||
callExpression(arrowFunctionExpression([], parentPath.node), [])); | ||
return; | ||
} | ||
parentPath.replaceWith(this.optionalCall(member, parentPath.node.arguments)); | ||
@@ -459,17 +420,29 @@ return; | ||
if (parentPath.isForXStatement({ | ||
if (this.delete && parentPath.isUnaryExpression({ | ||
operator: "delete" | ||
})) { | ||
parentPath.replaceWith(this.delete(member)); | ||
return; | ||
} | ||
if ( | ||
parentPath.isForXStatement({ | ||
left: node | ||
}) || parentPath.isObjectProperty({ | ||
}) || | ||
parentPath.isObjectProperty({ | ||
value: node | ||
}) && parentPath.parentPath.isObjectPattern() || parentPath.isAssignmentPattern({ | ||
}) && parentPath.parentPath.isObjectPattern() || | ||
parentPath.isAssignmentPattern({ | ||
left: node | ||
}) && parentPath.parentPath.isObjectProperty({ | ||
value: parent | ||
}) && parentPath.parentPath.parentPath.isObjectPattern() || parentPath.isArrayPattern() || parentPath.isAssignmentPattern({ | ||
}) && parentPath.parentPath.parentPath.isObjectPattern() || | ||
parentPath.isArrayPattern() || | ||
parentPath.isAssignmentPattern({ | ||
left: node | ||
}) && parentPath.parentPath.isArrayPattern() || parentPath.isRestElement()) { | ||
}) && parentPath.parentPath.isArrayPattern() || | ||
parentPath.isRestElement()) { | ||
member.replaceWith(this.destructureSet(member)); | ||
return; | ||
} | ||
if (parentPath.isTaggedTemplateExpression()) { | ||
@@ -481,3 +454,2 @@ member.replaceWith(this.boundGet(member)); | ||
} | ||
}; | ||
@@ -484,0 +456,0 @@ function memberExpressionToFunctions(path, visitor, state) { |
{ | ||
"name": "@babel/helper-member-expression-to-functions", | ||
"version": "7.18.9", | ||
"version": "7.20.7", | ||
"description": "Helper function to replace certain member expressions with function calls", | ||
@@ -18,6 +18,6 @@ "repository": { | ||
"dependencies": { | ||
"@babel/types": "^7.18.9" | ||
"@babel/types": "^7.20.7" | ||
}, | ||
"devDependencies": { | ||
"@babel/traverse": "^7.18.9" | ||
"@babel/traverse": "^7.20.7" | ||
}, | ||
@@ -24,0 +24,0 @@ "engines": { |
Sorry, the diff of this file is not supported yet
54314
401
Updated@babel/types@^7.20.7