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

babel-plugin-closure-elimination

Package Overview
Dependencies
Maintainers
2
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-closure-elimination - npm Package Compare versions

Comparing version 1.1.13 to 1.1.14

66

lib/index.js

@@ -22,11 +22,11 @@ 'use strict';

function _ref(path) {
function _ref3(path) {
return path.isFunction();
}
function _ref3(path) {
function _ref4(path) {
return path.type !== 'ArrowFunctionExpression';
}
function _ref4(parentArrow) {
function _ref5(parentArrow) {
parentArrow.node[$boundArrowFunction] = true;

@@ -36,12 +36,12 @@ }

function _enter(path) {
var parentFunctions = path.getAncestry().filter(_ref),
nearestNoArrowFunction = parentFunctions.findIndex(_ref3);
parentFunctions.slice(0, nearestNoArrowFunction).forEach(_ref4);
var parentFunctions = path.getAncestry().filter(_ref3),
nearestNoArrowFunction = parentFunctions.findIndex(_ref4);
parentFunctions.slice(0, nearestNoArrowFunction).forEach(_ref5);
}
function _ref5(path) {
function _ref6(path) {
return path.isFunction();
}
function _ref6(parentArrow) {
function _ref7(parentArrow) {
parentArrow.node[$usedEval] = true;

@@ -52,3 +52,3 @@ }

if (path.node.name === 'eval' && path.parentPath.type === 'CallExpression') {
path.getAncestry().filter(_ref5).forEach(_ref6);
path.getAncestry().filter(_ref6).forEach(_ref7);
}

@@ -62,3 +62,3 @@ }

function _getAllParentScopes(scope) {
function getAllParentScopes(scope) {
var scopes = [];

@@ -71,3 +71,3 @@ while (scope = scope.parent) {

function _getAttachmentPositio(bestParent, prevPath) {
function getAttachmentPosition(bestParent, prevPath) {
var prevParents = prevPath.getAncestry(),

@@ -111,3 +111,3 @@ bestParentIdx = prevParents.indexOf(bestParent);

if (bestParentScope) {
var attachPath = _getAttachmentPositio(bestParentScope.path, path);
var attachPath = getAttachmentPosition(bestParentScope.path, path);
if (attachPath) {

@@ -132,16 +132,13 @@ // _logAllProgram(path, 'before');// debug

path.scope.crawl(); // sibling plugins may not update scope of auto-generated functions
var parentScopes = _getAllParentScopes(path.scope),
var parentScopes = getAllParentScopes(path.scope),
parentBindings = path.scope.parent.getAllBindings();
function _ref7(subPath) {
return subPath.getAncestry().indexOf(path) !== -1;
}
for (var id in parentBindings) {
var hasUsageOfBinding = [].concat(parentBindings[id].referencePaths).concat(parentBindings[id].constantViolations).some(_ref7);
var parentBinding = parentBindings[id],
idx = parentScopes.indexOf(parentBinding.scope);
if (idx === -1) {
continue;
}
var hasUsageOfBinding = [].concat(parentBinding.referencePaths).concat(parentBinding.constantViolations).some(hasInPath);
if (hasUsageOfBinding) {
var idx = parentScopes.indexOf(parentBindings[id].scope);
if (idx !== -1) {
parentScopes.splice(idx + 1, Infinity);
}
parentScopes.splice(idx + 1, Infinity);
}

@@ -152,2 +149,9 @@ }

}).pop();
function hasInPath(subPath) {
while (subPath = subPath.parentPath) {
if (subPath === path) {
return true;
}
}
}
}function moveToNewPosition(path, attachPath) {

@@ -159,5 +163,7 @@ var node = path.node,

if (node.type === 'FunctionDeclaration') {
var uid = newScope.generateUidIdentifierBasedOnNode(node.id);
scope.rename(node.id.name, uid.name);
scope.moveBindingTo(uid.name, newScope);
if (newScope.bindings[node.id.name]) {
var uid = newScope.generateUidIdentifierBasedOnNode(node.id);
scope.rename(node.id.name, uid.name);
}
scope.moveBindingTo(node.id.name, newScope);
node._hoisted = true;

@@ -171,2 +177,3 @@ attachPath.insertBefore([node]);

scope.rename(node.id.name, _uid.name);
scope.moveBindingTo(node.id.name, newScope);
}

@@ -177,5 +184,8 @@ replacement.loc = node.loc;

replacement._hoisted = true;
attachPath.insertBefore([replacement]);
var declarePath = attachPath.insertBefore([replacement])[0];
path.replaceWith(t.identifier(_uid.name));
newScope.crawl();
if (!newScope.bindings[_uid.name]) {
newScope.registerDeclaration(declarePath);
}
newScope.bindings[_uid.name].reference(path);
}

@@ -182,0 +192,0 @@ }

{
"name": "babel-plugin-closure-elimination",
"version": "1.1.13",
"version": "1.1.14",
"description": "Removes closures from your JavaScript in the name of performance.",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -69,11 +69,13 @@ import 'babel-polyfill';

for (let id in parentBindings) {
const parentBinding = parentBindings[id],
idx = parentScopes.indexOf(parentBinding.scope);
if (idx === -1) {
continue;
}
let hasUsageOfBinding = []
.concat(parentBindings[id].referencePaths)
.concat(parentBindings[id].constantViolations)
.some(subPath => subPath.getAncestry().indexOf(path) !== -1);
.concat(parentBinding.referencePaths)
.concat(parentBinding.constantViolations)
.some(hasInPath);
if (hasUsageOfBinding) {
let idx = parentScopes.indexOf(parentBindings[id].scope);
if (idx !== -1) {
parentScopes.splice(idx + 1, Infinity);
}
parentScopes.splice(idx + 1, Infinity);
}

@@ -85,2 +87,9 @@ }

.pop();
function hasInPath(subPath) {
while (subPath = subPath.parentPath) {
if (subPath === path) {
return true;
}
}
}
}

@@ -115,5 +124,7 @@

if (node.type === 'FunctionDeclaration') {
let uid = newScope.generateUidIdentifierBasedOnNode(node.id);
scope.rename(node.id.name, uid.name);
scope.moveBindingTo(uid.name, newScope);
if (newScope.bindings[node.id.name]) {
const uid = newScope.generateUidIdentifierBasedOnNode(node.id);
scope.rename(node.id.name, uid.name);
}
scope.moveBindingTo(node.id.name, newScope);
node._hoisted = true;

@@ -131,2 +142,3 @@ attachPath.insertBefore([node]);

scope.rename(node.id.name, uid.name);
scope.moveBindingTo(node.id.name, newScope);
}

@@ -137,5 +149,8 @@ replacement.loc = node.loc;

replacement._hoisted = true;
attachPath.insertBefore([replacement]);
const declarePath = attachPath.insertBefore([replacement])[0];
path.replaceWith(t.identifier(uid.name));
newScope.crawl();
if (!newScope.bindings[uid.name]) {
newScope.registerDeclaration(declarePath);
}
newScope.bindings[uid.name].reference(path);
}

@@ -142,0 +157,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