diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-12-18 15:45:41 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-18 23:45:41 +0800 |
commit | 2415a72e755c7685c677c2edf0c1e91fbed54e2e (patch) | |
tree | e2db6adc5ada76c61326b6a6f43ca47b1ae9f7b3 | |
parent | 9c0718b162e537ee6ad1dd5c7af6fbf5fcb6ae1d (diff) | |
download | tracifyjs-2415a72e755c7685c677c2edf0c1e91fbed54e2e.tar.gz tracifyjs-2415a72e755c7685c677c2edf0c1e91fbed54e2e.zip |
fix corner case in `unused` (#4405)
fixes #4404
-rw-r--r-- | lib/compress.js | 10 | ||||
-rw-r--r-- | test/compress/drop-unused.js | 22 |
2 files changed, 31 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js index a3842bed..1249e620 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -5860,7 +5860,15 @@ merge(Compressor.prototype, { if (def.scope === self) assignments.add(def.id, node); } var node_def, props = [], sym = assign_as_unused(node, props); - if (sym && self.variables.get(sym.name) === (node_def = sym.definition())) { + if (sym && self.variables.get(sym.name) === (node_def = sym.definition()) + && !(is_arguments(node_def) && !all(self.argnames, function(argname) { + return !argname.match_symbol(function(node) { + if (node instanceof AST_SymbolFunarg) { + var def = node.definition(); + return def.references.length > def.replaced; + } + }, true); + }))) { props.forEach(function(prop) { prop.walk(tw); }); diff --git a/test/compress/drop-unused.js b/test/compress/drop-unused.js index 4448bdd8..1c9ab61f 100644 --- a/test/compress/drop-unused.js +++ b/test/compress/drop-unused.js @@ -3112,3 +3112,25 @@ issue_4235: { } expect_stdout: "undefined" } + +issue_4404: { + options = { + pure_getters: "strict", + unused: true, + } + input: { + function f(a) { + arguments[0] = "PASS"; + console.log(a); + } + f("FAIL"); + } + expect: { + function f(a) { + arguments[0] = "PASS"; + console.log(a); + } + f("FAIL"); + } + expect_stdout: "PASS" +} |