speed up `collapse_vars` (#3119)
authorAlex Lam S.L <alexlamsl@gmail.com>
Fri, 4 May 2018 10:38:13 +0000 (18:38 +0800)
committerGitHub <noreply@github.com>
Fri, 4 May 2018 10:38:13 +0000 (18:38 +0800)
lib/compress.js

index fec4b95..31747c9 100644 (file)
@@ -1062,9 +1062,11 @@ merge(Compressor.prototype, {
                     if (is_lhs(node, parent)) {
                         if (value_def) replaced++;
                         return node;
+                    } else {
+                        replaced++;
+                        if (value_def && candidate instanceof AST_VarDef) return node;
                     }
                     CHANGED = abort = true;
-                    replaced++;
                     compressor.info("Collapsing {name} [{file}:{line},{col}]", {
                         name: node.print_to_string(),
                         file: node.start.file,
@@ -1075,10 +1077,6 @@ merge(Compressor.prototype, {
                         return make_node(AST_UnaryPrefix, candidate, candidate);
                     }
                     if (candidate instanceof AST_VarDef) {
-                        if (value_def) {
-                            abort = false;
-                            return node;
-                        }
                         var def = candidate.name.definition();
                         if (def.references.length - def.replaced == 1 && !compressor.exposed(def)) {
                             def.replaced++;