Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@babel/plugin-transform-parameters

Package Overview
Dependencies
Maintainers
4
Versions
100
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@babel/plugin-transform-parameters - npm Package Compare versions

Comparing version 7.18.8 to 7.20.1

lib/index.js.map

12

lib/index.js

@@ -13,12 +13,7 @@ "use strict";

exports.default = void 0;
var _helperPluginUtils = require("@babel/helper-plugin-utils");
var _params = require("./params");
var _rest = require("./rest");
var _default = (0, _helperPluginUtils.declare)((api, options) => {
var _api$assumption, _api$assumption2;
api.assertVersion(7);

@@ -35,8 +30,7 @@ const ignoreFunctionLength = (_api$assumption = api.assumption("ignoreFunctionLength")) != null ? _api$assumption : options.loose;

});
if (!path.isFunctionExpression()) return;
}
const convertedRest = (0, _rest.default)(path);
const convertedParams = (0, _params.default)(path, ignoreFunctionLength);
if (convertedRest || convertedParams) {

@@ -46,7 +40,7 @@ path.scope.crawl();

}
}
};
});
exports.default = _default;
exports.default = _default;
//# sourceMappingURL=index.js.map

@@ -7,7 +7,4 @@ "use strict";

exports.default = convertFunctionParams;
var _core = require("@babel/core");
var _shadowUtils = require("./shadow-utils");
const buildDefaultParam = _core.template.statement(`

@@ -20,3 +17,2 @@ let VARIABLE_NAME =

`);
const buildLooseDefaultParam = _core.template.statement(`

@@ -27,7 +23,5 @@ if (ASSIGNMENT_IDENTIFIER === UNDEFINED) {

`);
const buildLooseDestructuredDefaultParam = _core.template.statement(`
let ASSIGNMENT_IDENTIFIER = PARAMETER_NAME === UNDEFINED ? DEFAULT_VALUE : PARAMETER_NAME ;
`);
const buildSafeArgumentsAccess = _core.template.statement(`

@@ -47,7 +41,5 @@ let $0 = arguments.length > $1 ? arguments[$1] : undefined;

const shadowedParams = new Set();
for (const param of params) {
(0, _shadowUtils.collectShadowedParamsNames)(param, scope, shadowedParams);
}
const state = {

@@ -57,3 +49,2 @@ needsOuterBinding: false,

};
if (shadowedParams.size === 0) {

@@ -65,20 +56,13 @@ for (const param of params) {

}
let firstOptionalIndex = null;
for (let i = 0; i < params.length; i++) {
const param = params[i];
if (shouldTransformParam && !shouldTransformParam(i)) {
continue;
}
const transformedRestNodes = [];
if (replaceRestElement) {
replaceRestElement(path, param, transformedRestNodes);
}
const paramIsAssignmentPattern = param.isAssignmentPattern();
if (paramIsAssignmentPattern && (ignoreFunctionLength || _core.types.isMethod(node, {

@@ -90,3 +74,2 @@ kind: "set"

const undefinedNode = scope.buildUndefinedNode();
if (left.isIdentifier()) {

@@ -125,9 +108,6 @@ body.push(buildLooseDefaultParam({

uid.typeAnnotation = param.node.typeAnnotation;
const defNode = _core.types.variableDeclaration("let", [_core.types.variableDeclarator(param.node, uid)]);
body.push(defNode);
param.replaceWith(_core.types.cloneNode(uid));
}
if (transformedRestNodes) {

@@ -145,11 +125,13 @@ for (const transformedNode of transformedRestNodes) {

path.ensureBlock();
if (state.needsOuterBinding || shadowedParams.size > 0) {
if (state.needsOuterBinding || shadowedParams.size > 0 || node.generator) {
body.push((0, _shadowUtils.buildScopeIIFE)(shadowedParams, path.node.body));
path.set("body", _core.types.blockStatement(body));
const bodyPath = path.get("body.body");
const arrowPath = bodyPath[bodyPath.length - 1].get("argument.callee");
arrowPath.arrowFunctionToExpression();
arrowPath.node.generator = path.node.generator;
arrowPath.node.async = path.node.async;
path.node.generator = false;

@@ -159,4 +141,5 @@ } else {

}
return true;
}
return true;
}
//# sourceMappingURL=params.js.map

@@ -7,7 +7,4 @@ "use strict";

exports.default = convertFunctionRest;
var _core = require("@babel/core");
var _shadowUtils = require("./shadow-utils");
const buildRest = _core.template.statement(`

@@ -22,15 +19,11 @@ for (var LEN = ARGUMENTS.length,

`);
const restIndex = _core.template.expression(`
(INDEX < OFFSET || ARGUMENTS.length <= INDEX) ? undefined : ARGUMENTS[INDEX]
`);
const restIndexImpure = _core.template.expression(`
REF = INDEX, (REF < OFFSET || ARGUMENTS.length <= REF) ? undefined : ARGUMENTS[REF]
`);
const restLength = _core.template.expression(`
ARGUMENTS.length <= OFFSET ? 0 : ARGUMENTS.length - OFFSET
`);
function referencesRest(path, state) {

@@ -40,6 +33,4 @@ if (path.node.name === state.name) {

}
return false;
}
const memberExpressionOptimisationVisitor = {

@@ -51,3 +42,2 @@ Scope(path, state) {

},
Flow(path) {

@@ -57,3 +47,2 @@ if (path.isTypeCastExpression()) return;

},
Function(path, state) {

@@ -64,5 +53,5 @@ const oldNoOptimise = state.noOptimise;

state.noOptimise = oldNoOptimise;
path.skip();
},
ReferencedIdentifier(path, state) {

@@ -78,3 +67,2 @@ const {

if (!referencesRest(path, state)) return;
if (state.noOptimise) {

@@ -95,6 +83,12 @@ state.deopted = true;

const grandparentPath = parentPath.parentPath;
const argsOptEligible = !state.deopted && !(grandparentPath.isAssignmentExpression() && parentPath.node === grandparentPath.node.left || grandparentPath.isLVal() || grandparentPath.isForXStatement() || grandparentPath.isUpdateExpression() || grandparentPath.isUnaryExpression({
const argsOptEligible = !state.deopted && !(
grandparentPath.isAssignmentExpression() && parentPath.node === grandparentPath.node.left ||
grandparentPath.isLVal() ||
grandparentPath.isForXStatement() ||
grandparentPath.isUpdateExpression() ||
grandparentPath.isUnaryExpression({
operator: "delete"
}) || (grandparentPath.isCallExpression() || grandparentPath.isNewExpression()) && parentPath.node === grandparentPath.node.callee);
}) ||
(grandparentPath.isCallExpression() || grandparentPath.isNewExpression()) && parentPath.node === grandparentPath.node.callee);
if (argsOptEligible) {

@@ -109,3 +103,4 @@ if (parentPath.node.computed) {

}
} else if (parentPath.node.property.name === "length") {
} else if (
parentPath.node.property.name === "length") {
state.candidates.push({

@@ -122,3 +117,2 @@ cause: "lengthGetter",

const call = parentPath.parentPath;
if (call.isCallExpression() && call.node.arguments.length === 1) {

@@ -132,3 +126,2 @@ state.candidates.push({

}
state.references.push(path);

@@ -143,8 +136,5 @@ }

}
};
function getParamsCount(node) {
let count = node.params.length;
if (count > 0 && _core.types.isIdentifier(node.params[0], {

@@ -155,6 +145,4 @@ name: "this"

}
return count;
}
function hasRest(node) {

@@ -164,9 +152,6 @@ const length = node.params.length;

}
function optimiseIndexGetter(path, argsId, offset) {
const offsetLiteral = _core.types.numericLiteral(offset);
let index;
const parent = path.parent;
if (_core.types.isNumericLiteral(parent.property)) {

@@ -179,3 +164,2 @@ index = _core.types.numericLiteral(parent.property.value + offset);

}
const {

@@ -185,3 +169,2 @@ scope,

} = path;
if (!scope.isPure(index)) {

@@ -206,5 +189,5 @@ const temp = scope.generateUidIdentifierBasedOnNode(index);

const replacedParentPath = parentPath;
const offsetTestPath = replacedParentPath.get("test");
const valRes = offsetTestPath.get("left").evaluate();
if (valRes.confident) {

@@ -219,3 +202,2 @@ if (valRes.value === true) {

}
function optimiseLengthGetter(path, argsId, offset) {

@@ -231,3 +213,2 @@ if (offset) {

}
function convertFunctionRest(path) {

@@ -240,3 +221,2 @@ const {

const restPath = path.get(`params.${node.params.length - 1}.argument`);
if (!restPath.isIdentifier()) {

@@ -246,3 +226,2 @@ const shadowedParams = new Set();

let needsIIFE = shadowedParams.size > 0;
if (!needsIIFE) {

@@ -256,3 +235,2 @@ const state = {

}
if (needsIIFE) {

@@ -263,3 +241,2 @@ path.ensureBlock();

}
let rest = restPath.node;

@@ -271,5 +248,3 @@ node.params.pop();

rest = scope.generateUidIdentifier("ref");
const declar = _core.types.variableDeclaration("let", [_core.types.variableDeclarator(pattern, rest)]);
path.ensureBlock();

@@ -280,6 +255,5 @@ node.body.body.unshift(declar);

}
const argsId = _core.types.identifier("arguments");
const paramsCount = getParamsCount(node);
const paramsCount = getParamsCount(node);
const state = {

@@ -302,3 +276,2 @@ references: [],

const clonedArgsId = _core.types.cloneNode(argsId);
switch (cause) {

@@ -308,7 +281,5 @@ case "indexGetter":

break;
case "lengthGetter":
optimiseLengthGetter(path, clonedArgsId, state.offset);
break;
default:

@@ -318,18 +289,14 @@ path.replaceWith(clonedArgsId);

}
return true;
}
state.references.push(...state.candidates.map(({
path
}) => path));
const start = _core.types.numericLiteral(paramsCount);
const key = scope.generateUidIdentifier("key");
const len = scope.generateUidIdentifier("len");
let arrKey, arrLen;
if (paramsCount) {
arrKey = _core.types.binaryExpression("-", _core.types.cloneNode(key), _core.types.cloneNode(start));
arrLen = _core.types.conditionalExpression(_core.types.binaryExpression(">", _core.types.cloneNode(len), _core.types.cloneNode(start)), _core.types.binaryExpression("-", _core.types.cloneNode(len), _core.types.cloneNode(start)), _core.types.numericLiteral(0));

@@ -340,3 +307,2 @@ } else {

}
const loop = buildRest({

@@ -351,3 +317,2 @@ ARGUMENTS: argsId,

});
if (state.deopted) {

@@ -357,2 +322,3 @@ node.body.body.unshift(loop);

let target = path.getEarliestCommonAncestorFrom(state.references).getStatementParent();
target.findParent(path => {

@@ -367,4 +333,5 @@ if (path.isLoop()) {

}
return true;
}
return true;
}
//# sourceMappingURL=rest.js.map

@@ -9,5 +9,3 @@ "use strict";

exports.iifeVisitor = void 0;
var _core = require("@babel/core");
const iifeVisitor = {

@@ -22,3 +20,2 @@ "ReferencedIdentifier|BindingIdentifier"(path, state) {

} = node;
if (name === "eval" || scope.getBinding(name) === state.scope.parent.getBinding(name) && state.scope.hasOwnBinding(name)) {

@@ -29,17 +26,12 @@ state.needsOuterBinding = true;

},
"TypeAnnotation|TSTypeAnnotation|TypeParameterDeclaration|TSTypeParameterDeclaration": path => path.skip()
};
exports.iifeVisitor = iifeVisitor;
function collectShadowedParamsNames(param, functionScope, shadowedParams) {
for (const name of Object.keys(param.getBindingIdentifiers())) {
var _functionScope$bindin;
const constantViolations = (_functionScope$bindin = functionScope.bindings[name]) == null ? void 0 : _functionScope$bindin.constantViolations;
if (constantViolations) {
for (const redeclarator of constantViolations) {
const node = redeclarator.node;
switch (node.type) {

@@ -50,3 +42,2 @@ case "VariableDeclarator":

const declaration = redeclarator.parentPath;
if (!declaration.parentPath.isFor() || declaration.parentPath.get("body") === declaration) {

@@ -57,7 +48,5 @@ redeclarator.remove();

}
shadowedParams.add(name);
break;
}
case "FunctionDeclaration":

@@ -71,7 +60,5 @@ shadowedParams.add(name);

}
function buildScopeIIFE(shadowedParams, body) {
const args = [];
const params = [];
for (const name of shadowedParams) {

@@ -81,4 +68,5 @@ args.push(_core.types.identifier(name));

}
return _core.types.returnStatement(_core.types.callExpression(_core.types.arrowFunctionExpression(params, body), args));
}
return _core.types.returnStatement(_core.types.callExpression(_core.types.arrowFunctionExpression(params, body), args));
}
//# sourceMappingURL=shadow-utils.js.map
{
"name": "@babel/plugin-transform-parameters",
"version": "7.18.8",
"version": "7.20.1",
"description": "Compile ES2015 default and rest parameters to ES5",

@@ -17,3 +17,3 @@ "repository": {

"dependencies": {
"@babel/helper-plugin-utils": "^7.18.6"
"@babel/helper-plugin-utils": "^7.19.0"
},

@@ -27,3 +27,3 @@ "keywords": [

"devDependencies": {
"@babel/core": "^7.18.6",
"@babel/core": "^7.19.6",
"@babel/helper-plugin-test-runner": "^7.18.6"

@@ -30,0 +30,0 @@ },

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc