diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2021-01-23 23:05:43 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-24 07:05:43 +0800 |
commit | ef9f7ca3e7c7f71df440645f782b3a7da4646d9b (patch) | |
tree | 996eae678d702ea98aadc03366219dd5ea60a585 | |
parent | acc443b2cf0614351aeb953e393260f13f783c96 (diff) | |
download | tracifyjs-ef9f7ca3e7c7f71df440645f782b3a7da4646d9b.tar.gz tracifyjs-ef9f7ca3e7c7f71df440645f782b3a7da4646d9b.zip |
fix corner case in `collapse_vars` (#4587)
fixes #4586
-rw-r--r-- | lib/compress.js | 2 | ||||
-rw-r--r-- | test/compress/collapse_vars.js | 45 |
2 files changed, 47 insertions, 0 deletions
diff --git a/lib/compress.js b/lib/compress.js index c6ebb34c..f4441775 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -2345,6 +2345,7 @@ merge(Compressor.prototype, { if (expr.operator == "=" && lhs instanceof AST_SymbolRef && (def = lhs.definition()).references[0] === lhs + && !(scope.uses_arguments && is_funarg(def)) && !compressor.exposed(def)) { var referenced = def.references.length - def.replaced; if (referenced > 1) mangleable_var(expr.right); @@ -2357,6 +2358,7 @@ merge(Compressor.prototype, { var def = expr.name.definition(); if (def.const_redefs) return; if (!member(expr.name, def.orig)) return; + if (scope.uses_arguments && is_funarg(def)) return; var declared = def.orig.length - def.eliminated - (declare_only[def.name] || 0); var referenced = def.references.length - def.replaced - (assignments[def.name] || 0); if (declared > 1 && !(expr.name instanceof AST_SymbolFunarg)) { diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js index 258df6f7..963906c5 100644 --- a/test/compress/collapse_vars.js +++ b/test/compress/collapse_vars.js @@ -8705,3 +8705,48 @@ collapse_or_assign: { } expect_stdout: "PASS" } + +issue_4586_1: { + options = { + collapse_vars: true, + } + input: { + var a = 42; + (function f(b) { + var b = a; + if (b === arguments[0]) + console.log("PASS"); + })(console); + } + expect: { + var a = 42; + (function f(b) { + var b = a; + if (b === arguments[0]) + console.log("PASS"); + })(console); + } + expect_stdout: "PASS" +} + +issue_4586_2: { + options = { + collapse_vars: true, + } + input: { + var a = 42; + (function f(b) { + b = a; + if (b === arguments[0]) + console.log("PASS"); + })(console); + } + expect: { + var a = 42; + (function f(b) { + if ((b = a) === arguments[0]) + console.log("PASS"); + })(console); + } + expect_stdout: "PASS" +} |