babel-plugin-minify-mangle-names
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -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` |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
74
16920
372
1