Add `drop_console` option to the compressor
authorMihai Bazon <mihai@bazon.net>
Tue, 10 Dec 2013 17:44:41 +0000 (19:44 +0200)
committerMihai Bazon <mihai@bazon.net>
Tue, 10 Dec 2013 17:44:41 +0000 (19:44 +0200)
README.md
lib/compress.js

index f2f2f21..80edb5f 100644 (file)
--- a/README.md
+++ b/README.md
@@ -249,6 +249,9 @@ to set `true`; it's effectively a shortcut for `foo=true`).
   statement would get discarded.  The current implementation adds some
   overhead (compression will be slower).
 
+- `drop_console` -- default `false`.  Pass `true` to discard calls to
+  `console.*` functions.
+
 ### The `unsafe` option
 
 It enables some transformations that *might* break code logic in certain
index 4c52f4d..2a8b4c2 100644 (file)
@@ -70,6 +70,7 @@ function Compressor(options, false_by_default) {
         pure_funcs    : null,
         negate_iife   : !false_by_default,
         screw_ie8     : false,
+        drop_console  : false,
 
         warnings      : true,
         global_defs   : {}
@@ -1773,6 +1774,14 @@ merge(Compressor.prototype, {
                 return make_node(AST_Undefined, self).transform(compressor);
             }
         }
+        if (compressor.option("drop_console")) {
+            if (self.expression instanceof AST_PropAccess &&
+                self.expression.expression instanceof AST_SymbolRef &&
+                self.expression.expression.name == "console" &&
+                self.expression.expression.undeclared()) {
+                return make_node(AST_Undefined, self).transform(compressor);
+            }
+        }
         return self.evaluate(compressor)[0];
     });