@@ -22,6 +22,13 @@ Optional<ESTree::Node *> JSParserImpl::parseFlowDeclaration() {
2222 assert (checkDeclaration ());
2323 SMLoc start = tok_->getStartLoc ();
2424
25+ if (context_.getParseFlowComponentSyntax () && check (asyncIdent_) &&
26+ checkAsyncComponentFlow ()) {
27+ advance (); // consume 'async'
28+ return parseComponentDeclarationFlow (
29+ start, /* declare */ false , /* isAsync */ true );
30+ }
31+
2532 if (context_.getParseFlowComponentSyntax () &&
2633 checkComponentDeclarationFlow ()) {
2734 return parseComponentDeclarationFlow (start, /* declare */ false );
@@ -101,6 +108,17 @@ Optional<ESTree::Node *> JSParserImpl::parseDeclareFLow(SMLoc start) {
101108 return parseDeclareHookFlow (start);
102109 }
103110
111+ if (context_.getParseFlowComponentSyntax () && check (asyncIdent_) &&
112+ checkAsyncComponentFlow ()) {
113+ error (
114+ tok_->getStartLoc (),
115+ " `async` is not supported for declared components. "
116+ " Use `declare component` instead." );
117+ advance (); // consume 'async'
118+ return parseComponentDeclarationFlow (
119+ start, /* declare */ true , /* isAsync */ true );
120+ }
121+
104122 if (context_.getParseFlowComponentSyntax () &&
105123 checkComponentDeclarationFlow ()) {
106124 return parseComponentDeclarationFlow (start, /* declare */ true );
@@ -167,9 +185,23 @@ bool JSParserImpl::checkComponentDeclarationFlow() {
167185 return optNext.hasValue () && *optNext == TokenKind::identifier;
168186}
169187
188+ bool JSParserImpl::checkAsyncComponentFlow () {
189+ // async [no LineTerminator here] component
190+ // ^
191+ // Callers must already check check(asyncIdent_).
192+ assert (check (asyncIdent_));
193+ JSLexer::SavePoint savePoint{&lexer_};
194+ advance ();
195+ bool result =
196+ !lexer_.isNewLineBeforeCurrentToken () && checkComponentDeclarationFlow ();
197+ savePoint.restore ();
198+ return result;
199+ }
200+
170201Optional<ESTree::Node *> JSParserImpl::parseComponentDeclarationFlow (
171202 SMLoc start,
172- bool declare) {
203+ bool declare,
204+ bool isAsync) {
173205 // component
174206 assert (check (componentIdent_));
175207 advance ();
@@ -247,7 +279,7 @@ Optional<ESTree::Node *> JSParserImpl::parseComponentDeclarationFlow(
247279 SaveStrictModeAndSeenDirectives saveStrictModeAndSeenDirectives{this };
248280
249281 auto parsedBody = parseFunctionBody (
250- Param{}, false , false , false , JSLexer::AllowRegExp, true );
282+ Param{}, false , false , isAsync , JSLexer::AllowRegExp, true );
251283 if (!parsedBody)
252284 return None;
253285 auto *body = parsedBody.getValue ();
@@ -256,7 +288,12 @@ Optional<ESTree::Node *> JSParserImpl::parseComponentDeclarationFlow(
256288 start,
257289 body,
258290 new (context_) ESTree::ComponentDeclarationNode (
259- *optId, std::move (paramList), body, typeParams, rendersType));
291+ *optId,
292+ std::move (paramList),
293+ body,
294+ typeParams,
295+ rendersType,
296+ isAsync));
260297}
261298
262299bool JSParserImpl::parseComponentParametersFlow (
@@ -2081,6 +2118,23 @@ Optional<ESTree::Node *> JSParserImpl::parseDeclareExportFlow(SMLoc start) {
20812118 new (context_) ESTree::DeclareExportDeclarationNode (
20822119 *optFunc, {}, nullptr , true ));
20832120 }
2121+ if (context_.getParseFlowComponentSyntax () && check (asyncIdent_) &&
2122+ checkAsyncComponentFlow ()) {
2123+ error (
2124+ tok_->getStartLoc (),
2125+ " `async` is not supported for declared components. "
2126+ " Use `declare component` instead." );
2127+ advance (); // consume 'async'
2128+ auto optComponent = parseComponentDeclarationFlow (
2129+ start, /* declare */ true , /* isAsync */ true );
2130+ if (!optComponent)
2131+ return None;
2132+ return setLocation (
2133+ start,
2134+ *optComponent,
2135+ new (context_) ESTree::DeclareExportDeclarationNode (
2136+ *optComponent, {}, nullptr , true ));
2137+ }
20842138 if (context_.getParseFlowComponentSyntax () &&
20852139 checkComponentDeclarationFlow ()) {
20862140 auto optComponent =
@@ -2148,6 +2202,24 @@ Optional<ESTree::Node *> JSParserImpl::parseDeclareExportFlow(SMLoc start) {
21482202 *optClass, {}, nullptr , false ));
21492203 }
21502204
2205+ if (context_.getParseFlowComponentSyntax () && check (asyncIdent_) &&
2206+ checkAsyncComponentFlow ()) {
2207+ error (
2208+ tok_->getStartLoc (),
2209+ " `async` is not supported for declared components. "
2210+ " Use `declare component` instead." );
2211+ advance (); // consume 'async'
2212+ auto optComponent = parseComponentDeclarationFlow (
2213+ start, /* declare */ true , /* isAsync */ true );
2214+ if (!optComponent)
2215+ return None;
2216+ return setLocation (
2217+ start,
2218+ *optComponent,
2219+ new (context_) ESTree::DeclareExportDeclarationNode (
2220+ *optComponent, {}, nullptr , false ));
2221+ }
2222+
21512223 if (context_.getParseFlowComponentSyntax () &&
21522224 checkComponentDeclarationFlow ()) {
21532225 auto optComponent =
0 commit comments