diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2019-03-15 01:15:50 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-15 01:15:50 +0800 |
commit | 627f5fb41eac761fec7481b7429f5edb878f9c04 (patch) | |
tree | 7d9eea9e0873f735c3b5b488d909379b0a85da2f /test/mocha/minify.js | |
parent | d90777b724689af625c36ed6d557b024775ee95a (diff) | |
download | tracifyjs-627f5fb41eac761fec7481b7429f5edb878f9c04.tar.gz tracifyjs-627f5fb41eac761fec7481b7429f5edb878f9c04.zip |
fix corner case with `nameCache` (#3338)
fixes #3301
Diffstat (limited to 'test/mocha/minify.js')
-rw-r--r-- | test/mocha/minify.js | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/test/mocha/minify.js b/test/mocha/minify.js index 6e6c7a78..d11f40ff 100644 --- a/test/mocha/minify.js +++ b/test/mocha/minify.js @@ -87,7 +87,7 @@ describe("minify", function() { assert.strictEqual(run_code(compressed), run_code(original)); }); - it("Should avoid mangled names in cache", function() { + it("Should avoid cached names when mangling top-level variables", function() { var cache = {}; var original = ""; var compressed = ""; @@ -116,6 +116,30 @@ describe("minify", function() { assert.strictEqual(run_code(compressed), run_code(original)); }); + it("Should avoid cached names when mangling inner-scoped variables", function() { + var cache = {}; + var original = ""; + var compressed = ""; + [ + 'var extend = function(a, b) { console.log("extend"); a(); b(); }; function A() { console.log("A"); };', + 'var B = function(A) { function B() { console.log("B") }; extend(B, A); return B; }(A);', + ].forEach(function(code) { + var result = UglifyJS.minify(code, { + compress: false, + nameCache: cache, + toplevel: true, + }); + if (result.error) throw result.error; + original += code; + compressed += result.code; + }); + assert.strictEqual(compressed, [ + 'var o=function(o,n){console.log("extend");o();n()};function n(){console.log("A")}', + 'var e=function(n){function e(){console.log("B")}o(e,n);return e}(n);', + ].join("")); + assert.strictEqual(run_code(compressed), run_code(original)); + }); + it("Should not parse invalid use of reserved words", function() { assert.strictEqual(UglifyJS.minify("function enum(){}").error, undefined); assert.strictEqual(UglifyJS.minify("function static(){}").error, undefined); |