support asynchronous arrow functions (#4530)
This commit is contained in:
@@ -749,11 +749,7 @@ merge(Compressor.prototype, {
|
||||
}
|
||||
});
|
||||
});
|
||||
if (fn instanceof AST_Arrow && fn.value) {
|
||||
fn.value.walk(tw);
|
||||
} else {
|
||||
walk_body(fn, tw);
|
||||
}
|
||||
walk_lambda(fn, tw);
|
||||
var safe_ids = tw.safe_ids;
|
||||
pop(tw);
|
||||
walk_defuns(tw, fn);
|
||||
@@ -1893,7 +1889,7 @@ merge(Compressor.prototype, {
|
||||
return !(argname instanceof AST_Destructured);
|
||||
})) {
|
||||
abort = true;
|
||||
} else if (fn instanceof AST_Arrow && fn.value) {
|
||||
} else if (is_arrow(fn) && fn.value) {
|
||||
fn.value.transform(scanner);
|
||||
} else for (var i = 0; !abort && i < fn.body.length; i++) {
|
||||
var stat = fn.body[i];
|
||||
@@ -3765,12 +3761,15 @@ merge(Compressor.prototype, {
|
||||
if (!(stat instanceof AST_Directive)) return stat;
|
||||
}
|
||||
}
|
||||
AST_Arrow.DEFMETHOD("first_statement", function() {
|
||||
|
||||
function arrow_first_statement() {
|
||||
if (this.value) return make_node(AST_Return, this.value, {
|
||||
value: this.value
|
||||
});
|
||||
return skip_directives(this.body);
|
||||
});
|
||||
}
|
||||
AST_Arrow.DEFMETHOD("first_statement", arrow_first_statement);
|
||||
AST_AsyncArrow.DEFMETHOD("first_statement", arrow_first_statement);
|
||||
AST_Lambda.DEFMETHOD("first_statement", function() {
|
||||
return skip_directives(this.body);
|
||||
});
|
||||
@@ -4384,6 +4383,9 @@ merge(Compressor.prototype, {
|
||||
def(AST_Arrow, function() {
|
||||
return basic_negation(this);
|
||||
});
|
||||
def(AST_AsyncArrow, function() {
|
||||
return basic_negation(this);
|
||||
});
|
||||
def(AST_AsyncFunction, function() {
|
||||
return basic_negation(this);
|
||||
});
|
||||
@@ -4783,7 +4785,7 @@ merge(Compressor.prototype, {
|
||||
return true;
|
||||
}
|
||||
if (node instanceof AST_This) {
|
||||
if (scopes.length == 0 && self instanceof AST_Arrow) result = false;
|
||||
if (scopes.length == 0 && is_arrow(self)) result = false;
|
||||
return true;
|
||||
}
|
||||
}));
|
||||
@@ -4869,7 +4871,7 @@ merge(Compressor.prototype, {
|
||||
return trim_block(self);
|
||||
});
|
||||
|
||||
OPT(AST_Arrow, function(self, compressor) {
|
||||
function opt_arrow(self, compressor) {
|
||||
if (!compressor.option("arrows")) return self;
|
||||
var body = tighten_body(self.value ? [ self.first_statement() ] : self.body, compressor);
|
||||
switch (body.length) {
|
||||
@@ -4886,7 +4888,9 @@ merge(Compressor.prototype, {
|
||||
break;
|
||||
}
|
||||
return self;
|
||||
});
|
||||
}
|
||||
OPT(AST_Arrow, opt_arrow);
|
||||
OPT(AST_AsyncArrow, opt_arrow);
|
||||
|
||||
OPT(AST_Function, function(self, compressor) {
|
||||
self.body = tighten_body(self.body, compressor);
|
||||
@@ -5116,11 +5120,7 @@ merge(Compressor.prototype, {
|
||||
});
|
||||
if (node.rest) node.rest.mark_symbol(marker, scanner);
|
||||
}
|
||||
if (node instanceof AST_Arrow && node.value) {
|
||||
node.value.walk(tw);
|
||||
} else {
|
||||
walk_body(node, tw);
|
||||
}
|
||||
walk_lambda(node, tw);
|
||||
pop();
|
||||
return true;
|
||||
}
|
||||
@@ -6735,6 +6735,7 @@ merge(Compressor.prototype, {
|
||||
}
|
||||
return this;
|
||||
});
|
||||
def(AST_AsyncArrow, return_null);
|
||||
def(AST_AsyncFunction, return_null);
|
||||
def(AST_Await, function(compressor) {
|
||||
if (!compressor.option("awaits")) return this;
|
||||
@@ -8226,7 +8227,7 @@ merge(Compressor.prototype, {
|
||||
&& can_drop
|
||||
&& all(fn.body, is_empty)
|
||||
&& (fn !== exp || fn_name_unused(fn, compressor))
|
||||
&& !(fn instanceof AST_Arrow && fn.value)) {
|
||||
&& !(is_arrow(fn) && fn.value)) {
|
||||
return make_sequence(self, convert_args()).optimize(compressor);
|
||||
}
|
||||
}
|
||||
@@ -8334,7 +8335,7 @@ merge(Compressor.prototype, {
|
||||
if (!safe) return true;
|
||||
if (node instanceof AST_Scope) {
|
||||
if (node === fn) return;
|
||||
if (node instanceof AST_Arrow) {
|
||||
if (is_arrow(node)) {
|
||||
for (var i = 0; safe && i < node.argnames.length; i++) node.argnames[i].walk(tw);
|
||||
} else if (is_defun(node) && node.name.name == "await") {
|
||||
safe = false;
|
||||
@@ -10562,7 +10563,7 @@ merge(Compressor.prototype, {
|
||||
while (p = compressor.parent(i++)) {
|
||||
if (p instanceof AST_Lambda) {
|
||||
if (p instanceof AST_Accessor) return;
|
||||
if (p instanceof AST_Arrow) continue;
|
||||
if (is_arrow(p)) continue;
|
||||
fn_parent = compressor.parent(i);
|
||||
return p;
|
||||
}
|
||||
@@ -10571,13 +10572,14 @@ merge(Compressor.prototype, {
|
||||
});
|
||||
|
||||
AST_Arrow.DEFMETHOD("contains_this", return_false);
|
||||
AST_AsyncArrow.DEFMETHOD("contains_this", return_false);
|
||||
AST_Scope.DEFMETHOD("contains_this", function() {
|
||||
var result;
|
||||
var self = this;
|
||||
self.walk(new TreeWalker(function(node) {
|
||||
if (result) return true;
|
||||
if (node instanceof AST_This) return result = true;
|
||||
if (node !== self && node instanceof AST_Scope && !(node instanceof AST_Arrow)) return true;
|
||||
if (node !== self && node instanceof AST_Scope && !is_arrow(node)) return true;
|
||||
}));
|
||||
return result;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user