babel-plugin-transform-optional-chaining
Advanced tools
Comparing version 7.0.0-alpha.13.1 to 7.0.0-alpha.14
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.__esModule = true; | ||
@@ -34,8 +32,8 @@ exports.default = function (_ref) { | ||
for (var i = optionals.length - 1; i >= 0; i--) { | ||
var node = optionals[i]; | ||
node.optional = false; | ||
var _node = optionals[i]; | ||
_node.optional = false; | ||
var isCall = t.isCallExpression(node); | ||
var replaceKey = isCall || t.isNewExpression(node) ? "callee" : "object"; | ||
var chain = node[replaceKey]; | ||
var isCall = t.isCallExpression(_node); | ||
var replaceKey = isCall || t.isNewExpression(_node) ? "callee" : "object"; | ||
var chain = _node[replaceKey]; | ||
@@ -45,4 +43,2 @@ var ref = void 0; | ||
if (loose && isCall) { | ||
// If we are using a loose transform (avoiding a Function#call) and we are at the call, | ||
// we can avoid a needless memoize. | ||
check = ref = chain; | ||
@@ -53,3 +49,3 @@ } else { | ||
check = t.assignmentExpression("=", ref, chain); | ||
node[replaceKey] = ref; | ||
_node[replaceKey] = ref; | ||
} else { | ||
@@ -60,12 +56,6 @@ check = ref = chain; | ||
// Ensure call expressions have the proper `this` | ||
// `foo.bar()` has context `foo`. | ||
if (isCall && t.isMemberExpression(chain)) { | ||
if (loose) { | ||
// To avoid a Function#call, we can instead re-grab the property from the context object. | ||
// `a.?b.?()` translates roughly to `_a.b != null && _a.b()` | ||
node.callee = chain; | ||
_node.callee = chain; | ||
} else { | ||
// Otherwise, we need to memoize the context object, and change the call into a Function#call. | ||
// `a.?b.?()` translates roughly to `(_b = _a.b) != null && _b.call(_a)` | ||
var object = chain.object; | ||
@@ -80,4 +70,4 @@ | ||
node.arguments.unshift(context); | ||
node.callee = t.memberExpression(node.callee, t.identifier("call")); | ||
_node.arguments.unshift(context); | ||
_node.callee = t.memberExpression(_node.callee, t.identifier("call")); | ||
} | ||
@@ -84,0 +74,0 @@ } |
{ | ||
"name": "babel-plugin-transform-optional-chaining", | ||
"version": "7.0.0-alpha.13.1", | ||
"version": "7.0.0-alpha.14", | ||
"description": "Transform optional chaining operators into a series of nil checks", | ||
@@ -9,3 +9,3 @@ "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-optional-chaining", | ||
"dependencies": { | ||
"babel-plugin-syntax-optional-chaining": "7.0.0-alpha.13" | ||
"babel-plugin-syntax-optional-chaining": "7.0.0-alpha.14" | ||
}, | ||
@@ -16,4 +16,4 @@ "keywords": [ | ||
"devDependencies": { | ||
"babel-helper-plugin-test-runner": "7.0.0-alpha.12" | ||
"babel-helper-plugin-test-runner": "7.0.0-alpha.14" | ||
} | ||
} |
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
6055
95
1
+ Addedbabel-plugin-syntax-optional-chaining@7.0.0-alpha.14(transitive)
- Removedbabel-plugin-syntax-optional-chaining@7.0.0-alpha.13(transitive)