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.6 to 7.18.8

lib/shadow-utils.js

80

lib/params.js

@@ -10,2 +10,4 @@ "use strict";

var _shadowUtils = require("./shadow-utils");
const buildDefaultParam = _core.template.statement(`

@@ -33,21 +35,2 @@ let VARIABLE_NAME =

const iifeVisitor = {
"ReferencedIdentifier|BindingIdentifier"(path, state) {
const {
scope,
node
} = path;
const {
name
} = node;
if (name === "eval" || scope.getBinding(name) === state.scope.parent.getBinding(name) && state.scope.hasOwnBinding(name)) {
state.needsOuterBinding = true;
path.stop();
}
},
"TypeAnnotation|TSTypeAnnotation|TypeParameterDeclaration|TSTypeParameterDeclaration": path => path.skip()
};
function convertFunctionParams(path, ignoreFunctionLength, shouldTransformParam, replaceRestElement) {

@@ -61,7 +44,2 @@ const params = path.get("params");

} = path;
const state = {
stop: false,
needsOuterBinding: false,
scope
};
const body = [];

@@ -71,39 +49,13 @@ const shadowedParams = new Set();

for (const param of params) {
for (const name of Object.keys(param.getBindingIdentifiers())) {
var _scope$bindings$name;
(0, _shadowUtils.collectShadowedParamsNames)(param, scope, shadowedParams);
}
const constantViolations = (_scope$bindings$name = scope.bindings[name]) == null ? void 0 : _scope$bindings$name.constantViolations;
const state = {
needsOuterBinding: false,
scope
};
if (constantViolations) {
for (const redeclarator of constantViolations) {
const node = redeclarator.node;
switch (node.type) {
case "VariableDeclarator":
{
if (node.init === null) {
const declaration = redeclarator.parentPath;
if (!declaration.parentPath.isFor() || declaration.parentPath.get("body") === declaration) {
redeclarator.remove();
break;
}
}
shadowedParams.add(name);
break;
}
case "FunctionDeclaration":
shadowedParams.add(name);
break;
}
}
}
}
}
if (shadowedParams.size === 0) {
for (const param of params) {
if (!param.isIdentifier()) param.traverse(iifeVisitor, state);
if (!param.isIdentifier()) param.traverse(_shadowUtils.iifeVisitor, state);
if (state.needsOuterBinding) break;

@@ -191,3 +143,3 @@ }

if (state.needsOuterBinding || shadowedParams.size > 0) {
body.push(buildScopeIIFE(shadowedParams, path.get("body").node));
body.push((0, _shadowUtils.buildScopeIIFE)(shadowedParams, path.node.body));
path.set("body", _core.types.blockStatement(body));

@@ -205,14 +157,2 @@ const bodyPath = path.get("body.body");

return true;
}
function buildScopeIIFE(shadowedParams, body) {
const args = [];
const params = [];
for (const name of shadowedParams) {
args.push(_core.types.identifier(name));
params.push(_core.types.identifier(name));
}
return _core.types.returnStatement(_core.types.callExpression(_core.types.arrowFunctionExpression(params, body), args));
}

@@ -10,2 +10,4 @@ "use strict";

var _shadowUtils = require("./shadow-utils");
const buildRest = _core.template.statement(`

@@ -219,4 +221,27 @@ for (var LEN = ARGUMENTS.length,

if (!hasRest(node)) return false;
let rest = node.params.pop().argument;
const restPath = path.get(`params.${node.params.length - 1}.argument`);
if (!restPath.isIdentifier()) {
const shadowedParams = new Set();
(0, _shadowUtils.collectShadowedParamsNames)(restPath, path.scope, shadowedParams);
let needsIIFE = shadowedParams.size > 0;
if (!needsIIFE) {
const state = {
needsOuterBinding: false,
scope
};
restPath.traverse(_shadowUtils.iifeVisitor, state);
needsIIFE = state.needsOuterBinding;
}
if (needsIIFE) {
path.ensureBlock();
path.set("body", _core.types.blockStatement([(0, _shadowUtils.buildScopeIIFE)(shadowedParams, path.node.body)]));
}
}
let rest = restPath.node;
node.params.pop();
if (_core.types.isPattern(rest)) {

@@ -223,0 +248,0 @@ const pattern = rest;

{
"name": "@babel/plugin-transform-parameters",
"version": "7.18.6",
"version": "7.18.8",
"description": "Compile ES2015 default and rest parameters to ES5",

@@ -5,0 +5,0 @@ "repository": {

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