babel-plugin-minify-mangle-names
Advanced tools
Comparing version 0.5.0-alpha.7ba5821f to 0.5.0-alpha.830ce3f1
@@ -335,16 +335,8 @@ "use strict"; | ||
mangler.visitedScopes.add(scope); // Helpers to generate names | ||
mangler.visitedScopes.add(scope); | ||
const bindings = scopeTracker.bindings.get(scope); | ||
const names = [...bindings.keys()]; // A counter to generate names and reset | ||
// so we can reuse removed names | ||
let i = 0; | ||
function getNext() { | ||
return mangler.charset.getIdentifier(i++); | ||
} | ||
function resetNext() { | ||
i = 0; | ||
} | ||
const bindings = scopeTracker.bindings.get(scope); | ||
const names = [...bindings.keys()]; | ||
let counter = 0; | ||
/** | ||
@@ -360,4 +352,4 @@ * 1. Iterate through the list of BindingIdentifiers | ||
for (let i = 0; i < names.length; i++) { | ||
const oldName = names[i]; | ||
for (var _i = 0; _i < names.length; _i++) { | ||
const oldName = names[_i]; | ||
const binding = bindings.get(oldName); | ||
@@ -369,9 +361,20 @@ | ||
do { | ||
next = getNext(); | ||
next = mangler.charset.getIdentifier(counter++); | ||
} while (!mangler.isValidName(next, binding, scope)); // Reset so variables which are removed can be reused | ||
// | ||
// the following is an assumtion (for perf) | ||
// the length 3 is an assumption that if the oldName isn't | ||
// 1 or 2 characters, then probably we are not going to find | ||
// a name - because for almost all usecases we have 1 or 2 | ||
// character new names only. And for the edge cases where | ||
// one scope has lots and lots of variables, it's okay to | ||
// name something with 3 characters instead of 1 | ||
resetNext(); // Once we detected a valid `next` Identifier which could be used, | ||
if (oldName.length < 3) { | ||
counter = 0; | ||
} // Once we detected a valid `next` Identifier which could be used, | ||
// call the renamer | ||
mangler.rename(scope, binding, oldName, next); | ||
@@ -378,0 +381,0 @@ } |
{ | ||
"name": "babel-plugin-minify-mangle-names", | ||
"version": "0.5.0-alpha.7ba5821f", | ||
"version": "0.5.0-alpha.830ce3f1", | ||
"description": "", | ||
@@ -15,4 +15,4 @@ "keywords": [ | ||
"dependencies": { | ||
"babel-helper-mark-eval-scopes": "^0.5.0-alpha.7ba5821f" | ||
"babel-helper-mark-eval-scopes": "^0.5.0-alpha.830ce3f1" | ||
} | ||
} |
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
34775
915