Replace the correct node when replacing in `void` sequences
authorRichard van Velzen <rvanvelzen@experty.com>
Mon, 12 Jan 2015 16:09:34 +0000 (17:09 +0100)
committerRichard van Velzen <rvanvelzen@experty.com>
Mon, 12 Jan 2015 16:09:34 +0000 (17:09 +0100)
Close #611.

lib/compress.js
test/compress/issue-611.js [new file with mode: 0644]

index 1f1d4b5..72e4d92 100644 (file)
@@ -1937,7 +1937,7 @@ merge(Compressor.prototype, {
         if (self.cdr instanceof AST_UnaryPrefix
             && self.cdr.operator == "void"
             && !self.cdr.expression.has_side_effects(compressor)) {
-            self.cdr.operator = self.car;
+            self.cdr.expression = self.car;
             return self.cdr;
         }
         if (self.cdr instanceof AST_Undefined) {
diff --git a/test/compress/issue-611.js b/test/compress/issue-611.js
new file mode 100644 (file)
index 0000000..6f2c65d
--- /dev/null
@@ -0,0 +1,21 @@
+issue_611: {
+  options = {
+    sequences: true,
+    side_effects: true
+  };
+  input: {
+    define(function() {
+      function fn() {}
+      if (fn()) {
+        fn();
+        return void 0;
+      }
+    });
+  }
+  expect: {
+    define(function() {
+      function fn(){}
+      if (fn()) return void fn();
+    });
+  }
+}