From c3190303737db4cb3380e6fba19ec1cd86c12124 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Mon, 21 Dec 2020 06:03:18 +0000 Subject: [PATCH] fix corner case in `reduce_vars` (#4433) fixes #4432 --- lib/compress.js | 12 +++++++++--- test/compress/arguments.js | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index d532300c..81fe8866 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -912,10 +912,16 @@ merge(Compressor.prototype, { init.walk(tw); if (init instanceof AST_Definitions) { init.definitions[0].name.match_symbol(function(node) { - if (node instanceof AST_SymbolDeclaration) node.definition().fixed = false; + if (node instanceof AST_SymbolDeclaration) { + var def = node.definition(); + def.assignments++; + def.fixed = false; + } }, true); - } else if (init instanceof AST_SymbolRef) { - init.definition().fixed = false; + } else if (init instanceof AST_SymbolRef && !init.is_immutable()) { + var def = init.definition(); + def.assignments++; + def.fixed = false; } this.body.walk(tw); pop(tw); diff --git a/test/compress/arguments.js b/test/compress/arguments.js index 39628b50..ddf5695b 100644 --- a/test/compress/arguments.js +++ b/test/compress/arguments.js @@ -942,3 +942,23 @@ issue_4410_3: { } expect_stdout: "PASS" } + +issue_4432: { + options = { + arguments: true, + reduce_vars: true, + } + input: { + console.log(function(a) { + for (a in { FAIL: 42 }); + return arguments[0]; + }() || "PASS"); + } + expect: { + console.log(function(a) { + for (a in { FAIL: 42 }); + return arguments[0]; + }() || "PASS"); + } + expect_stdout: "PASS" +} -- 2.34.1