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.references.push(name);
} }
def.assignments++;
def.eliminated++; def.eliminated++;
def.single_use = false; def.single_use = false;
return a; return a;

View File

@@ -151,9 +151,9 @@ issue_4487_1: {
var b = a(); var b = a();
} }
expect: { expect: {
function a() { var a = function f() {
var f = console.log(typeof f); var f = console.log(typeof f);
} };
a(); a();
} }
expect_stdout: "undefined" expect_stdout: "undefined"
@@ -175,6 +175,31 @@ issue_4487_2: {
}; };
var b = a(); 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: { expect: {
(function a() { (function a() {
console.log(typeof void 0); console.log(typeof void 0);
@@ -256,9 +281,8 @@ issue_4736: {
expect: { expect: {
(function() { (function() {
(function() { (function() {
var b = 1 << 30;
0, 0,
console.log(b); console.log(1073741824);
})(); })();
})(); })();
} }
@@ -275,18 +299,18 @@ issue_4839: {
unused: true, unused: true,
} }
input: { input: {
var o = function(a, b) { var log = console.log, o = function(a, b) {
return b && b; return b && b;
}("foo"); }("foo");
for (var k in o) for (var k in o)
throw "FAIL"; throw "FAIL";
console.log("PASS"); log("PASS");
} }
expect: { expect: {
var k, o = void 0; var k, log = console.log;
for (k in o) for (k in void 0)
throw "FAIL"; throw "FAIL";
console.log("PASS"); log("PASS");
} }
expect_stdout: "PASS" expect_stdout: "PASS"
} }
@@ -312,8 +336,7 @@ issue_4859: {
} }
expect: { expect: {
(function f(a) { (function f(a) {
var d = 1 / 0, d = Infinity; console.log(Infinity);
console.log(d);
return f; return f;
})(); })();
} }
@@ -448,3 +471,32 @@ issue_5187: {
} }
expect_stdout: "42" 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]"
}