babel-plugin-minify-mangle-names
Advanced tools
Comparing version 0.5.0-alpha.6889f45d to 0.5.0-alpha.7195fa98
@@ -277,2 +277,38 @@ "use strict"; | ||
/** | ||
* Tells if the name can be mangled in the current observed scope with | ||
* the input binding | ||
* | ||
* @param {string} oldName the old name that needs to be mangled | ||
* @param {Binding} binding Binding of the name | ||
* @param {Scope} scope The current scope the mangler is run | ||
*/ | ||
canMangle(oldName, binding, scope) { | ||
const cannotMangle = // arguments - for non-strict mode | ||
oldName === "arguments" || // labels | ||
binding.path.isLabeledStatement() || // ClassDeclaration has binding in two scopes | ||
// 1. The scope in which it is declared | ||
// 2. The class's own scope | ||
binding.path.isClassDeclaration() && binding.path === scope.path || // excluded | ||
this.isExcluded(oldName) || ( // function names | ||
this.keepFnName ? isFunction(binding.path) : false) || ( // class names | ||
this.keepClassName ? isClass(binding.path) : false) || // named export | ||
this.isExportedWithName(binding); | ||
return !cannotMangle; | ||
} | ||
/** | ||
* Tells if the newName can be used as a valid name for the input binding | ||
* in the input scope | ||
* | ||
* @param {string} newName the old name that needs to be mangled | ||
* @param {Binding} binding Binding of the name that this new name will replace | ||
* @param {Scope} scope The current scope the mangler is run | ||
*/ | ||
isValidName(newName, binding, scope) { | ||
return t.isValidIdentifier(newName) && !this.scopeTracker.hasBinding(scope, newName) && !scope.hasGlobal(newName) && !this.scopeTracker.hasReference(scope, newName) && this.scopeTracker.canUseInReferencedScopes(binding, newName); | ||
} | ||
/** | ||
* Mangle the scope | ||
@@ -318,2 +354,6 @@ * @param {Scope} scope | ||
* 3. Update the scope tree. | ||
* | ||
* We cannot use a for..of loop over bindings.keys() | ||
* because (2) we rename in place and update the bindings | ||
* as we traverse through the keys | ||
*/ | ||
@@ -325,26 +365,15 @@ | ||
if ( // arguments - for non-strict mode | ||
oldName === "arguments" || // labels | ||
binding.path.isLabeledStatement() || // ClassDeclaration has binding in two scopes | ||
// 1. The scope in which it is declared | ||
// 2. The class's own scope | ||
binding.path.isClassDeclaration() && binding.path === scope.path || // excluded | ||
mangler.isExcluded(oldName) || ( // function names | ||
mangler.keepFnName ? isFunction(binding.path) : false) || ( // class names | ||
mangler.keepClassName ? isClass(binding.path) : false) || // named export | ||
mangler.isExportedWithName(binding)) { | ||
continue; | ||
} | ||
if (mangler.canMangle(oldName, binding, scope)) { | ||
let next; | ||
let next; | ||
do { | ||
next = getNext(); | ||
} while (!mangler.isValidName(next, binding, scope)); // Reset so variables which are removed can be reused | ||
do { | ||
next = getNext(); | ||
} while (!t.isValidIdentifier(next) || scopeTracker.hasBinding(scope, next) || scope.hasGlobal(next) || scopeTracker.hasReference(scope, next) || !scopeTracker.canUseInReferencedScopes(binding, next)); // Reset so variables which are removed can be reused | ||
resetNext(); // Once we detected a valid `next` Identifier which could be used, | ||
// call the renamer | ||
resetNext(); // Once we detected a valid `next` Identifier which could be used, | ||
// call the renamer | ||
mangler.rename(scope, binding, oldName, next); | ||
mangler.rename(scope, binding, oldName, next); | ||
} | ||
} | ||
@@ -351,0 +380,0 @@ } |
{ | ||
"name": "babel-plugin-minify-mangle-names", | ||
"version": "0.5.0-alpha.6889f45d", | ||
"version": "0.5.0-alpha.7195fa98", | ||
"description": "", | ||
@@ -15,4 +15,4 @@ "keywords": [ | ||
"dependencies": { | ||
"babel-helper-mark-eval-scopes": "^0.5.0-alpha.6889f45d" | ||
"babel-helper-mark-eval-scopes": "^0.5.0-alpha.7195fa98" | ||
} | ||
} |
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
34339
910