support async function within object literal (#4424)

This commit is contained in:
Alex Lam S.L
2020-12-20 00:19:04 +00:00
committed by GitHub
parent 8ce3c7d70f
commit b7c49b72b3
4 changed files with 85 additions and 19 deletions

View File

@@ -1482,7 +1482,39 @@ function parse($TEXT, options) {
}));
continue;
}
if (!is("punc", ":") && start.type == "name") switch (key) {
if (is("punc", ":")) {
next();
a.push(new AST_ObjectKeyVal({
start: start,
key: key,
value: maybe_assign(),
end: prev(),
}));
continue;
}
if (is("punc", ",") || is("punc", "}")) {
a.push(new AST_ObjectKeyVal({
start: start,
key: key,
value: _make_symbol(AST_SymbolRef, start),
end: prev(),
}));
continue;
}
if (start.type == "name") switch (key) {
case "async":
key = as_property_key();
var func_start = S.token;
var func = function_(AST_AsyncFunction);
func.start = func_start;
func.end = prev();
a.push(new AST_ObjectKeyVal({
start: start,
key: key,
value: func,
end: prev(),
}));
continue;
case "get":
a.push(new AST_ObjectGetter({
start: start,
@@ -1499,22 +1531,8 @@ function parse($TEXT, options) {
end: prev(),
}));
continue;
default:
a.push(new AST_ObjectKeyVal({
start: start,
key: key,
value: _make_symbol(AST_SymbolRef, start),
end: prev(),
}));
continue;
}
expect(":");
a.push(new AST_ObjectKeyVal({
start: start,
key: key,
value: maybe_assign(),
end: prev(),
}));
unexpected();
}
next();
return new AST_Object({ properties: a });