зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1339964 - Support export async function f() {}. r=till
This commit is contained in:
Родитель
fa1ef124e8
Коммит
030e18d7ef
|
@ -5233,14 +5233,15 @@ Parser<ParseHandler>::exportVariableStatement(uint32_t begin)
|
|||
|
||||
template <typename ParseHandler>
|
||||
typename ParseHandler::Node
|
||||
Parser<ParseHandler>::exportFunctionDeclaration(uint32_t begin)
|
||||
Parser<ParseHandler>::exportFunctionDeclaration(uint32_t begin,
|
||||
FunctionAsyncKind asyncKind /* = SyncFunction */)
|
||||
{
|
||||
if (!abortIfSyntaxParser())
|
||||
return null();
|
||||
|
||||
MOZ_ASSERT(tokenStream.isCurrentTokenType(TOK_FUNCTION));
|
||||
|
||||
Node kid = functionStmt(YieldIsKeyword, NameRequired);
|
||||
Node kid = functionStmt(YieldIsKeyword, NameRequired, asyncKind);
|
||||
if (!kid)
|
||||
return null();
|
||||
|
||||
|
@ -5463,6 +5464,20 @@ Parser<ParseHandler>::exportDeclaration()
|
|||
case TOK_FUNCTION:
|
||||
return exportFunctionDeclaration(begin);
|
||||
|
||||
case TOK_ASYNC: {
|
||||
TokenKind nextSameLine = TOK_EOF;
|
||||
if (!tokenStream.peekTokenSameLine(&nextSameLine))
|
||||
return null();
|
||||
|
||||
if (nextSameLine == TOK_FUNCTION) {
|
||||
tokenStream.consumeKnownToken(TOK_FUNCTION);
|
||||
return exportFunctionDeclaration(begin, AsyncFunction);
|
||||
}
|
||||
|
||||
error(JSMSG_DECLARATION_AFTER_EXPORT);
|
||||
return null();
|
||||
}
|
||||
|
||||
case TOK_CLASS:
|
||||
return exportClassDeclaration(begin);
|
||||
|
||||
|
|
|
@ -1203,7 +1203,8 @@ class Parser final : public ParserBase, private JS::AutoGCRooter
|
|||
Node exportBatch(uint32_t begin);
|
||||
bool checkLocalExportNames(Node node);
|
||||
Node exportClause(uint32_t begin);
|
||||
Node exportFunctionDeclaration(uint32_t begin);
|
||||
Node exportFunctionDeclaration(uint32_t begin,
|
||||
FunctionAsyncKind asyncKind = SyncFunction);
|
||||
Node exportVariableStatement(uint32_t begin);
|
||||
Node exportClassDeclaration(uint32_t begin);
|
||||
Node exportLexicalDeclaration(uint32_t begin, DeclarationKind kind);
|
||||
|
|
|
@ -16,6 +16,12 @@ if (typeof parseModule === "function") {
|
|||
assertThrows(() => parseModule("async function f() { function g() { await 3; } }"), SyntaxError);
|
||||
|
||||
if (typeof Reflect !== "undefined" && Reflect.parse) {
|
||||
Reflect.parse("export async function f() {}", { target: "module" });
|
||||
assertThrows(() => Reflect.parse("export async function() {}", { target: "module" }), SyntaxError);
|
||||
|
||||
Reflect.parse("export default async function() {}", { target: "module" });
|
||||
Reflect.parse("export default async function f() {}", { target: "module" });
|
||||
|
||||
assertThrows(() => Reflect.parse("export default async function() { yield; }", { target: "module" }), SyntaxError);
|
||||
assertThrows(() => Reflect.parse("export default async function() { yield = 1; }", { target: "module" }), SyntaxError);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче