From 43d5432274501794f332c6ed77bf233f604f16e3 Mon Sep 17 00:00:00 2001 From: Boopathi Rajaa Date: Thu, 13 Oct 2016 00:10:08 +0200 Subject: [PATCH] Mangler - rename keepFnames to keepFnName (#183) --- packages/babel-plugin-minify-mangle-names/README.md | 2 +- .../__tests__/mangle-names-test.js | 4 ++-- packages/babel-plugin-minify-mangle-names/src/index.js | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/babel-plugin-minify-mangle-names/README.md b/packages/babel-plugin-minify-mangle-names/README.md index de06d86d8..3184bdb62 100644 --- a/packages/babel-plugin-minify-mangle-names/README.md +++ b/packages/babel-plugin-minify-mangle-names/README.md @@ -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` diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/mangle-names-test.js b/packages/babel-plugin-minify-mangle-names/__tests__/mangle-names-test.js index e38983089..20868b2c0 100644 --- a/packages/babel-plugin-minify-mangle-names/__tests__/mangle-names-test.js +++ b/packages/babel-plugin-minify-mangle-names/__tests__/mangle-names-test.js @@ -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 {} @@ -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", () => { diff --git a/packages/babel-plugin-minify-mangle-names/src/index.js b/packages/babel-plugin-minify-mangle-names/src/index.js index 62222864a..0d12a5e0f 100644 --- a/packages/babel-plugin-minify-mangle-names/src/index.js +++ b/packages/babel-plugin-minify-mangle-names/src/index.js @@ -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; @@ -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; } @@ -275,7 +275,7 @@ class Charset { } } -// for keepFnames +// for keepFnName function isFunction(path) { return path.isFunctionExpression() || path.isFunctionDeclaration()