babel-plugin-transform-object-rest-spread
Advanced tools
Comparing version 6.20.2 to 6.22.0
@@ -73,8 +73,12 @@ "use strict"; | ||
function replaceRestProperty(paramsPath, i, numParams) { | ||
if (paramsPath.isObjectPattern() && hasRestProperty(paramsPath)) { | ||
var parentPath = paramsPath.parentPath; | ||
function replaceRestProperty(parentPath, paramPath, i, numParams) { | ||
if (paramPath.isAssignmentPattern()) { | ||
replaceRestProperty(parentPath, paramPath.get("left"), i, numParams); | ||
return; | ||
} | ||
if (paramPath.isObjectPattern() && hasRestProperty(paramPath)) { | ||
var uid = parentPath.scope.generateUidIdentifier("ref"); | ||
var declar = t.variableDeclaration("let", [t.variableDeclarator(paramsPath.node, uid)]); | ||
var declar = t.variableDeclaration("let", [t.variableDeclarator(paramPath.node, uid)]); | ||
declar._blockHoist = i ? numParams - i : 1; | ||
@@ -84,3 +88,3 @@ | ||
parentPath.get("body").unshiftContainer("body", declar); | ||
paramsPath.replaceWith(uid); | ||
paramPath.replaceWith(uid); | ||
} | ||
@@ -96,3 +100,3 @@ } | ||
for (var i = 0; i < params.length; i++) { | ||
replaceRestProperty(params[i], i, params.length); | ||
replaceRestProperty(params[i].parentPath, params[i], i, params.length); | ||
} | ||
@@ -104,7 +108,17 @@ }, | ||
} | ||
var kind = path.parentPath.node.kind; | ||
var nodes = []; | ||
path.traverse({ | ||
var insertionPath = path; | ||
path.get("id").traverse({ | ||
RestProperty: function RestProperty(path) { | ||
if (this.originalPath.node.id.properties.length > 1 && !t.isIdentifier(this.originalPath.node.init)) { | ||
var initRef = path.scope.generateUidIdentifierBasedOnNode(this.originalPath.node.init, "ref"); | ||
this.originalPath.insertBefore(t.variableDeclarator(initRef, this.originalPath.node.init)); | ||
this.originalPath.replaceWith(t.variableDeclarator(this.originalPath.node.id, initRef)); | ||
return; | ||
} | ||
var ref = this.originalPath.node.init; | ||
@@ -124,7 +138,9 @@ | ||
nodes.push(t.variableDeclarator(argument, callExpression)); | ||
insertionPath.insertAfter(t.variableDeclarator(argument, callExpression)); | ||
insertionPath = insertionPath.getSibling(insertionPath.key + 1); | ||
if (path.parentPath.node.properties.length === 0) { | ||
path.findParent(function (path) { | ||
return path.isObjectProperty() || path.isVariableDeclaration(); | ||
return path.isObjectProperty() || path.isVariableDeclarator(); | ||
}).remove(); | ||
@@ -136,6 +152,2 @@ } | ||
}); | ||
if (nodes.length > 0) { | ||
path.parentPath.getSibling(path.parentPath.key + 1).insertBefore(t.variableDeclaration(kind, nodes)); | ||
} | ||
}, | ||
@@ -158,3 +170,4 @@ ExportNamedDeclaration: function ExportNamedDeclaration(path) { | ||
CatchClause: function CatchClause(path) { | ||
replaceRestProperty(path.get("param")); | ||
var paramPath = path.get("param"); | ||
replaceRestProperty(paramPath.parentPath, paramPath); | ||
}, | ||
@@ -161,0 +174,0 @@ AssignmentExpression: function AssignmentExpression(path, file) { |
{ | ||
"name": "babel-plugin-transform-object-rest-spread", | ||
"version": "6.20.2", | ||
"version": "6.22.0", | ||
"description": "Compile object rest and spread to ES5", | ||
@@ -13,7 +13,7 @@ "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-object-rest-spread", | ||
"babel-plugin-syntax-object-rest-spread": "^6.8.0", | ||
"babel-runtime": "^6.20.0" | ||
"babel-runtime": "^6.22.0" | ||
}, | ||
"devDependencies": { | ||
"babel-helper-plugin-test-runner": "^6.8.0" | ||
"babel-helper-plugin-test-runner": "^6.22.0" | ||
} | ||
} |
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
11610
215
Updatedbabel-runtime@^6.22.0