Skip to content

Commit

Permalink
Mangler - rename keepFnames to keepFnName (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
boopathi authored and kangax committed Oct 12, 2016
1 parent 32fcce4 commit 43d5432
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/babel-plugin-minify-mangle-names/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ require("babel-core").transform("code", {

+ `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`
+ `keepFnName` - prevent mangler from altering function names. Useful for code depending on `fn.name`
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ describe("mangle-names", () => {
expect(actual).toBe(expected);
});

it("should NOT mangle functions & classes when keep_fnames is true", () => {
it("should NOT mangle functions & classes when keepFnName is true", () => {
const source = unpad(`
(function() {
class Foo {}
Expand Down Expand Up @@ -765,7 +765,7 @@ describe("mangle-names", () => {
c();
})();
`);
expect(transform(source, {keepFnames: true})).toBe(expected);
expect(transform(source, {keepFnName: true})).toBe(expected);
});

it("should mangle variable re-declaration / K violations", () => {
Expand Down
8 changes: 4 additions & 4 deletions packages/babel-plugin-minify-mangle-names/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ module.exports = ({ types: t }) => {
class Mangler {
constructor(charset, program, {
blacklist = {},
keepFnames = false,
keepFnName = false,
eval: _eval = false
} = {}) {
this.charset = charset;
this.program = program;
this.blacklist = blacklist;
this.keepFnames = keepFnames;
this.keepFnName = keepFnName;
this.eval = _eval;

this.unsafeScopes = new Set;
Expand Down Expand Up @@ -124,7 +124,7 @@ module.exports = ({ types: t }) => {
// blacklisted
|| mangler.isBlacklist(oldName)
// function names
|| (mangler.keepFnames ? isFunction(binding.path) : false)
|| (mangler.keepFnName ? isFunction(binding.path) : false)
) {
continue;
}
Expand Down Expand Up @@ -275,7 +275,7 @@ class Charset {
}
}

// for keepFnames
// for keepFnName
function isFunction(path) {
return path.isFunctionExpression()
|| path.isFunctionDeclaration()
Expand Down

0 comments on commit 43d5432

Please sign in to comment.