@babel/plugin-transform-object-rest-spread
Advanced tools
Comparing version 7.22.5 to 8.0.0-alpha.0
153
lib/index.js
@@ -1,16 +0,8 @@ | ||
'use strict'; | ||
import { declare } from '@babel/helper-plugin-utils'; | ||
import syntaxObjectRestSpread from '@babel/plugin-syntax-object-rest-spread'; | ||
import { types } from '@babel/core'; | ||
import { convertFunctionParams } from '@babel/plugin-transform-parameters'; | ||
import { isRequired } from '@babel/helper-compilation-targets'; | ||
import compatData from '@babel/compat-data/corejs2-built-ins'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var helperPluginUtils = require('@babel/helper-plugin-utils'); | ||
var syntaxObjectRestSpread = require('@babel/plugin-syntax-object-rest-spread'); | ||
var core = require('@babel/core'); | ||
var pluginTransformParameters = require('@babel/plugin-transform-parameters'); | ||
var helperCompilationTargets = require('@babel/helper-compilation-targets'); | ||
var compatData = require('@babel/compat-data/corejs2-built-ins'); | ||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
var compatData__default = /*#__PURE__*/_interopDefaultLegacy(compatData); | ||
const { | ||
@@ -23,3 +15,3 @@ isObjectProperty: isObjectProperty$1, | ||
isIdentifier | ||
} = core.types; | ||
} = types; | ||
function shouldStoreRHSInTemporaryVariable(node) { | ||
@@ -54,15 +46,8 @@ if (isArrayPattern(node)) { | ||
isObjectProperty | ||
} = core.types; | ||
{ | ||
const node = core.types.identifier("a"); | ||
const property = core.types.objectProperty(core.types.identifier("key"), node); | ||
const pattern = core.types.objectPattern([property]); | ||
var ZERO_REFS = core.types.isReferenced(node, property, pattern) ? 1 : 0; | ||
} | ||
var index = helperPluginUtils.declare((api, opts) => { | ||
var _api$assumption, _api$assumption2, _api$assumption3, _api$assumption4; | ||
} = types; | ||
var index = declare((api, opts) => { | ||
api.assertVersion(7); | ||
const targets = api.targets(); | ||
const supportsObjectAssign = !helperCompilationTargets.isRequired("es6.object.assign", targets, { | ||
compatData: compatData__default["default"] | ||
const supportsObjectAssign = !isRequired("es6.object.assign", targets, { | ||
compatData | ||
}); | ||
@@ -76,8 +61,8 @@ const { | ||
} | ||
const ignoreFunctionLength = (_api$assumption = api.assumption("ignoreFunctionLength")) != null ? _api$assumption : loose; | ||
const objectRestNoSymbols = (_api$assumption2 = api.assumption("objectRestNoSymbols")) != null ? _api$assumption2 : loose; | ||
const pureGetters = (_api$assumption3 = api.assumption("pureGetters")) != null ? _api$assumption3 : loose; | ||
const setSpreadProperties = (_api$assumption4 = api.assumption("setSpreadProperties")) != null ? _api$assumption4 : loose; | ||
const ignoreFunctionLength = api.assumption("ignoreFunctionLength") ?? loose; | ||
const objectRestNoSymbols = api.assumption("objectRestNoSymbols") ?? loose; | ||
const pureGetters = api.assumption("pureGetters") ?? loose; | ||
const setSpreadProperties = api.assumption("setSpreadProperties") ?? loose; | ||
function getExtendsHelper(file) { | ||
return useBuiltIns ? core.types.memberExpression(core.types.identifier("Object"), core.types.identifier("assign")) : file.addHelper("extends"); | ||
return useBuiltIns ? types.memberExpression(types.identifier("Object"), types.identifier("assign")) : file.addHelper("extends"); | ||
} | ||
@@ -118,3 +103,3 @@ function hasRestElement(path) { | ||
for (const prop of node.properties) { | ||
if (core.types.isSpreadElement(prop)) { | ||
if (types.isSpreadElement(prop)) { | ||
return true; | ||
@@ -131,11 +116,11 @@ } | ||
for (const prop of props) { | ||
if (core.types.isIdentifier(prop.key) && !prop.computed) { | ||
keys.push(core.types.stringLiteral(prop.key.name)); | ||
} else if (core.types.isTemplateLiteral(prop.key)) { | ||
keys.push(core.types.cloneNode(prop.key)); | ||
if (types.isIdentifier(prop.key) && !prop.computed) { | ||
keys.push(types.stringLiteral(prop.key.name)); | ||
} else if (types.isTemplateLiteral(prop.key)) { | ||
keys.push(types.cloneNode(prop.key)); | ||
hasTemplateLiteral = true; | ||
} else if (core.types.isLiteral(prop.key)) { | ||
keys.push(core.types.stringLiteral(String(prop.key.value))); | ||
} else if (types.isLiteral(prop.key)) { | ||
keys.push(types.stringLiteral(String(prop.key.value))); | ||
} else { | ||
keys.push(core.types.cloneNode(prop.key)); | ||
keys.push(types.cloneNode(prop.key)); | ||
allLiteral = false; | ||
@@ -156,5 +141,5 @@ } | ||
const name = scope.generateUidBasedOnNode(key.node); | ||
const declarator = core.types.variableDeclarator(core.types.identifier(name), key.node); | ||
const declarator = types.variableDeclarator(types.identifier(name), key.node); | ||
impureComputedPropertyDeclarators.push(declarator); | ||
key.replaceWith(core.types.identifier(name)); | ||
key.replaceWith(types.identifier(name)); | ||
} | ||
@@ -168,3 +153,3 @@ } | ||
const bindingParentPath = bindings[bindingName].parentPath; | ||
if (path.scope.getBinding(bindingName).references > ZERO_REFS || !bindingParentPath.isObjectProperty()) { | ||
if (path.scope.getBinding(bindingName).references > 0 || !bindingParentPath.isObjectProperty()) { | ||
return; | ||
@@ -178,4 +163,4 @@ } | ||
const last = props[props.length - 1]; | ||
core.types.assertRestElement(last.node); | ||
const restElement = core.types.cloneNode(last.node); | ||
types.assertRestElement(last.node); | ||
const restElement = types.cloneNode(last.node); | ||
last.remove(); | ||
@@ -189,10 +174,10 @@ const impureComputedPropertyDeclarators = replaceImpureComputedKeys(path.get("properties"), path.scope); | ||
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)])])]; | ||
return [impureComputedPropertyDeclarators, restElement.argument, types.callExpression(getExtendsHelper(file), [types.objectExpression([]), types.sequenceExpression([types.callExpression(file.addHelper("objectDestructuringEmpty"), [types.cloneNode(objRef)]), types.cloneNode(objRef)])])]; | ||
} | ||
let keyExpression; | ||
if (!allLiteral) { | ||
keyExpression = core.types.callExpression(core.types.memberExpression(core.types.arrayExpression(keys), core.types.identifier("map")), [file.addHelper("toPropertyKey")]); | ||
keyExpression = types.callExpression(types.memberExpression(types.arrayExpression(keys), types.identifier("map")), [file.addHelper("toPropertyKey")]); | ||
} else { | ||
keyExpression = core.types.arrayExpression(keys); | ||
if (!hasTemplateLiteral && !core.types.isProgram(path.scope.block)) { | ||
keyExpression = types.arrayExpression(keys); | ||
if (!hasTemplateLiteral && !types.isProgram(path.scope.block)) { | ||
const program = path.findParent(path => path.isProgram()); | ||
@@ -205,6 +190,6 @@ const id = path.scope.generateUidIdentifier("excluded"); | ||
}); | ||
keyExpression = core.types.cloneNode(id); | ||
keyExpression = types.cloneNode(id); | ||
} | ||
} | ||
return [impureComputedPropertyDeclarators, restElement.argument, core.types.callExpression(file.addHelper(`objectWithoutProperties${objectRestNoSymbols ? "Loose" : ""}`), [core.types.cloneNode(objRef), keyExpression])]; | ||
return [impureComputedPropertyDeclarators, restElement.argument, types.callExpression(file.addHelper(`objectWithoutProperties${objectRestNoSymbols ? "Loose" : ""}`), [types.cloneNode(objRef), keyExpression])]; | ||
} | ||
@@ -224,3 +209,3 @@ function replaceRestElement(parentPath, paramPath, container) { | ||
const uid = parentPath.scope.generateUidIdentifier("ref"); | ||
const declar = core.types.variableDeclaration("let", [core.types.variableDeclarator(paramPath.node, uid)]); | ||
const declar = types.variableDeclaration("let", [types.variableDeclarator(paramPath.node, uid)]); | ||
if (container) { | ||
@@ -232,3 +217,3 @@ container.push(declar); | ||
} | ||
paramPath.replaceWith(core.types.cloneNode(uid)); | ||
paramPath.replaceWith(types.cloneNode(uid)); | ||
} | ||
@@ -284,3 +269,3 @@ } | ||
const shouldTransformParam = idx => idx >= i - 1 || paramsWithRestElement.has(idx); | ||
pluginTransformParameters.convertFunctionParams(path, ignoreFunctionLength, shouldTransformParam, replaceRestElement); | ||
convertFunctionParams(path, ignoreFunctionLength, shouldTransformParam, replaceRestElement); | ||
} | ||
@@ -298,6 +283,6 @@ }, | ||
} | ||
if (shouldStoreRHSInTemporaryVariable(originalPath.node.id) && !core.types.isIdentifier(originalPath.node.init)) { | ||
if (shouldStoreRHSInTemporaryVariable(originalPath.node.id) && !types.isIdentifier(originalPath.node.init)) { | ||
const initRef = path.scope.generateUidIdentifierBasedOnNode(originalPath.node.init, "ref"); | ||
originalPath.insertBefore(core.types.variableDeclarator(initRef, originalPath.node.init)); | ||
originalPath.replaceWith(core.types.variableDeclarator(originalPath.node.id, core.types.cloneNode(initRef))); | ||
originalPath.insertBefore(types.variableDeclarator(initRef, originalPath.node.init)); | ||
originalPath.replaceWith(types.variableDeclarator(originalPath.node.id, types.cloneNode(initRef))); | ||
return; | ||
@@ -321,3 +306,3 @@ } | ||
} = prop; | ||
ref = core.types.memberExpression(ref, core.types.cloneNode(node.key), node.computed || core.types.isLiteral(node.key)); | ||
ref = types.memberExpression(ref, types.cloneNode(node.key), node.computed || types.isLiteral(node.key)); | ||
}); | ||
@@ -329,6 +314,6 @@ const objectPatternPath = path.findParent(path => path.isObjectPattern()); | ||
} | ||
core.types.assertIdentifier(argument); | ||
types.assertIdentifier(argument); | ||
insertionPath.insertBefore(impureComputedPropertyDeclarators); | ||
insertionPath.insertBefore(impureObjRefComputedDeclarators); | ||
insertionPath = insertionPath.insertAfter(core.types.variableDeclarator(argument, callExpression))[0]; | ||
insertionPath = insertionPath.insertAfter(types.variableDeclarator(argument, callExpression))[0]; | ||
path.scope.registerBinding(kind, insertionPath); | ||
@@ -347,6 +332,6 @@ if (objectPatternPath.node.properties.length === 0) { | ||
for (const name of Object.keys(path.getOuterBindingIdentifiers(true))) { | ||
specifiers.push(core.types.exportSpecifier(core.types.identifier(name), core.types.identifier(name))); | ||
specifiers.push(types.exportSpecifier(types.identifier(name), types.identifier(name))); | ||
} | ||
path.replaceWith(declaration.node); | ||
path.insertAfter(core.types.exportNamedDeclaration(null, specifiers)); | ||
path.insertAfter(types.exportNamedDeclaration(null, specifiers)); | ||
}, | ||
@@ -362,12 +347,12 @@ CatchClause(path) { | ||
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)])); | ||
const [impureComputedPropertyDeclarators, argument, callExpression] = createObjectRest(leftPath, file, core.types.identifier(refName)); | ||
nodes.push(types.variableDeclaration("var", [types.variableDeclarator(types.identifier(refName), path.node.right)])); | ||
const [impureComputedPropertyDeclarators, argument, callExpression] = createObjectRest(leftPath, file, types.identifier(refName)); | ||
if (impureComputedPropertyDeclarators.length > 0) { | ||
nodes.push(core.types.variableDeclaration("var", impureComputedPropertyDeclarators)); | ||
nodes.push(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.expressionStatement(core.types.assignmentExpression("=", argument, callExpression))); | ||
nodes.push(core.types.expressionStatement(core.types.identifier(refName))); | ||
const nodeWithoutSpread = types.cloneNode(path.node); | ||
nodeWithoutSpread.right = types.identifier(refName); | ||
nodes.push(types.expressionStatement(nodeWithoutSpread)); | ||
nodes.push(types.expressionStatement(types.assignmentExpression("=", argument, callExpression))); | ||
nodes.push(types.expressionStatement(types.identifier(refName))); | ||
path.replaceWithMultiple(nodes); | ||
@@ -386,18 +371,18 @@ } | ||
} | ||
if (!core.types.isVariableDeclaration(left)) { | ||
if (!types.isVariableDeclaration(left)) { | ||
const temp = scope.generateUidIdentifier("ref"); | ||
node.left = core.types.variableDeclaration("var", [core.types.variableDeclarator(temp)]); | ||
node.left = types.variableDeclaration("var", [types.variableDeclarator(temp)]); | ||
path.ensureBlock(); | ||
const body = path.node.body; | ||
if (body.body.length === 0 && path.isCompletionRecord()) { | ||
body.body.unshift(core.types.expressionStatement(scope.buildUndefinedNode())); | ||
body.body.unshift(types.expressionStatement(scope.buildUndefinedNode())); | ||
} | ||
body.body.unshift(core.types.expressionStatement(core.types.assignmentExpression("=", left, core.types.cloneNode(temp)))); | ||
body.body.unshift(types.expressionStatement(types.assignmentExpression("=", left, types.cloneNode(temp)))); | ||
} else { | ||
const pattern = left.declarations[0].id; | ||
const key = scope.generateUidIdentifier("ref"); | ||
node.left = core.types.variableDeclaration(left.kind, [core.types.variableDeclarator(key, null)]); | ||
node.left = types.variableDeclaration(left.kind, [types.variableDeclarator(key, null)]); | ||
path.ensureBlock(); | ||
const body = node.body; | ||
body.body.unshift(core.types.variableDeclaration(node.left.kind, [core.types.variableDeclarator(pattern, core.types.cloneNode(key))])); | ||
body.body.unshift(types.variableDeclaration(node.left.kind, [types.variableDeclarator(pattern, types.cloneNode(key))])); | ||
} | ||
@@ -413,4 +398,4 @@ }, | ||
const uid = path.scope.generateUidIdentifier("ref"); | ||
objectPatterns.push(core.types.variableDeclarator(objectPattern.node, uid)); | ||
objectPattern.replaceWith(core.types.cloneNode(uid)); | ||
objectPatterns.push(types.variableDeclarator(objectPattern.node, uid)); | ||
objectPattern.replaceWith(types.cloneNode(uid)); | ||
path.skip(); | ||
@@ -422,3 +407,3 @@ }); | ||
const kind = statementNode.type === "VariableDeclaration" ? statementNode.kind : "var"; | ||
statementPath.insertAfter(core.types.variableDeclaration(kind, objectPatterns)); | ||
statementPath.insertAfter(types.variableDeclaration(kind, objectPatterns)); | ||
} | ||
@@ -434,3 +419,3 @@ }, | ||
helper = file.addHelper("objectSpread2"); | ||
} catch (_unused) { | ||
} catch { | ||
this.file.declarations["objectSpread2"] = null; | ||
@@ -444,6 +429,6 @@ helper = file.addHelper("objectSpread"); | ||
const hadProps = props.length > 0; | ||
const obj = core.types.objectExpression(props); | ||
const obj = types.objectExpression(props); | ||
props = []; | ||
if (!exp) { | ||
exp = core.types.callExpression(helper, [obj]); | ||
exp = types.callExpression(helper, [obj]); | ||
return; | ||
@@ -457,6 +442,6 @@ } | ||
} | ||
exp = core.types.callExpression(core.types.cloneNode(helper), [exp, ...(hadProps ? [core.types.objectExpression([]), obj] : [])]); | ||
exp = types.callExpression(types.cloneNode(helper), [exp, ...(hadProps ? [types.objectExpression([]), obj] : [])]); | ||
} | ||
for (const prop of path.node.properties) { | ||
if (core.types.isSpreadElement(prop)) { | ||
if (types.isSpreadElement(prop)) { | ||
make(); | ||
@@ -475,3 +460,3 @@ exp.arguments.push(prop.argument); | ||
exports["default"] = index; | ||
export { index as default }; | ||
//# sourceMappingURL=index.js.map |
@@ -1,8 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = shouldStoreRHSInTemporaryVariable; | ||
var _core = require("@babel/core"); | ||
import { types as t } from "@babel/core"; | ||
const { | ||
@@ -15,4 +9,4 @@ isObjectProperty, | ||
isIdentifier | ||
} = _core.types; | ||
function shouldStoreRHSInTemporaryVariable(node) { | ||
} = t; | ||
export default function shouldStoreRHSInTemporaryVariable(node) { | ||
if (isArrayPattern(node)) { | ||
@@ -19,0 +13,0 @@ const nonNullElements = node.elements.filter(element => element !== null); |
{ | ||
"name": "@babel/plugin-transform-object-rest-spread", | ||
"version": "7.22.5", | ||
"version": "8.0.0-alpha.0", | ||
"description": "Compile object rest and spread to ES5", | ||
@@ -20,21 +20,25 @@ "repository": { | ||
"dependencies": { | ||
"@babel/compat-data": "^7.22.5", | ||
"@babel/helper-compilation-targets": "^7.22.5", | ||
"@babel/helper-plugin-utils": "^7.22.5", | ||
"@babel/compat-data": "^8.0.0-alpha.0", | ||
"@babel/helper-compilation-targets": "^8.0.0-alpha.0", | ||
"@babel/helper-plugin-utils": "^8.0.0-alpha.0", | ||
"@babel/plugin-syntax-object-rest-spread": "^7.8.3", | ||
"@babel/plugin-transform-parameters": "^7.22.5" | ||
"@babel/plugin-transform-parameters": "^8.0.0-alpha.0" | ||
}, | ||
"peerDependencies": { | ||
"@babel/core": "^7.0.0-0" | ||
"@babel/core": "^8.0.0-alpha.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.22.5", | ||
"@babel/helper-plugin-test-runner": "^7.22.5", | ||
"@babel/parser": "^7.22.5" | ||
"@babel/core": "^8.0.0-alpha.0", | ||
"@babel/helper-plugin-test-runner": "^8.0.0-alpha.0", | ||
"@babel/parser": "^8.0.0-alpha.0" | ||
}, | ||
"engines": { | ||
"node": ">=6.9.0" | ||
"node": "^16.20.0 || ^18.16.0 || >=20.0.0" | ||
}, | ||
"author": "The Babel Team (https://babel.dev/team)", | ||
"type": "commonjs" | ||
"exports": { | ||
".": "./lib/index.js", | ||
"./package.json": "./package.json" | ||
}, | ||
"type": "module" | ||
} |
@@ -5,3 +5,3 @@ # @babel/plugin-transform-object-rest-spread | ||
See our website [@babel/plugin-transform-object-rest-spread](https://babeljs.io/docs/en/babel-plugin-transform-object-rest-spread) for more information. | ||
See our website [@babel/plugin-transform-object-rest-spread](https://babeljs.io/docs/babel-plugin-transform-object-rest-spread) for more information. | ||
@@ -8,0 +8,0 @@ ## Install |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
Yes
73026
470
1
+ Added@babel/code-frame@8.0.0-alpha.12(transitive)
+ Added@babel/compat-data@8.0.0-alpha.12(transitive)
+ Added@babel/core@8.0.0-alpha.12(transitive)
+ Added@babel/generator@8.0.0-alpha.12(transitive)
+ Added@babel/helper-compilation-targets@8.0.0-alpha.12(transitive)
+ Added@babel/helper-plugin-utils@8.0.0-alpha.12(transitive)
+ Added@babel/helper-string-parser@8.0.0-alpha.12(transitive)
+ Added@babel/helper-validator-identifier@8.0.0-alpha.12(transitive)
+ Added@babel/helper-validator-option@8.0.0-alpha.12(transitive)
+ Added@babel/helpers@8.0.0-alpha.12(transitive)
+ Added@babel/highlight@8.0.0-alpha.12(transitive)
+ Added@babel/parser@8.0.0-alpha.12(transitive)
+ Added@babel/plugin-transform-parameters@8.0.0-alpha.12(transitive)
+ Added@babel/template@8.0.0-alpha.12(transitive)
+ Added@babel/traverse@8.0.0-alpha.12(transitive)
+ Added@babel/types@8.0.0-alpha.12(transitive)
+ Addedglobals@15.9.0(transitive)
+ Addedjs-tokens@8.0.3(transitive)
+ Addedjsesc@3.0.2(transitive)
+ Addedlru-cache@7.18.3(transitive)
+ Addedsemver@7.6.3(transitive)
+ Addedto-fast-properties@3.0.1(transitive)
- Removed@babel/plugin-transform-parameters@7.24.7(transitive)