diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-03-06 18:27:42 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-06 18:27:42 +0000 |
commit | 421bb7083a9300b09e1da191a1e574b2be3a339e (patch) | |
tree | 312d3ef7f2a1341f511d12524cb6dca931bbdea3 | |
parent | bdc8ef221802a4da600ff1cdca34e9cc5c5fafc2 (diff) | |
download | tracifyjs-421bb7083a9300b09e1da191a1e574b2be3a339e.tar.gz tracifyjs-421bb7083a9300b09e1da191a1e574b2be3a339e.zip |
fix corner case in `unused` (#3747)
fixes #3746
-rw-r--r-- | lib/compress.js | 16 | ||||
-rw-r--r-- | test/compress/drop-unused.js | 31 |
2 files changed, 41 insertions, 6 deletions
diff --git a/lib/compress.js b/lib/compress.js index 763aabd8..96229369 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -3916,14 +3916,18 @@ merge(Compressor.prototype, { } else if (node instanceof AST_Unary) { if (node.write_only) sym = node.expression; } - if (!/strict/.test(compressor.option("pure_getters"))) return sym instanceof AST_SymbolRef && sym; - while (sym instanceof AST_PropAccess && !sym.expression.may_throw_on_access(compressor)) { - if (sym instanceof AST_Sub) props.unshift(sym.property); - sym = sym.expression; + if (/strict/.test(compressor.option("pure_getters"))) { + while (sym instanceof AST_PropAccess && !sym.expression.may_throw_on_access(compressor)) { + if (sym instanceof AST_Sub) props.unshift(sym.property); + sym = sym.expression; + } } - return sym instanceof AST_SymbolRef && all(sym.definition().orig, function(sym) { + if (!(sym instanceof AST_SymbolRef)) return; + if (compressor.exposed(sym.definition())) return; + if (!all(sym.definition().orig, function(sym) { return !(sym instanceof AST_SymbolLambda); - }) && sym; + })) return; + return sym; }; var in_use = []; var in_use_ids = Object.create(null); // avoid expensive linear scans of in_use diff --git a/test/compress/drop-unused.js b/test/compress/drop-unused.js index 2d2f3d43..99ab7b40 100644 --- a/test/compress/drop-unused.js +++ b/test/compress/drop-unused.js @@ -2413,3 +2413,34 @@ issue_3673: { } expect_stdout: "PASS" } + +issue_3746: { + options = { + keep_fargs: "strict", + side_effects: true, + unused: true, + } + input: { + try { + A; + } catch (e) { + var e; + } + (function f(a) { + e = a; + })(); + console.log("PASS"); + } + expect: { + try { + A; + } catch (e) { + var e; + } + (function(a) { + e = a; + })(); + console.log("PASS"); + } + expect_stdout: "PASS" +} |