Skip to content

Commit

Permalink
fix corner case in reduce_vars (#4950)
Browse files Browse the repository at this point in the history
fixes #4949
  • Loading branch information
alexlamsl committed May 21, 2021
1 parent 4a19575 commit de376c3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
20 changes: 20 additions & 0 deletions test/compress/reduce_vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit de376c3

Please sign in to comment.