@babel/plugin-transform-optional-chaining
Advanced tools
Comparing version 7.22.10 to 7.22.11
@@ -6,3 +6,2 @@ 'use strict'; | ||
var helperPluginUtils = require('@babel/helper-plugin-utils'); | ||
var syntaxOptionalChaining = require('@babel/plugin-syntax-optional-chaining'); | ||
var core = require('@babel/core'); | ||
@@ -173,6 +172,10 @@ var helperSkipTransparentExpressionWrappers = require('@babel/helper-skip-transparent-expression-wrappers'); | ||
const ifNullishFalse = ifNullishBoolean && ifNullish.value === false; | ||
const ifNullishVoid = !ifNullishBoolean && core.types.isUnaryExpression(ifNullish, { | ||
operator: "void" | ||
}); | ||
const isEvaluationValueIgnored = (core.types.isExpressionStatement(replacementPath.parent) || core.types.isSequenceExpression(replacementPath.parent)) && !replacementPath.isCompletionRecord(); | ||
const tpl = ifNullishFalse ? noDocumentAll ? NULLISH_CHECK_NO_DDA_NEG : NULLISH_CHECK_NEG : noDocumentAll ? NULLISH_CHECK_NO_DDA : NULLISH_CHECK; | ||
const logicalOp = ifNullishFalse ? "&&" : "||"; | ||
const check = checks.map(tpl).reduce((expr, check) => core.types.logicalExpression(logicalOp, expr, check)); | ||
replacementPath.replaceWith(ifNullishBoolean ? core.types.logicalExpression(logicalOp, check, result) : core.types.conditionalExpression(check, ifNullish, result)); | ||
replacementPath.replaceWith(ifNullishBoolean || ifNullishVoid && isEvaluationValueIgnored ? core.types.logicalExpression(logicalOp, check, result) : core.types.conditionalExpression(check, ifNullish, result)); | ||
} | ||
@@ -223,3 +226,3 @@ function transform(path, assumptions) { | ||
name: "transform-optional-chaining", | ||
inherits: syntaxOptionalChaining.default, | ||
inherits: require("@babel/plugin-syntax-optional-chaining").default, | ||
visitor: { | ||
@@ -236,4 +239,4 @@ "OptionalCallExpression|OptionalMemberExpression"(path) { | ||
exports["default"] = index; | ||
exports.default = index; | ||
exports.transform = transform; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@babel/plugin-transform-optional-chaining", | ||
"version": "7.22.10", | ||
"version": "7.22.11", | ||
"description": "Transform optional chaining operators into a series of nil checks", | ||
@@ -28,6 +28,6 @@ "repository": { | ||
"devDependencies": { | ||
"@babel/core": "^7.22.10", | ||
"@babel/core": "^7.22.11", | ||
"@babel/helper-plugin-test-runner": "^7.22.5", | ||
"@babel/plugin-transform-block-scoping": "^7.22.10", | ||
"@babel/traverse": "^7.22.10" | ||
"@babel/traverse": "^7.22.11" | ||
}, | ||
@@ -34,0 +34,0 @@ "engines": { |
Sorry, the diff of this file is not supported yet
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
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
30
1
1
1
17
37261
5
232