fix corner case in hoist_vars (#5627)

fixes #5626
This commit is contained in:
Alex Lam S.L
2022-08-23 17:19:47 +01:00
committed by GitHub
parent 4653e8aec0
commit 4db81065ee
6 changed files with 119 additions and 65 deletions

View File

@@ -668,6 +668,8 @@ drop_fargs: {
hoist_vars: {
options = {
hoist_vars: true,
join_vars: true,
unused: true,
}
input: {
var a = "PASS";
@@ -675,8 +677,7 @@ hoist_vars: {
console.log(a, b);
}
expect: {
var a = "PASS";
var [ b = 42 ] = [];
var a = "PASS", [ b = 42 ] = [];
console.log(a, b);
}
expect_stdout: "PASS 42"
@@ -3035,7 +3036,8 @@ issue_5566_5: {
(function(a, f = function() {
return a;
}) {
var b, a = "foo";
var a, b;
a = "foo";
console.log(a, f());
})("bar");
}

View File

@@ -1652,6 +1652,8 @@ fn_name_unused: {
hoist_vars: {
options = {
hoist_vars: true,
join_vars: true,
unused: true,
}
input: {
var a = "PASS";
@@ -1659,8 +1661,7 @@ hoist_vars: {
console.log(a, b);
}
expect: {
var a = "PASS";
var [ b ] = [ 42 ];
var a = "PASS", b = [ 42 ][0];
console.log(a, b);
}
expect_stdout: "PASS 42"

View File

@@ -2,6 +2,8 @@ statements: {
options = {
hoist_funs: false,
hoist_vars: true,
join_vars: true,
unused: true,
}
input: {
function f() {
@@ -25,6 +27,8 @@ statements_funs: {
options = {
hoist_funs: true,
hoist_vars: true,
join_vars: true,
unused: true,
}
input: {
function f() {
@@ -48,6 +52,8 @@ sequences: {
options = {
hoist_funs: false,
hoist_vars: true,
join_vars: true,
unused: true,
}
input: {
function f() {
@@ -71,6 +77,8 @@ sequences_funs: {
options = {
hoist_funs: true,
hoist_vars: true,
join_vars: true,
unused: true,
}
input: {
function f() {
@@ -108,7 +116,8 @@ catch_var: {
console.log(a);
}
expect: {
var a = "PASS";
a = "PASS";
var a;
console.log(a);
}
expect_stdout: "PASS"
@@ -118,6 +127,8 @@ issue_2295: {
options = {
collapse_vars: true,
hoist_vars: true,
join_vars: true,
unused: true,
}
input: {
function foo(o) {
@@ -139,6 +150,7 @@ issue_4487_1: {
options = {
functions: true,
hoist_vars: true,
join_vars: true,
keep_fnames: true,
reduce_vars: true,
toplevel: true,
@@ -163,6 +175,7 @@ issue_4487_2: {
options = {
functions: true,
hoist_vars: true,
join_vars: true,
keep_fnames: true,
passes: 2,
reduce_vars: true,
@@ -188,6 +201,7 @@ issue_4487_3: {
options = {
functions: true,
hoist_vars: true,
join_vars: true,
keep_fnames: true,
passes: 3,
reduce_vars: true,
@@ -248,8 +262,7 @@ issue_4517: {
}
expect: {
console.log(function() {
var a = 2;
return (A = a) + typeof !1;
return (A = 2) + typeof !1;
}());
}
expect_stdout: "2boolean"
@@ -260,6 +273,7 @@ issue_4736: {
collapse_vars: true,
evaluate: true,
hoist_vars: true,
join_vars: true,
merge_vars: true,
reduce_vars: true,
toplevel: true,
@@ -279,7 +293,7 @@ issue_4736: {
expect: {
(function() {
(function() {
0,
0;
console.log(1 << 30);
})();
})();
@@ -291,6 +305,7 @@ issue_4839: {
options = {
evaluate: true,
hoist_vars: true,
join_vars: true,
keep_fargs: false,
reduce_vars: true,
toplevel: true,
@@ -317,6 +332,7 @@ issue_4859: {
options = {
evaluate: true,
hoist_vars: true,
join_vars: true,
keep_infinity: true,
merge_vars: true,
reduce_vars: true,
@@ -441,7 +457,7 @@ issue_4898: {
expect_stdout: "PASS"
}
issue_5187: {
issue_5187_1: {
options = {
hoist_props: true,
hoist_vars: true,
@@ -459,6 +475,37 @@ issue_5187: {
}
f();
}
expect: {
(function() {
var a, b;
a = 42;
do {
b = { 0: a++ };
} while (console.log(b[b ^= 0]));
})();
}
expect_stdout: "42"
}
issue_5187_2: {
options = {
hoist_props: true,
hoist_vars: true,
join_vars: true,
reduce_vars: true,
side_effects: true,
toplevel: true,
unused: true,
}
input: {
function f() {
var a = 42;
do {
var b = { 0: a++ };
} while (console.log(b[b ^= 0]));
}
f();
}
expect: {
(function() {
var b, a = 42;
@@ -547,9 +594,9 @@ issue_5411_1: {
console.log(b);
}
expect: {
var b, c, a = "PASS";
var a, b, c;
b++;
b = a;
b = a = "PASS";
c = c && c[b];
console.log(b);
}
@@ -596,6 +643,30 @@ issue_5411_3: {
var a = A = a;
console.log(A);
}
expect: {
var a;
a = console;
a = A = ++a;
console.log(A);
}
expect_stdout: "NaN"
}
issue_5411_4: {
options = {
collapse_vars: true,
hoist_vars: true,
join_vars: true,
reduce_vars: true,
toplevel: true,
unused: true,
}
input: {
var a = console;
a++;
var a = A = a;
console.log(A);
}
expect: {
var a = console;
a = A = ++a;
@@ -603,3 +674,30 @@ issue_5411_3: {
}
expect_stdout: "NaN"
}
issue_5626: {
options = {
conditionals: true,
evaluate: true,
hoist_vars: true,
reduce_vars: true,
side_effects: true,
toplevel: true,
unused: true,
}
input: {
var a = function() {
return console.log(arguments[0]), 42;
}("PASS") ? null : "foo";
for (var b in a)
FAIL;
}
expect: {
(function() {
console.log(arguments[0]);
}("PASS"));
for (var b in null)
FAIL;
}
expect_stdout: "PASS"
}

View File

@@ -1,17 +1,18 @@
keep_var_for_in: {
options = {
hoist_vars: true,
join_vars: true,
unused: true,
}
input: {
(function(obj){
(function(obj) {
var foo = 5;
for (var i in obj)
return foo;
})();
}
expect: {
(function(obj){
(function(obj) {
var i, foo = 5;
for (i in obj)
return foo;

View File

@@ -1540,10 +1540,12 @@ this_toString: {
issue_4803: {
options = {
hoist_vars: true,
join_vars: true,
pure_getters: "strict",
reduce_vars: true,
side_effects: true,
toplevel: true,
unused: true,
}
input: {
var o = {