enhance merge_vars (#5194)

closes #5182
This commit is contained in:
Alex Lam S.L
2021-11-24 10:21:50 +00:00
committed by alexlamsl
parent bfd0ac7f4b
commit 0b6c185818
6 changed files with 75 additions and 11 deletions

View File

@@ -203,6 +203,7 @@ merge(Compressor.prototype, {
if (this.option("expression")) {
node.process_expression(true);
}
var merge_vars = this.options.merge_vars;
var passes = +this.options.passes || 1;
var min_count = 1 / 0;
var stopping = false;
@@ -211,6 +212,7 @@ merge(Compressor.prototype, {
node.figure_out_scope(mangle);
if (pass > 0 || this.option("reduce_vars"))
node.reset_opt_flags(this);
this.options.merge_vars = merge_vars && (stopping || pass == passes - 1);
node = node.transform(this);
if (passes > 1) {
var count = 0;
@@ -259,8 +261,8 @@ merge(Compressor.prototype, {
descend(node, this);
var opt = node.optimize(this);
if (is_scope && opt === node && !this.has_directive("use asm") && !opt.pinned()) {
opt.merge_variables(this);
opt.drop_unused(this);
if (opt.merge_variables(this)) opt.drop_unused(this);
descend(opt, this);
}
if (opt === node) opt._squeezed = true;
@@ -5994,6 +5996,7 @@ merge(Compressor.prototype, {
});
tw.directives = Object.create(compressor.directives);
self.walk(tw);
var changed = false;
var merged = Object.create(null);
while (first.length && last.length) {
var head = first.pop();
@@ -6037,10 +6040,12 @@ merge(Compressor.prototype, {
def.references = refs.concat(def.references);
def.fixed = tail.definition.fixed && def.fixed;
merged[id] = def;
changed = true;
break;
} while (last.length);
if (skipped.length) last = last.concat(skipped);
}
return changed;
function push() {
segment = Object.create(segment);