From 29a1e7170531320f37026013262193c7a91b1be6 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Thu, 23 Dec 2021 06:26:07 +0000 Subject: [PATCH] fix corner case in `inline` (#5231) fixes #5230 --- lib/compress.js | 4 +++- test/compress/functions.js | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/lib/compress.js b/lib/compress.js index 5a8f9ad5..b48d7bcf 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -10245,7 +10245,9 @@ Compressor.prototype.compress = function(node) { if (stat instanceof AST_LambdaDefinition) { if (in_loop) { var name = make_node(AST_SymbolVar, stat.name, flatten_var(stat.name)); - name.definition().orig.push(name); + var def = name.definition(); + def.fixed = false; + def.orig.push(name); append_var(decls, expressions, name, to_func_expr(stat, true)); } else { var def = stat.name.definition(); diff --git a/test/compress/functions.js b/test/compress/functions.js index e9c25474..02735195 100644 --- a/test/compress/functions.js +++ b/test/compress/functions.js @@ -7071,3 +7071,35 @@ issue_5173_2: { } expect_stdout: "undefined" } + +issue_5230: { + options = { + collapse_vars: true, + inline: true, + merge_vars: true, + reduce_vars: true, + side_effects: true, + toplevel: true, + } + input: { + while (function() { + function f(a) { + var b = 42, c = (console, [ a ]); + for (var k in c) + c, console.log(b++); + } + f(f); + }()); + } + expect: { + while (void (f = function(c) { + var b = 42; + console; + var c; + for (var k in c = [ c ]) + console.log(b++); + })(f)); + var f; + } + expect_stdout: "42" +}