Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@babel/plugin-transform-destructuring

Package Overview
Dependencies
Maintainers
6
Versions
105
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@babel/plugin-transform-destructuring - npm Package Compare versions

Comparing version 7.0.0-beta.43 to 7.0.0-beta.44

328

lib/index.js

@@ -9,5 +9,5 @@ "use strict";

function _helperPluginUtils() {
const data = require("@babel/helper-plugin-utils");
var data = require("@babel/helper-plugin-utils");
_helperPluginUtils = function () {
_helperPluginUtils = function _helperPluginUtils() {
return data;

@@ -20,5 +20,5 @@ };

function _core() {
const data = require("@babel/core");
var data = require("@babel/core");
_core = function () {
_core = function _core() {
return data;

@@ -30,14 +30,14 @@ };

var _default = (0, _helperPluginUtils().declare)((api, options) => {
var _default = (0, _helperPluginUtils().declare)(function (api, options) {
api.assertVersion(7);
const {
loose = false,
useBuiltIns = false
} = options;
var _options$loose = options.loose,
loose = _options$loose === void 0 ? false : _options$loose,
_options$useBuiltIns = options.useBuiltIns,
useBuiltIns = _options$useBuiltIns === void 0 ? false : _options$useBuiltIns;
if (typeof loose !== "boolean") {
throw new Error(`.loose must be a boolean or undefined`);
throw new Error(".loose must be a boolean or undefined");
}
const arrayOnlySpread = loose;
var arrayOnlySpread = loose;

@@ -49,3 +49,7 @@ function getExtendsHelper(file) {

function variableDeclarationHasPattern(node) {
for (const declar of node.declarations) {
var _arr = node.declarations;
for (var _i = 0; _i < _arr.length; _i++) {
var declar = _arr[_i];
if (_core().types.isPattern(declar.id)) {

@@ -60,3 +64,7 @@ return true;

function hasRest(pattern) {
for (const elem of pattern.elements) {
var _arr2 = pattern.elements;
for (var _i2 = 0; _i2 < _arr2.length; _i2++) {
var elem = _arr2[_i2];
if (_core().types.isRestElement(elem)) {

@@ -70,4 +78,4 @@ return true;

const arrayUnpackVisitor = {
ReferencedIdentifier(path, state) {
var arrayUnpackVisitor = {
ReferencedIdentifier: function ReferencedIdentifier(path, state) {
if (state.bindings[path.node.name]) {

@@ -78,7 +86,6 @@ state.deopt = true;

}
};
class DestructuringTransformer {
constructor(opts) {
var DestructuringTransformer = function () {
function DestructuringTransformer(opts) {
this.blockHoist = opts.blockHoist;

@@ -94,6 +101,8 @@ this.operator = opts.operator;

buildVariableAssignment(id, init) {
let op = this.operator;
var _proto = DestructuringTransformer.prototype;
_proto.buildVariableAssignment = function buildVariableAssignment(id, init) {
var op = this.operator;
if (_core().types.isMemberExpression(id)) op = "=";
let node;
var node;

@@ -108,13 +117,13 @@ if (op) {

return node;
}
};
buildVariableDeclaration(id, init) {
const declar = _core().types.variableDeclaration("var", [_core().types.variableDeclarator(_core().types.cloneNode(id), _core().types.cloneNode(init))]);
_proto.buildVariableDeclaration = function buildVariableDeclaration(id, init) {
var declar = _core().types.variableDeclaration("var", [_core().types.variableDeclarator(_core().types.cloneNode(id), _core().types.cloneNode(init))]);
declar._blockHoist = this.blockHoist;
return declar;
}
};
push(id, _init) {
const init = _core().types.cloneNode(_init);
_proto.push = function push(id, _init) {
var init = _core().types.cloneNode(_init);

@@ -130,5 +139,5 @@ if (_core().types.isObjectPattern(id)) {

}
}
};
toArray(node, count) {
_proto.toArray = function toArray(node, count) {
if (this.arrayOnlySpread || _core().types.isIdentifier(node) && this.arrays[node.name]) {

@@ -139,16 +148,15 @@ return node;

}
}
};
pushAssignmentPattern({
left,
right
}, valueRef) {
const tempId = this.scope.generateUidIdentifierBasedOnNode(valueRef);
_proto.pushAssignmentPattern = function pushAssignmentPattern(_ref, valueRef) {
var left = _ref.left,
right = _ref.right;
var tempId = this.scope.generateUidIdentifierBasedOnNode(valueRef);
this.nodes.push(this.buildVariableDeclaration(tempId, valueRef));
const tempConditional = _core().types.conditionalExpression(_core().types.binaryExpression("===", _core().types.cloneNode(tempId), this.scope.buildUndefinedNode()), right, _core().types.cloneNode(tempId));
var tempConditional = _core().types.conditionalExpression(_core().types.binaryExpression("===", _core().types.cloneNode(tempId), this.scope.buildUndefinedNode()), right, _core().types.cloneNode(tempId));
if (_core().types.isPattern(left)) {
let patternId;
let node;
var patternId;
var node;

@@ -168,12 +176,12 @@ if (this.kind === "const") {

}
}
};
pushObjectRest(pattern, objRef, spreadProp, spreadPropIndex) {
let keys = [];
_proto.pushObjectRest = function pushObjectRest(pattern, objRef, spreadProp, spreadPropIndex) {
var keys = [];
for (let i = 0; i < pattern.properties.length; i++) {
const prop = pattern.properties[i];
for (var i = 0; i < pattern.properties.length; i++) {
var prop = pattern.properties[i];
if (i >= spreadPropIndex) break;
if (_core().types.isRestElement(prop)) continue;
let key = prop.key;
var key = prop.key;

@@ -187,3 +195,3 @@ if (_core().types.isIdentifier(key) && !prop.computed) {

let value;
var value;

@@ -198,9 +206,9 @@ if (keys.length === 0) {

this.nodes.push(this.buildVariableAssignment(spreadProp.argument, value));
}
};
pushObjectProperty(prop, propRef) {
_proto.pushObjectProperty = function pushObjectProperty(prop, propRef) {
if (_core().types.isLiteral(prop.key)) prop.computed = true;
const pattern = prop.value;
var pattern = prop.value;
const objRef = _core().types.memberExpression(_core().types.cloneNode(propRef), prop.key, prop.computed);
var objRef = _core().types.memberExpression(_core().types.cloneNode(propRef), prop.key, prop.computed);

@@ -212,5 +220,5 @@ if (_core().types.isPattern(pattern)) {

}
}
};
pushObjectPattern(pattern, objRef) {
_proto.pushObjectPattern = function pushObjectPattern(pattern, objRef) {
if (!pattern.properties.length) {

@@ -221,3 +229,3 @@ this.nodes.push(_core().types.expressionStatement(_core().types.callExpression(this.addHelper("objectDestructuringEmpty"), [objRef])));

if (pattern.properties.length > 1 && !this.scope.isStatic(objRef)) {
const temp = this.scope.generateUidIdentifierBasedOnNode(objRef);
var temp = this.scope.generateUidIdentifierBasedOnNode(objRef);
this.nodes.push(this.buildVariableDeclaration(temp, objRef));

@@ -227,4 +235,4 @@ objRef = temp;

for (let i = 0; i < pattern.properties.length; i++) {
const prop = pattern.properties[i];
for (var i = 0; i < pattern.properties.length; i++) {
var prop = pattern.properties[i];

@@ -237,5 +245,5 @@ if (_core().types.isRestElement(prop)) {

}
}
};
canUnpackArrayPattern(pattern, arr) {
_proto.canUnpackArrayPattern = function canUnpackArrayPattern(pattern, arr) {
if (!_core().types.isArrayExpression(arr)) return false;

@@ -248,3 +256,6 @@ if (pattern.elements.length > arr.elements.length) return;

for (const elem of pattern.elements) {
var _arr3 = pattern.elements;
for (var _i3 = 0; _i3 < _arr3.length; _i3++) {
var elem = _arr3[_i3];
if (!elem) return false;

@@ -254,21 +265,24 @@ if (_core().types.isMemberExpression(elem)) return false;

for (const elem of arr.elements) {
if (_core().types.isSpreadElement(elem)) return false;
if (_core().types.isCallExpression(elem)) return false;
if (_core().types.isMemberExpression(elem)) return false;
var _arr4 = arr.elements;
for (var _i4 = 0; _i4 < _arr4.length; _i4++) {
var _elem = _arr4[_i4];
if (_core().types.isSpreadElement(_elem)) return false;
if (_core().types.isCallExpression(_elem)) return false;
if (_core().types.isMemberExpression(_elem)) return false;
}
const bindings = _core().types.getBindingIdentifiers(pattern);
var bindings = _core().types.getBindingIdentifiers(pattern);
const state = {
var state = {
deopt: false,
bindings
bindings: bindings
};
this.scope.traverse(arr, arrayUnpackVisitor, state);
return !state.deopt;
}
};
pushUnpackedArrayPattern(pattern, arr) {
for (let i = 0; i < pattern.elements.length; i++) {
const elem = pattern.elements[i];
_proto.pushUnpackedArrayPattern = function pushUnpackedArrayPattern(pattern, arr) {
for (var i = 0; i < pattern.elements.length; i++) {
var elem = pattern.elements[i];

@@ -281,5 +295,5 @@ if (_core().types.isRestElement(elem)) {

}
}
};
pushArrayPattern(pattern, arrayRef) {
_proto.pushArrayPattern = function pushArrayPattern(pattern, arrayRef) {
if (!pattern.elements) return;

@@ -291,4 +305,4 @@

const count = !hasRest(pattern) && pattern.elements.length;
const toArray = this.toArray(arrayRef, count);
var count = !hasRest(pattern) && pattern.elements.length;
var toArray = this.toArray(arrayRef, count);

@@ -303,6 +317,6 @@ if (_core().types.isIdentifier(toArray)) {

for (let i = 0; i < pattern.elements.length; i++) {
let elem = pattern.elements[i];
for (var i = 0; i < pattern.elements.length; i++) {
var elem = pattern.elements[i];
if (!elem) continue;
let elemRef;
var elemRef = void 0;

@@ -319,7 +333,7 @@ if (_core().types.isRestElement(elem)) {

}
}
};
init(pattern, ref) {
_proto.init = function init(pattern, ref) {
if (!_core().types.isArrayExpression(ref) && !_core().types.isMemberExpression(ref)) {
const memo = this.scope.maybeGenerateMemoised(ref, true);
var memo = this.scope.maybeGenerateMemoised(ref, true);

@@ -334,15 +348,16 @@ if (memo) {

return this.nodes;
}
};
}
return DestructuringTransformer;
}();
return {
visitor: {
ExportNamedDeclaration(path) {
const declaration = path.get("declaration");
ExportNamedDeclaration: function ExportNamedDeclaration(path) {
var declaration = path.get("declaration");
if (!declaration.isVariableDeclaration()) return;
if (!variableDeclarationHasPattern(declaration.node)) return;
const specifiers = [];
var specifiers = [];
for (const name in path.getOuterBindingIdentifiers(path)) {
for (var name in path.getOuterBindingIdentifiers(path)) {
specifiers.push(_core().types.exportSpecifier(_core().types.identifier(name), _core().types.identifier(name)));

@@ -354,12 +369,11 @@ }

},
ForXStatement: function ForXStatement(path) {
var _this = this;
ForXStatement(path) {
const {
node,
scope
} = path;
const left = node.left;
var node = path.node,
scope = path.scope;
var left = node.left;
if (_core().types.isPattern(left)) {
const temp = scope.generateUidIdentifier("ref");
var temp = scope.generateUidIdentifier("ref");
node.left = _core().types.variableDeclaration("var", [_core().types.variableDeclarator(temp)]);

@@ -372,35 +386,39 @@ path.ensureBlock();

if (!_core().types.isVariableDeclaration(left)) return;
const pattern = left.declarations[0].id;
var pattern = left.declarations[0].id;
if (!_core().types.isPattern(pattern)) return;
const key = scope.generateUidIdentifier("ref");
var key = scope.generateUidIdentifier("ref");
node.left = _core().types.variableDeclaration(left.kind, [_core().types.variableDeclarator(key, null)]);
const nodes = [];
const destructuring = new DestructuringTransformer({
var nodes = [];
var destructuring = new DestructuringTransformer({
kind: left.kind,
scope: scope,
nodes: nodes,
arrayOnlySpread,
addHelper: name => this.addHelper(name)
arrayOnlySpread: arrayOnlySpread,
addHelper: function addHelper(name) {
return _this.addHelper(name);
}
});
destructuring.init(pattern, key);
path.ensureBlock();
const block = node.body;
var block = node.body;
block.body = nodes.concat(block.body);
},
CatchClause: function CatchClause(_ref2) {
var _this2 = this;
CatchClause({
node,
scope
}) {
const pattern = node.param;
var node = _ref2.node,
scope = _ref2.scope;
var pattern = node.param;
if (!_core().types.isPattern(pattern)) return;
const ref = scope.generateUidIdentifier("ref");
var ref = scope.generateUidIdentifier("ref");
node.param = ref;
const nodes = [];
const destructuring = new DestructuringTransformer({
var nodes = [];
var destructuring = new DestructuringTransformer({
kind: "let",
scope: scope,
nodes: nodes,
arrayOnlySpread,
addHelper: name => this.addHelper(name)
arrayOnlySpread: arrayOnlySpread,
addHelper: function addHelper(name) {
return _this2.addHelper(name);
}
});

@@ -410,18 +428,19 @@ destructuring.init(pattern, ref);

},
AssignmentExpression: function AssignmentExpression(path) {
var _this3 = this;
AssignmentExpression(path) {
const {
node,
scope
} = path;
var node = path.node,
scope = path.scope;
if (!_core().types.isPattern(node.left)) return;
const nodes = [];
const destructuring = new DestructuringTransformer({
var nodes = [];
var destructuring = new DestructuringTransformer({
operator: node.operator,
scope: scope,
nodes: nodes,
arrayOnlySpread,
addHelper: name => this.addHelper(name)
arrayOnlySpread: arrayOnlySpread,
addHelper: function addHelper(name) {
return _this3.addHelper(name);
}
});
let ref;
var ref;

@@ -445,21 +464,20 @@ if (path.isCompletionRecord() || !path.parentPath.isExpressionStatement()) {

},
VariableDeclaration: function VariableDeclaration(path) {
var _this4 = this;
VariableDeclaration(path) {
const {
node,
scope,
parent
} = path;
var node = path.node,
scope = path.scope,
parent = path.parent;
if (_core().types.isForXStatement(parent)) return;
if (!parent || !path.container) return;
if (!variableDeclarationHasPattern(node)) return;
const nodeKind = node.kind;
const nodes = [];
let declar;
var nodeKind = node.kind;
var nodes = [];
var declar;
for (let i = 0; i < node.declarations.length; i++) {
for (var i = 0; i < node.declarations.length; i++) {
declar = node.declarations[i];
const patternId = declar.init;
const pattern = declar.id;
const destructuring = new DestructuringTransformer({
var patternId = declar.init;
var pattern = declar.id;
var destructuring = new DestructuringTransformer({
blockHoist: node._blockHoist,

@@ -469,4 +487,6 @@ nodes: nodes,

kind: node.kind,
arrayOnlySpread,
addHelper: name => this.addHelper(name)
arrayOnlySpread: arrayOnlySpread,
addHelper: function addHelper(name) {
return _this4.addHelper(name);
}
});

@@ -485,23 +505,38 @@

let tail = null;
const nodesOut = [];
var tail = null;
var nodesOut = [];
for (const node of nodes) {
if (tail !== null && _core().types.isVariableDeclaration(node)) {
tail.declarations.push(...node.declarations);
for (var _i5 = 0; _i5 < nodes.length; _i5++) {
var _node = nodes[_i5];
if (tail !== null && _core().types.isVariableDeclaration(_node)) {
var _tail$declarations;
(_tail$declarations = tail.declarations).push.apply(_tail$declarations, _node.declarations);
} else {
node.kind = nodeKind;
nodesOut.push(node);
tail = _core().types.isVariableDeclaration(node) ? node : null;
_node.kind = nodeKind;
nodesOut.push(_node);
tail = _core().types.isVariableDeclaration(_node) ? _node : null;
}
}
for (const nodeOut of nodesOut) {
for (var _i6 = 0; _i6 < nodesOut.length; _i6++) {
var nodeOut = nodesOut[_i6];
if (!nodeOut.declarations) continue;
for (const declaration of nodeOut.declarations) {
const {
name
} = declaration.id;
for (var _iterator = nodeOut.declarations, _isArray = Array.isArray(_iterator), _i7 = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var _ref3;
if (_isArray) {
if (_i7 >= _iterator.length) break;
_ref3 = _iterator[_i7++];
} else {
_i7 = _iterator.next();
if (_i7.done) break;
_ref3 = _i7.value;
}
var declaration = _ref3;
var name = declaration.id.name;
if (scope.bindings[name]) {

@@ -519,3 +554,2 @@ scope.bindings[name].kind = nodeOut.kind;

}
}

@@ -522,0 +556,0 @@ };

{
"name": "@babel/plugin-transform-destructuring",
"version": "7.0.0-beta.43",
"version": "7.0.0-beta.44",
"description": "Compile ES2015 destructuring to ES5",

@@ -12,11 +12,11 @@ "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-destructuring",

"dependencies": {
"@babel/helper-plugin-utils": "7.0.0-beta.43"
"@babel/helper-plugin-utils": "7.0.0-beta.44"
},
"peerDependencies": {
"@babel/core": "7.0.0-beta.43"
"@babel/core": "7.0.0-beta.44"
},
"devDependencies": {
"@babel/core": "7.0.0-beta.43",
"@babel/helper-plugin-test-runner": "7.0.0-beta.43"
"@babel/core": "7.0.0-beta.44",
"@babel/helper-plugin-test-runner": "7.0.0-beta.44"
}
}
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