aboutsummaryrefslogtreecommitdiff
path: root/test/compress
diff options
context:
space:
mode:
Diffstat (limited to 'test/compress')
-rw-r--r--test/compress/comparisons.js8
-rw-r--r--test/compress/conditionals.js67
-rw-r--r--test/compress/issue-1034.js4
-rw-r--r--test/compress/issue-640.js2
4 files changed, 72 insertions, 9 deletions
diff --git a/test/compress/comparisons.js b/test/compress/comparisons.js
index bb140fd8..a4e0acc9 100644
--- a/test/compress/comparisons.js
+++ b/test/compress/comparisons.js
@@ -33,10 +33,10 @@ unsafe_comps: {
}
expect: {
var obj1, obj2;
- obj2 < obj1 ? g1() : f1();
- obj1 < obj2 ? f2() : g2();
- obj1 < obj2 ? g3() : f3();
- obj2 < obj1 ? f4() : g4();
+ (obj2 < obj1 ? g1 : f1)();
+ (obj1 < obj2 ? f2 : g2)();
+ (obj1 < obj2 ? g3 : f3)();
+ (obj2 < obj1 ? f4 : g4)();
}
}
diff --git a/test/compress/conditionals.js b/test/compress/conditionals.js
index 3e7a0927..3f3df72d 100644
--- a/test/compress/conditionals.js
+++ b/test/compress/conditionals.js
@@ -41,7 +41,7 @@ ifs_2: {
}
expect: {
foo ? x() : bar ? y() : baz && z();
- foo ? x() : bar ? y() : baz ? z() : t();
+ (foo ? x : bar ? y : baz ? z : t)();
}
}
@@ -289,7 +289,7 @@ cond_5: {
}
}
expect: {
- some_condition() && some_other_condition() ? do_something() : alternate();
+ (some_condition() && some_other_condition() ? do_something : alternate)();
some_condition() && some_other_condition() && do_something();
}
}
@@ -663,6 +663,69 @@ cond_9: {
}
}
+cond_10: {
+ options = {
+ conditionals: true,
+ if_return: true,
+ }
+ input: {
+ function f(a) {
+ if (1 == a) return "foo";
+ if (2 == a) return "foo";
+ if (3 == a) return "foo";
+ if (4 == a) return 42;
+ if (5 == a) return "foo";
+ if (6 == a) return "foo";
+ return "bar";
+ }
+ console.log(f(1), f(2), f(3), f(4), f(5), f(6), f(7));
+ }
+ expect: {
+ function f(a) {
+ return 1 == a || 2 == a || 3 == a ? "foo" : 4 == a ? 42 : 5 == a || 6 == a ? "foo" : "bar";
+ }
+ console.log(f(1), f(2), f(3), f(4), f(5), f(6), f(7));
+ }
+ expect_stdout: "foo foo foo 42 foo foo bar"
+}
+
+cond_11: {
+ options = {
+ conditionals: true,
+ }
+ input: {
+ var o = {
+ p: "foo",
+ q: function() {
+ return this.p;
+ }
+ };
+ function f() {
+ return "bar";
+ }
+ function g(a) {
+ return a ? f() : o.q();
+ }
+ console.log(g(0), g(1));
+ }
+ expect: {
+ var o = {
+ p: "foo",
+ q: function() {
+ return this.p;
+ }
+ };
+ function f() {
+ return "bar";
+ }
+ function g(a) {
+ return a ? f() : o.q();
+ }
+ console.log(g(0), g(1));
+ }
+ expect_stdout: "foo bar"
+}
+
ternary_boolean_consequent: {
options = {
booleans: true,
diff --git a/test/compress/issue-1034.js b/test/compress/issue-1034.js
index e8b69187..316d6a75 100644
--- a/test/compress/issue-1034.js
+++ b/test/compress/issue-1034.js
@@ -30,7 +30,7 @@ non_hoisted_function_after_return: {
}
expect: {
function foo(x) {
- return x ? bar() : baz();
+ return (x ? bar : baz)();
function bar() { return 7 }
function baz() { return 8 }
}
@@ -181,7 +181,7 @@ non_hoisted_function_after_return_strict: {
expect: {
"use strict";
function foo(x) {
- return x ? bar() : baz();
+ return (x ? bar : baz)();
function bar() { return 7 }
function baz() { return 8 }
}
diff --git a/test/compress/issue-640.js b/test/compress/issue-640.js
index 88b63abd..394d6ba2 100644
--- a/test/compress/issue-640.js
+++ b/test/compress/issue-640.js
@@ -21,7 +21,7 @@ cond_5: {
}
}
expect: {
- some_condition() && some_other_condition() ? do_something() : alternate();
+ (some_condition() && some_other_condition() ? do_something : alternate)();
if (some_condition() && some_other_condition()) do_something();
}
}