fix corner case in hoist_vars (#5196)

fixes #5195
This commit is contained in:
Alex Lam S.L
2021-11-24 20:49:38 +00:00
committed by GitHub
parent 0b6c185818
commit 1b4bd7082b
2 changed files with 64 additions and 11 deletions

View File

@@ -9102,6 +9102,7 @@ merge(Compressor.prototype, {
});
def.references.push(name);
}
def.assignments++;
def.eliminated++;
def.single_use = false;
return a;

View File

@@ -151,9 +151,9 @@ issue_4487_1: {
var b = a();
}
expect: {
function a() {
var a = function f() {
var f = console.log(typeof f);
}
};
a();
}
expect_stdout: "undefined"
@@ -175,6 +175,31 @@ issue_4487_2: {
};
var b = a();
}
expect: {
function a() {
var f = console.log(typeof f);
}
a();
}
expect_stdout: "undefined"
}
issue_4487_3: {
options = {
functions: true,
hoist_vars: true,
keep_fnames: true,
passes: 3,
reduce_vars: true,
toplevel: true,
unused: true,
}
input: {
var a = function f() {
var f = console.log(typeof f);
};
var b = a();
}
expect: {
(function a() {
console.log(typeof void 0);
@@ -256,9 +281,8 @@ issue_4736: {
expect: {
(function() {
(function() {
var b = 1 << 30;
0,
console.log(b);
console.log(1073741824);
})();
})();
}
@@ -275,18 +299,18 @@ issue_4839: {
unused: true,
}
input: {
var o = function(a, b) {
var log = console.log, o = function(a, b) {
return b && b;
}("foo");
for (var k in o)
throw "FAIL";
console.log("PASS");
log("PASS");
}
expect: {
var k, o = void 0;
for (k in o)
var k, log = console.log;
for (k in void 0)
throw "FAIL";
console.log("PASS");
log("PASS");
}
expect_stdout: "PASS"
}
@@ -312,8 +336,7 @@ issue_4859: {
}
expect: {
(function f(a) {
var d = 1 / 0, d = Infinity;
console.log(d);
console.log(Infinity);
return f;
})();
}
@@ -448,3 +471,32 @@ issue_5187: {
}
expect_stdout: "42"
}
issue_5195: {
options = {
hoist_props: true,
hoist_vars: true,
reduce_vars: true,
side_effects: true,
toplevel: true,
unused: true,
}
input: {
function f() {
var a;
do {
var b = { p: a };
} while (console.log(b += ""));
}
f();
}
expect: {
(function() {
var a, b;
do {
b = { p: a };
} while (console.log(b += ""));
})();
}
expect_stdout: "[object Object]"
}