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

babel-plugin-minify-mangle-names

Package Overview
Dependencies
Maintainers
5
Versions
87
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-minify-mangle-names - npm Package Compare versions

Comparing version 0.5.0-alpha.6889f45d to 0.5.0-alpha.7195fa98

69

lib/index.js

@@ -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"
}
}
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