From b483678ca7f5e539cef9c57324ecc92d65800f7d Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Mon, 15 Jan 2018 16:42:31 +0800 Subject: avoid suboptimal termination in `passes` (#2787) --- lib/compress.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index 7e3503fe..a461cb06 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -171,7 +171,8 @@ merge(Compressor.prototype, { node.process_expression(true); } var passes = +this.options.passes || 1; - var last_count = 1 / 0; + var min_count = 1 / 0; + var stopping = false; var mangle = { ie8: this.option("ie8") }; for (var pass = 0; pass < passes; pass++) { node.figure_out_scope(mangle); @@ -183,9 +184,15 @@ merge(Compressor.prototype, { node.walk(new TreeWalker(function() { count++; })); - this.info("pass " + pass + ": last_count: " + last_count + ", count: " + count); - if (count >= last_count) break; - last_count = count; + this.info("pass " + pass + ": last_count: " + min_count + ", count: " + count); + if (count < min_count) { + min_count = count; + stopping = false; + } else if (stopping) { + break; + } else { + stopping = true; + } } } if (this.option("expression")) { -- cgit v1.2.3