fix corner case in `dead_code` (#4571)
authorAlex Lam S.L <alexlamsl@gmail.com>
Tue, 19 Jan 2021 01:33:57 +0000 (01:33 +0000)
committerGitHub <noreply@github.com>
Tue, 19 Jan 2021 01:33:57 +0000 (09:33 +0800)
fixes #4570

lib/compress.js
test/compress/dead-code.js

index e33f4f3..21072f0 100644 (file)
@@ -9987,7 +9987,7 @@ merge(Compressor.prototype, {
                 var scope = def.scope.resolve();
                 var local = scope === compressor.find_parent(AST_Lambda);
                 var level = 0, node;
-                parent = self;
+                parent = compressor.self();
                 do {
                     node = parent;
                     parent = compressor.parent(level++);
index cfbc6fa..1720a0d 100644 (file)
@@ -1399,3 +1399,21 @@ issue_4366: {
     expect_stdout: "PASS"
     node_version: ">=4"
 }
+
+issue_4570: {
+    options = {
+        dead_code: true,
+        inline: true,
+    }
+    input: {
+        var a = function(b) {
+            return a += b;
+        }() ? 0 : a;
+        console.log(a);
+    }
+    expect: {
+        var a = (a += void 0) ? 0 : a;
+        console.log(a);
+    }
+    expect_stdout: "NaN"
+}