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
2
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.0.1 to 0.0.2

74

lib/index.js

@@ -7,4 +7,2 @@ "use strict";

var Renamer = require("./renamer");
module.exports = function (_ref) {

@@ -144,3 +142,3 @@ var t = _ref.types;

// resetNext();
mangler.renameNew(scope, b, next);
mangler.rename(scope, b, next);
});

@@ -156,4 +154,4 @@ }

}, {
key: "renameNew",
value: function renameNew(scope, oldName, newName) {
key: "rename",
value: function rename(scope, oldName, newName) {
var binding = scope.getBinding(oldName);

@@ -194,56 +192,22 @@

if (!path.isIdentifier()) {
// if this occurs, then it is
// probably an upstream bug (in babel)
throw new Error("Unexpected " + path.node.type + ". Expected an Identifier");
}
if (!isLabelIdentifier(path)) {
// 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/babili/issues/122
// replacement in dce from `x` to `!x` gives referencePath as `!x`
path.traverse({
ReferencedIdentifier: function ReferencedIdentifier(refPath) {
if (refPath.node.name === oldName && refPath.scope === scope) {
refPath.node.name = newName;
}
}
});
} else if (!isLabelIdentifier(path)) {
node.name = newName;
}
}
// update references
// TODO
}
}, {
key: "rename",
value: function rename(scope, oldName, newName) {
var binding = scope.getBinding(oldName);
if (!binding) {
throw new Error("Binding not found - " + oldName);
}
new Renamer(binding, oldName, newName).rename();
this.referencesToUpdate.set(oldName, {
scope: scope,
referenced: false
});
}
}, {
key: "updateReferences",
value: function updateReferences() {
var mangler = this;
this.program.traverse({
Identifier: function Identifier(path) {
var node = path.node;
if (path.parentPath.isMemberExpression({ property: node }) || path.parentPath.isObjectProperty({ key: node })) return;
mangler.referencesToUpdate.forEach(function (ref, oldName) {
if (node.name === oldName) {
mangler.referencesToUpdate.get(oldName).referenced = true;
}
});
}
});
this.referencesToUpdate.forEach(function (ref, oldName) {
if (ref.referenced) return;
var current = ref.scope;
do {
current.references[oldName] = false;
} while (current = current.parent);
});
}
}]);

@@ -250,0 +214,0 @@

{
"name": "babel-plugin-minify-mangle-names",
"version": "0.0.1",
"version": "0.0.2",
"description": "",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/babel/babili#readme",

@@ -51,3 +51,3 @@ # babel-plugin-minify-mangle-names

{
"plugins": ["minify-mangle-names", { "mangleBlacklist": { "foo": true, "bar": true} }]
"plugins": ["minify-mangle-names", { "blacklist": { "foo": true, "bar": true} }]
}

@@ -69,1 +69,7 @@ ```

```
## Options
+ `blacklist` - A plain JS Object with keys as identifier names and values indicating whether to exclude
+ `eval` - mangle identifiers in scopes accessible by eval
+ `keepFnames` - prevent mangler from alterning function names. Useful for code depending on `fn.name`
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