diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2019-03-20 02:53:04 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-20 02:53:04 +0800 |
commit | b9615f7a62c8d9fb5721b1699d2f4f3f14bcc5be (patch) | |
tree | 2e46467bdc5c4417e042e11050dc0825b5baddc9 /test/mocha | |
parent | c520e99eda6a516ea275b58fc100eff378261145 (diff) | |
download | tracifyjs-b9615f7a62c8d9fb5721b1699d2f4f3f14bcc5be.tar.gz tracifyjs-b9615f7a62c8d9fb5721b1699d2f4f3f14bcc5be.zip |
improve `compress` performance (#3348)
fixes #3174
Diffstat (limited to 'test/mocha')
-rw-r--r-- | test/mocha/cli.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/mocha/cli.js b/test/mocha/cli.js index af537f37..811c493f 100644 --- a/test/mocha/cli.js +++ b/test/mocha/cli.js @@ -1,6 +1,7 @@ var assert = require("assert"); var exec = require("child_process").exec; var fs = require("fs"); +var run_code = require("../sandbox").run_code; function read(path) { return fs.readFileSync(path, "utf8"); @@ -714,4 +715,32 @@ describe("bin/uglifyjs", function() { done(); }); }); + it("Should compress swarm of unused variables with reasonable performance", function(done) { + var code = [ + "console.log(function() {", + ]; + for (var i = 0; i < 10000; i++) { + code.push("var obj" + i + " = {p: " + i + "};"); + } + code.push("var map = {"); + for (var i = 0; i < 10000; i++) { + code.push("obj" + i + ": obj" + i + ","); + } + code = code.concat([ + "};", + "return obj25.p + obj121.p + obj1024.p;", + "}());", + ]).join("\n"); + exec(uglifyjscmd + " -mc", function(err, stdout) { + if (err) throw err; + assert.strictEqual(stdout, [ + "console.log(function(){", + "var p={p:25},n={p:121},o={p:1024};", + "return p.p+n.p+o.p", + "}());\n", + ].join("")); + assert.strictEqual(run_code(stdout), run_code(code)); + done(); + }).stdin.end(code); + }); }); |