fix corner cases in assignments, reduce_vars & unused (#3950)
fixes #3949 fixes #3951
This commit is contained in:
@@ -407,3 +407,57 @@ issue_3429_2: {
|
||||
}
|
||||
expect_stdout: "undefined"
|
||||
}
|
||||
|
||||
issue_3949_1: {
|
||||
options = {
|
||||
assignments: true,
|
||||
evaluate: true,
|
||||
reduce_vars: true,
|
||||
}
|
||||
input: {
|
||||
var a = 42;
|
||||
function f() {
|
||||
var b = a;
|
||||
b = b >> 2;
|
||||
return 100 + b;
|
||||
}
|
||||
console.log(f());
|
||||
}
|
||||
expect: {
|
||||
var a = 42;
|
||||
function f() {
|
||||
var b = a;
|
||||
b >>= 2;
|
||||
return 100 + b;
|
||||
}
|
||||
console.log(f());
|
||||
}
|
||||
expect_stdout: "110"
|
||||
}
|
||||
|
||||
issue_3949_2: {
|
||||
options = {
|
||||
assignments: true,
|
||||
evaluate: true,
|
||||
reduce_vars: true,
|
||||
}
|
||||
input: {
|
||||
var a = 42;
|
||||
function f() {
|
||||
var b = a;
|
||||
b = 5 & b;
|
||||
return 100 + b;
|
||||
}
|
||||
console.log(f());
|
||||
}
|
||||
expect: {
|
||||
var a = 42;
|
||||
function f() {
|
||||
var b = a;
|
||||
b &= 5;
|
||||
return 100 + b;
|
||||
}
|
||||
console.log(f());
|
||||
}
|
||||
expect_stdout: "100"
|
||||
}
|
||||
@@ -3001,6 +3001,7 @@ issue_2298: {
|
||||
expect: {
|
||||
!function() {
|
||||
(function() {
|
||||
0;
|
||||
try {
|
||||
!function(b) {
|
||||
(void 0)[1] = "foo";
|
||||
|
||||
@@ -2285,7 +2285,7 @@ issue_3598: {
|
||||
try {
|
||||
(function() {
|
||||
a = "PASS";
|
||||
var c = (void (c.p = 0))[!1];
|
||||
(void ((void 0).p = 0))[!1];
|
||||
})();
|
||||
} catch (e) {}
|
||||
console.log(a);
|
||||
@@ -2557,10 +2557,9 @@ issue_3899: {
|
||||
console.log(typeof a);
|
||||
}
|
||||
expect: {
|
||||
0;
|
||||
var a = function() {
|
||||
function a() {
|
||||
return 2;
|
||||
};
|
||||
}
|
||||
console.log(typeof a);
|
||||
}
|
||||
expect_stdout: "function"
|
||||
@@ -2625,3 +2624,31 @@ assign_if_assign_read: {
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_3951: {
|
||||
options = {
|
||||
pure_getters: "strict",
|
||||
reduce_vars: true,
|
||||
side_effects: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
var a = console.log("PASS");
|
||||
console.log(a);
|
||||
a = "0";
|
||||
console.log(a.p = 0);
|
||||
a && a;
|
||||
}
|
||||
expect: {
|
||||
var a = console.log("PASS");
|
||||
console.log(a);
|
||||
a = "0";
|
||||
console.log(a.p = 0);
|
||||
}
|
||||
expect_stdout: [
|
||||
"PASS",
|
||||
"undefined",
|
||||
"0",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1579,9 +1579,9 @@ issue_2968_1: {
|
||||
expect: {
|
||||
var c = "FAIL";
|
||||
(function() {
|
||||
b = -(a = 42),
|
||||
void ((a <<= 0) && (a[(c = "PASS", 0 >>> (b += 1))] = 0));
|
||||
var a, b;
|
||||
a = 42,
|
||||
void ((a <<= 0) && (a[(c = "PASS", 0)] = 0));
|
||||
var a;
|
||||
})();
|
||||
console.log(c);
|
||||
}
|
||||
@@ -2341,10 +2341,7 @@ issue_3878_1: {
|
||||
console.log(b ? "PASS" : "FAIL");
|
||||
}
|
||||
expect: {
|
||||
var b = function(a) {
|
||||
return (a = 0) == (a && this > (a += 0));
|
||||
}();
|
||||
console.log(b ? "PASS" : "FAIL");
|
||||
console.log(true ? "PASS" : "FAIL");
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
@@ -2435,12 +2432,11 @@ issue_3903: {
|
||||
console.log(d);
|
||||
}
|
||||
expect: {
|
||||
var a = "PASS";
|
||||
function f(b, c) {
|
||||
return console, c;
|
||||
}
|
||||
var d = f(f(), a = a);
|
||||
console.log(d);
|
||||
f(f(), "PASS");
|
||||
console.log("PASS");
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
@@ -2649,7 +2645,7 @@ issue_3933: {
|
||||
}
|
||||
expect: {
|
||||
(function(a, b) {
|
||||
1, (b ^= 1), console.log("PASS");
|
||||
1, 1, console.log("PASS");
|
||||
})();
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
|
||||
@@ -808,9 +808,9 @@ issue_3795: {
|
||||
}
|
||||
expect: {
|
||||
var a = "FAIL", d = function() {
|
||||
if (a = 42, d) return -1;
|
||||
if (void 0) return -1;
|
||||
a = "PASS";
|
||||
}();
|
||||
}(a = 42);
|
||||
console.log(a, d);
|
||||
}
|
||||
expect_stdout: "PASS undefined"
|
||||
|
||||
@@ -306,6 +306,7 @@ issue_2298: {
|
||||
expect: {
|
||||
!function() {
|
||||
(function() {
|
||||
0;
|
||||
try {
|
||||
!function() {
|
||||
(void 0)[1] = "foo";
|
||||
|
||||
@@ -1520,8 +1520,7 @@ func_inline: {
|
||||
}
|
||||
expect: {
|
||||
function f() {
|
||||
console.log(1 + h());
|
||||
var h;
|
||||
console.log(1 + (void 0)());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2671,8 +2670,8 @@ var_assign_6: {
|
||||
}
|
||||
expect: {
|
||||
!function() {
|
||||
var a = function(){}(a = 1);
|
||||
console.log(a);
|
||||
(function(){}());
|
||||
console.log(void 0);
|
||||
}();
|
||||
}
|
||||
expect_stdout: "undefined"
|
||||
@@ -7111,3 +7110,166 @@ issue_3922: {
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_3949_1: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
reduce_vars: true,
|
||||
}
|
||||
input: {
|
||||
(function f(a) {
|
||||
var a = void (a = 0, g);
|
||||
function g() {
|
||||
console.log(typeof a);
|
||||
}
|
||||
g();
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
(function f(a) {
|
||||
var a = void (a = 0, g);
|
||||
function g() {
|
||||
console.log(typeof a);
|
||||
}
|
||||
g();
|
||||
})();
|
||||
}
|
||||
expect_stdout: "undefined"
|
||||
}
|
||||
|
||||
issue_3949_2: {
|
||||
options = {
|
||||
reduce_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
(function f(a) {
|
||||
var a = void (a = 0, g);
|
||||
function g() {
|
||||
console.log(typeof a);
|
||||
}
|
||||
g();
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
(function(a) {
|
||||
a = void (a = 0, g);
|
||||
function g() {
|
||||
console.log(typeof a);
|
||||
}
|
||||
g();
|
||||
})();
|
||||
}
|
||||
expect_stdout: "undefined"
|
||||
}
|
||||
|
||||
issue_3949_3: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
reduce_vars: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
function f() {}
|
||||
for (var a, i = 3; 0 <= --i; ) {
|
||||
a = f;
|
||||
console.log(a === b);
|
||||
var b = a;
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
function f() {}
|
||||
for (var a, i = 3; 0 <= --i; ) {
|
||||
a = f;
|
||||
console.log(a === b);
|
||||
var b = a;
|
||||
}
|
||||
}
|
||||
expect_stdout: [
|
||||
"false",
|
||||
"true",
|
||||
"true",
|
||||
]
|
||||
}
|
||||
|
||||
issue_3949_4: {
|
||||
options = {
|
||||
reduce_vars: true,
|
||||
unused: true,
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
function f() {}
|
||||
for (var a, i = 3; 0 <= --i; ) {
|
||||
a = f;
|
||||
console.log(a === b);
|
||||
var b = a;
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
function f() {}
|
||||
for (var a, i = 3; 0 <= --i; ) {
|
||||
a = f;
|
||||
console.log(a === b);
|
||||
var b = a;
|
||||
}
|
||||
}
|
||||
expect_stdout: [
|
||||
"false",
|
||||
"true",
|
||||
"true",
|
||||
]
|
||||
}
|
||||
|
||||
local_assignment_lambda: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
reduce_vars: true,
|
||||
sequences: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
var a = "FAIL";
|
||||
function f() {
|
||||
a = "PASS";
|
||||
console.log(a);
|
||||
}
|
||||
f();
|
||||
f();
|
||||
}
|
||||
expect: {
|
||||
function f() {
|
||||
console.log("PASS");
|
||||
}
|
||||
f(),
|
||||
f();
|
||||
}
|
||||
expect_stdout: [
|
||||
"PASS",
|
||||
"PASS",
|
||||
]
|
||||
}
|
||||
|
||||
local_assignment_loop: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
reduce_vars: true,
|
||||
sequences: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
var a = "FAIL";
|
||||
do {
|
||||
a = "PASS";
|
||||
console.log(a);
|
||||
} while (!console);
|
||||
}
|
||||
expect: {
|
||||
do {
|
||||
console.log("PASS");
|
||||
} while (!console);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
@@ -97,9 +97,8 @@ issue_2233_2: {
|
||||
var RegExp;
|
||||
UndeclaredGlobal;
|
||||
function foo() {
|
||||
var Number;
|
||||
AnotherUndeclaredGlobal;
|
||||
Number.isNaN;
|
||||
(void 0).isNaN;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user