From dc5f70eab5cf89f1046482e97267030b3bbf2b66 Mon Sep 17 00:00:00 2001 From: Mihai Bazon Date: Tue, 10 Dec 2013 19:44:41 +0200 Subject: [PATCH] Add `drop_console` option to the compressor --- README.md | 3 +++ lib/compress.js | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/README.md b/README.md index f2f2f212..80edb5fc 100644 --- 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 diff --git a/lib/compress.js b/lib/compress.js index 4c52f4dd..2a8b4c2e 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -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]; }); -- 2.34.1