fix corner case in switches (#3585)

This commit is contained in:
Alex Lam S.L
2019-11-14 02:29:55 +08:00
committed by GitHub
parent 4bd36dc8da
commit 910799ca99
2 changed files with 100 additions and 60 deletions

View File

@@ -393,6 +393,57 @@ drop_case_2: {
}
}
drop_case_3: {
options = {
dead_code: true,
switches: true,
}
input: {
var c = "PASS";
switch ({}.p) {
default:
case void 0:
break;
case c = "FAIL":
}
console.log(c);
}
expect: {
var c = "PASS";
switch ({}.p) {
default:
case void 0:
break;
case c = "FAIL":
}
console.log(c);
}
expect_stdout: "PASS"
}
drop_case_4: {
options = {
dead_code: true,
switches: true,
}
input: {
switch (0) {
case [ a, typeof b ]:
default:
var a;
}
console.log("PASS");
}
expect: {
switch (0) {
case [ a, typeof b ]:
var a;
}
console.log("PASS");
}
expect_stdout: "PASS"
}
keep_case: {
options = {
dead_code: true,
@@ -521,7 +572,7 @@ issue_1674: {
expect_stdout: "PASS"
}
issue_1679_1: {
issue_1679: {
options = {
dead_code: true,
evaluate: true,
@@ -548,34 +599,6 @@ issue_1679_1: {
console.log(a, b);
}
expect: {
var a = 100, b = 10;
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) {
@@ -589,23 +612,6 @@ issue_1679_2: {
}
break;
case (a++):
break;
}
}
f();
console.log(a, b);
}
expect: {
var a = 100, b = 10;
function f() {
switch (--b) {
case b--:
switch (0) {
default:
case a--:
}
break;
case (a++):
}
}
f();
@@ -998,3 +1004,27 @@ drop_switch_3: {
}
expect_stdout: "PASS"
}
drop_switch_4: {
options = {
dead_code: true,
switches: true,
}
input: {
var a = "FAIL";
switch (0) {
default:
case a:
var b = a = "PASS";
break;
}
console.log(a);
}
expect: {
var a = "FAIL";
0;
var b = a = "PASS";
console.log(a);
}
expect_stdout: "PASS"
}