diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2017-06-29 12:48:34 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-29 12:48:34 +0800 |
commit | bdeadffbf582b393dbc14a45b3e69ddf16f47690 (patch) | |
tree | 44575bdd928b43ddcdc630f2cd898786dbbd3172 /test/mocha/minify.js | |
parent | 5e6f26445f932a180890be4792dab574e07cbb0f (diff) | |
download | tracifyjs-bdeadffbf582b393dbc14a45b3e69ddf16f47690.tar.gz tracifyjs-bdeadffbf582b393dbc14a45b3e69ddf16f47690.zip |
improve usability of name cache under `minify()` (#2176)
fixes #2174
Diffstat (limited to 'test/mocha/minify.js')
-rw-r--r-- | test/mocha/minify.js | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/test/mocha/minify.js b/test/mocha/minify.js index b4722ce2..88e9c4eb 100644 --- a/test/mocha/minify.js +++ b/test/mocha/minify.js @@ -1,6 +1,7 @@ var Uglify = require('../../'); var assert = require("assert"); var readFileSync = require("fs").readFileSync; +var run_code = require("../sandbox").run_code; function read(path) { return readFileSync(path, "utf8"); @@ -20,6 +21,58 @@ describe("minify", function() { assert.strictEqual(result.code, "alert(2);"); }); + it("Should work with mangle.cache", function() { + var cache = {}; + var original = ""; + var compressed = ""; + [ + "bar.es5", + "baz.es5", + "foo.es5", + "qux.js", + ].forEach(function(file) { + var code = read("test/input/issue-1242/" + file); + var result = Uglify.minify(code, { + mangle: { + cache: cache, + toplevel: true + } + }); + if (result.error) throw result.error; + original += code; + compressed += result.code; + }); + assert.strictEqual(JSON.stringify(cache).slice(0, 20), '{"cname":5,"props":{'); + assert.strictEqual(compressed, 'function n(n){return 3*n}function r(n){return n/2}function c(o){l("Foo:",2*o)}var l=console.log.bind(console);var f=n(3),i=r(12);l("qux",f,i),c(11);'); + assert.strictEqual(run_code(compressed), run_code(original)); + }); + + it("Should work with nameCache", function() { + var cache = {}; + var original = ""; + var compressed = ""; + [ + "bar.es5", + "baz.es5", + "foo.es5", + "qux.js", + ].forEach(function(file) { + var code = read("test/input/issue-1242/" + file); + var result = Uglify.minify(code, { + mangle: { + toplevel: true + }, + nameCache: cache + }); + if (result.error) throw result.error; + original += code; + compressed += result.code; + }); + assert.strictEqual(JSON.stringify(cache).slice(0, 28), '{"vars":{"cname":5,"props":{'); + assert.strictEqual(compressed, 'function n(n){return 3*n}function r(n){return n/2}function c(o){l("Foo:",2*o)}var l=console.log.bind(console);var f=n(3),i=r(12);l("qux",f,i),c(11);'); + assert.strictEqual(run_code(compressed), run_code(original)); + }); + describe("keep_quoted_props", function() { it("Should preserve quotes in object literals", function() { var js = 'var foo = {"x": 1, y: 2, \'z\': 3};'; |