aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2019-11-13 20:03:48 +0800
committerGitHub <noreply@github.com>2019-11-13 20:03:48 +0800
commitab15c40770410e0dbd5ebb382aa711f3bf5aeb38 (patch)
tree186c86c12429be17746ca1f909e8c936980ed4f3 /test
parentfe65ce965885815a30d88aa7d9eccec5443e6a3b (diff)
downloadtracifyjs-ab15c40770410e0dbd5ebb382aa711f3bf5aeb38.tar.gz
tracifyjs-ab15c40770410e0dbd5ebb382aa711f3bf5aeb38.zip
enhance `switches` (#3583)
Diffstat (limited to 'test')
-rw-r--r--test/compress/switch.js162
1 files changed, 148 insertions, 14 deletions
diff --git a/test/compress/switch.js b/test/compress/switch.js
index 547843fa..b41247b4 100644
--- a/test/compress/switch.js
+++ b/test/compress/switch.js
@@ -261,13 +261,13 @@ drop_default_1: {
}
input: {
switch (foo) {
- case 'bar': baz();
+ case "bar": baz();
default:
}
}
expect: {
switch (foo) {
- case 'bar': baz();
+ case "bar": baz();
}
}
}
@@ -279,14 +279,14 @@ drop_default_2: {
}
input: {
switch (foo) {
- case 'bar': baz(); break;
+ case "bar": baz(); break;
default:
break;
}
}
expect: {
switch (foo) {
- case 'bar': baz();
+ case "bar": baz();
}
}
}
@@ -298,7 +298,7 @@ keep_default: {
}
input: {
switch (foo) {
- case 'bar': baz();
+ case "bar": baz();
default:
something();
break;
@@ -306,7 +306,7 @@ keep_default: {
}
expect: {
switch (foo) {
- case 'bar': baz();
+ case "bar": baz();
default:
something();
}
@@ -347,21 +347,48 @@ issue_1663: {
expect_stdout: true
}
-drop_case: {
+drop_case_1: {
options = {
dead_code: true,
switches: true,
}
input: {
switch (foo) {
- case 'bar': baz(); break;
- case 'moo':
+ case "bar": baz(); break;
+ case "moo":
break;
}
}
expect: {
switch (foo) {
- case 'bar': baz();
+ case "bar": baz();
+ }
+ }
+}
+
+drop_case_2: {
+ options = {
+ dead_code: true,
+ switches: true,
+ }
+ input: {
+ switch (foo) {
+ case "bar":
+ bar();
+ break;
+ default:
+ case "moo":
+ moo();
+ break;
+ }
+ }
+ expect: {
+ switch (foo) {
+ case "bar":
+ bar();
+ break;
+ default:
+ moo();
}
}
}
@@ -373,14 +400,14 @@ keep_case: {
}
input: {
switch (foo) {
- case 'bar': baz(); break;
+ case "bar": baz(); break;
case moo:
break;
}
}
expect: {
switch (foo) {
- case 'bar': baz(); break;
+ case "bar": baz(); break;
case moo:
}
}
@@ -494,7 +521,7 @@ issue_1674: {
expect_stdout: "PASS"
}
-issue_1679: {
+issue_1679_1: {
options = {
dead_code: true,
evaluate: true,
@@ -525,6 +552,34 @@ issue_1679: {
function f() {
switch (--b) {
default:
+ break;
+ case b--:
+ switch (0) {
+ default:
+ case a--:
+ }
+ break;
+ case (a++):
+ }
+ }
+ f();
+ console.log(a, b);
+ }
+ expect_stdout: "99 8"
+}
+
+issue_1679_2: {
+ options = {
+ dead_code: true,
+ evaluate: true,
+ passes: 2,
+ switches: true,
+ }
+ input: {
+ var a = 100, b = 10;
+ function f() {
+ switch (--b) {
+ default:
case !function x() {}:
break;
case b--:
@@ -534,12 +589,29 @@ issue_1679: {
}
break;
case (a++):
+ break;
}
}
f();
console.log(a, b);
}
- expect_stdout: true
+ expect: {
+ var a = 100, b = 10;
+ function f() {
+ switch (--b) {
+ case b--:
+ switch (0) {
+ default:
+ case a--:
+ }
+ break;
+ case (a++):
+ }
+ }
+ f();
+ console.log(a, b);
+ }
+ expect_stdout: "99 8"
}
issue_1680_1: {
@@ -864,3 +936,65 @@ issue_1750: {
}
expect_stdout: "0 2"
}
+
+drop_switch_1: {
+ options = {
+ dead_code: true,
+ switches: true,
+ }
+ input: {
+ switch (foo) {
+ default:
+ break;
+ case "bar":
+ break;
+ }
+ }
+ expect: {
+ foo;
+ }
+}
+
+drop_switch_2: {
+ options = {
+ dead_code: true,
+ switches: true,
+ }
+ input: {
+ switch (foo) {
+ default:
+ case "bar":
+ baz();
+ }
+ }
+ expect: {
+ foo;
+ baz();
+ }
+}
+
+drop_switch_3: {
+ options = {
+ dead_code: true,
+ switches: true,
+ }
+ input: {
+ console.log(function() {
+ switch (0) {
+ default:
+ return "PASS";
+ case 1:
+ }
+ }());
+ }
+ expect: {
+ console.log(function() {
+ switch (0) {
+ default:
+ return "PASS";
+ case 1:
+ }
+ }());
+ }
+ expect_stdout: "PASS"
+}