fix corner case in `reduce_vars` (#3867)
authorAlex Lam S.L <alexlamsl@gmail.com>
Sun, 10 May 2020 08:35:03 +0000 (09:35 +0100)
committerGitHub <noreply@github.com>
Sun, 10 May 2020 08:35:03 +0000 (16:35 +0800)
fixes #3866

lib/compress.js
test/compress/reduce_vars.js
test/ufuzz/index.js

index fb4836b..6e0d36a 100644 (file)
@@ -577,9 +577,10 @@ merge(Compressor.prototype, {
             sym.fixed = d.fixed = eq ? function() {
                 return node.right;
             } : function() {
-                return make_node(AST_Binary, node, {
+                var value = fixed instanceof AST_Node ? fixed : fixed();
+                return value && make_node(AST_Binary, node, {
                     operator: node.operator.slice(0, -1),
-                    left: fixed instanceof AST_Node ? fixed : fixed(),
+                    left: value,
                     right: node.right
                 });
             };
@@ -858,11 +859,12 @@ merge(Compressor.prototype, {
             var fixed = d.fixed;
             if (!fixed) return;
             exp.fixed = d.fixed = function() {
-                return make_node(AST_Binary, node, {
+                var value = fixed instanceof AST_Node ? fixed : fixed();
+                return value && make_node(AST_Binary, node, {
                     operator: node.operator.slice(0, -1),
                     left: make_node(AST_UnaryPrefix, node, {
                         operator: "+",
-                        expression: fixed instanceof AST_Node ? fixed : fixed()
+                        expression: value
                     }),
                     right: make_node(AST_Number, node, {
                         value: 1
index 67d473d..ec75e91 100644 (file)
@@ -7033,3 +7033,24 @@ issue_3844: {
     }
     expect_stdout: "undefined"
 }
+
+issue_3866: {
+    options = {
+        dead_code: true,
+        evaluate: true,
+        reduce_vars: true,
+    }
+    input: {
+        console.log(function() {
+            {
+                return "PASS";
+                var a = 0;
+            }
+            return --a;
+        }());
+    }
+    expect: {
+        console.log("PASS");
+    }
+    expect_stdout: "PASS"
+}
index 1a2163e..616378c 100644 (file)
@@ -1181,7 +1181,7 @@ for (var round = 1; round <= num_iterations; round++) {
                 }
             }
         } else {
-            uglify_code = uglify_code.error;
+            uglify_code = uglify_result = uglify_code.error;
             ok = sandbox.same_stdout(original_result, uglify_result);
         }
         if (verbose || (verbose_interval && !(round % INTERVAL_COUNT)) || !ok) log(options);