optimize return undefined and return void 0

This commit is contained in:
kzc
2015-10-28 13:25:27 -04:00
committed by Richard van Velzen
parent 335e349314
commit 7491d07666
2 changed files with 239 additions and 0 deletions

View File

@@ -65,6 +65,7 @@ function Compressor(options, false_by_default) {
keep_fnames : false,
hoist_vars : false,
if_return : !false_by_default,
return_void_0 : !false_by_default,
join_vars : !false_by_default,
cascade : !false_by_default,
side_effects : !false_by_default,
@@ -2519,4 +2520,13 @@ merge(Compressor.prototype, {
OPT(AST_Object, literals_in_boolean_context);
OPT(AST_RegExp, literals_in_boolean_context);
OPT(AST_Return, function(self, compressor){
if (compressor.option("return_void_0")) {
if (self.value instanceof AST_Undefined) {
self.value = null;
}
}
return self;
});
})();