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
This commit is contained in:
@@ -1873,11 +1873,16 @@ merge(Compressor.prototype, {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (compressor.option("drop_console")) {
|
if (compressor.option("drop_console")) {
|
||||||
if (self.expression instanceof AST_PropAccess &&
|
if (self.expression instanceof AST_PropAccess) {
|
||||||
self.expression.expression instanceof AST_SymbolRef &&
|
var name = self.expression.expression;
|
||||||
self.expression.expression.name == "console" &&
|
while (name.expression) {
|
||||||
self.expression.expression.undeclared()) {
|
name = name.expression;
|
||||||
return make_node(AST_Undefined, self).transform(compressor);
|
}
|
||||||
|
if (name instanceof AST_SymbolRef
|
||||||
|
&& name.name == "console"
|
||||||
|
&& name.undeclared()) {
|
||||||
|
return make_node(AST_Undefined, self).transform(compressor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return self.evaluate(compressor)[0];
|
return self.evaluate(compressor)[0];
|
||||||
|
|||||||
24
test/compress/drop-console.js
Normal file
24
test/compress/drop-console.js
Normal file
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user