@babel/plugin-proposal-object-rest-spread
Advanced tools
Comparing version 7.5.5 to 7.6.2
@@ -67,5 +67,5 @@ "use strict"; | ||
let foundRestElement = false; | ||
visitRestElements(path, () => { | ||
visitRestElements(path, restElement => { | ||
foundRestElement = true; | ||
path.stop(); | ||
restElement.stop(); | ||
}); | ||
@@ -75,2 +75,13 @@ return foundRestElement; | ||
function hasObjectPatternRestElement(path) { | ||
let foundRestElement = false; | ||
visitRestElements(path, restElement => { | ||
if (restElement.parentPath.isObjectPattern()) { | ||
foundRestElement = true; | ||
restElement.stop(); | ||
} | ||
}); | ||
return foundRestElement; | ||
} | ||
function visitRestElements(path, visitor) { | ||
@@ -186,5 +197,5 @@ path.traverse({ | ||
function replaceRestElement(parentPath, paramPath, i, numParams) { | ||
function replaceRestElement(parentPath, paramPath) { | ||
if (paramPath.isAssignmentPattern()) { | ||
replaceRestElement(parentPath, paramPath.get("left"), i, numParams); | ||
replaceRestElement(parentPath, paramPath.get("left")); | ||
return; | ||
@@ -197,3 +208,3 @@ } | ||
for (let i = 0; i < elements.length; i++) { | ||
replaceRestElement(parentPath, elements[i], i, elements.length); | ||
replaceRestElement(parentPath, elements[i]); | ||
} | ||
@@ -221,3 +232,3 @@ } | ||
for (let i = params.length - 1; i >= 0; i--) { | ||
replaceRestElement(params[i].parentPath, params[i], i, params.length); | ||
replaceRestElement(params[i].parentPath, params[i]); | ||
} | ||
@@ -334,3 +345,7 @@ }, | ||
if (_core().types.isObjectPattern(left) && hasRestElement(leftPath)) { | ||
if (!hasObjectPatternRestElement(leftPath)) { | ||
return; | ||
} | ||
if (!_core().types.isVariableDeclaration(left)) { | ||
const temp = scope.generateUidIdentifier("ref"); | ||
@@ -345,12 +360,29 @@ node.left = _core().types.variableDeclaration("var", [_core().types.variableDeclarator(temp)]); | ||
node.body.body.unshift(_core().types.expressionStatement(_core().types.assignmentExpression("=", left, _core().types.cloneNode(temp)))); | ||
return; | ||
} else { | ||
const pattern = left.declarations[0].id; | ||
const key = scope.generateUidIdentifier("ref"); | ||
node.left = _core().types.variableDeclaration(left.kind, [_core().types.variableDeclarator(key, null)]); | ||
path.ensureBlock(); | ||
node.body.body.unshift(_core().types.variableDeclaration(node.left.kind, [_core().types.variableDeclarator(pattern, _core().types.cloneNode(key))])); | ||
} | ||
}, | ||
if (!_core().types.isVariableDeclaration(left)) return; | ||
const pattern = left.declarations[0].id; | ||
if (!_core().types.isObjectPattern(pattern)) return; | ||
const key = scope.generateUidIdentifier("ref"); | ||
node.left = _core().types.variableDeclaration(left.kind, [_core().types.variableDeclarator(key, null)]); | ||
path.ensureBlock(); | ||
node.body.body.unshift(_core().types.variableDeclaration(node.left.kind, [_core().types.variableDeclarator(pattern, _core().types.cloneNode(key))])); | ||
ArrayPattern(path) { | ||
const objectPatterns = []; | ||
visitRestElements(path, path => { | ||
if (!path.parentPath.isObjectPattern()) { | ||
return; | ||
} | ||
const objectPattern = path.parentPath; | ||
const uid = path.scope.generateUidIdentifier("ref"); | ||
objectPatterns.push(_core().types.variableDeclarator(objectPattern.node, uid)); | ||
objectPattern.replaceWith(_core().types.cloneNode(uid)); | ||
path.skip(); | ||
}); | ||
if (objectPatterns.length > 0) { | ||
const statementPath = path.getStatementParent(); | ||
statementPath.insertAfter(_core().types.variableDeclaration(statementPath.node.kind || "var", objectPatterns)); | ||
} | ||
}, | ||
@@ -357,0 +389,0 @@ |
{ | ||
"name": "@babel/plugin-proposal-object-rest-spread", | ||
"version": "7.5.5", | ||
"version": "7.6.2", | ||
"description": "Compile object rest and spread to ES5", | ||
@@ -22,6 +22,6 @@ "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-proposal-object-rest-spread", | ||
"devDependencies": { | ||
"@babel/core": "^7.5.5", | ||
"@babel/core": "^7.6.2", | ||
"@babel/helper-plugin-test-runner": "^7.0.0" | ||
}, | ||
"gitHead": "0407f034f09381b95e9cabefbf6b176c76485a43" | ||
"gitHead": "b9cb4af953afb1a5aeed9b18526192ab15bb45c1" | ||
} |
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
16221
336