fix corner case in `collapse_vars` (#3885)
authorAlex Lam S.L <alexlamsl@gmail.com>
Mon, 11 May 2020 20:01:14 +0000 (21:01 +0100)
committerGitHub <noreply@github.com>
Mon, 11 May 2020 20:01:14 +0000 (04:01 +0800)
fixes #3884

lib/compress.js
test/compress/collapse_vars.js

index cb5d9c7..415f9bd 100644 (file)
@@ -1243,6 +1243,7 @@ merge(Compressor.prototype, {
                         col: node.start.col
                     });
                     if (candidate instanceof AST_UnaryPostfix) {
+                        delete candidate.expression.fixed;
                         return make_node(AST_UnaryPrefix, candidate, candidate);
                     }
                     if (candidate instanceof AST_VarDef) {
index c93a146..ff0837a 100644 (file)
@@ -7954,3 +7954,28 @@ mangleable_var: {
     }
     expect_stdout: "PASS"
 }
+
+issue_3884: {
+    options = {
+        collapse_vars: true,
+        evaluate: true,
+        reduce_vars: true,
+        side_effects: true,
+        toplevel: true,
+        unused: true,
+    }
+    input: {
+        var a = 100, b = 1;
+        {
+            a++ + a || a;
+            b <<= a;
+        }
+        console.log(a, b);
+    }
+    expect: {
+        var a = 100;
+        ++a;
+        console.log(a, 32);
+    }
+    expect_stdout: "101 32"
+}