@@ -210,10 +210,19 @@ Compressor.prototype = new TreeTransformer(function(node, descend) {
210
210
// output and performance.
211
211
descend(node, this);
212
212
var opt = node.optimize(this);
213
- if (is_scope && opt === node && !this.has_directive("use asm") && !opt.pinned()) {
214
- opt.drop_unused(this);
215
- if (opt.merge_variables(this)) opt.drop_unused(this);
216
- descend(opt, this);
213
+ if (is_scope) {
214
+ if (opt === node && !this.has_directive("use asm") && !opt.pinned()) {
215
+ opt.drop_unused(this);
216
+ if (opt.merge_variables(this)) opt.drop_unused(this);
217
+ descend(opt, this);
218
+ }
219
+ if (this.option("arrows") && is_arrow(opt) && opt.body.length == 1) {
220
+ var stat = opt.body[0];
221
+ if (stat instanceof AST_Return) {
222
+ opt.body.length = 0;
223
+ opt.value = stat.value;
224
+ }
225
+ }
217
226
}
218
227
if (opt === node) opt._squeezed = true;
219
228
return opt;
@@ -6474,29 +6483,6 @@ Compressor.prototype.compress = function(node) {
6474
6483
return self;
6475
6484
});
6476
6485
6477
- function opt_arrow(self, compressor) {
6478
- if (!compressor.option("arrows")) return self;
6479
- drop_rest_farg(self, compressor);
6480
- if (self.value) self.body = [ self.first_statement() ];
6481
- var body = tighten_body(self.body, compressor);
6482
- switch (body.length) {
6483
- case 1:
6484
- var stat = body[0];
6485
- if (stat instanceof AST_Return) {
6486
- self.body.length = 0;
6487
- self.value = stat.value;
6488
- break;
6489
- }
6490
- default:
6491
- self.body = body;
6492
- self.value = null;
6493
- break;
6494
- }
6495
- return self;
6496
- }
6497
- OPT(AST_Arrow, opt_arrow);
6498
- OPT(AST_AsyncArrow, opt_arrow);
6499
-
6500
6486
OPT(AST_Function, function(self, compressor) {
6501
6487
drop_rest_farg(self, compressor);
6502
6488
self.body = tighten_body(self.body, compressor);
@@ -11138,6 +11124,19 @@ Compressor.prototype.compress = function(node) {
11138
11124
return make_sequence(self, convert_args()).optimize(compressor);
11139
11125
}
11140
11126
}
11127
+ if (compressor.option("arrows")
11128
+ && compressor.option("module")
11129
+ && (exp instanceof AST_AsyncFunction || exp instanceof AST_Function)
11130
+ && !exp.name
11131
+ && !exp.uses_arguments
11132
+ && !exp.pinned()
11133
+ && !exp.contains_this()) {
11134
+ var arrow = make_node(is_async(exp) ? AST_AsyncArrow : AST_Arrow, exp, exp);
11135
+ arrow.init_vars(exp.parent_scope, exp);
11136
+ arrow.variables.del("arguments");
11137
+ self.expression = arrow.transform(compressor);
11138
+ return self;
11139
+ }
11141
11140
if (compressor.option("drop_console")) {
11142
11141
if (exp instanceof AST_PropAccess) {
11143
11142
var name = exp.expression;
@@ -14233,8 +14232,8 @@ Compressor.prototype.compress = function(node) {
14233
14232
if (fn.pinned()) return;
14234
14233
if (is_generator(fn)) return;
14235
14234
var arrow = is_arrow(fn);
14236
- if ( arrow && fn.value) return ;
14237
- if (fn.body [0] instanceof AST_Directive) return;
14235
+ var fn_body = arrow && fn.value ? [ fn.first_statement() ] : fn.body ;
14236
+ if (fn_body [0] instanceof AST_Directive) return;
14238
14237
if (fn.contains_this()) return;
14239
14238
if (!scope) scope = find_scope(compressor);
14240
14239
var defined = new Dictionary();
@@ -14333,7 +14332,7 @@ Compressor.prototype.compress = function(node) {
14333
14332
return !abort;
14334
14333
};
14335
14334
}
14336
- if (verify_body && !all(fn.body , verify_body)) return;
14335
+ if (verify_body && !all(fn_body , verify_body)) return;
14337
14336
if (!safe_from_await_yield(fn, avoid_await_yield(compressor, scope))) return;
14338
14337
fn.functions.each(function(def, name) {
14339
14338
scope.functions.set(name, def);
@@ -14404,7 +14403,7 @@ Compressor.prototype.compress = function(node) {
14404
14403
[].unshift.apply(def.orig, orig);
14405
14404
def.eliminated += orig.length;
14406
14405
});
14407
- [].push.apply(body, in_loop ? fn.body .filter(function(stat) {
14406
+ [].push.apply(body, in_loop ? fn_body .filter(function(stat) {
14408
14407
if (!(stat instanceof AST_LambdaDefinition)) return true;
14409
14408
var name = make_node(AST_SymbolVar, flatten_var(stat.name));
14410
14409
var def = name.definition();
@@ -14418,7 +14417,7 @@ Compressor.prototype.compress = function(node) {
14418
14417
}) ],
14419
14418
}));
14420
14419
return false;
14421
- }) : fn.body );
14420
+ }) : fn_body );
14422
14421
var inlined = make_node(AST_BlockStatement, call, { body: body });
14423
14422
if (!no_return) {
14424
14423
if (async) scan_local_returns(inlined, function(node) {
0 commit comments