@babel/plugin-proposal-object-rest-spread
Advanced tools
Comparing version 7.21.4-esm.3 to 7.21.4-esm.4
142
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,15 @@ if (isArrayPattern(node)) { | ||
isObjectProperty | ||
} = core.types; | ||
} = 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; | ||
const node = types.identifier("a"); | ||
const property = types.objectProperty(types.identifier("key"), node); | ||
const pattern = types.objectPattern([property]); | ||
var ZERO_REFS = types.isReferenced(node, property, pattern) ? 1 : 0; | ||
} | ||
var index = helperPluginUtils.declare((api, opts) => { | ||
var index = declare((api, opts) => { | ||
var _api$assumption, _api$assumption2, _api$assumption3, _api$assumption4; | ||
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 | ||
}); | ||
@@ -81,3 +73,3 @@ const { | ||
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 +110,3 @@ function hasRestElement(path) { | ||
for (const prop of node.properties) { | ||
if (core.types.isSpreadElement(prop)) { | ||
if (types.isSpreadElement(prop)) { | ||
return true; | ||
@@ -131,11 +123,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 +148,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)); | ||
} | ||
@@ -177,4 +169,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(); | ||
@@ -188,10 +180,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()); | ||
@@ -204,6 +196,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])]; | ||
} | ||
@@ -223,3 +215,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) { | ||
@@ -231,3 +223,3 @@ container.push(declar); | ||
} | ||
paramPath.replaceWith(core.types.cloneNode(uid)); | ||
paramPath.replaceWith(types.cloneNode(uid)); | ||
} | ||
@@ -283,3 +275,3 @@ } | ||
const shouldTransformParam = idx => idx >= i - 1 || paramsWithRestElement.has(idx); | ||
pluginTransformParameters.convertFunctionParams(path, ignoreFunctionLength, shouldTransformParam, replaceRestElement); | ||
convertFunctionParams(path, ignoreFunctionLength, shouldTransformParam, replaceRestElement); | ||
} | ||
@@ -297,6 +289,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; | ||
@@ -320,3 +312,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)); | ||
}); | ||
@@ -328,6 +320,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); | ||
@@ -346,6 +338,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)); | ||
}, | ||
@@ -361,12 +353,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); | ||
@@ -385,18 +377,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))])); | ||
} | ||
@@ -412,4 +404,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(); | ||
@@ -421,3 +413,3 @@ }); | ||
const kind = statementNode.type === "VariableDeclaration" ? statementNode.kind : "var"; | ||
statementPath.insertAfter(core.types.variableDeclaration(kind, objectPatterns)); | ||
statementPath.insertAfter(types.variableDeclaration(kind, objectPatterns)); | ||
} | ||
@@ -442,6 +434,6 @@ }, | ||
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; | ||
@@ -455,6 +447,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(); | ||
@@ -473,3 +465,3 @@ exp.arguments.push(prop.argument); | ||
exports["default"] = index; | ||
export { index as default }; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@babel/plugin-proposal-object-rest-spread", | ||
"version": "7.21.4-esm.3", | ||
"version": "7.21.4-esm.4", | ||
"description": "Compile object rest and spread to ES5", | ||
@@ -20,7 +20,7 @@ "repository": { | ||
"dependencies": { | ||
"@babel/compat-data": "7.21.4-esm.3", | ||
"@babel/helper-compilation-targets": "7.21.4-esm.3", | ||
"@babel/helper-plugin-utils": "7.21.4-esm.3", | ||
"@babel/compat-data": "7.21.4-esm.4", | ||
"@babel/helper-compilation-targets": "7.21.4-esm.4", | ||
"@babel/helper-plugin-utils": "7.21.4-esm.4", | ||
"@babel/plugin-syntax-object-rest-spread": "^7.8.3", | ||
"@babel/plugin-transform-parameters": "7.21.4-esm.3" | ||
"@babel/plugin-transform-parameters": "7.21.4-esm.4" | ||
}, | ||
@@ -31,5 +31,5 @@ "peerDependencies": { | ||
"devDependencies": { | ||
"@babel/core": "7.21.4-esm.3", | ||
"@babel/helper-plugin-test-runner": "7.21.4-esm.3", | ||
"@babel/parser": "7.21.4-esm.3" | ||
"@babel/core": "7.21.4-esm.4", | ||
"@babel/helper-plugin-test-runner": "7.21.4-esm.4", | ||
"@babel/parser": "7.21.4-esm.4" | ||
}, | ||
@@ -36,0 +36,0 @@ "engines": { |
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
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
6
69853
442
+ Added@babel/compat-data@7.21.4-esm.4(transitive)
+ Added@babel/helper-compilation-targets@7.21.4-esm.4(transitive)
+ Added@babel/helper-plugin-utils@7.21.4-esm.4(transitive)
+ Added@babel/helper-validator-option@7.21.4-esm.4(transitive)
+ Added@babel/plugin-transform-parameters@7.21.4-esm.4(transitive)
- Removed@babel/compat-data@7.21.4-esm.3(transitive)
- Removed@babel/helper-compilation-targets@7.21.4-esm.3(transitive)
- Removed@babel/helper-plugin-utils@7.21.4-esm.3(transitive)
- Removed@babel/helper-validator-option@7.21.4-esm.3(transitive)
- Removed@babel/plugin-transform-parameters@7.21.4-esm.3(transitive)