enhance arrows (#4403)

This commit is contained in:
Alex Lam S.L
2020-12-18 06:55:20 +00:00
committed by GitHub
parent d2c50ace99
commit 9c0718b162
2 changed files with 32 additions and 14 deletions

View File

@@ -4670,22 +4670,19 @@ merge(Compressor.prototype, {
OPT(AST_Arrow, function(self, compressor) {
if (!compressor.option("arrows")) return self;
if (self.value) {
var value = self.value;
if (is_undefined(value, compressor)) {
self.value = null;
} else if (value instanceof AST_UnaryPrefix && value.operator == "void") {
self.body.push(make_node(AST_SimpleStatement, value, {
body: value.expression
}));
self.value = null;
}
} else if (self.body.length == 1) {
var stat = self.body[0];
if (stat instanceof AST_Return && stat.value) {
self.body.pop();
var body = tighten_body(self.value ? [ self.first_statement() ] : self.body, compressor);
switch (body.length) {
case 1:
var stat = body[0];
if (stat instanceof AST_Return) {
self.body.length = 0;
self.value = stat.value;
break;
}
default:
self.body = body;
self.value = null;
break;
}
return self;
});