From de376c3d3316fc4a33a876793eb4d693422415a0 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Fri, 21 May 2021 11:49:07 +0100 Subject: [PATCH] fix corner case in `reduce_vars` (#4950) fixes #4949 --- lib/compress.js | 9 ++++++--- test/compress/reduce_vars.js | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index 8975f47b..4f50f52a 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -580,9 +580,12 @@ merge(Compressor.prototype, { } function safe_to_assign(tw, def, declare) { - if (!(declare || all(def.orig, function(sym) { - return !(sym instanceof AST_SymbolConst); - }))) return false; + if (!declare) { + if (is_funarg(def) && def.scope.uses_arguments && !tw.has_directive("use strict")) return false; + if (!all(def.orig, function(sym) { + return !(sym instanceof AST_SymbolConst); + })) return false; + } if (def.fixed === undefined) return declare || all(def.orig, function(sym) { return !(sym instanceof AST_SymbolLet); }); diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js index 04d96b51..33d59982 100644 --- a/test/compress/reduce_vars.js +++ b/test/compress/reduce_vars.js @@ -7722,3 +7722,23 @@ issue_4943_2: { "bar", ] } + +issue_4949: { + options = { + reduce_vars: true, + unused: true, + } + input: { + (function f(a) { + a = 0; + console.log(a++, arguments[0]); + })(0); + } + expect: { + (function(a) { + a = 0; + console.log(a++, arguments[0]); + })(0); + } + expect_stdout: "0 1" +}