@babel/plugin-proposal-object-rest-spread
Advanced tools
Comparing version 7.19.4 to 7.20.2
@@ -34,3 +34,2 @@ 'use strict'; | ||
const firstProperty = properties[0]; | ||
if (isObjectProperty$1(firstProperty)) { | ||
@@ -60,2 +59,3 @@ return shouldStoreRHSInTemporaryVariable(firstProperty.value); | ||
const pattern = core.types.objectPattern([property]); | ||
var ZERO_REFS = core.types.isReferenced(node, property, pattern) ? 1 : 0; | ||
@@ -65,3 +65,2 @@ } | ||
var _api$assumption, _api$assumption2, _api$assumption3, _api$assumption4; | ||
api.assertVersion(7); | ||
@@ -76,7 +75,5 @@ const targets = api.targets(); | ||
} = opts; | ||
if (typeof loose !== "boolean") { | ||
throw new Error(".loose must be a boolean, or undefined"); | ||
} | ||
const ignoreFunctionLength = (_api$assumption = api.assumption("ignoreFunctionLength")) != null ? _api$assumption : loose; | ||
@@ -86,7 +83,5 @@ const objectRestNoSymbols = (_api$assumption2 = api.assumption("objectRestNoSymbols")) != null ? _api$assumption2 : loose; | ||
const setSpreadProperties = (_api$assumption4 = api.assumption("setSpreadProperties")) != null ? _api$assumption4 : loose; | ||
function getExtendsHelper(file) { | ||
return useBuiltIns ? core.types.memberExpression(core.types.identifier("Object"), core.types.identifier("assign")) : file.addHelper("extends"); | ||
} | ||
function hasRestElement(path) { | ||
@@ -100,3 +95,2 @@ let foundRestElement = false; | ||
} | ||
function hasObjectPatternRestElement(path) { | ||
@@ -112,3 +106,2 @@ let foundRestElement = false; | ||
} | ||
function visitRestElements(path, visitor) { | ||
@@ -121,3 +114,2 @@ path.traverse({ | ||
} = path; | ||
if (isAssignmentPattern(parent) && key === "right" || isObjectProperty(parent) && parent.computed && key === "key") { | ||
@@ -127,7 +119,5 @@ path.skip(); | ||
}, | ||
RestElement: visitor | ||
}); | ||
} | ||
function hasSpread(node) { | ||
@@ -139,3 +129,2 @@ for (const prop of node.properties) { | ||
} | ||
return false; | ||
@@ -149,3 +138,2 @@ } | ||
let hasTemplateLiteral = false; | ||
for (const prop of props) { | ||
@@ -158,3 +146,4 @@ if (core.types.isIdentifier(prop.key) && !prop.computed) { | ||
} else if (core.types.isLiteral(prop.key)) { | ||
keys.push(core.types.stringLiteral(String(prop.key.value))); | ||
keys.push(core.types.stringLiteral(String( | ||
prop.key.value))); | ||
} else { | ||
@@ -165,3 +154,2 @@ keys.push(core.types.cloneNode(prop.key)); | ||
} | ||
return { | ||
@@ -176,6 +164,4 @@ keys, | ||
const impureComputedPropertyDeclarators = []; | ||
for (const propPath of properties) { | ||
const key = propPath.get("key"); | ||
if (propPath.node.computed && !key.isPure()) { | ||
@@ -188,6 +174,4 @@ const name = scope.generateUidBasedOnNode(key.node); | ||
} | ||
return impureComputedPropertyDeclarators; | ||
} | ||
function removeUnusedExcludedKeys(path) { | ||
@@ -197,7 +181,5 @@ const bindings = path.getOuterBindingIdentifierPaths(); | ||
const bindingParentPath = bindings[bindingName].parentPath; | ||
if (path.scope.getBinding(bindingName).references > ZERO_REFS || !bindingParentPath.isObjectProperty()) { | ||
return; | ||
} | ||
bindingParentPath.remove(); | ||
@@ -219,9 +201,6 @@ }); | ||
} = extractNormalizedKeys(path.node); | ||
if (keys.length === 0) { | ||
return [impureComputedPropertyDeclarators, restElement.argument, core.types.callExpression(getExtendsHelper(file), [core.types.objectExpression([]), core.types.sequenceExpression([core.types.callExpression(file.addHelper("objectDestructuringEmpty"), [core.types.cloneNode(objRef)]), core.types.cloneNode(objRef)])])]; | ||
} | ||
let keyExpression; | ||
if (!allLiteral) { | ||
@@ -231,3 +210,2 @@ keyExpression = core.types.callExpression(core.types.memberExpression(core.types.arrayExpression(keys), core.types.identifier("map")), [file.addHelper("toPropertyKey")]); | ||
keyExpression = core.types.arrayExpression(keys); | ||
if (!hasTemplateLiteral && !core.types.isProgram(path.scope.block)) { | ||
@@ -244,6 +222,4 @@ const program = path.findParent(path => path.isProgram()); | ||
} | ||
return [impureComputedPropertyDeclarators, restElement.argument, core.types.callExpression(file.addHelper(`objectWithoutProperties${objectRestNoSymbols ? "Loose" : ""}`), [core.types.cloneNode(objRef), keyExpression])]; | ||
} | ||
function replaceRestElement(parentPath, paramPath, container) { | ||
@@ -254,6 +230,4 @@ if (paramPath.isAssignmentPattern()) { | ||
} | ||
if (paramPath.isArrayPattern() && hasRestElement(paramPath)) { | ||
const elements = paramPath.get("elements"); | ||
for (let i = 0; i < elements.length; i++) { | ||
@@ -263,7 +237,5 @@ replaceRestElement(parentPath, elements[i], container); | ||
} | ||
if (paramPath.isObjectPattern() && hasRestElement(paramPath)) { | ||
const uid = parentPath.scope.generateUidIdentifier("ref"); | ||
const declar = core.types.variableDeclaration("let", [core.types.variableDeclarator(paramPath.node, uid)]); | ||
if (container) { | ||
@@ -275,7 +247,5 @@ container.push(declar); | ||
} | ||
paramPath.replaceWith(core.types.cloneNode(uid)); | ||
} | ||
} | ||
return { | ||
@@ -289,9 +259,6 @@ name: "proposal-object-rest-spread", | ||
const idsInRestParams = new Set(); | ||
for (let i = 0; i < params.length; ++i) { | ||
const param = params[i]; | ||
if (hasRestElement(param)) { | ||
paramsWithRestElement.add(i); | ||
for (const name of Object.keys(param.getBindingIdentifiers())) { | ||
@@ -304,6 +271,4 @@ idsInRestParams.add(name); | ||
let idInRest = false; | ||
const IdentifierHandler = function (path, functionScope) { | ||
const name = path.node.name; | ||
if (path.scope.getBinding(name) === functionScope.getBinding(name) && idsInRestParams.has(name)) { | ||
@@ -314,8 +279,5 @@ idInRest = true; | ||
}; | ||
let i; | ||
for (i = 0; i < params.length && !idInRest; ++i) { | ||
const param = params[i]; | ||
if (!paramsWithRestElement.has(i)) { | ||
@@ -332,7 +294,5 @@ if (param.isReferencedIdentifier() || param.isBindingIdentifier()) { | ||
} | ||
if (!idInRest) { | ||
for (let i = 0; i < params.length; ++i) { | ||
const param = params[i]; | ||
if (paramsWithRestElement.has(i)) { | ||
@@ -344,7 +304,5 @@ replaceRestElement(path, param); | ||
const shouldTransformParam = idx => idx >= i - 1 || paramsWithRestElement.has(idx); | ||
pluginTransformParameters.convertFunctionParams(path, ignoreFunctionLength, shouldTransformParam, replaceRestElement); | ||
} | ||
}, | ||
VariableDeclarator(path, file) { | ||
@@ -354,3 +312,2 @@ if (!path.get("id").isObjectPattern()) { | ||
} | ||
let insertionPath = path; | ||
@@ -362,4 +319,4 @@ const originalPath = path; | ||
} | ||
if (shouldStoreRHSInTemporaryVariable(originalPath.node.id) && !core.types.isIdentifier(originalPath.node.init)) { | ||
if ( | ||
shouldStoreRHSInTemporaryVariable(originalPath.node.id) && !core.types.isIdentifier(originalPath.node.init)) { | ||
const initRef = path.scope.generateUidIdentifierBasedOnNode(originalPath.node.init, "ref"); | ||
@@ -370,3 +327,2 @@ originalPath.insertBefore(core.types.variableDeclarator(initRef, originalPath.node.init)); | ||
} | ||
let ref = originalPath.node.init; | ||
@@ -390,9 +346,8 @@ const refPropertyPath = []; | ||
}); | ||
const objectPatternPath = path.findParent(path => path.isObjectPattern()); | ||
const [impureComputedPropertyDeclarators, argument, callExpression] = createObjectRest(objectPatternPath, file, ref); | ||
if (pureGetters) { | ||
removeUnusedExcludedKeys(objectPatternPath); | ||
} | ||
core.types.assertIdentifier(argument); | ||
@@ -403,3 +358,2 @@ insertionPath.insertBefore(impureComputedPropertyDeclarators); | ||
path.scope.registerBinding(kind, insertionPath); | ||
if (objectPatternPath.node.properties.length === 0) { | ||
@@ -410,3 +364,2 @@ objectPatternPath.findParent(path => path.isObjectProperty() || path.isVariableDeclarator()).remove(); | ||
}, | ||
ExportNamedDeclaration(path) { | ||
@@ -418,3 +371,2 @@ const declaration = path.get("declaration"); | ||
const specifiers = []; | ||
for (const name of Object.keys(path.getOuterBindingIdentifiers(true))) { | ||
@@ -427,3 +379,2 @@ specifiers.push(core.types.exportSpecifier(core.types.identifier(name), core.types.identifier(name))); | ||
}, | ||
CatchClause(path) { | ||
@@ -433,6 +384,4 @@ const paramPath = path.get("param"); | ||
}, | ||
AssignmentExpression(path, file) { | ||
const leftPath = path.get("left"); | ||
if (leftPath.isObjectPattern() && hasRestElement(leftPath)) { | ||
@@ -443,11 +392,9 @@ const nodes = []; | ||
const [impureComputedPropertyDeclarators, argument, callExpression] = createObjectRest(leftPath, file, core.types.identifier(refName)); | ||
if (impureComputedPropertyDeclarators.length > 0) { | ||
nodes.push(core.types.variableDeclaration("var", impureComputedPropertyDeclarators)); | ||
} | ||
const nodeWithoutSpread = core.types.cloneNode(path.node); | ||
nodeWithoutSpread.right = core.types.identifier(refName); | ||
nodes.push(core.types.expressionStatement(nodeWithoutSpread)); | ||
nodes.push(core.types.toStatement(core.types.assignmentExpression("=", argument, callExpression))); | ||
nodes.push(core.types.expressionStatement(core.types.assignmentExpression("=", argument, callExpression))); | ||
nodes.push(core.types.expressionStatement(core.types.identifier(refName))); | ||
@@ -457,3 +404,2 @@ path.replaceWithMultiple(nodes); | ||
}, | ||
ForXStatement(path) { | ||
@@ -466,7 +412,5 @@ const { | ||
const left = node.left; | ||
if (!hasObjectPatternRestElement(leftPath)) { | ||
return; | ||
} | ||
if (!core.types.isVariableDeclaration(left)) { | ||
@@ -477,7 +421,5 @@ const temp = scope.generateUidIdentifier("ref"); | ||
const body = path.node.body; | ||
if (body.body.length === 0 && path.isCompletionRecord()) { | ||
body.body.unshift(core.types.expressionStatement(scope.buildUndefinedNode())); | ||
} | ||
body.body.unshift(core.types.expressionStatement(core.types.assignmentExpression("=", left, core.types.cloneNode(temp)))); | ||
@@ -493,3 +435,2 @@ } else { | ||
}, | ||
ArrayPattern(path) { | ||
@@ -501,3 +442,2 @@ const objectPatterns = []; | ||
} | ||
const objectPattern = path.parentPath; | ||
@@ -509,3 +449,2 @@ const uid = path.scope.generateUidIdentifier("ref"); | ||
}); | ||
if (objectPatterns.length > 0) { | ||
@@ -518,7 +457,5 @@ const statementPath = path.getStatementParent(); | ||
}, | ||
ObjectExpression(path, file) { | ||
if (!hasSpread(path.node)) return; | ||
let helper; | ||
if (setSpreadProperties) { | ||
@@ -531,9 +468,8 @@ helper = getExtendsHelper(file); | ||
this.file.declarations["objectSpread2"] = null; | ||
helper = file.addHelper("objectSpread"); | ||
} | ||
} | ||
let exp = null; | ||
let props = []; | ||
function make() { | ||
@@ -543,3 +479,2 @@ const hadProps = props.length > 0; | ||
props = []; | ||
if (!exp) { | ||
@@ -554,9 +489,7 @@ exp = core.types.callExpression(helper, [obj]); | ||
} | ||
return; | ||
} | ||
exp = core.types.callExpression(core.types.cloneNode(helper), [exp, ...(hadProps ? [core.types.objectExpression([]), obj] : [])]); | ||
exp = core.types.callExpression(core.types.cloneNode(helper), [exp, | ||
...(hadProps ? [core.types.objectExpression([]), obj] : [])]); | ||
} | ||
for (const prop of path.node.properties) { | ||
@@ -570,7 +503,5 @@ if (core.types.isSpreadElement(prop)) { | ||
} | ||
if (props.length) make(); | ||
path.replaceWith(exp); | ||
} | ||
} | ||
@@ -577,0 +508,0 @@ }; |
{ | ||
"name": "@babel/plugin-proposal-object-rest-spread", | ||
"version": "7.19.4", | ||
"version": "7.20.2", | ||
"description": "Compile object rest and spread to ES5", | ||
@@ -20,7 +20,7 @@ "repository": { | ||
"dependencies": { | ||
"@babel/compat-data": "^7.19.4", | ||
"@babel/helper-compilation-targets": "^7.19.3", | ||
"@babel/helper-plugin-utils": "^7.19.0", | ||
"@babel/compat-data": "^7.20.1", | ||
"@babel/helper-compilation-targets": "^7.20.0", | ||
"@babel/helper-plugin-utils": "^7.20.2", | ||
"@babel/plugin-syntax-object-rest-spread": "^7.8.3", | ||
"@babel/plugin-transform-parameters": "^7.18.8" | ||
"@babel/plugin-transform-parameters": "^7.20.1" | ||
}, | ||
@@ -31,5 +31,5 @@ "peerDependencies": { | ||
"devDependencies": { | ||
"@babel/core": "^7.19.3", | ||
"@babel/core": "^7.20.2", | ||
"@babel/helper-plugin-test-runner": "^7.18.6", | ||
"@babel/parser": "^7.19.4" | ||
"@babel/parser": "^7.20.2" | ||
}, | ||
@@ -36,0 +36,0 @@ "engines": { |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
449
0
70551