From 9693552c5ca6694bd9b60917a98bda10f7aea158 Mon Sep 17 00:00:00 2001 From: Job Bautista Date: Sat, 6 May 2023 15:15:33 +0800 Subject: [PATCH] Issue #2232 - Parse exported async functions. --- js/src/frontend/Parser.cpp | 19 +++++++++++++++++-- js/src/frontend/Parser.h | 3 ++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/js/src/frontend/Parser.cpp b/js/src/frontend/Parser.cpp index a33b3d0d90..841eb5f096 100644 --- a/js/src/frontend/Parser.cpp +++ b/js/src/frontend/Parser.cpp @@ -5778,14 +5778,15 @@ Parser::exportVariableStatement(uint32_t begin) template typename ParseHandler::UnaryNodeType -Parser::exportFunctionDeclaration(uint32_t begin) +Parser::exportFunctionDeclaration(uint32_t begin, + FunctionAsyncKind asyncKind /* = SyncFunction */) { if (!abortIfSyntaxParser()) return null(); MOZ_ASSERT(tokenStream.isCurrentTokenType(TOK_FUNCTION)); - Node kid = functionStmt(pos().begin, YieldIsKeyword, NameRequired); + Node kid = functionStmt(pos().begin, YieldIsKeyword, NameRequired, asyncKind); if (!kid) return null(); @@ -6008,6 +6009,20 @@ Parser::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); diff --git a/js/src/frontend/Parser.h b/js/src/frontend/Parser.h index 6976487c50..1819873308 100644 --- a/js/src/frontend/Parser.h +++ b/js/src/frontend/Parser.h @@ -1337,7 +1337,8 @@ FOR_EACH_PARSENODE_SUBCLASS(DECLARE_TYPE) BinaryNodeType exportBatch(uint32_t begin); bool checkLocalExportNames(ListNodeType node); Node exportClause(uint32_t begin); - UnaryNodeType exportFunctionDeclaration(uint32_t begin); + UnaryNodeType exportFunctionDeclaration(uint32_t begin, + FunctionAsyncKind asyncKind = SyncFunction); UnaryNodeType exportVariableStatement(uint32_t begin); UnaryNodeType exportClassDeclaration(uint32_t begin); UnaryNodeType exportLexicalDeclaration(uint32_t begin, DeclarationKind kind);