@babel/plugin-proposal-object-rest-spread
Advanced tools
Comparing version 7.0.0-beta.46 to 7.0.0-beta.47
186
lib/index.js
@@ -9,3 +9,3 @@ "use strict"; | ||
function _helperPluginUtils() { | ||
var data = require("@babel/helper-plugin-utils"); | ||
const data = require("@babel/helper-plugin-utils"); | ||
@@ -20,3 +20,3 @@ _helperPluginUtils = function _helperPluginUtils() { | ||
function _pluginSyntaxObjectRestSpread() { | ||
var data = _interopRequireDefault(require("@babel/plugin-syntax-object-rest-spread")); | ||
const data = _interopRequireDefault(require("@babel/plugin-syntax-object-rest-spread")); | ||
@@ -31,3 +31,3 @@ _pluginSyntaxObjectRestSpread = function _pluginSyntaxObjectRestSpread() { | ||
function _core() { | ||
var data = require("@babel/core"); | ||
const data = require("@babel/core"); | ||
@@ -43,8 +43,8 @@ _core = function _core() { | ||
var _default = (0, _helperPluginUtils().declare)(function (api, opts) { | ||
var _default = (0, _helperPluginUtils().declare)((api, opts) => { | ||
api.assertVersion(7); | ||
var _opts$useBuiltIns = opts.useBuiltIns, | ||
useBuiltIns = _opts$useBuiltIns === void 0 ? false : _opts$useBuiltIns, | ||
_opts$loose = opts.loose, | ||
loose = _opts$loose === void 0 ? false : _opts$loose; | ||
const _opts$useBuiltIns = opts.useBuiltIns, | ||
useBuiltIns = _opts$useBuiltIns === void 0 ? false : _opts$useBuiltIns, | ||
_opts$loose = opts.loose, | ||
loose = _opts$loose === void 0 ? false : _opts$loose; | ||
@@ -60,4 +60,4 @@ if (typeof loose !== "boolean") { | ||
function hasRestElement(path) { | ||
var foundRestElement = false; | ||
visitRestElements(path, function () { | ||
let foundRestElement = false; | ||
visitRestElements(path, () => { | ||
foundRestElement = true; | ||
@@ -71,4 +71,4 @@ path.stop(); | ||
path.traverse({ | ||
Expression: function Expression(path) { | ||
var parentType = path.parent.type; | ||
Expression(path) { | ||
const parentType = path.parent.type; | ||
@@ -79,2 +79,3 @@ if (parentType == "AssignmentPattern" && path.key === "right" || parentType == "ObjectProperty" && path.parent.computed && path.key === "key") { | ||
}, | ||
RestElement: visitor | ||
@@ -97,3 +98,3 @@ }); | ||
var prop = _ref; | ||
const prop = _ref; | ||
@@ -109,5 +110,5 @@ if (_core().types.isSpreadElement(prop)) { | ||
function extractNormalizedKeys(path) { | ||
var props = path.node.properties; | ||
var keys = []; | ||
var allLiteral = true; | ||
const props = path.node.properties; | ||
const keys = []; | ||
let allLiteral = true; | ||
@@ -126,3 +127,3 @@ for (var _iterator2 = props, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { | ||
var prop = _ref2; | ||
const prop = _ref2; | ||
@@ -140,4 +141,4 @@ if (_core().types.isIdentifier(prop.key) && !prop.computed) { | ||
return { | ||
keys: keys, | ||
allLiteral: allLiteral | ||
keys, | ||
allLiteral | ||
}; | ||
@@ -147,3 +148,3 @@ } | ||
function replaceImpureComputedKeys(path) { | ||
var impureComputedPropertyDeclarators = []; | ||
const impureComputedPropertyDeclarators = []; | ||
@@ -162,9 +163,9 @@ for (var _iterator3 = path.get("properties"), _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) { | ||
var propPath = _ref3; | ||
var key = propPath.get("key"); | ||
const propPath = _ref3; | ||
const key = propPath.get("key"); | ||
if (propPath.node.computed && !key.isPure()) { | ||
var name = path.scope.generateUidBasedOnNode(key.node); | ||
const name = path.scope.generateUidBasedOnNode(key.node); | ||
var declarator = _core().types.variableDeclarator(_core().types.identifier(name), key.node); | ||
const declarator = _core().types.variableDeclarator(_core().types.identifier(name), key.node); | ||
@@ -180,15 +181,15 @@ impureComputedPropertyDeclarators.push(declarator); | ||
function createObjectSpread(path, file, objRef) { | ||
var props = path.get("properties"); | ||
var last = props[props.length - 1]; | ||
const props = path.get("properties"); | ||
const last = props[props.length - 1]; | ||
_core().types.assertRestElement(last.node); | ||
var restElement = _core().types.cloneNode(last.node); | ||
const restElement = _core().types.cloneNode(last.node); | ||
last.remove(); | ||
var impureComputedPropertyDeclarators = replaceImpureComputedKeys(path); | ||
const impureComputedPropertyDeclarators = replaceImpureComputedKeys(path); | ||
var _extractNormalizedKey = extractNormalizedKeys(path), | ||
keys = _extractNormalizedKey.keys, | ||
allLiteral = _extractNormalizedKey.allLiteral; | ||
const _extractNormalizedKey = extractNormalizedKeys(path), | ||
keys = _extractNormalizedKey.keys, | ||
allLiteral = _extractNormalizedKey.allLiteral; | ||
@@ -199,3 +200,3 @@ if (keys.length === 0) { | ||
var keyExpression; | ||
let keyExpression; | ||
@@ -218,6 +219,6 @@ if (!allLiteral) { | ||
if (paramPath.isArrayPattern() && hasRestElement(paramPath)) { | ||
var elements = paramPath.get("elements"); | ||
const elements = paramPath.get("elements"); | ||
for (var _i4 = 0; _i4 < elements.length; _i4++) { | ||
replaceRestElement(parentPath, elements[_i4], _i4, elements.length); | ||
for (let i = 0; i < elements.length; i++) { | ||
replaceRestElement(parentPath, elements[i], i, elements.length); | ||
} | ||
@@ -227,5 +228,5 @@ } | ||
if (paramPath.isObjectPattern() && hasRestElement(paramPath)) { | ||
var uid = parentPath.scope.generateUidIdentifier("ref"); | ||
const uid = parentPath.scope.generateUidIdentifier("ref"); | ||
var declar = _core().types.variableDeclaration("let", [_core().types.variableDeclarator(paramPath.node, uid)]); | ||
const declar = _core().types.variableDeclaration("let", [_core().types.variableDeclarator(paramPath.node, uid)]); | ||
@@ -241,10 +242,11 @@ parentPath.ensureBlock(); | ||
visitor: { | ||
Function: function Function(path) { | ||
var params = path.get("params"); | ||
Function(path) { | ||
const params = path.get("params"); | ||
for (var i = params.length - 1; i >= 0; i--) { | ||
for (let i = params.length - 1; i >= 0; i--) { | ||
replaceRestElement(params[i].parentPath, params[i], i, params.length); | ||
} | ||
}, | ||
VariableDeclarator: function VariableDeclarator(path, file) { | ||
VariableDeclarator(path, file) { | ||
if (!path.get("id").isObjectPattern()) { | ||
@@ -254,5 +256,5 @@ return; | ||
var insertionPath = path; | ||
var originalPath = path; | ||
visitRestElements(path.get("id"), function (path) { | ||
let insertionPath = path; | ||
const originalPath = path; | ||
visitRestElements(path.get("id"), path => { | ||
if (!path.parentPath.isObjectPattern()) { | ||
@@ -263,3 +265,3 @@ return; | ||
if (originalPath.node.id.properties.length > 1 && !_core().types.isIdentifier(originalPath.node.init)) { | ||
var initRef = path.scope.generateUidIdentifierBasedOnNode(originalPath.node.init, "ref"); | ||
const initRef = path.scope.generateUidIdentifierBasedOnNode(originalPath.node.init, "ref"); | ||
originalPath.insertBefore(_core().types.variableDeclarator(initRef, originalPath.node.init)); | ||
@@ -270,6 +272,6 @@ originalPath.replaceWith(_core().types.variableDeclarator(originalPath.node.id, _core().types.cloneNode(initRef))); | ||
var ref = originalPath.node.init; | ||
var refPropertyPath = []; | ||
var kind; | ||
path.findParent(function (path) { | ||
let ref = originalPath.node.init; | ||
const refPropertyPath = []; | ||
let kind; | ||
path.findParent(path => { | ||
if (path.isObjectProperty()) { | ||
@@ -284,3 +286,3 @@ refPropertyPath.unshift(path.node.key.name); | ||
if (refPropertyPath.length) { | ||
refPropertyPath.forEach(function (prop) { | ||
refPropertyPath.forEach(prop => { | ||
ref = _core().types.memberExpression(ref, _core().types.identifier(prop)); | ||
@@ -290,10 +292,8 @@ }); | ||
var objectPatternPath = path.findParent(function (path) { | ||
return path.isObjectPattern(); | ||
}); | ||
const objectPatternPath = path.findParent(path => path.isObjectPattern()); | ||
var _createObjectSpread = createObjectSpread(objectPatternPath, file, ref), | ||
impureComputedPropertyDeclarators = _createObjectSpread[0], | ||
argument = _createObjectSpread[1], | ||
callExpression = _createObjectSpread[2]; | ||
const _createObjectSpread = createObjectSpread(objectPatternPath, file, ref), | ||
impureComputedPropertyDeclarators = _createObjectSpread[0], | ||
argument = _createObjectSpread[1], | ||
callExpression = _createObjectSpread[2]; | ||
@@ -308,18 +308,15 @@ _core().types.assertIdentifier(argument); | ||
if (objectPatternPath.node.properties.length === 0) { | ||
objectPatternPath.findParent(function (path) { | ||
return path.isObjectProperty() || path.isVariableDeclarator(); | ||
}).remove(); | ||
objectPatternPath.findParent(path => path.isObjectProperty() || path.isVariableDeclarator()).remove(); | ||
} | ||
}); | ||
}, | ||
ExportNamedDeclaration: function ExportNamedDeclaration(path) { | ||
var declaration = path.get("declaration"); | ||
ExportNamedDeclaration(path) { | ||
const declaration = path.get("declaration"); | ||
if (!declaration.isVariableDeclaration()) return; | ||
var hasRest = declaration.get("declarations").some(function (path) { | ||
return hasRestElement(path.get("id")); | ||
}); | ||
const hasRest = declaration.get("declarations").some(path => hasRestElement(path.get("id"))); | ||
if (!hasRest) return; | ||
var specifiers = []; | ||
const specifiers = []; | ||
for (var name in path.getOuterBindingIdentifiers(path)) { | ||
for (const name in path.getOuterBindingIdentifiers(path)) { | ||
specifiers.push(_core().types.exportSpecifier(_core().types.identifier(name), _core().types.identifier(name))); | ||
@@ -331,18 +328,20 @@ } | ||
}, | ||
CatchClause: function CatchClause(path) { | ||
var paramPath = path.get("param"); | ||
CatchClause(path) { | ||
const paramPath = path.get("param"); | ||
replaceRestElement(paramPath.parentPath, paramPath); | ||
}, | ||
AssignmentExpression: function AssignmentExpression(path, file) { | ||
var leftPath = path.get("left"); | ||
AssignmentExpression(path, file) { | ||
const leftPath = path.get("left"); | ||
if (leftPath.isObjectPattern() && hasRestElement(leftPath)) { | ||
var nodes = []; | ||
var refName = path.scope.generateUidBasedOnNode(path.node.right, "ref"); | ||
const nodes = []; | ||
const refName = path.scope.generateUidBasedOnNode(path.node.right, "ref"); | ||
nodes.push(_core().types.variableDeclaration("var", [_core().types.variableDeclarator(_core().types.identifier(refName), path.node.right)])); | ||
var _createObjectSpread2 = createObjectSpread(leftPath, file, _core().types.identifier(refName)), | ||
impureComputedPropertyDeclarators = _createObjectSpread2[0], | ||
argument = _createObjectSpread2[1], | ||
callExpression = _createObjectSpread2[2]; | ||
const _createObjectSpread2 = createObjectSpread(leftPath, file, _core().types.identifier(refName)), | ||
impureComputedPropertyDeclarators = _createObjectSpread2[0], | ||
argument = _createObjectSpread2[1], | ||
callExpression = _createObjectSpread2[2]; | ||
@@ -353,3 +352,3 @@ if (impureComputedPropertyDeclarators.length > 0) { | ||
var nodeWithoutSpread = _core().types.cloneNode(path.node); | ||
const nodeWithoutSpread = _core().types.cloneNode(path.node); | ||
@@ -363,10 +362,11 @@ nodeWithoutSpread.right = _core().types.identifier(refName); | ||
}, | ||
ForXStatement: function ForXStatement(path) { | ||
var node = path.node, | ||
scope = path.scope; | ||
var leftPath = path.get("left"); | ||
var left = node.left; | ||
ForXStatement(path) { | ||
const node = path.node, | ||
scope = path.scope; | ||
const leftPath = path.get("left"); | ||
const left = node.left; | ||
if (_core().types.isObjectPattern(left) && hasRestElement(leftPath)) { | ||
var temp = scope.generateUidIdentifier("ref"); | ||
const temp = scope.generateUidIdentifier("ref"); | ||
node.left = _core().types.variableDeclaration("var", [_core().types.variableDeclarator(temp)]); | ||
@@ -379,5 +379,5 @@ path.ensureBlock(); | ||
if (!_core().types.isVariableDeclaration(left)) return; | ||
var pattern = left.declarations[0].id; | ||
const pattern = left.declarations[0].id; | ||
if (!_core().types.isObjectPattern(pattern)) return; | ||
var key = scope.generateUidIdentifier("ref"); | ||
const key = scope.generateUidIdentifier("ref"); | ||
node.left = _core().types.variableDeclaration(left.kind, [_core().types.variableDeclarator(key, null)]); | ||
@@ -387,6 +387,7 @@ path.ensureBlock(); | ||
}, | ||
ObjectExpression: function ObjectExpression(path, file) { | ||
ObjectExpression(path, file) { | ||
if (!hasSpread(path.node)) return; | ||
var args = []; | ||
var props = []; | ||
const args = []; | ||
let props = []; | ||
@@ -405,4 +406,4 @@ function push() { | ||
for (var _i5 = 0; _i5 < _arr.length; _i5++) { | ||
var prop = _arr[_i5]; | ||
for (var _i4 = 0; _i4 < _arr.length; _i4++) { | ||
const prop = _arr[_i4]; | ||
@@ -418,3 +419,3 @@ if (_core().types.isSpreadElement(prop)) { | ||
push(); | ||
var helper; | ||
let helper; | ||
@@ -429,2 +430,3 @@ if (loose) { | ||
} | ||
} | ||
@@ -431,0 +433,0 @@ }; |
{ | ||
"name": "@babel/plugin-proposal-object-rest-spread", | ||
"version": "7.0.0-beta.46", | ||
"version": "7.0.0-beta.47", | ||
"description": "Compile object rest and spread to ES5", | ||
@@ -12,12 +12,12 @@ "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-proposal-object-rest-spread", | ||
"dependencies": { | ||
"@babel/helper-plugin-utils": "7.0.0-beta.46", | ||
"@babel/plugin-syntax-object-rest-spread": "7.0.0-beta.46" | ||
"@babel/helper-plugin-utils": "7.0.0-beta.47", | ||
"@babel/plugin-syntax-object-rest-spread": "7.0.0-beta.47" | ||
}, | ||
"peerDependencies": { | ||
"@babel/core": "7.0.0-beta.46" | ||
"@babel/core": "7.0.0-beta.47" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "7.0.0-beta.46", | ||
"@babel/helper-plugin-test-runner": "7.0.0-beta.46" | ||
"@babel/core": "7.0.0-beta.47", | ||
"@babel/helper-plugin-test-runner": "7.0.0-beta.47" | ||
} | ||
} |
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
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
0
16904
315
+ Added@babel/code-frame@7.0.0-beta.47(transitive)
+ Added@babel/core@7.0.0-beta.47(transitive)
+ Added@babel/generator@7.0.0-beta.47(transitive)
+ Added@babel/helper-function-name@7.0.0-beta.47(transitive)
+ Added@babel/helper-get-function-arity@7.0.0-beta.47(transitive)
+ Added@babel/helper-plugin-utils@7.0.0-beta.47(transitive)
+ Added@babel/helper-split-export-declaration@7.0.0-beta.47(transitive)
+ Added@babel/helpers@7.0.0-beta.47(transitive)
+ Added@babel/highlight@7.0.0-beta.47(transitive)
+ Added@babel/plugin-syntax-object-rest-spread@7.0.0-beta.47(transitive)
+ Added@babel/template@7.0.0-beta.47(transitive)
+ Added@babel/traverse@7.0.0-beta.47(transitive)
+ Added@babel/types@7.0.0-beta.47(transitive)
+ Addedbabylon@7.0.0-beta.47(transitive)
- Removed@babel/code-frame@7.0.0-beta.46(transitive)
- Removed@babel/core@7.0.0-beta.46(transitive)
- Removed@babel/generator@7.0.0-beta.46(transitive)
- Removed@babel/helper-function-name@7.0.0-beta.46(transitive)
- Removed@babel/helper-get-function-arity@7.0.0-beta.46(transitive)
- Removed@babel/helper-plugin-utils@7.0.0-beta.46(transitive)
- Removed@babel/helper-split-export-declaration@7.0.0-beta.46(transitive)
- Removed@babel/helpers@7.0.0-beta.46(transitive)
- Removed@babel/highlight@7.0.0-beta.46(transitive)
- Removed@babel/plugin-syntax-object-rest-spread@7.0.0-beta.46(transitive)
- Removed@babel/template@7.0.0-beta.46(transitive)
- Removed@babel/traverse@7.0.0-beta.46(transitive)
- Removed@babel/types@7.0.0-beta.46(transitive)
- Removedbabylon@7.0.0-beta.46(transitive)
Updated@babel/plugin-syntax-object-rest-spread@7.0.0-beta.47