support asynchronous arrow functions (#4530)

This commit is contained in:
Alex Lam S.L
2021-01-10 03:34:26 +00:00
committed by GitHub
parent 0818d396c5
commit ba54d074d8
10 changed files with 159 additions and 56 deletions

View File

@@ -692,7 +692,7 @@ function OutputStream(options) {
// [ 1, (2, 3), 4 ] ==> [ 1, 3, 4 ]
return p instanceof AST_Array
// () => (foo, bar)
|| p instanceof AST_Arrow && p.value === this
|| is_arrow(p) && p.value === this
// await (foo, bar)
|| p instanceof AST_Await
// 1 + (2, 3) + 4 ==> 8
@@ -813,6 +813,9 @@ function OutputStream(options) {
// ({ p: a } = o);
if (this.left instanceof AST_DestructuredObject) return needs_parens_obj(output);
});
PARENS(AST_AsyncArrow, function(output) {
return needs_parens_assign_cond(this, output);
});
PARENS(AST_Conditional, function(output) {
return needs_parens_assign_cond(this, output);
});
@@ -1005,8 +1008,7 @@ function OutputStream(options) {
}
});
}
DEFPRINT(AST_Arrow, function(output) {
var self = this;
function print_arrow(self, output) {
if (self.argnames.length == 1 && self.argnames[0] instanceof AST_SymbolFunarg && !self.rest) {
self.argnames[0].print(output);
} else {
@@ -1020,6 +1022,14 @@ function OutputStream(options) {
} else {
print_braced(self, output, true);
}
}
DEFPRINT(AST_Arrow, function(output) {
print_arrow(this, output);
});
DEFPRINT(AST_AsyncArrow, function(output) {
output.print("async");
output.space();
print_arrow(this, output);
});
function print_lambda(self, output) {
if (self.name) {
@@ -1207,7 +1217,7 @@ function OutputStream(options) {
if (noin) node.walk(new TreeWalker(function(node) {
if (parens) return true;
if (node instanceof AST_Binary && node.operator == "in") return parens = true;
if (node instanceof AST_Scope && !(node instanceof AST_Arrow && node.value)) return true;
if (node instanceof AST_Scope && !(is_arrow(node) && node.value)) return true;
}));
node.print(output, parens);
}