diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2021-05-21 11:49:07 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-21 18:49:07 +0800 |
commit | de376c3d3316fc4a33a876793eb4d693422415a0 (patch) | |
tree | ef923654b91daf8ead2baeaaa1a547d8edc9a9e7 | |
parent | 4a19575e74beaf4c934581623c3372d084ebfeb7 (diff) | |
download | tracifyjs-de376c3d3316fc4a33a876793eb4d693422415a0.tar.gz tracifyjs-de376c3d3316fc4a33a876793eb4d693422415a0.zip |
fix corner case in `reduce_vars` (#4950)
fixes #4949
-rw-r--r-- | lib/compress.js | 9 | ||||
-rw-r--r-- | 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" +} |