diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-04-18 03:06:20 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-18 10:06:20 +0800 |
commit | dac9e69f9efb491c274670f36301fd38b0ef4dd6 (patch) | |
tree | 57af957b1fb01a25cc05f61dac0cc4bc9a3bfd2c /lib | |
parent | 39aa33749b24031e88a794481abfb4650700bc68 (diff) | |
download | tracifyjs-dac9e69f9efb491c274670f36301fd38b0ef4dd6.tar.gz tracifyjs-dac9e69f9efb491c274670f36301fd38b0ef4dd6.zip |
enhance `collapse_vars` (#3793)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/compress.js | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/lib/compress.js b/lib/compress.js index 70ac9b8f..d07c2412 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1307,12 +1307,10 @@ merge(Compressor.prototype, { if (candidate instanceof AST_Assign) referenced--; if (replaced && referenced == replaced) { abort = false; - } else if (candidate instanceof AST_Assign) { + } else { candidates.push(hit_stack); force_single = true; continue; - } else { - replaced = false; } if (replaced) { hit_index = 0; @@ -1320,6 +1318,9 @@ merge(Compressor.prototype, { for (var i = stat_index; !abort && i < statements.length; i++) { if (!statements[i].transform(multi_replacer)) statements.splice(i--, 1); } + if (candidate instanceof AST_VarDef) { + replaced = !compressor.exposed(def) && def.references.length == def.replaced; + } value_def.single_use = false; } } @@ -1738,8 +1739,11 @@ merge(Compressor.prototype, { if (!member(expr.name, def.orig)) return; var referenced = def.references.length - def.replaced; var declared = def.orig.length - def.eliminated; - if (declared > 1 && !(expr.name instanceof AST_SymbolFunarg) - || (referenced > 1 ? mangleable_var(expr.value) : !compressor.exposed(def))) { + if (declared > 1 && !(expr.name instanceof AST_SymbolFunarg)) { + mangleable_var(expr.value); + return make_node(AST_SymbolRef, expr.name, expr.name); + } + if (referenced > 1 ? mangleable_var(expr.value) : !compressor.exposed(def)) { return make_node(AST_SymbolRef, expr.name, expr.name); } } else if (expr instanceof AST_Assign) { @@ -1863,6 +1867,7 @@ merge(Compressor.prototype, { found = true; if (node instanceof AST_VarDef) { node.value = null; + if (value_def) value_def.replaced++; return node; } return in_list ? List.skip : null; |