Socket
Socket
Sign inDemoInstall

babel-plugin-transform-optional-chaining

Package Overview
Dependencies
Maintainers
4
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-transform-optional-chaining - npm Package Compare versions

Comparing version 7.0.0-alpha.13.1 to 7.0.0-alpha.14

30

lib/index.js
"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"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc