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.3.0-alpha.6ae655c0 to 0.3.0-alpha.6ceffb8d

23

lib/bfs-traverse.js
"use strict";
module.exports = function bfsTraverseCreator({ types: t, traverse }) {
module.exports = function bfsTraverseCreator(_ref) {
var t = _ref.types,
traverse = _ref.traverse;
function getFields(path) {

@@ -12,6 +15,6 @@ return t.VISITOR_KEYS[path.type];

}
const visitor = traverse.explode(_visitor);
var visitor = traverse.explode(_visitor);
const queue = [path];
let current;
var queue = [path];
var current = void 0;

@@ -23,3 +26,3 @@ while (queue.length > 0) {

if (visitor && visitor[current.type] && Array.isArray(visitor[current.type].enter)) {
const fns = visitor[current.type].enter;
var fns = visitor[current.type].enter;
var _iteratorNormalCompletion = true;

@@ -31,3 +34,3 @@ var _didIteratorError = false;

for (var _iterator = fns[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
const fn = _step.value;
var fn = _step.value;

@@ -52,3 +55,3 @@ if (typeof fn === "function") fn(current);

const fields = getFields(current);
var fields = getFields(current);

@@ -61,5 +64,5 @@ var _iteratorNormalCompletion2 = true;

for (var _iterator2 = fields[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
const field = _step2.value;
var field = _step2.value;
const child = current.get(field);
var child = current.get(field);

@@ -74,3 +77,3 @@ if (Array.isArray(child)) {

for (var _iterator3 = child[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
const c = _step3.value;
var c = _step3.value;

@@ -77,0 +80,0 @@ if (c.node) queue.push(c);

"use strict";
const CHARSET = ("abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ$_").split("");
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
module.exports = class Charset {
constructor(shouldConsider) {
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var CHARSET = ("abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ$_").split("");
module.exports = function () {
function Charset(shouldConsider) {
var _this = this;
_classCallCheck(this, Charset);
this.shouldConsider = shouldConsider;
this.chars = CHARSET.slice();
this.frequency = {};
this.chars.forEach(c => {
this.frequency[c] = 0;
this.chars.forEach(function (c) {
_this.frequency[c] = 0;
});

@@ -16,36 +24,49 @@ this.finalized = false;

consider(str) {
if (!this.shouldConsider) {
return;
}
_createClass(Charset, [{
key: "consider",
value: function consider(str) {
var _this2 = this;
str.split("").forEach(c => {
if (this.frequency[c] != null) {
this.frequency[c]++;
if (!this.shouldConsider) {
return;
}
});
}
sort() {
if (this.shouldConsider) {
this.chars = this.chars.sort((a, b) => this.frequency[b] - this.frequency[a]);
str.split("").forEach(function (c) {
if (_this2.frequency[c] != null) {
_this2.frequency[c]++;
}
});
}
}, {
key: "sort",
value: function sort() {
var _this3 = this;
this.finalized = true;
}
if (this.shouldConsider) {
this.chars = this.chars.sort(function (a, b) {
return _this3.frequency[b] - _this3.frequency[a];
});
}
getIdentifier(num) {
if (!this.finalized) {
throw new Error("Should sort first");
this.finalized = true;
}
}, {
key: "getIdentifier",
value: function getIdentifier(num) {
if (!this.finalized) {
throw new Error("Should sort first");
}
let ret = "";
num++;
do {
num--;
ret += this.chars[num % this.chars.length];
num = Math.floor(num / this.chars.length);
} while (num > 0);
return ret;
}
};
var ret = "";
num++;
do {
num--;
ret += this.chars[num % this.chars.length];
num = Math.floor(num / this.chars.length);
} while (num > 0);
return ret;
}
}]);
return Charset;
}();
"use strict";
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
// Set that counts
module.exports = class CountedSet {
constructor() {
module.exports = function () {
function CountedSet() {
_classCallCheck(this, CountedSet);
// because you can't simply extend Builtins yet
this.map = new Map();
}
keys() {
return [...this.map.keys()];
}
has(value) {
return this.map.has(value);
}
add(value) {
if (!this.has(value)) {
this.map.set(value, 0);
_createClass(CountedSet, [{
key: "keys",
value: function keys() {
return [].concat(_toConsumableArray(this.map.keys()));
}
this.map.set(value, this.map.get(value) + 1);
}
delete(value) {
if (!this.has(value)) return;
const count = this.map.get(value);
if (count <= 1) {
this.map.delete(value);
} else {
this.map.set(value, count - 1);
}, {
key: "has",
value: function has(value) {
return this.map.has(value);
}
}
};
}, {
key: "add",
value: function add(value) {
if (!this.has(value)) {
this.map.set(value, 0);
}
this.map.set(value, this.map.get(value) + 1);
}
}, {
key: "delete",
value: function _delete(value) {
if (!this.has(value)) return;
var count = this.map.get(value);
if (count <= 1) {
this.map.delete(value);
} else {
this.map.set(value, count - 1);
}
}
}]);
return CountedSet;
}();

@@ -12,11 +12,11 @@ "use strict";

}
const fnScope = path.scope.getFunctionParent() || path.scope.getProgramParent();
const bindingIds = path.getOuterBindingIdentifierPaths();
var fnScope = path.scope.getFunctionParent() || path.scope.getProgramParent();
var bindingIds = path.getOuterBindingIdentifierPaths();
for (const name in bindingIds) {
const binding = path.scope.getBinding(name);
for (var name in bindingIds) {
var binding = path.scope.getBinding(name);
// var isn't hoisted to fnScope
if (binding.scope !== fnScope) {
const existingBinding = fnScope.bindings[name];
var existingBinding = fnScope.bindings[name];
// make sure we are clear that the fnScope doesn't already have

@@ -37,3 +37,3 @@ // an existing binding

// binding.scope and fnScope
const newName = fnScope.generateUid(binding.scope.generateUid(name));
var newName = fnScope.generateUid(binding.scope.generateUid(name));

@@ -40,0 +40,0 @@ // rename binding in the original scope

"use strict";
const Charset = require("./charset");
const ScopeTracker = require("./scope-tracker");
const isLabelIdentifier = require("./is-label-identifier");
const bfsTraverseCreator = require("./bfs-traverse");
const fixupVarScoping = require("./fixup-var-scoping");
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _require = require("babel-helper-mark-eval-scopes");
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
const markEvalScopes = _require.markEvalScopes,
isEvalScopesMarked = _require.isMarked,
hasEval = _require.hasEval;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Charset = require("./charset");
var ScopeTracker = require("./scope-tracker");
var isLabelIdentifier = require("./is-label-identifier");
var bfsTraverseCreator = require("./bfs-traverse");
var fixupVarScoping = require("./fixup-var-scoping");
const newIssueUrl = "https://github.com/babel/minify/issues/new";
var _require = require("babel-helper-mark-eval-scopes"),
markEvalScopes = _require.markEvalScopes,
isEvalScopesMarked = _require.isMarked,
hasEval = _require.hasEval;
module.exports = babel => {
const t = babel.types,
traverse = babel.traverse;
var newIssueUrl = "https://github.com/babel/minify/issues/new";
const bfsTraverse = bfsTraverseCreator(babel);
const hop = Object.prototype.hasOwnProperty;
module.exports = function (babel) {
var t = babel.types,
traverse = babel.traverse;
class Mangler {
constructor(charset, program, {
exclude = {},
keepFnName = false,
keepClassName = false,
eval: _eval = false,
topLevel = false
} = {}) {
var bfsTraverse = bfsTraverseCreator(babel);
var hop = Object.prototype.hasOwnProperty;
var Mangler = function () {
function Mangler(charset, program) {
var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
_ref$exclude = _ref.exclude,
exclude = _ref$exclude === undefined ? {} : _ref$exclude,
_ref$keepFnName = _ref.keepFnName,
keepFnName = _ref$keepFnName === undefined ? false : _ref$keepFnName,
_ref$keepClassName = _ref.keepClassName,
keepClassName = _ref$keepClassName === undefined ? false : _ref$keepClassName,
_ref$eval = _ref.eval,
_eval = _ref$eval === undefined ? false : _ref$eval,
_ref$topLevel = _ref.topLevel,
topLevel = _ref$topLevel === undefined ? false : _ref$topLevel;
_classCallCheck(this, Mangler);
this.charset = charset;

@@ -52,368 +64,405 @@ this.program = program;

*/
run() {
this.crawlScope();
this.collect();
this.fixup();
this.charset.sort();
this.mangle();
}
/**
* Tells if a variable name is excluded
* @param {String} name
*/
isExcluded(name) {
return hop.call(this.exclude, name) && this.exclude[name];
}
/**
* Clears traverse cache and recrawls the AST
*
* to recompute the bindings, references, other scope information
* and paths because the other transformations in the same pipeline
* (other plugins and presets) changes the AST and does NOT update
* the scope objects
*/
crawlScope() {
(traverse.clearCache || traverse.cache.clear)();
this.program.scope.crawl();
}
_createClass(Mangler, [{
key: "run",
value: function run() {
this.crawlScope();
this.collect();
this.fixup();
this.charset.sort();
this.mangle();
}
/**
* Re-crawling comes with a side-effect that let->var conversion
* reverts the update of the binding information (block to fn scope).
* This function takes care of it by updating it again.
*
* TODO: This is unnecessary work and needs to be fixed in babel.
* https://github.com/babel/babel/issues/4818
*
* When this is removed, remember to remove fixup's dependency in
* ScopeTracker
*/
fixup() {
fixupVarScoping(this);
}
/**
* Tells if a variable name is excluded
* @param {String} name
*/
/**
* A single pass through the AST to collect info for
*
* 1. Scope Tracker
* 2. Unsafe Scopes (direct eval scopes)
* 3. Charset considerations for better gzip compression
*
* Traversed in the same fashion(BFS) the mangling is done
*/
collect() {
const mangler = this;
const scopeTracker = mangler.scopeTracker;
}, {
key: "isExcluded",
value: function isExcluded(name) {
return hop.call(this.exclude, name) && this.exclude[name];
}
/**
* Clears traverse cache and recrawls the AST
*
* to recompute the bindings, references, other scope information
* and paths because the other transformations in the same pipeline
* (other plugins and presets) changes the AST and does NOT update
* the scope objects
*/
scopeTracker.addScope(this.program.scope);
}, {
key: "crawlScope",
value: function crawlScope() {
(traverse.clearCache || traverse.cache.clear)();
this.program.scope.crawl();
}
/**
* Same usage as in DCE, whichever runs first
* Re-crawling comes with a side-effect that let->var conversion
* reverts the update of the binding information (block to fn scope).
* This function takes care of it by updating it again.
*
* TODO: This is unnecessary work and needs to be fixed in babel.
* https://github.com/babel/babel/issues/4818
*
* When this is removed, remember to remove fixup's dependency in
* ScopeTracker
*/
if (!isEvalScopesMarked(mangler.program)) {
markEvalScopes(mangler.program);
}, {
key: "fixup",
value: function fixup() {
fixupVarScoping(this);
}
/**
* The visitors to be used in traversal.
* A single pass through the AST to collect info for
*
* Note: BFS traversal supports only the `enter` handlers, `exit`
* handlers are simply dropped without Errors
* 1. Scope Tracker
* 2. Unsafe Scopes (direct eval scopes)
* 3. Charset considerations for better gzip compression
*
* Collects items defined in the ScopeTracker
* Traversed in the same fashion(BFS) the mangling is done
*/
const collectVisitor = {
Scopable({ scope }) {
scopeTracker.addScope(scope);
// Collect bindings defined in the scope
Object.keys(scope.bindings).forEach(name => {
scopeTracker.addBinding(scope.bindings[name]);
});
},
}, {
key: "collect",
value: function collect() {
var mangler = this;
var scopeTracker = mangler.scopeTracker;
scopeTracker.addScope(this.program.scope);
/**
* This is necessary because, in Babel, the scope.references
* does NOT contain the references in that scope. Only the program
* scope (top most level) contains all the references.
*
* We collect the references in a fashion where all the scopes between
* and including the referenced scope and scope where it is declared
* is considered as scope referencing that identifier
* Same usage as in DCE, whichever runs first
*/
ReferencedIdentifier(path) {
if (isLabelIdentifier(path)) return;
const scope = path.scope,
name = path.node.name;
const binding = scope.getBinding(name);
if (!binding) {
// Do not collect globals as they are already available via
// babel's API
if (scope.hasGlobal(name)) return;
// This should NOT happen ultimately. Panic if this code block is
// reached
throw new Error(`Binding not found for ReferencedIdentifier "${name}" ` + `present in "${path.parentPath.type}". ` + `Please report this at ${newIssueUrl}`);
} else {
// Add it to our scope tracker if everything is fine
scopeTracker.addReference(scope, binding, name);
}
},
if (!isEvalScopesMarked(mangler.program)) {
markEvalScopes(mangler.program);
}
/**
* This is useful to detect binding ids and add them to the
* scopeTracker's bindings
* The visitors to be used in traversal.
*
* TODO:
* Note: BFS traversal supports only the `enter` handlers, `exit`
* handlers are simply dropped without Errors
*
* This visitor is probably unnecessary. It was added to capture the
* bindings that was not present in scope.bindings. But, now, it looks
* like the unit and smoke tests pass without this.
* Collects items defined in the ScopeTracker
*/
BindingIdentifier(path) {
if (isLabelIdentifier(path)) return;
var collectVisitor = {
Scopable(_ref2) {
var scope = _ref2.scope;
const scope = path.scope,
scopeTracker.addScope(scope);
// Collect bindings defined in the scope
Object.keys(scope.bindings).forEach(function (name) {
scopeTracker.addBinding(scope.bindings[name]);
});
},
/**
* This is necessary because, in Babel, the scope.references
* does NOT contain the references in that scope. Only the program
* scope (top most level) contains all the references.
*
* We collect the references in a fashion where all the scopes between
* and including the referenced scope and scope where it is declared
* is considered as scope referencing that identifier
*/
ReferencedIdentifier(path) {
if (isLabelIdentifier(path)) return;
var scope = path.scope,
name = path.node.name;
const binding = scope.getBinding(name);
var binding = scope.getBinding(name);
if (!binding) {
// Do not collect globals as they are already available via
// babel's API
if (scope.hasGlobal(name)) return;
// This should NOT happen ultimately. Panic if this code block is
// reached
throw new Error(`Binding not found for ReferencedIdentifier "${name}" ` + `present in "${path.parentPath.type}". ` + `Please report this at ${newIssueUrl}`);
} else {
// Add it to our scope tracker if everything is fine
scopeTracker.addReference(scope, binding, name);
}
},
/**
* We have already captured the bindings when traversing through
* Scopables, if a binding identifier doesn't have a binding, it
* probably means that another transformation created a new binding,
* refer https://github.com/babel/minify/issues/549 for example -
* binding created by plugin transform-es2015-function-name
* This is useful to detect binding ids and add them to the
* scopeTracker's bindings
*
* So we just don't care about bindings that do not exist
*
* TODO:
*
* this deopts in DCE as this name can be removed for this particular
* case (es2015-function-name)
* This visitor is probably unnecessary. It was added to capture the
* bindings that was not present in scope.bindings. But, now, it looks
* like the unit and smoke tests pass without this.
*/
if (!binding) return;
BindingIdentifier(path) {
if (isLabelIdentifier(path)) return;
/**
* Detect constant violations
*
* If it's a constant violation, then add the Identifier Path as
* a Reference instead of Binding - This is because the ScopeTracker
* tracks these Re-declaration and mutation of variables as References
* as it is simple to rename them
*/
if (binding.identifier === path.node) {
scopeTracker.addBinding(binding);
} else {
// constant violation
scopeTracker.addReference(scope, binding, name);
}
}
};
var scope = path.scope,
name = path.node.name;
/**
* These visitors are for collecting the Characters used in the program
* to measure the frequency and generate variable names for mangling so
* as to improve the gzip compression - as gzip likes repetition
*/
if (this.charset.shouldConsider) {
collectVisitor.Identifier = function Identifer(path) {
const node = path.node;
var binding = scope.getBinding(name);
// We don't mangle properties, so we collect them as they contribute
// to the frequency of characters
/**
* We have already captured the bindings when traversing through
* Scopables, if a binding identifier doesn't have a binding, it
* probably means that another transformation created a new binding,
* refer https://github.com/babel/minify/issues/549 for example -
* binding created by plugin transform-es2015-function-name
*
* So we just don't care about bindings that do not exist
*
* TODO:
*
* this deopts in DCE as this name can be removed for this particular
* case (es2015-function-name)
*/
if (!binding) return;
if (path.parentPath.isMemberExpression({ property: node }) || path.parentPath.isObjectProperty({ key: node })) {
mangler.charset.consider(node.name);
/**
* Detect constant violations
*
* If it's a constant violation, then add the Identifier Path as
* a Reference instead of Binding - This is because the ScopeTracker
* tracks these Re-declaration and mutation of variables as References
* as it is simple to rename them
*/
if (binding.identifier === path.node) {
scopeTracker.addBinding(binding);
} else {
// constant violation
scopeTracker.addReference(scope, binding, name);
}
}
};
collectVisitor.Literal = function Literal({ node }) {
mangler.charset.consider(String(node.value));
};
}
// Traverse the AST
bfsTraverse(mangler.program, collectVisitor);
}
/**
* These visitors are for collecting the Characters used in the program
* to measure the frequency and generate variable names for mangling so
* as to improve the gzip compression - as gzip likes repetition
*/
if (this.charset.shouldConsider) {
collectVisitor.Identifier = function Identifer(path) {
var node = path.node;
/**
* Tells if a binding is exported as a NamedExport - so as to NOT mangle
*
* Babel treats NamedExports as a binding referenced by this NamedExport decl
* @param {Binding} binding
*/
isExportedWithName(binding) {
// short circuit
if (!this.topLevel) {
return false;
}
// We don't mangle properties, so we collect them as they contribute
// to the frequency of characters
const refs = binding.referencePaths;
if (path.parentPath.isMemberExpression({ property: node }) || path.parentPath.isObjectProperty({ key: node })) {
mangler.charset.consider(node.name);
}
};
collectVisitor.Literal = function Literal(_ref3) {
var node = _ref3.node;
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
mangler.charset.consider(String(node.value));
};
}
try {
for (var _iterator = refs[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
const ref = _step.value;
// Traverse the AST
bfsTraverse(mangler.program, collectVisitor);
}
if (ref.isExportNamedDeclaration()) {
return true;
}
/**
* Tells if a binding is exported as a NamedExport - so as to NOT mangle
*
* Babel treats NamedExports as a binding referenced by this NamedExport decl
* @param {Binding} binding
*/
}, {
key: "isExportedWithName",
value: function isExportedWithName(binding) {
// short circuit
if (!this.topLevel) {
return false;
}
// default
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
var refs = binding.referencePaths;
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
for (var _iterator = refs[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var ref = _step.value;
if (ref.isExportNamedDeclaration()) {
return true;
}
}
// default
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
if (_didIteratorError) {
throw _iteratorError;
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return false;
}
return false;
}
/**
* Mangle the scope
* @param {Scope} scope
*/
/**
* Mangle the scope
* @param {Scope} scope
*/
mangleScope(scope) {
const mangler = this;
const scopeTracker = mangler.scopeTracker;
}, {
key: "mangleScope",
value: function mangleScope(scope) {
var mangler = this;
var scopeTracker = mangler.scopeTracker;
// Unsafe Scope
// Unsafe Scope
if (!mangler.eval && hasEval(scope)) return;
if (!mangler.eval && hasEval(scope)) return;
// Already visited
// This is because for a function, in Babel, the function and
// the function body's BlockStatement has the same scope, and will
// be visited twice by the Scopable handler, and we want to mangle
// it only once
if (mangler.visitedScopes.has(scope)) return;
mangler.visitedScopes.add(scope);
// Already visited
// This is because for a function, in Babel, the function and
// the function body's BlockStatement has the same scope, and will
// be visited twice by the Scopable handler, and we want to mangle
// it only once
if (mangler.visitedScopes.has(scope)) return;
mangler.visitedScopes.add(scope);
// Helpers to generate names
let i = 0;
function getNext() {
return mangler.charset.getIdentifier(i++);
}
function resetNext() {
i = 0;
}
// Helpers to generate names
var i = 0;
function getNext() {
return mangler.charset.getIdentifier(i++);
}
function resetNext() {
i = 0;
}
const bindings = scopeTracker.bindings.get(scope);
const names = [...bindings.keys()];
var bindings = scopeTracker.bindings.get(scope);
var names = [].concat(_toConsumableArray(bindings.keys()));
/**
* 1. Iterate through the list of BindingIdentifiers
* 2. Rename each of them in-place
* 3. Update the scope tree.
*/
for (let i = 0; i < names.length; i++) {
const oldName = names[i];
const binding = bindings.get(oldName);
/**
* 1. Iterate through the list of BindingIdentifiers
* 2. Rename each of them in-place
* 3. Update the scope tree.
*/
for (var _i = 0; _i < names.length; _i++) {
var oldName = names[_i];
var binding = bindings.get(oldName);
// Names which should NOT be mangled
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;
// Names which should NOT be mangled
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;
}
var next = void 0;
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
mangler.rename(scope, binding, oldName, next);
}
}
let next;
do {
next = getNext();
} while (!t.isValidIdentifier(next) || scopeTracker.hasBinding(scope, next) || scope.hasGlobal(next) || scopeTracker.hasReference(scope, next) || !scopeTracker.canUseInReferencedScopes(binding, next));
/**
* The mangle function that traverses through all the Scopes in a BFS
* fashion - calls mangleScope
*/
// Reset so variables which are removed can be reused
resetNext();
}, {
key: "mangle",
value: function mangle() {
var mangler = this;
// Once we detected a valid `next` Identifier which could be used,
// call the renamer
mangler.rename(scope, binding, oldName, next);
bfsTraverse(this.program, {
Scopable(path) {
if (!path.isProgram() || mangler.topLevel) mangler.mangleScope(path.scope);
}
});
}
}
/**
* The mangle function that traverses through all the Scopes in a BFS
* fashion - calls mangleScope
*/
mangle() {
const mangler = this;
/**
* Given a NodePath, collects all the Identifiers which are BindingIdentifiers
* and replaces them with the new name
*
* For example,
* var a = 1, { b } = c; // a and b are BindingIdentifiers
*
* @param {NodePath} path
* @param {String} oldName
* @param {String} newName
* @param {Function} predicate
*/
bfsTraverse(this.program, {
Scopable(path) {
if (!path.isProgram() || mangler.topLevel) mangler.mangleScope(path.scope);
}
});
}
}, {
key: "renameBindingIds",
value: function renameBindingIds(path, oldName, newName) {
var predicate = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : function () {
return true;
};
/**
* Given a NodePath, collects all the Identifiers which are BindingIdentifiers
* and replaces them with the new name
*
* For example,
* var a = 1, { b } = c; // a and b are BindingIdentifiers
*
* @param {NodePath} path
* @param {String} oldName
* @param {String} newName
* @param {Function} predicate
*/
renameBindingIds(path, oldName, newName, predicate = () => true) {
const bindingIds = path.getBindingIdentifierPaths(true, false);
for (const name in bindingIds) {
if (name !== oldName) continue;
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
var bindingIds = path.getBindingIdentifierPaths(true, false);
for (var name in bindingIds) {
if (name !== oldName) continue;
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator2 = bindingIds[name][Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
const idPath = _step2.value;
try {
for (var _iterator2 = bindingIds[name][Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var idPath = _step2.value;
if (predicate(idPath)) {
this.renamedNodes.add(idPath.node);
idPath.replaceWith(t.identifier(newName));
this.renamedNodes.add(idPath.node);
if (predicate(idPath)) {
this.renamedNodes.add(idPath.node);
idPath.replaceWith(t.identifier(newName));
this.renamedNodes.add(idPath.node);
}
}
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}

@@ -423,97 +472,104 @@ }

}
}
/**
* The Renamer:
* Renames the following for one Binding in a Scope
*
* 1. Binding in that Scope
* 2. All the Binding's constant violations
* 3. All its References
* 4. Updates mangler.scopeTracker
* 5. Updates Babel's Scope tracking
*
* @param {Scope} scope
* @param {Binding} binding
* @param {String} oldName
* @param {String} newName
*/
rename(scope, binding, oldName, newName) {
const mangler = this;
const scopeTracker = mangler.scopeTracker;
/**
* The Renamer:
* Renames the following for one Binding in a Scope
*
* 1. Binding in that Scope
* 2. All the Binding's constant violations
* 3. All its References
* 4. Updates mangler.scopeTracker
* 5. Updates Babel's Scope tracking
*
* @param {Scope} scope
* @param {Binding} binding
* @param {String} oldName
* @param {String} newName
*/
// rename at the declaration level
}, {
key: "rename",
value: function rename(scope, binding, oldName, newName) {
var mangler = this;
var scopeTracker = mangler.scopeTracker;
this.renameBindingIds(binding.path, oldName, newName, idPath => idPath.node === binding.identifier);
// rename at the declaration level
// update mangler's ScopeTracker
scopeTracker.renameBinding(scope, oldName, newName);
this.renameBindingIds(binding.path, oldName, newName, function (idPath) {
return idPath.node === binding.identifier;
});
// update all constant violations
const violations = binding.constantViolations;
for (let i = 0; i < violations.length; i++) {
if (violations[i].isLabeledStatement()) continue;
// update mangler's ScopeTracker
scopeTracker.renameBinding(scope, oldName, newName);
this.renameBindingIds(violations[i], oldName, newName);
scopeTracker.updateReference(violations[i].scope, binding, oldName, newName);
}
// update all constant violations
var violations = binding.constantViolations;
for (var i = 0; i < violations.length; i++) {
if (violations[i].isLabeledStatement()) continue;
// update all referenced places
const refs = binding.referencePaths;
for (let i = 0; i < refs.length; i++) {
const path = refs[i];
this.renameBindingIds(violations[i], oldName, newName);
scopeTracker.updateReference(violations[i].scope, binding, oldName, newName);
}
const node = path.node;
// update all referenced places
var refs = binding.referencePaths;
for (var _i2 = 0; _i2 < refs.length; _i2++) {
var path = refs[_i2];
var node = path.node;
if (!path.isIdentifier()) {
// Ideally, this should not happen
// it happens in these places now -
// case 1: Export Statements
// This is a bug in babel
// https://github.com/babel/babel/pull/3629
// case 2: Replacements in other plugins
// eg: https://github.com/babel/minify/issues/122
// replacement in dce from `x` to `!x` gives referencePath as `!x`
path.traverse({
ReferencedIdentifier(refPath) {
if (refPath.node.name !== oldName) {
return;
if (!path.isIdentifier()) {
// Ideally, this should not happen
// it happens in these places now -
// case 1: Export Statements
// This is a bug in babel
// https://github.com/babel/babel/pull/3629
// case 2: Replacements in other plugins
// eg: https://github.com/babel/minify/issues/122
// replacement in dce from `x` to `!x` gives referencePath as `!x`
path.traverse({
ReferencedIdentifier(refPath) {
if (refPath.node.name !== oldName) {
return;
}
var actualBinding = refPath.scope.getBinding(oldName);
if (actualBinding !== binding) {
return;
}
mangler.renamedNodes.add(refPath.node);
refPath.replaceWith(t.identifier(newName));
mangler.renamedNodes.add(refPath.node);
scopeTracker.updateReference(refPath.scope, binding, oldName, newName);
}
const actualBinding = refPath.scope.getBinding(oldName);
if (actualBinding !== binding) {
return;
}
mangler.renamedNodes.add(refPath.node);
refPath.replaceWith(t.identifier(newName));
mangler.renamedNodes.add(refPath.node);
scopeTracker.updateReference(refPath.scope, binding, oldName, newName);
});
} else if (!isLabelIdentifier(path)) {
if (path.node.name === oldName) {
mangler.renamedNodes.add(path.node);
path.replaceWith(t.identifier(newName));
mangler.renamedNodes.add(path.node);
scopeTracker.updateReference(path.scope, binding, oldName, newName);
} else if (mangler.renamedNodes.has(path.node)) {
// already renamed,
// just update the references
scopeTracker.updateReference(path.scope, binding, oldName, newName);
} else {
throw new Error(`Unexpected Rename Error: ` + `Trying to replace "${node.name}": from "${oldName}" to "${newName}". ` + `Please report it at ${newIssueUrl}`);
}
});
} else if (!isLabelIdentifier(path)) {
if (path.node.name === oldName) {
mangler.renamedNodes.add(path.node);
path.replaceWith(t.identifier(newName));
mangler.renamedNodes.add(path.node);
scopeTracker.updateReference(path.scope, binding, oldName, newName);
} else if (mangler.renamedNodes.has(path.node)) {
// already renamed,
// just update the references
scopeTracker.updateReference(path.scope, binding, oldName, newName);
} else {
throw new Error(`Unexpected Rename Error: ` + `Trying to replace "${node.name}": from "${oldName}" to "${newName}". ` + `Please report it at ${newIssueUrl}`);
}
// else label identifier - silently ignore
}
// else label identifier - silently ignore
// update babel's scope tracking
var bindings = scope.bindings;
bindings[newName] = binding;
delete bindings[oldName];
}
}]);
// update babel's scope tracking
const bindings = scope.bindings;
return Mangler;
}();
bindings[newName] = binding;
delete bindings[oldName];
}
}
return {

@@ -531,7 +587,7 @@ name: "minify-mangle-names",

// sorting on the character set. Currently the number is pretty arbitrary.
const shouldConsiderSource = path.getSource().length > 70000;
var shouldConsiderSource = path.getSource().length > 70000;
const charset = new Charset(shouldConsiderSource);
var charset = new Charset(shouldConsiderSource);
const mangler = new Mangler(charset, path, this.opts);
var mangler = new Mangler(charset, path, this.opts);
mangler.run();

@@ -550,4 +606,4 @@ }

const map = {};
for (let i = 0; i < value.length; i++) {
var map = {};
for (var i = 0; i < value.length; i++) {
map[value[i]] = true;

@@ -554,0 +610,0 @@ }

@@ -6,5 +6,5 @@ "use strict";

function isLabelIdentifier(path) {
const node = path.node;
var node = path.node;
return path.parentPath.isLabeledStatement({ label: node }) || path.parentPath.isBreakStatement({ label: node }) || path.parentPath.isContinueStatement({ label: node });
}
"use strict";
const CountedSet = require("./counted-set");
const isLabelIdentifier = require("./is-label-identifier");
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
const newIssueUrl = "https://github.com/babel/minify/issues/new";
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var CountedSet = require("./counted-set");
var isLabelIdentifier = require("./is-label-identifier");
var newIssueUrl = "https://github.com/babel/minify/issues/new";
/**

@@ -13,4 +17,6 @@ * ScopeTracker

*/
module.exports = class ScopeTracker {
constructor() {
module.exports = function () {
function ScopeTracker() {
_classCallCheck(this, ScopeTracker);
this.references = new Map();

@@ -24,114 +30,134 @@ this.bindings = new Map();

*/
addScope(scope) {
if (!this.references.has(scope)) {
this.references.set(scope, new CountedSet());
_createClass(ScopeTracker, [{
key: "addScope",
value: function addScope(scope) {
if (!this.references.has(scope)) {
this.references.set(scope, new CountedSet());
}
if (!this.bindings.has(scope)) {
this.bindings.set(scope, new Map());
}
}
if (!this.bindings.has(scope)) {
this.bindings.set(scope, new Map());
/**
* Add reference to all Scopes between and including the ReferencedScope
* and Binding's Scope
* @param {Scope} scope
* @param {Binding} binding
* @param {String} name
*/
}, {
key: "addReference",
value: function addReference(scope, binding, name) {
var parent = scope;
do {
this.references.get(parent).add(name);
if (!binding) {
throw new Error(`Binding Not Found for ${name} during scopeTracker.addRefernce. ` + `Please report at ${newIssueUrl}`);
}
if (binding.scope === parent) break;
} while (parent = parent.parent);
}
}
/**
* Add reference to all Scopes between and including the ReferencedScope
* and Binding's Scope
* @param {Scope} scope
* @param {Binding} binding
* @param {String} name
*/
addReference(scope, binding, name) {
let parent = scope;
do {
this.references.get(parent).add(name);
if (!binding) {
throw new Error(`Binding Not Found for ${name} during scopeTracker.addRefernce. ` + `Please report at ${newIssueUrl}`);
}
if (binding.scope === parent) break;
} while (parent = parent.parent);
}
/**
* has a Reference in the given {Scope} or a child Scope
*
* Refer {addReference} to know why the following call will be valid
* for detecting references in child Scopes
*
* @param {Scope} scope
* @param {String} name
*/
/**
* has a Reference in the given {Scope} or a child Scope
*
* Refer {addReference} to know why the following call will be valid
* for detecting references in child Scopes
*
* @param {Scope} scope
* @param {String} name
*/
hasReference(scope, name) {
return this.references.get(scope).has(name);
}
}, {
key: "hasReference",
value: function hasReference(scope, name) {
return this.references.get(scope).has(name);
}
/**
* Update reference count in all scopes between and including the
* Referenced Scope and the Binding's Scope
*
* @param {Scope} scope
* @param {Binding} binding
* @param {String} oldName
* @param {String} newName
*/
updateReference(scope, binding, oldName, newName) {
let parent = scope;
do {
const ref = this.references.get(parent);
/**
* Update reference count in all scopes between and including the
* Referenced Scope and the Binding's Scope
*
* @param {Scope} scope
* @param {Binding} binding
* @param {String} oldName
* @param {String} newName
*/
ref.delete(oldName);
ref.add(newName);
}, {
key: "updateReference",
value: function updateReference(scope, binding, oldName, newName) {
var parent = scope;
do {
var ref = this.references.get(parent);
if (!binding) {
// Something went wrong - panic
throw new Error("Binding Not Found during scopeTracker.updateRefernce " + `while updating "${oldName}" to "${newName}". ` + `Please report at ${newIssueUrl}`);
}
ref.delete(oldName);
ref.add(newName);
if (binding.scope === parent) break;
} while (parent = parent.parent);
}
if (!binding) {
// Something went wrong - panic
throw new Error("Binding Not Found during scopeTracker.updateRefernce " + `while updating "${oldName}" to "${newName}". ` + `Please report at ${newIssueUrl}`);
}
/**
* has either a Binding or a Reference
* @param {Scope} scope
* @param {Binding} binding
* @param {String} name
*/
hasBindingOrReference(scope, binding, name) {
return this.hasReference(scope, name) || this.hasBinding(scope, name);
}
if (binding.scope === parent) break;
} while (parent = parent.parent);
}
/**
* For a Binding visit all places where the Binding is used and detect
* if the newName {next} can be used in all these places
*
* 1. binding's own scope
* 2. constant violations' scopes
* 3. referencePaths' scopes
*
* @param {Binding} binding
* @param {String} next
*/
canUseInReferencedScopes(binding, next) {
const tracker = this;
/**
* has either a Binding or a Reference
* @param {Scope} scope
* @param {Binding} binding
* @param {String} name
*/
if (tracker.hasBindingOrReference(binding.scope, binding, next)) {
return false;
}, {
key: "hasBindingOrReference",
value: function hasBindingOrReference(scope, binding, name) {
return this.hasReference(scope, name) || this.hasBinding(scope, name);
}
// Safari raises a syntax error for a `let` or `const` declaration in a
// `for` loop initialization that shadows a parent function's parameter.
// https://github.com/babel/minify/issues/559
// https://bugs.webkit.org/show_bug.cgi?id=171041
// https://trac.webkit.org/changeset/217200/webkit/trunk/Source
const maybeDecl = binding.path.parentPath;
const isBlockScoped = maybeDecl.isVariableDeclaration({ kind: "let" }) || maybeDecl.isVariableDeclaration({ kind: "const" });
if (isBlockScoped) {
const maybeFor = maybeDecl.parentPath;
const isForLoopBinding = maybeFor.isForStatement({ init: maybeDecl.node }) || maybeFor.isForXStatement({ left: maybeDecl.node });
if (isForLoopBinding) {
const fnParent = maybeFor.getFunctionParent();
if (fnParent.isFunction({ body: maybeFor.parent })) {
const parentFunctionBinding = this.bindings.get(fnParent.scope).get(next);
if (parentFunctionBinding) {
const parentFunctionHasParamBinding = parentFunctionBinding.kind === "param";
if (parentFunctionHasParamBinding) {
return false;
/**
* For a Binding visit all places where the Binding is used and detect
* if the newName {next} can be used in all these places
*
* 1. binding's own scope
* 2. constant violations' scopes
* 3. referencePaths' scopes
*
* @param {Binding} binding
* @param {String} next
*/
}, {
key: "canUseInReferencedScopes",
value: function canUseInReferencedScopes(binding, next) {
var tracker = this;
if (tracker.hasBindingOrReference(binding.scope, binding, next)) {
return false;
}
// Safari raises a syntax error for a `let` or `const` declaration in a
// `for` loop initialization that shadows a parent function's parameter.
// https://github.com/babel/minify/issues/559
// https://bugs.webkit.org/show_bug.cgi?id=171041
// https://trac.webkit.org/changeset/217200/webkit/trunk/Source
var maybeDecl = binding.path.parentPath;
var isBlockScoped = maybeDecl.isVariableDeclaration({ kind: "let" }) || maybeDecl.isVariableDeclaration({ kind: "const" });
if (isBlockScoped) {
var maybeFor = maybeDecl.parentPath;
var isForLoopBinding = maybeFor.isForStatement({ init: maybeDecl.node }) || maybeFor.isForXStatement({ left: maybeDecl.node });
if (isForLoopBinding) {
var fnParent = maybeFor.getFunctionParent();
if (fnParent.isFunction({ body: maybeFor.parent })) {
var parentFunctionBinding = this.bindings.get(fnParent.scope).get(next);
if (parentFunctionBinding) {
var parentFunctionHasParamBinding = parentFunctionBinding.kind === "param";
if (parentFunctionHasParamBinding) {
return false;
}
}

@@ -141,88 +167,102 @@ }

}
}
for (let i = 0; i < binding.constantViolations.length; i++) {
const violation = binding.constantViolations[i];
if (tracker.hasBindingOrReference(violation.scope, binding, next)) {
return false;
for (var i = 0; i < binding.constantViolations.length; i++) {
var violation = binding.constantViolations[i];
if (tracker.hasBindingOrReference(violation.scope, binding, next)) {
return false;
}
}
}
for (let i = 0; i < binding.referencePaths.length; i++) {
const ref = binding.referencePaths[i];
if (!ref.isIdentifier()) {
let canUse = true;
ref.traverse({
ReferencedIdentifier(path) {
if (path.node.name !== next) return;
if (tracker.hasBindingOrReference(path.scope, binding, next)) {
canUse = false;
for (var _i = 0; _i < binding.referencePaths.length; _i++) {
var ref = binding.referencePaths[_i];
if (!ref.isIdentifier()) {
var canUse = true;
ref.traverse({
ReferencedIdentifier(path) {
if (path.node.name !== next) return;
if (tracker.hasBindingOrReference(path.scope, binding, next)) {
canUse = false;
}
}
});
if (!canUse) {
return canUse;
}
});
if (!canUse) {
return canUse;
} else if (!isLabelIdentifier(ref)) {
if (tracker.hasBindingOrReference(ref.scope, binding, next)) {
return false;
}
}
} else if (!isLabelIdentifier(ref)) {
if (tracker.hasBindingOrReference(ref.scope, binding, next)) {
return false;
}
}
return true;
}
return true;
}
/**
* Add a binding to Tracker in binding's own Scope
* @param {Binding} binding
*/
/**
* Add a binding to Tracker in binding's own Scope
* @param {Binding} binding
*/
addBinding(binding) {
if (!binding) {
return;
}, {
key: "addBinding",
value: function addBinding(binding) {
if (!binding) {
return;
}
var bindings = this.bindings.get(binding.scope);
var existingBinding = bindings.get(binding.identifier.name);
if (existingBinding && existingBinding !== binding) {
throw new Error(`scopeTracker.addBinding: ` + `Binding "${existingBinding.identifier.name}" already exists. ` + `Trying to add "${binding.identifier.name}" again.`);
}
bindings.set(binding.identifier.name, binding);
}
const bindings = this.bindings.get(binding.scope);
const existingBinding = bindings.get(binding.identifier.name);
/**
* Moves Binding from it's own Scope to {toScope}
*
* required for fixup-var-scope
*
* @param {Binding} binding
* @param {Scope} toScope
*/
if (existingBinding && existingBinding !== binding) {
throw new Error(`scopeTracker.addBinding: ` + `Binding "${existingBinding.identifier.name}" already exists. ` + `Trying to add "${binding.identifier.name}" again.`);
}, {
key: "moveBinding",
value: function moveBinding(binding, toScope) {
this.bindings.get(binding.scope).delete(binding.identifier.name);
this.bindings.get(toScope).set(binding.identifier.name, binding);
}
bindings.set(binding.identifier.name, binding);
}
/**
* has a Binding in the current {Scope}
* @param {Scope} scope
* @param {String} name
*/
/**
* Moves Binding from it's own Scope to {toScope}
*
* required for fixup-var-scope
*
* @param {Binding} binding
* @param {Scope} toScope
*/
moveBinding(binding, toScope) {
this.bindings.get(binding.scope).delete(binding.identifier.name);
this.bindings.get(toScope).set(binding.identifier.name, binding);
}
}, {
key: "hasBinding",
value: function hasBinding(scope, name) {
return this.bindings.get(scope).has(name);
}
/**
* has a Binding in the current {Scope}
* @param {Scope} scope
* @param {String} name
*/
hasBinding(scope, name) {
return this.bindings.get(scope).has(name);
}
/**
* Update the ScopeTracker on rename
* @param {Scope} scope
* @param {String} oldName
* @param {String} newName
*/
/**
* Update the ScopeTracker on rename
* @param {Scope} scope
* @param {String} oldName
* @param {String} newName
*/
renameBinding(scope, oldName, newName) {
const bindings = this.bindings.get(scope);
bindings.set(newName, bindings.get(oldName));
bindings.delete(oldName);
}
};
}, {
key: "renameBinding",
value: function renameBinding(scope, oldName, newName) {
var bindings = this.bindings.get(scope);
bindings.set(newName, bindings.get(oldName));
bindings.delete(oldName);
}
}]);
return ScopeTracker;
}();
{
"name": "babel-plugin-minify-mangle-names",
"version": "0.3.0-alpha.6ae655c0",
"version": "0.3.0-alpha.6ceffb8d",
"description": "",

@@ -15,4 +15,4 @@ "keywords": [

"dependencies": {
"babel-helper-mark-eval-scopes": "^0.3.0-alpha.6ae655c0"
"babel-helper-mark-eval-scopes": "^0.3.0-alpha.6ceffb8d"
}
}
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