fix corner case in `merge_vars` (#5143)
authorAlex Lam S.L <alexlamsl@gmail.com>
Mon, 4 Oct 2021 16:42:46 +0000 (17:42 +0100)
committerGitHub <noreply@github.com>
Mon, 4 Oct 2021 16:42:46 +0000 (00:42 +0800)
fixes #5142

lib/compress.js
test/compress/classes.js

index 3c0bf53..0f567f5 100644 (file)
@@ -5694,7 +5694,7 @@ merge(Compressor.prototype, {
             if (node instanceof AST_Call) {
                 var exp = node.expression;
                 var tail = exp.tail_node();
-                if (!(tail instanceof AST_LambdaExpression)) {
+                if (!is_lambda(tail)) {
                     descend();
                     return mark_expression(exp);
                 }
index 5ed3002..2ac97b0 100644 (file)
@@ -2066,3 +2066,34 @@ issue_5082_2: {
     expect_stdout: "PASS"
     node_version: ">=12"
 }
+
+issue_5142: {
+    options = {
+        evaluate: true,
+        merge_vars: true,
+        reduce_vars: true,
+        toplevel: true,
+    }
+    input: {
+        var a = 0, b;
+        if (++a)
+            new class {
+                p = b = null;
+                constructor(c) {
+                    console.log(c ? "FAIL" : "PASS");
+                }
+            }(b, a);
+    }
+    expect: {
+        var a = 0, b;
+        if (++a)
+            new class {
+                p = b = null;
+                constructor(c) {
+                    console.log(c ? "FAIL" : "PASS");
+                }
+            }(b, 1);
+    }
+    expect_stdout: "PASS"
+    node_version: ">=12"
+}