Socket
Socket
Sign inDemoInstall

babel-plugin-transform-es2015-destructuring

Package Overview
Dependencies
Maintainers
6
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-transform-es2015-destructuring - npm Package Compare versions

Comparing version 6.9.0 to 6.16.0

133

lib/index.js

@@ -1,2 +0,2 @@

/*istanbul ignore next*/"use strict";
"use strict";

@@ -13,13 +13,8 @@ exports.__esModule = true;

exports.default = function ( /*istanbul ignore next*/_ref) {
/*istanbul ignore next*/var t = _ref.types;
exports.default = function (_ref) {
var t = _ref.types;
/**
* Test if a VariableDeclaration's declarations contains any Patterns.
*/
function variableDeclarationHasPattern(node) {
for ( /*istanbul ignore next*/var _iterator = node.declarations, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) {
/*istanbul ignore next*/
for (var _iterator = node.declarations, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) {
var _ref2;

@@ -45,9 +40,4 @@

/**
* Test if an ArrayPattern's elements contain any RestElements.
*/
function hasRest(pattern) {
for ( /*istanbul ignore next*/var _iterator2 = pattern.elements, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : (0, _getIterator3.default)(_iterator2);;) {
/*istanbul ignore next*/
for (var _iterator2 = pattern.elements, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : (0, _getIterator3.default)(_iterator2);;) {
var _ref3;

@@ -73,3 +63,3 @@

var arrayUnpackVisitor = { /*istanbul ignore next*/
var arrayUnpackVisitor = {
ReferencedIdentifier: function ReferencedIdentifier(path, state) {

@@ -83,6 +73,5 @@ if (state.bindings[path.node.name]) {

/*istanbul ignore next*/
var DestructuringTransformer = function () {
function /*istanbul ignore next*/DestructuringTransformer(opts) {
/*istanbul ignore next*/(0, _classCallCheck3.default)(this, DestructuringTransformer);
function DestructuringTransformer(opts) {
(0, _classCallCheck3.default)(this, DestructuringTransformer);

@@ -102,3 +91,3 @@ this.blockHoist = opts.blockHoist;

var node = /*istanbul ignore next*/void 0;
var node = void 0;

@@ -143,4 +132,2 @@ if (op) {

DestructuringTransformer.prototype.pushAssignmentPattern = function pushAssignmentPattern(pattern, valueRef) {
// we need to assign the current value of the assignment to avoid evaluating
// it more than once

@@ -153,4 +140,2 @@ var tempValueRef = this.scope.generateUidIdentifierBasedOnNode(valueRef);

//
var tempConditional = t.conditionalExpression(t.binaryExpression("===", tempValueRef, t.identifier("undefined")), pattern.right, tempValueRef);

@@ -171,3 +156,2 @@

DestructuringTransformer.prototype.pushObjectRest = function pushObjectRest(pattern, objRef, spreadProp, spreadPropIndex) {
// get all the keys that appear in this object before the current spread

@@ -179,7 +163,4 @@ var keys = [];

// we've exceeded the index of the spread property to all properties to the
// right need to be ignored
if (i >= spreadPropIndex) break;
// ignore other spread properties
if (t.isRestProperty(prop)) continue;

@@ -194,4 +175,2 @@

//
var value = t.callExpression(this.file.addHelper("objectWithoutProperties"), [objRef, keys]);

@@ -215,3 +194,2 @@ this.nodes.push(this.buildVariableAssignment(spreadProp.argument, value));

DestructuringTransformer.prototype.pushObjectPattern = function pushObjectPattern(pattern, objRef) {
// https://github.com/babel/babel/issues/681

@@ -222,6 +200,2 @@ if (!pattern.properties.length) {

// if we have more than one properties in this pattern and the objectRef is a
// member expression then we need to assign it to a temporary variable so it's
// only evaluated once
if (pattern.properties.length > 1 && !this.scope.isStatic(objRef)) {

@@ -233,4 +207,2 @@ var temp = this.scope.generateUidIdentifierBasedOnNode(objRef);

//
for (var i = 0; i < pattern.properties.length; i++) {

@@ -247,12 +219,8 @@ var prop = pattern.properties[i];

DestructuringTransformer.prototype.canUnpackArrayPattern = function canUnpackArrayPattern(pattern, arr) {
// not an array so there's no way we can deal with this
if (!t.isArrayExpression(arr)) return false;
// pattern has less elements than the array and doesn't have a rest so some
// elements wont be evaluated
if (pattern.elements.length > arr.elements.length) return;
if (pattern.elements.length < arr.elements.length && !hasRest(pattern)) return false;
for ( /*istanbul ignore next*/var _iterator3 = pattern.elements, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : (0, _getIterator3.default)(_iterator3);;) {
/*istanbul ignore next*/
for (var _iterator3 = pattern.elements, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : (0, _getIterator3.default)(_iterator3);;) {
var _ref4;

@@ -271,11 +239,8 @@

// deopt on holes
if (!elem) return false;
// deopt on member expressions as they may be included in the RHS
if (t.isMemberExpression(elem)) return false;
}
for ( /*istanbul ignore next*/var _iterator4 = arr.elements, _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : (0, _getIterator3.default)(_iterator4);;) {
/*istanbul ignore next*/
for (var _iterator4 = arr.elements, _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : (0, _getIterator3.default)(_iterator4);;) {
var _ref5;

@@ -294,7 +259,9 @@

// deopt on spread elements
if (t.isSpreadElement(_elem)) return false;
if (t.isCallExpression(_elem)) return false;
if (t.isMemberExpression(_elem)) return false;
}
// deopt on reference to left side identifiers
var bindings = t.getBindingIdentifiers(pattern);

@@ -320,9 +287,2 @@ var state = { deopt: false, bindings: bindings };

// optimise basic array destructuring of an array expression
//
// we can't do this to a pattern of unequal size to it's right hand
// array expression as then there will be values that wont be evaluated
//
// eg: let [a, b] = [1, 2];
if (this.canUnpackArrayPattern(pattern, arrayRef)) {

@@ -332,16 +292,7 @@ return this.pushUnpackedArrayPattern(pattern, arrayRef);

// if we have a rest then we need all the elements so don't tell
// `scope.toArray` to only get a certain amount
var count = !hasRest(pattern) && pattern.elements.length;
// so we need to ensure that the `arrayRef` is an array, `scope.toArray` will
// return a locally bound identifier if it's been inferred to be an array,
// otherwise it'll be a call to a helper that will ensure it's one
var toArray = this.toArray(arrayRef, count);
if (t.isIdentifier(toArray)) {
// we've been given an identifier so it must have been inferred to be an
// array
arrayRef = toArray;

@@ -354,11 +305,8 @@ } else {

//
for (var i = 0; i < pattern.elements.length; i++) {
var elem = pattern.elements[i];
// hole
if (!elem) continue;
var elemRef = /*istanbul ignore next*/void 0;
var elemRef = void 0;

@@ -372,4 +320,2 @@ if (t.isRestElement(elem)) {

// set the element to the rest element argument since we've dealt with it
// being a rest already
elem = elem.argument;

@@ -385,4 +331,2 @@ } else {

DestructuringTransformer.prototype.init = function init(pattern, ref) {
// trying to destructure a value that we can't evaluate more than once so we
// need to save it to a variable

@@ -397,4 +341,2 @@ if (!t.isArrayExpression(ref) && !t.isMemberExpression(ref)) {

//
this.push(pattern, ref);

@@ -409,3 +351,3 @@

return {
visitor: { /*istanbul ignore next*/
visitor: {
ExportNamedDeclaration: function ExportNamedDeclaration(path) {

@@ -423,11 +365,8 @@ var declaration = path.get("declaration");

// Split the declaration and export list into two declarations so that the variable
// declaration can be split up later without needing to worry about not being a
// top-level statement.
path.replaceWith(declaration.node);
path.insertAfter(t.exportNamedDeclaration(null, specifiers));
},
/*istanbul ignore next*/ForXStatement: function ForXStatement(path, file) {
/*istanbul ignore next*/var node = path.node;
/*istanbul ignore next*/var scope = path.scope;
ForXStatement: function ForXStatement(path, file) {
var node = path.node;
var scope = path.scope;

@@ -437,3 +376,2 @@ var left = node.left;

if (t.isPattern(left)) {
// for ({ length: k } in { abc: 3 });

@@ -475,5 +413,5 @@ var temp = scope.generateUidIdentifier("ref");

},
/*istanbul ignore next*/CatchClause: function CatchClause(_ref6, file) {
/*istanbul ignore next*/var node = _ref6.node;
/*istanbul ignore next*/var scope = _ref6.scope;
CatchClause: function CatchClause(_ref6, file) {
var node = _ref6.node;
var scope = _ref6.scope;

@@ -498,5 +436,5 @@ var pattern = node.param;

},
/*istanbul ignore next*/AssignmentExpression: function AssignmentExpression(path, file) {
/*istanbul ignore next*/var node = path.node;
/*istanbul ignore next*/var scope = path.scope;
AssignmentExpression: function AssignmentExpression(path, file) {
var node = path.node;
var scope = path.scope;

@@ -514,3 +452,3 @@ if (!t.isPattern(node.left)) return;

var ref = /*istanbul ignore next*/void 0;
var ref = void 0;
if (path.isCompletionRecord() || !path.parentPath.isExpressionStatement()) {

@@ -534,13 +472,13 @@ ref = scope.generateUidIdentifierBasedOnNode(node.right, "ref");

},
/*istanbul ignore next*/VariableDeclaration: function VariableDeclaration(path, file) {
/*istanbul ignore next*/var node = path.node;
/*istanbul ignore next*/var scope = path.scope;
/*istanbul ignore next*/var parent = path.parent;
VariableDeclaration: function VariableDeclaration(path, file) {
var node = path.node;
var scope = path.scope;
var parent = path.parent;
if (t.isForXStatement(parent)) return;
if (!parent || !path.container) return; // i don't know why this is necessary - TODO
if (!parent || !path.container) return;
if (!variableDeclarationHasPattern(node)) return;
var nodes = [];
var declar = /*istanbul ignore next*/void 0;
var declar = void 0;

@@ -565,4 +503,2 @@ for (var i = 0; i < node.declarations.length; i++) {

if (+i !== node.declarations.length - 1) {
// we aren't the last declarator so let's just make the
// last transformed node inherit from us
t.inherits(nodes[nodes.length - 1], declar);

@@ -581,5 +517,4 @@ }

/*istanbul ignore next*/
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
module.exports = exports["default"]; /* eslint max-len: 0 */
module.exports = exports["default"];
{
"name": "babel-plugin-transform-es2015-destructuring",
"version": "6.9.0",
"version": "6.16.0",
"description": "Compile ES2015 destructuring to ES5",

@@ -5,0 +5,0 @@ "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-es2015-destructuring",

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