aboutsummaryrefslogtreecommitdiff
path: root/test/compress
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2017-04-02 14:52:25 +0800
committerGitHub <noreply@github.com>2017-04-02 14:52:25 +0800
commitf7ca4f229795f87674d32e2df3de3cf1f8367a39 (patch)
tree3350123bdb3d590b3266009ff7649c5106c58afe /test/compress
parentc076e7b60d356def1b94e5856034b38fc93312fd (diff)
downloadtracifyjs-f7ca4f229795f87674d32e2df3de3cf1f8367a39.tar.gz
tracifyjs-f7ca4f229795f87674d32e2df3de3cf1f8367a39.zip
fix corner cases in switch and undefined (#1762)
- fix side effects in switch condition for singular blocks - fix `undefined` confusion with local variable - gate `OPT(AST_Switch)` with `switches` fixes #1758 fixes #1759
Diffstat (limited to 'test/compress')
-rw-r--r--test/compress/issue-1750.js1
-rw-r--r--test/compress/reduce_vars.js12
-rw-r--r--test/compress/sequences.js26
-rw-r--r--test/compress/switch.js119
4 files changed, 146 insertions, 12 deletions
diff --git a/test/compress/issue-1750.js b/test/compress/issue-1750.js
index 53a78e65..c1448afe 100644
--- a/test/compress/issue-1750.js
+++ b/test/compress/issue-1750.js
@@ -2,6 +2,7 @@ case_1: {
options = {
dead_code: true,
evaluate: true,
+ switches: true,
}
input: {
var a = 0, b = 1;
diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js
index 87942ab9..cdc4ef20 100644
--- a/test/compress/reduce_vars.js
+++ b/test/compress/reduce_vars.js
@@ -1399,6 +1399,8 @@ issue_1670_1: {
evaluate: true,
dead_code: true,
reduce_vars: true,
+ side_effects: true,
+ switches: true,
unused: true,
}
input: {
@@ -1429,6 +1431,8 @@ issue_1670_2: {
dead_code: true,
passes: 2,
reduce_vars: true,
+ side_effects: true,
+ switches: true,
unused: true,
}
input: {
@@ -1458,6 +1462,8 @@ issue_1670_3: {
evaluate: true,
dead_code: true,
reduce_vars: true,
+ side_effects: true,
+ switches: true,
unused: true,
}
input: {
@@ -1488,6 +1494,8 @@ issue_1670_4: {
dead_code: true,
passes: 2,
reduce_vars: true,
+ side_effects: true,
+ switches: true,
unused: true,
}
input: {
@@ -1516,6 +1524,8 @@ issue_1670_5: {
evaluate: true,
keep_fargs: false,
reduce_vars: true,
+ side_effects: true,
+ switches: true,
unused: true,
}
input: {
@@ -1544,6 +1554,8 @@ issue_1670_6: {
evaluate: true,
keep_fargs: false,
reduce_vars: true,
+ side_effects: true,
+ switches: true,
unused: true,
}
input: {
diff --git a/test/compress/sequences.js b/test/compress/sequences.js
index f1fa0e87..b3c54635 100644
--- a/test/compress/sequences.js
+++ b/test/compress/sequences.js
@@ -440,3 +440,29 @@ func_def_5: {
}
expect_stdout: "true"
}
+
+issue_1758: {
+ options = {
+ sequences: true,
+ side_effects: true,
+ }
+ input: {
+ console.log(function(c) {
+ var undefined = 42;
+ return function() {
+ c--;
+ c--, c.toString();
+ return;
+ }();
+ }());
+ }
+ expect: {
+ console.log(function(c) {
+ var undefined = 42;
+ return function() {
+ return c--, c--, c.toString(), void 0;
+ }();
+ }());
+ }
+ expect_stdout: "undefined"
+}
diff --git a/test/compress/switch.js b/test/compress/switch.js
index 82d725f2..03c1e00a 100644
--- a/test/compress/switch.js
+++ b/test/compress/switch.js
@@ -1,5 +1,10 @@
constant_switch_1: {
- options = { dead_code: true, evaluate: true };
+ options = {
+ dead_code: true,
+ evaluate: true,
+ side_effects: true,
+ switches: true,
+ }
input: {
switch (1+1) {
case 1: foo(); break;
@@ -13,7 +18,12 @@ constant_switch_1: {
}
constant_switch_2: {
- options = { dead_code: true, evaluate: true };
+ options = {
+ dead_code: true,
+ evaluate: true,
+ side_effects: true,
+ switches: true,
+ }
input: {
switch (1) {
case 1: foo();
@@ -28,7 +38,12 @@ constant_switch_2: {
}
constant_switch_3: {
- options = { dead_code: true, evaluate: true };
+ options = {
+ dead_code: true,
+ evaluate: true,
+ side_effects: true,
+ switches: true,
+ }
input: {
switch (10) {
case 1: foo();
@@ -44,7 +59,12 @@ constant_switch_3: {
}
constant_switch_4: {
- options = { dead_code: true, evaluate: true };
+ options = {
+ dead_code: true,
+ evaluate: true,
+ side_effects: true,
+ switches: true,
+ }
input: {
switch (2) {
case 1:
@@ -65,7 +85,12 @@ constant_switch_4: {
}
constant_switch_5: {
- options = { dead_code: true, evaluate: true };
+ options = {
+ dead_code: true,
+ evaluate: true,
+ side_effects: true,
+ switches: true,
+ }
input: {
switch (1) {
case 1:
@@ -94,7 +119,12 @@ constant_switch_5: {
}
constant_switch_6: {
- options = { dead_code: true, evaluate: true };
+ options = {
+ dead_code: true,
+ evaluate: true,
+ side_effects: true,
+ switches: true,
+ }
input: {
OUT: {
foo();
@@ -123,7 +153,12 @@ constant_switch_6: {
}
constant_switch_7: {
- options = { dead_code: true, evaluate: true };
+ options = {
+ dead_code: true,
+ evaluate: true,
+ side_effects: true,
+ switches: true,
+ }
input: {
OUT: {
foo();
@@ -161,7 +196,12 @@ constant_switch_7: {
}
constant_switch_8: {
- options = { dead_code: true, evaluate: true };
+ options = {
+ dead_code: true,
+ evaluate: true,
+ side_effects: true,
+ switches: true,
+ }
input: {
OUT: switch (1) {
case 1:
@@ -185,7 +225,12 @@ constant_switch_8: {
}
constant_switch_9: {
- options = { dead_code: true, evaluate: true };
+ options = {
+ dead_code: true,
+ evaluate: true,
+ side_effects: true,
+ switches: true,
+ }
input: {
OUT: switch (1) {
case 1:
@@ -210,7 +255,10 @@ constant_switch_9: {
}
drop_default_1: {
- options = { dead_code: true };
+ options = {
+ dead_code: true,
+ switches: true,
+ }
input: {
switch (foo) {
case 'bar': baz();
@@ -225,7 +273,10 @@ drop_default_1: {
}
drop_default_2: {
- options = { dead_code: true };
+ options = {
+ dead_code: true,
+ switches: true,
+ }
input: {
switch (foo) {
case 'bar': baz(); break;
@@ -241,7 +292,10 @@ drop_default_2: {
}
keep_default: {
- options = { dead_code: true };
+ options = {
+ dead_code: true,
+ switches: true,
+ }
input: {
switch (foo) {
case 'bar': baz();
@@ -263,6 +317,8 @@ issue_1663: {
options = {
dead_code: true,
evaluate: true,
+ side_effects: true,
+ switches: true,
}
input: {
var a = 100, b = 10;
@@ -294,6 +350,7 @@ issue_1663: {
drop_case: {
options = {
dead_code: true,
+ switches: true,
}
input: {
switch (foo) {
@@ -312,6 +369,7 @@ drop_case: {
keep_case: {
options = {
dead_code: true,
+ switches: true,
}
input: {
switch (foo) {
@@ -332,6 +390,7 @@ issue_376: {
options = {
dead_code: true,
evaluate: true,
+ switches: true,
}
input: {
switch (true) {
@@ -354,6 +413,7 @@ issue_376: {
issue_441_1: {
options = {
dead_code: true,
+ switches: true,
}
input: {
switch (foo) {
@@ -381,6 +441,7 @@ issue_441_1: {
issue_441_2: {
options = {
dead_code: true,
+ switches: true,
}
input: {
switch (foo) {
@@ -414,6 +475,8 @@ issue_1674: {
options = {
dead_code: true,
evaluate: true,
+ side_effects: true,
+ switches: true,
}
input: {
switch (0) {
@@ -435,6 +498,7 @@ issue_1679: {
options = {
dead_code: true,
evaluate: true,
+ switches: true,
}
input: {
var a = 100, b = 10;
@@ -482,6 +546,7 @@ issue_1680_1: {
options = {
dead_code: true,
evaluate: true,
+ switches: true,
}
input: {
function f(x) {
@@ -522,6 +587,7 @@ issue_1680_1: {
issue_1680_2: {
options = {
dead_code: true,
+ switches: true,
}
input: {
var a = 100, b = 10;
@@ -557,6 +623,7 @@ issue_1680_2: {
issue_1690_1: {
options = {
dead_code: true,
+ switches: true,
}
input: {
switch (console.log("PASS")) {}
@@ -570,6 +637,7 @@ issue_1690_1: {
issue_1690_2: {
options = {
dead_code: false,
+ switches: true,
}
input: {
switch (console.log("PASS")) {}
@@ -585,6 +653,7 @@ if_switch_typeof: {
conditionals: true,
dead_code: true,
side_effects: true,
+ switches: true,
}
input: {
if (a) switch(typeof b) {}
@@ -597,6 +666,7 @@ if_switch_typeof: {
issue_1698: {
options = {
side_effects: true,
+ switches: true,
}
input: {
var a = 1;
@@ -618,6 +688,7 @@ issue_1698: {
issue_1705_1: {
options = {
dead_code: true,
+ switches: true,
}
input: {
var a = 0;
@@ -646,6 +717,7 @@ issue_1705_2: {
reduce_vars: true,
sequences: true,
side_effects: true,
+ switches: true,
toplevel: true,
unused: true,
}
@@ -666,6 +738,7 @@ issue_1705_2: {
issue_1705_3: {
options = {
dead_code: true,
+ switches: true,
}
input: {
switch (a) {
@@ -721,3 +794,25 @@ beautify: {
"}",
]
}
+
+issue_1758: {
+ options = {
+ dead_code: true,
+ switches: true,
+ }
+ input: {
+ var a = 1, b = 2;
+ switch (a--) {
+ default:
+ b++;
+ }
+ console.log(a, b);
+ }
+ expect: {
+ var a = 1, b = 2;
+ a--;
+ b++;
+ console.log(a, b);
+ }
+ expect_stdout: "0 3"
+}