improve fix for #3976 (#3980)
authorAlex Lam S.L <alexlamsl@gmail.com>
Tue, 9 Jun 2020 16:00:57 +0000 (17:00 +0100)
committerGitHub <noreply@github.com>
Tue, 9 Jun 2020 16:00:57 +0000 (00:00 +0800)
bin/uglifyjs
lib/compress.js

index fcbdff6..da2528d 100755 (executable)
@@ -112,7 +112,7 @@ function process_option(name, no_value) {
                 "  --verbose                                Print diagnostic messages.",
                 "  --warn                                   Print warning messages.",
                 "  --wrap <name>                            Embed everything as a function with “exports” corresponding to “name” globally.",
-                "  --reduce-test                            Reduce a standalone test case.",
+                "  --reduce-test                            Reduce a standalone test case (assumes cloned repository).",
             ].join("\n"));
         }
         process.exit();
@@ -303,7 +303,7 @@ function run() {
     }
     var result;
     if (specified["reduce-test"]) {
-        // load on demand - assumes dev tree checked out
+        // load on demand - assumes cloned repository
         var reduce_test = require("../test/reduce");
         if (Object.keys(files).length != 1) fatal("can only test on a single file");
         result = reduce_test(files[Object.keys(files)[0]], options, {
index cfbafbe..5564528 100644 (file)
@@ -1466,12 +1466,13 @@ merge(Compressor.prototype, {
             function is_last_node(node, parent) {
                 if (node.TYPE == "Binary") return node.operator == "in" && !is_object(node.right.tail_node());
                 if (node instanceof AST_Call) {
-                    var fn = node.expression;
+                    var def, fn = node.expression;
                     if (fn instanceof AST_SymbolRef) {
-                        if (recursive_ref(compressor, fn.definition())) return true;
+                        def = fn.definition();
                         fn = fn.fixed_value();
                     }
                     if (!(fn instanceof AST_Lambda)) return true;
+                    if (def && recursive_ref(compressor, def)) return true;
                     if (fn.collapse_scanning) return false;
                     fn.collapse_scanning = true;
                     var replace = can_replace;
@@ -7572,13 +7573,10 @@ merge(Compressor.prototype, {
     });
 
     function recursive_ref(compressor, def) {
-        var node;
-        for (var i = 0; node = compressor.parent(i); i++) {
-            if (node instanceof AST_Lambda) {
-                var name = node.name;
-                if (name && name.definition() === def) break;
-            }
-        }
+        var level = 0, node = compressor.self();
+        do {
+            if (node instanceof AST_Lambda && node.name && node.name.definition() === def) break;
+        } while (node = compressor.parent(level++));
         return node;
     }