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

@@ -567,8 +567,20 @@ var AST_Accessor = DEFNODE("Accessor", null, {
},
}, AST_Lambda);
function is_arrow(node) {
return node instanceof AST_AsyncArrow || node instanceof AST_Arrow;
}
function is_function(node) {
return node instanceof AST_Arrow || node instanceof AST_AsyncFunction || node instanceof AST_Function;
return is_arrow(node) || node instanceof AST_AsyncFunction || node instanceof AST_Function;
}
function walk_lambda(node, tw) {
if (is_arrow(node) && node.value) {
node.value.walk(tw);
} else {
walk_body(node, tw);
}
}
var AST_Arrow = DEFNODE("Arrow", "inlined value", {
@@ -601,9 +613,38 @@ var AST_Arrow = DEFNODE("Arrow", "inlined value", {
}, AST_Lambda);
function is_async(node) {
return node instanceof AST_AsyncDefun || node instanceof AST_AsyncFunction;
return node instanceof AST_AsyncArrow || node instanceof AST_AsyncDefun || node instanceof AST_AsyncFunction;
}
var AST_AsyncArrow = DEFNODE("AsyncArrow", "inlined value", {
$documentation: "An asynchronous arrow function expression",
$propdoc: {
value: "[AST_Node?] simple return expression, or null if using function body.",
},
walk: function(visitor) {
var node = this;
visitor.visit(node, function() {
node.argnames.forEach(function(argname) {
argname.walk(visitor);
});
if (node.rest) node.rest.walk(visitor);
if (node.value) {
node.value.walk(visitor);
} else {
walk_body(node, visitor);
}
});
},
_validate: function() {
if (this.name != null) throw new Error("name must be null");
if (this.uses_arguments) throw new Error("uses_arguments must be false");
if (this.value != null) {
must_be_expression(this, "value");
if (this.body.length) throw new Error("body must be empty if value exists");
}
},
}, AST_Lambda);
var AST_AsyncFunction = DEFNODE("AsyncFunction", "inlined name", {
$documentation: "An asynchronous function expression",
$propdoc: {