optimize trivial arrow functions with a return statement in braces (#1681)
fixes #1676
This commit is contained in:
@@ -3943,6 +3943,14 @@ merge(Compressor.prototype, {
|
|||||||
return self;
|
return self;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
OPT(AST_Arrow, function(self, compressor){
|
||||||
|
if (self.body.length === 1 && self.body[0] instanceof AST_Return) {
|
||||||
|
var value = self.body[0].value;
|
||||||
|
self.body = value ? value : [];
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
});
|
||||||
|
|
||||||
OPT(AST_Class, function(self, compressor){
|
OPT(AST_Class, function(self, compressor){
|
||||||
// HACK to avoid compress failure.
|
// HACK to avoid compress failure.
|
||||||
// AST_Class is not really an AST_Scope/AST_Block as it lacks a body.
|
// AST_Class is not really an AST_Scope/AST_Block as it lacks a body.
|
||||||
|
|||||||
@@ -9,7 +9,19 @@ arrow_functions: {
|
|||||||
a=>{return b;}
|
a=>{return b;}
|
||||||
a => 'lel'; // Dropping the parens
|
a => 'lel'; // Dropping the parens
|
||||||
}
|
}
|
||||||
expect_exact: "a=>b;(a,b)=>c;()=>b;a=>b=>c;a=>b=>c;()=>(b,c)=>d;a=>{return b};a=>\"lel\";"
|
expect_exact: "a=>b;(a,b)=>c;()=>b;a=>b=>c;a=>b=>c;()=>(b,c)=>d;a=>b;a=>\"lel\";"
|
||||||
|
}
|
||||||
|
|
||||||
|
arrow_return: {
|
||||||
|
input: {
|
||||||
|
() => {};
|
||||||
|
() => { return; };
|
||||||
|
a => { return 1; }
|
||||||
|
a => { return -b }
|
||||||
|
a => { return b; var b; }
|
||||||
|
(x, y) => { return x - y; }
|
||||||
|
}
|
||||||
|
expect_exact: "()=>{};()=>{};a=>1;a=>-b;a=>{return b;var b};(x,y)=>x-y;"
|
||||||
}
|
}
|
||||||
|
|
||||||
regression_arrow_functions_and_hoist: {
|
regression_arrow_functions_and_hoist: {
|
||||||
|
|||||||
Reference in New Issue
Block a user