Skip to content

Commit

Permalink
fix corner case in hoist_vars (#4840)
Browse files Browse the repository at this point in the history
fixes #4839
  • Loading branch information
alexlamsl committed Apr 3, 2021
1 parent 10fbf8e commit 0df0281
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/compress.js
Expand Up @@ -6937,7 +6937,9 @@ merge(Compressor.prototype, {
&& vars.has(sym.name)) {
var def = vars.get(sym.name);
if (def.value) break;
def.value = expr.right.clone();
var value = expr.right;
if (value instanceof AST_Sequence) value = value.clone();
def.value = value;
remove(defs, def);
defs.push(def);
body.shift();
Expand Down
27 changes: 26 additions & 1 deletion test/compress/hoist_vars.js
Expand Up @@ -140,7 +140,6 @@ issue_4487: {
functions: true,
hoist_vars: true,
keep_fnames: true,
passes: 2,
reduce_vars: true,
toplevel: true,
unused: true,
Expand Down Expand Up @@ -240,3 +239,29 @@ issue_4736: {
}
expect_stdout: "1073741824"
}

issue_4839: {
options = {
evaluate: true,
hoist_vars: true,
keep_fargs: false,
reduce_vars: true,
toplevel: true,
unused: true,
}
input: {
var o = function(a, b) {
return b && b;
}("foo");
for (var k in o)
throw "FAIL";
console.log("PASS");
}
expect: {
var k, o = void 0;
for (k in o)
throw "FAIL";
console.log("PASS");
}
expect_stdout: "PASS"
}

0 comments on commit 0df0281

Please sign in to comment.