Skip to content

Commit

Permalink
fix corner case in inline (#5289)
Browse files Browse the repository at this point in the history
fixes #5288
  • Loading branch information
alexlamsl committed Jan 12, 2022
1 parent 9a58270 commit f8602ac
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/compress.js
Expand Up @@ -10446,9 +10446,8 @@ Compressor.prototype.compress = function(node) {
append_var(decl_var, expr_var, name, value);
if (!in_loop) continue;
if (arg_used.has(name.name)) continue;
var def = fn.variables.get(name.name);
if (fn.functions.has(name.name) && def.orig.length == 1) continue;
var def = fn.variables.get(name.name);
var def = name.definition();
if (def.orig.length == 1 && fn.functions.has(name.name)) continue;
var sym = make_node(AST_SymbolRef, name, name);
def.references.push(sym);
expr_loop.push(make_node(AST_Assign, var_def, {
Expand Down Expand Up @@ -13094,8 +13093,8 @@ Compressor.prototype.compress = function(node) {
scope.variables.set(name, def);
def.single_use = false;
if (!in_loop) return;
if (fn.functions.has(name) && def.orig.length == 1) return;
if (def.references.length == def.replaced) return;
if (def.orig.length == 1 && fn.functions.has(name)) return;
if (!all(def.orig, function(sym) {
if (sym instanceof AST_SymbolConst) return false;
if (sym instanceof AST_SymbolFunarg) return def.scope.resolve() !== fn;
Expand Down
25 changes: 25 additions & 0 deletions test/compress/destructured.js
Expand Up @@ -3367,3 +3367,28 @@ issue_5189_2: {
expect_stdout: "PASS"
node_version: ">=6"
}

issue_5288: {
options = {
conditionals: true,
inline: true,
reduce_vars: true,
toplevel: true,
unused: true,
varify: true,
}
input: {
while (function([]) {}([ function f() {
if (console)
return console.log("PASS");
else {
let a = 0;
}
}() ]));
}
expect: {
while ([ [ console ? console.log("PASS") : 0 ] ], void 0);
}
expect_stdout: "PASS"
node_version: ">=6"
}

0 comments on commit f8602ac

Please sign in to comment.