[Pkg-javascript-commits] [uglifyjs] 46/77: Drop all `console` statements properly
Jonas Smedegaard
dr at jones.dk
Tue May 19 00:02:31 UTC 2015
This is an automated email from the git hooks/post-receive script.
js pushed a commit to tag v2.4.18
in repository uglifyjs.
commit 605362f89da444e46bae35e7f9384b5cba2eeb80
Author: Richard van Velzen <rvanvelzen1 at gmail.com>
Date: Sat Jan 31 13:22:07 2015 +0100
Drop all `console` statements properly
Because the base reference can be an member expression as well, we have to dig a bit deeper to find the leftmost base reference.
Fixes #451
---
lib/compress.js | 15 ++++++++++-----
test/compress/drop-console.js | 24 ++++++++++++++++++++++++
2 files changed, 34 insertions(+), 5 deletions(-)
diff --git a/lib/compress.js b/lib/compress.js
index ae20d48..2728598 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1873,11 +1873,16 @@ merge(Compressor.prototype, {
}
}
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);
+ if (self.expression instanceof AST_PropAccess) {
+ var name = self.expression.expression;
+ while (name.expression) {
+ name = name.expression;
+ }
+ if (name instanceof AST_SymbolRef
+ && name.name == "console"
+ && name.undeclared()) {
+ return make_node(AST_Undefined, self).transform(compressor);
+ }
}
}
return self.evaluate(compressor)[0];
diff --git a/test/compress/drop-console.js b/test/compress/drop-console.js
new file mode 100644
index 0000000..162b339
--- /dev/null
+++ b/test/compress/drop-console.js
@@ -0,0 +1,24 @@
+drop_console_1: {
+ options = {};
+ input: {
+ console.log('foo');
+ console.log.apply(console, arguments);
+ }
+ expect: {
+ console.log('foo');
+ console.log.apply(console, arguments);
+ }
+}
+
+drop_console_1: {
+ options = { drop_console: true };
+ input: {
+ console.log('foo');
+ console.log.apply(console, arguments);
+ }
+ expect: {
+ // with regular compression these will be stripped out as well
+ void 0;
+ void 0;
+ }
+}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/uglifyjs.git
More information about the Pkg-javascript-commits
mailing list