Merge 352bdaecb6 into 491f16c766
This commit is contained in:
commit
b7eae12569
|
|
@ -428,9 +428,13 @@ to set `true`; it's effectively a shortcut for `foo=true`).
|
||||||
such as `console.info` and/or retain side effects from function arguments
|
such as `console.info` and/or retain side effects from function arguments
|
||||||
after dropping the function call then use `pure_funcs` instead.
|
after dropping the function call then use `pure_funcs` instead.
|
||||||
|
|
||||||
|
- `drop_error` -- default `false`. Pass `true` to discard description
|
||||||
|
of Error() calls.
|
||||||
|
|
||||||
- `expression` -- default `false`. Pass `true` to preserve completion values
|
- `expression` -- default `false`. Pass `true` to preserve completion values
|
||||||
from terminal statements without `return`, e.g. in bookmarklets.
|
from terminal statements without `return`, e.g. in bookmarklets.
|
||||||
|
|
||||||
|
|
||||||
- `keep_fargs` -- default `true`. Prevents the
|
- `keep_fargs` -- default `true`. Prevents the
|
||||||
compressor from discarding unused function arguments. You need this
|
compressor from discarding unused function arguments. You need this
|
||||||
for code which relies on `Function.length`.
|
for code which relies on `Function.length`.
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,7 @@ function Compressor(options, false_by_default) {
|
||||||
negate_iife : !false_by_default,
|
negate_iife : !false_by_default,
|
||||||
screw_ie8 : true,
|
screw_ie8 : true,
|
||||||
drop_console : false,
|
drop_console : false,
|
||||||
|
drop_error : false,
|
||||||
angular : false,
|
angular : false,
|
||||||
expression : false,
|
expression : false,
|
||||||
warnings : true,
|
warnings : true,
|
||||||
|
|
@ -2854,6 +2855,22 @@ merge(Compressor.prototype, {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (compressor.option("drop_error")) {
|
||||||
|
var exp = self.expression;
|
||||||
|
if (exp instanceof AST_SymbolRef
|
||||||
|
&& (exp.name == "Error" ||
|
||||||
|
exp.name == "EvalError" ||
|
||||||
|
exp.name == "InternalError" ||
|
||||||
|
exp.name == "RangeError" ||
|
||||||
|
exp.name == "ReferenceError" ||
|
||||||
|
exp.name == "SyntaxError" ||
|
||||||
|
exp.name == "TypeError" ||
|
||||||
|
exp.name == "URIError")
|
||||||
|
&& exp.undeclared()) {
|
||||||
|
// drop error description(s)
|
||||||
|
self.args = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
if (exp instanceof AST_Function) {
|
if (exp instanceof AST_Function) {
|
||||||
if (exp.body[0] instanceof AST_Return) {
|
if (exp.body[0] instanceof AST_Return) {
|
||||||
var value = exp.body[0].value;
|
var value = exp.body[0].value;
|
||||||
|
|
@ -2891,6 +2908,23 @@ merge(Compressor.prototype, {
|
||||||
});
|
});
|
||||||
|
|
||||||
OPT(AST_New, function(self, compressor){
|
OPT(AST_New, function(self, compressor){
|
||||||
|
|
||||||
|
if (compressor.option("drop_error")) {
|
||||||
|
var exp = self.expression;
|
||||||
|
if (exp instanceof AST_SymbolRef
|
||||||
|
&& (exp.name == "Error" ||
|
||||||
|
exp.name == "EvalError" ||
|
||||||
|
exp.name == "InternalError" ||
|
||||||
|
exp.name == "RangeError" ||
|
||||||
|
exp.name == "ReferenceError" ||
|
||||||
|
exp.name == "SyntaxError" ||
|
||||||
|
exp.name == "TypeError" ||
|
||||||
|
exp.name == "URIError")
|
||||||
|
&& exp.undeclared()) {
|
||||||
|
// drop error description(s)
|
||||||
|
self.args = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
if (compressor.option("unsafe")) {
|
if (compressor.option("unsafe")) {
|
||||||
var exp = self.expression;
|
var exp = self.expression;
|
||||||
if (exp instanceof AST_SymbolRef && exp.undeclared()) {
|
if (exp instanceof AST_SymbolRef && exp.undeclared()) {
|
||||||
|
|
@ -2899,6 +2933,12 @@ merge(Compressor.prototype, {
|
||||||
case "RegExp":
|
case "RegExp":
|
||||||
case "Function":
|
case "Function":
|
||||||
case "Error":
|
case "Error":
|
||||||
|
case "EvalError":
|
||||||
|
case "InternalError":
|
||||||
|
case "RangeError":
|
||||||
|
case "ReferenceError":
|
||||||
|
case "SyntaxError":
|
||||||
|
case "URIError":
|
||||||
case "Array":
|
case "Array":
|
||||||
return make_node(AST_Call, self, self).transform(compressor);
|
return make_node(AST_Call, self, self).transform(compressor);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
80
test/compress/drop-error.js
Normal file
80
test/compress/drop-error.js
Normal file
|
|
@ -0,0 +1,80 @@
|
||||||
|
drop_error_1: {
|
||||||
|
options = {};
|
||||||
|
input: {
|
||||||
|
Error('foo');
|
||||||
|
Error('foo', arguments);
|
||||||
|
EvalError('foo');
|
||||||
|
EvalError('foo', arguments);
|
||||||
|
InternalError('foo');
|
||||||
|
InternalError('foo', arguments);
|
||||||
|
RangeError('foo');
|
||||||
|
RangeError('foo', arguments);
|
||||||
|
ReferenceError('foo');
|
||||||
|
ReferenceError('foo', arguments);
|
||||||
|
SyntaxError('foo');
|
||||||
|
SyntaxError('foo', arguments);
|
||||||
|
TypeError('foo');
|
||||||
|
TypeError('foo', arguments);
|
||||||
|
URIError('foo');
|
||||||
|
URIError('foo', arguments);
|
||||||
|
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
Error('foo');
|
||||||
|
Error('foo', arguments);
|
||||||
|
EvalError('foo');
|
||||||
|
EvalError('foo', arguments);
|
||||||
|
InternalError('foo');
|
||||||
|
InternalError('foo', arguments);
|
||||||
|
RangeError('foo');
|
||||||
|
RangeError('foo', arguments);
|
||||||
|
ReferenceError('foo');
|
||||||
|
ReferenceError('foo', arguments);
|
||||||
|
SyntaxError('foo');
|
||||||
|
SyntaxError('foo', arguments);
|
||||||
|
TypeError('foo');
|
||||||
|
TypeError('foo', arguments);
|
||||||
|
URIError('foo');
|
||||||
|
URIError('foo', arguments);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
drop_error_2: {
|
||||||
|
options = { drop_error: true };
|
||||||
|
input: {
|
||||||
|
Error('foo');
|
||||||
|
Error('foo', arguments);
|
||||||
|
EvalError('foo');
|
||||||
|
EvalError('foo', arguments);
|
||||||
|
InternalError('foo');
|
||||||
|
InternalError('foo', arguments);
|
||||||
|
RangeError('foo');
|
||||||
|
RangeError('foo', arguments);
|
||||||
|
ReferenceError('foo');
|
||||||
|
ReferenceError('foo', arguments);
|
||||||
|
SyntaxError('foo');
|
||||||
|
SyntaxError('foo', arguments);
|
||||||
|
TypeError('foo');
|
||||||
|
TypeError('foo', arguments);
|
||||||
|
URIError('foo');
|
||||||
|
URIError('foo', arguments);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
Error();
|
||||||
|
Error();
|
||||||
|
EvalError();
|
||||||
|
EvalError();
|
||||||
|
InternalError();
|
||||||
|
InternalError();
|
||||||
|
RangeError();
|
||||||
|
RangeError();
|
||||||
|
ReferenceError();
|
||||||
|
ReferenceError();
|
||||||
|
SyntaxError();
|
||||||
|
SyntaxError();
|
||||||
|
TypeError();
|
||||||
|
TypeError();
|
||||||
|
URIError();
|
||||||
|
URIError();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user