aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAnthony Van de Gejuchte <anthonyvdgent@gmail.com>2017-02-18 18:56:18 +0800
committeralexlamsl <alexlamsl@gmail.com>2017-02-18 18:56:18 +0800
commitdd31d12a9110b34c1b45a72b6e1f2b64c2d7afe9 (patch)
tree1aa21b366261d20c0dfa4e5adc7d39f568499784 /test
parent7f8d72d9d37396f2da05d5d824f74bd414c30119 (diff)
downloadtracifyjs-dd31d12a9110b34c1b45a72b6e1f2b64c2d7afe9.tar.gz
tracifyjs-dd31d12a9110b34c1b45a72b6e1f2b64c2d7afe9.zip
Improve optimizing `function() { if(c){return foo} bar();}`
closes #1437
Diffstat (limited to 'test')
-rw-r--r--test/compress/if_return.js101
-rw-r--r--test/compress/issue-979.js2
-rw-r--r--test/mocha/cli.js2
3 files changed, 101 insertions, 4 deletions
diff --git a/test/compress/if_return.js b/test/compress/if_return.js
index 78a6e818..0ac45c3c 100644
--- a/test/compress/if_return.js
+++ b/test/compress/if_return.js
@@ -170,8 +170,51 @@ if_return_7: {
}
}
expect: {
- // suboptimal
- function f(x){return!!x||(foo(),void bar())}
+ function f(x){if(x)return!0;foo(),bar()}
+ }
+}
+
+if_return_8: {
+ options = {
+ if_return: true,
+ sequences: true,
+ conditionals: true,
+ side_effects : true,
+ }
+ input: {
+ function f(e) {
+ if (2 == e) return foo();
+ if (3 == e) return bar();
+ if (4 == e) return baz();
+ fail(e);
+ }
+
+ function g(e) {
+ if (a(e)) return foo();
+ if (b(e)) return bar();
+ if (c(e)) return baz();
+ fail(e);
+ }
+
+ function h(e) {
+ if (a(e)) return foo();
+ else if (b(e)) return bar();
+ else if (c(e)) return baz();
+ else fail(e);
+ }
+
+ function i(e) {
+ if (a(e)) return foo();
+ else if (b(e)) return bar();
+ else if (c(e)) return baz();
+ fail(e);
+ }
+ }
+ expect: {
+ function f(e){return 2==e?foo():3==e?bar():4==e?baz():void fail(e)}
+ function g(e){return a(e)?foo():b(e)?bar():c(e)?baz():void fail(e)}
+ function h(e){return a(e)?foo():b(e)?bar():c(e)?baz():void fail(e)}
+ function i(e){return a(e)?foo():b(e)?bar():c(e)?baz():void fail(e)}
}
}
@@ -205,3 +248,57 @@ issue_1089: {
}
}
}
+
+issue_1437: {
+ options = {
+ if_return : true,
+ sequences : true,
+ conditionals : false
+ }
+ input: {
+ function x() {
+ if (a())
+ return b();
+ if (c())
+ return d();
+ else
+ e();
+ f();
+ }
+ }
+ expect: {
+ function x() {
+ if (a())
+ return b();
+ if (c())
+ return d();
+ else
+ e()
+ f();
+ }
+ }
+}
+
+issue_1437_conditionals: {
+ options = {
+ conditionals : true,
+ if_return : true,
+ sequences : true
+ }
+ input: {
+ function x() {
+ if (a())
+ return b();
+ if (c())
+ return d();
+ else
+ e();
+ f();
+ }
+ }
+ expect: {
+ function x() {
+ return a() ? b() : c() ? d() : (e(), f(), void 0);
+ }
+ }
+}
diff --git a/test/compress/issue-979.js b/test/compress/issue-979.js
index bae15db8..7ed5801d 100644
--- a/test/compress/issue-979.js
+++ b/test/compress/issue-979.js
@@ -82,7 +82,7 @@ issue979_test_negated_is_best: {
1!=a||2!=b||foo();
}
function f7() {
- return 1!=a&&2!=b?bar():void foo();
+ if(1!=a&&2!=b)return bar();foo()
}
}
}
diff --git a/test/mocha/cli.js b/test/mocha/cli.js
index a8de05c5..c5b571bd 100644
--- a/test/mocha/cli.js
+++ b/test/mocha/cli.js
@@ -4,7 +4,7 @@ var exec = require("child_process").exec;
describe("bin/uglifyjs", function () {
var uglifyjscmd = '"' + process.argv[0] + '" bin/uglifyjs';
it("should produce a functional build when using --self", function (done) {
- this.timeout(5000);
+ this.timeout(15000);
var command = uglifyjscmd + ' --self -cm --wrap WrappedUglifyJS';