@babel/plugin-proposal-optional-chaining
Advanced tools
Comparing version 7.10.1 to 7.10.3
@@ -32,10 +32,17 @@ "use strict"; | ||
const { | ||
parentPath, | ||
scope | ||
} = path; | ||
let maybeParenthesized = path; | ||
const parentPath = path.findParent(p => { | ||
if (!p.isParenthesizedExpression()) return true; | ||
maybeParenthesized = p; | ||
}); | ||
let isDeleteOperation = false; | ||
const parentIsCall = parentPath.isCallExpression({ | ||
callee: maybeParenthesized.node | ||
}) && path.isOptionalMemberExpression(); | ||
const optionals = []; | ||
let optionalPath = path; | ||
while (optionalPath.isOptionalMemberExpression() || optionalPath.isOptionalCallExpression()) { | ||
while (optionalPath.isOptionalMemberExpression() || optionalPath.isOptionalCallExpression() || optionalPath.isParenthesizedExpression() || optionalPath.isTSNonNullExpression()) { | ||
const { | ||
@@ -55,5 +62,3 @@ node | ||
optionalPath = optionalPath.get("callee"); | ||
} | ||
if (optionalPath.isTSNonNullExpression()) { | ||
} else { | ||
optionalPath = optionalPath.get("expression"); | ||
@@ -117,3 +122,24 @@ } | ||
replacementPath.replaceWith(_core.types.conditionalExpression(loose ? _core.types.binaryExpression("==", _core.types.cloneNode(check), _core.types.nullLiteral()) : _core.types.logicalExpression("||", _core.types.binaryExpression("===", _core.types.cloneNode(check), _core.types.nullLiteral()), _core.types.binaryExpression("===", _core.types.cloneNode(ref), scope.buildUndefinedNode())), isDeleteOperation ? _core.types.booleanLiteral(true) : scope.buildUndefinedNode(), replacementPath.node)); | ||
let replacement = replacementPath.node; | ||
if (i === 0 && parentIsCall) { | ||
var _baseRef; | ||
const { | ||
object | ||
} = replacement; | ||
let baseRef; | ||
if (!loose || !isSimpleMemberExpression(object)) { | ||
baseRef = scope.maybeGenerateMemoised(object); | ||
if (baseRef) { | ||
replacement.object = _core.types.assignmentExpression("=", baseRef, object); | ||
} | ||
} | ||
replacement = _core.types.callExpression(_core.types.memberExpression(replacement, _core.types.identifier("bind")), [_core.types.cloneNode((_baseRef = baseRef) != null ? _baseRef : object)]); | ||
} | ||
replacementPath.replaceWith(_core.types.conditionalExpression(loose ? _core.types.binaryExpression("==", _core.types.cloneNode(check), _core.types.nullLiteral()) : _core.types.logicalExpression("||", _core.types.binaryExpression("===", _core.types.cloneNode(check), _core.types.nullLiteral()), _core.types.binaryExpression("===", _core.types.cloneNode(ref), scope.buildUndefinedNode())), isDeleteOperation ? _core.types.booleanLiteral(true) : scope.buildUndefinedNode(), replacement)); | ||
replacementPath = replacementPath.get("alternate"); | ||
@@ -120,0 +146,0 @@ } |
{ | ||
"name": "@babel/plugin-proposal-optional-chaining", | ||
"version": "7.10.1", | ||
"version": "7.10.3", | ||
"description": "Transform optional chaining operators into a series of nil checks", | ||
@@ -19,3 +19,3 @@ "repository": { | ||
"dependencies": { | ||
"@babel/helper-plugin-utils": "^7.10.1", | ||
"@babel/helper-plugin-utils": "^7.10.3", | ||
"@babel/plugin-syntax-optional-chaining": "^7.8.0" | ||
@@ -27,7 +27,7 @@ }, | ||
"devDependencies": { | ||
"@babel/core": "^7.10.1", | ||
"@babel/helper-plugin-test-runner": "^7.10.1", | ||
"@babel/core": "^7.10.3", | ||
"@babel/helper-plugin-test-runner": "^7.10.3", | ||
"@babel/plugin-transform-block-scoping": "^7.10.1" | ||
}, | ||
"gitHead": "88f57a7ea659d25232bf62de1efceb5d6299b8cf" | ||
"gitHead": "2787ee2f967b6d8e1121fca00a8d578d75449a53" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7763
120
1