enhance arrows (#4403)
This commit is contained in:
@@ -4670,22 +4670,19 @@ merge(Compressor.prototype, {
|
|||||||
|
|
||||||
OPT(AST_Arrow, function(self, compressor) {
|
OPT(AST_Arrow, function(self, compressor) {
|
||||||
if (!compressor.option("arrows")) return self;
|
if (!compressor.option("arrows")) return self;
|
||||||
if (self.value) {
|
var body = tighten_body(self.value ? [ self.first_statement() ] : self.body, compressor);
|
||||||
var value = self.value;
|
switch (body.length) {
|
||||||
if (is_undefined(value, compressor)) {
|
case 1:
|
||||||
self.value = null;
|
var stat = body[0];
|
||||||
} else if (value instanceof AST_UnaryPrefix && value.operator == "void") {
|
if (stat instanceof AST_Return) {
|
||||||
self.body.push(make_node(AST_SimpleStatement, value, {
|
self.body.length = 0;
|
||||||
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();
|
|
||||||
self.value = stat.value;
|
self.value = stat.value;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
self.body = body;
|
||||||
|
self.value = null;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -320,6 +320,8 @@ inline_this: {
|
|||||||
trim_body: {
|
trim_body: {
|
||||||
options = {
|
options = {
|
||||||
arrows: true,
|
arrows: true,
|
||||||
|
if_return: true,
|
||||||
|
side_effects: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
var f = a => {
|
var f = a => {
|
||||||
@@ -337,6 +339,25 @@ trim_body: {
|
|||||||
node_version: ">=4"
|
node_version: ">=4"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
collapse_value: {
|
||||||
|
options = {
|
||||||
|
arrows: true,
|
||||||
|
collapse_vars: true,
|
||||||
|
keep_fargs: "strict",
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 42;
|
||||||
|
console.log((b => Math.floor(b))(a));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 42;
|
||||||
|
console.log((() => Math.floor(a))());
|
||||||
|
}
|
||||||
|
expect_stdout: "42"
|
||||||
|
node_version: ">=4"
|
||||||
|
}
|
||||||
|
|
||||||
reduce_iife_1: {
|
reduce_iife_1: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user