enhance reduce_vars (#5636)

This commit is contained in:
Alex Lam S.L
2022-08-30 09:00:43 +01:00
committed by GitHub
parent 15b608f74c
commit 10bc86ba10
7 changed files with 109 additions and 40 deletions

View File

@@ -9321,12 +9321,11 @@ issue_4874: {
})(a = 42);
}
expect: {
var a;
null;
(function(b) {
for (var c in a && a[console.log("PASS")])
for (var c in 42, 42[console.log("PASS")])
console;
})(a = 42);
})();
}
expect_stdout: "PASS"
}

View File

@@ -2505,7 +2505,7 @@ issue_5463: {
var a, b, b;
console.log("PASS") && (
b = a = void 0,
b = [a = FAIL] = a && a
b = [a = FAIL] = a
);
}
expect_stdout: "PASS"

View File

@@ -1878,7 +1878,7 @@ issue_2846: {
var c = function(a, b) {
a = 0;
b && b(a);
return a++;
return +a;
}();
console.log(c);
}
@@ -2976,14 +2976,12 @@ issue_4025: {
console.log(a, b, d);
}
expect: {
var c = 0;
try {
console.log(c);
console.log(0);
} finally {
var d = c + 1;
c = 0;
0;
}
console.log(1, 1, d);
console.log(1, 1, 1);
}
expect_stdout: [
"0",
@@ -3696,7 +3694,7 @@ issue_5224: {
(function() {
var a = "FAIL 1";
null;
a = console.log(a);
console.log(a);
})(function() {
console.log(1 / 0);
a;

View File

@@ -624,7 +624,7 @@ issue_5411_2: {
var b, c;
b++;
b = "PASS",
c = c && c[b];
c;
console.log(b);
}
expect_stdout: "PASS"

View File

@@ -1834,6 +1834,33 @@ switch_return_5: {
]
}
merged_references: {
options = {
if_return: true,
reduce_vars: true,
unused: true,
}
input: {
var a, b = "PASS";
console.log(function(c) {
if (c = b)
return a || c;
c = FAIL;
return a || c;
}());
}
expect: {
var a, b = "PASS";
console.log(function(c) {
if (c = b);
else
c = FAIL;
return a || c;
}());
}
expect_stdout: "PASS"
}
issue_5583: {
options = {
conditionals: true,

View File

@@ -2488,7 +2488,7 @@ side_effects_assign: {
console.log(a);
}
expect: {
var a = typeof void (a && a.in);
var a = "undefined";
console.log(a);
}
expect_stdout: "undefined"
@@ -2530,7 +2530,8 @@ pure_getters_2: {
var a = a && a.b;
}
expect: {
var a = a && a.b;
var a;
a && a.b;
}
}
@@ -5424,7 +5425,7 @@ issue_2774: {
get a() {
var b;
(b = true) && b.c;
b = void 0;
void 0;
}
}.a);
}