fix AST corruption due to `collapse_vars` & `inline` (#2899)
authorAlex Lam S.L <alexlamsl@gmail.com>
Thu, 8 Feb 2018 22:54:37 +0000 (06:54 +0800)
committerGitHub <noreply@github.com>
Thu, 8 Feb 2018 22:54:37 +0000 (06:54 +0800)
fixes #2898

lib/compress.js
test/compress/functions.js

index e70af43..282ab78 100644 (file)
@@ -4379,6 +4379,7 @@ merge(Compressor.prototype, {
                 && !self.pure
                 && !fn.contains_this()
                 && can_inject_symbols()) {
+                fn._squeezed = true;
                 return make_sequence(self, flatten_fn()).optimize(compressor);
             }
             if (compressor.option("side_effects") && all(fn.body, is_empty)) {
index 8732882..a964f10 100644 (file)
@@ -1989,3 +1989,33 @@ issue_2783: {
     }
     expect_stdout: "PASS"
 }
+
+issue_2898: {
+    options = {
+        collapse_vars: true,
+        inline: true,
+        reduce_vars: true,
+        sequences: true,
+        unused: true,
+    }
+    input: {
+        var c = 0;
+        (function() {
+            while (f());
+            function f() {
+                var b = (c = 1 + c, void (c = 1 + c));
+                b && b[0];
+            }
+        })();
+        console.log(c);
+    }
+    expect: {
+        var c = 0;
+        (function() {
+            while (b = void 0, void ((b = void (c = 1 + (c = 1 + c))) && b[0]));
+            var b;
+        })(),
+        console.log(c);
+    }
+    expect_stdout: "2"
+}