diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-04-18 16:12:20 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-18 23:12:20 +0800 |
commit | 2a508c6e5f1e69e78d84480b5fc3db2f8087c166 (patch) | |
tree | f4c80e34a02e28b4d06dcccb467f0c19dbbb04d3 /lib | |
parent | fd6144d95baebb9eaa75b5695bd75a492479c691 (diff) | |
download | tracifyjs-2a508c6e5f1e69e78d84480b5fc3db2f8087c166.tar.gz tracifyjs-2a508c6e5f1e69e78d84480b5fc3db2f8087c166.zip |
enhance `collapse_vars` (#3799)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/compress.js | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/lib/compress.js b/lib/compress.js index 872e2bbf..9504241b 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1264,6 +1264,7 @@ merge(Compressor.prototype, { if (stat_index == 0 && compressor.option("unused")) extract_args(); // Find collapsible assignments var hit_stack = []; + var declare_only = Object.create(null); extract_candidates(statements[stat_index]); while (candidates.length > 0) { hit_stack = candidates.pop(); @@ -1574,6 +1575,8 @@ merge(Compressor.prototype, { candidates.push(hit_stack.slice()); } extract_candidates(expr.value); + } else { + declare_only[expr.name.name] = (declare_only[expr.name.name] || 0) + 1; } } hit_stack.pop(); @@ -1739,6 +1742,7 @@ merge(Compressor.prototype, { if (!member(expr.name, def.orig)) return; var referenced = def.references.length - def.replaced; var declared = def.orig.length - def.eliminated; + declared -= declare_only[def.name] || 0; if (declared > 1 && !(expr.name instanceof AST_SymbolFunarg)) { mangleable_var(expr.value); return make_node(AST_SymbolRef, expr.name, expr.name); |