fix(rslint_parser): Async identifier in `for await` loop
MODIFY
crates/rslint_parser/src/syntax/expr.rs
crates/rslint_parser/src/syntax/expr.rs
@@ -1063,7 +1063,8 @@ fn parse_primary_expression(p: &mut Parser) -> ParsedSyntax {
parse_function_expression(p).unwrap()
} else {
// `async a => {}` and `async (a) => {}`
- if p.state.potential_arrow_start() && (is_nth_at_name(p, 1) || p.nth(1) == T!['('])
+ if p.state.potential_arrow_start()
+ && ((is_nth_at_name(p, 1) && p.nth_at(2, T![=>])) || p.nth(1) == T!['('])
{
// test async_arrow_expr
// let a = async foo => {}

ADD
crates/rslint_parser/test_data/inline/err/for_of_async_identifier.js
+let async;
+for (async of [1]) ;

ADD
crates/rslint_parser/test_data/inline/ok/for_await_async_identifier.js
+let async;
+async function fn() {
+ for await (async of [7]);
+}

ADD
crates/rslint_parser/test_data/inline/ok/for_await_async_identifier.rast
+JsModule {
+ interpreter_token: missing (optional),
+ directives: JsDirectiveList [],
+ items: JsModuleItemList [
+ JsVariableStatement {
+ declarations: JsVariableDeclarations {
+ kind: LET_KW@0..4 "let" [] [Whitespace(" ")],
+ items: JsVariableDeclarationList [
+ JsVariableDeclaration {
+ id: JsIdentifierBinding {
+ name_token: IDENT@4..9 "async" [] [],
+ },
+ excl_token: missing (optional),
+ type_annotation: missing (optional),
+ initializer: missing (optional),
+ },
+ ],
+ },
+ semicolon_token: SEMICOLON@9..10 ";" [] [],
+ },
+ JsFunctionStatement {
+ async_token: ASYNC_KW@10..17 "async" [Newline("\n")] [Whitespace(" ")],
+ function_token: FUNCTION_KW@17..26 "function" [] [Whitespace(" ")],
+ star_token: missing (optional),
+ id: JsIdentifierBinding {
+ name_token: IDENT@26..28 "fn" [] [],
+ },
+ type_parameters: missing (optional),
+ parameters: JsParameters {
+ l_paren_token: L_PAREN@28..29 "(" [] [],
+ items: JsParameterList [],
+ r_paren_token: R_PAREN@29..31 ")" [] [Whitespace(" ")],
+ },
+ return_type: missing (optional),
+ body: JsFunctionBody {
+ l_curly_token: L_CURLY@31..32 "{" [] [],
+ directives: JsDirectiveList [],
+ statements: JsStatementList [
+ JsForOfStatement {
+ for_token: FOR_KW@32..39 "for" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")],
+ await_token: AWAIT_KW@39..45 "await" [] [Whitespace(" ")],
+ l_paren_token: L_PAREN@45..46 "(" [] [],
+ initializer: JsIdentifierAssignment {
+ name_token: IDENT@46..52 "async" [] [Whitespace(" ")],
+ },
+ of_token: OF_KW@52..55 "of" [] [Whitespace(" ")],
+ expression: JsArrayExpression {
+ l_brack_token: L_BRACK@55..56 "[" [] [],
+ elements: JsArrayElementList [
+ JsNumberLiteralExpression {
+ value_token: JS_NUMBER_LITERAL@56..57 "7" [] [],
+ },
+ ],
+ r_brack_token: R_BRACK@57..58 "]" [] [],
+ },
+ r_paren_token: R_PAREN@58..59 ")" [] [],
+ body: JsEmptyStatement {
+ semicolon_token: SEMICOLON@59..60 ";" [] [],
+ },
+ },
+ ],
+ r_curly_token: R_CURLY@60..62 "}" [Newline("\n")] [],
+ },
+ },
+ ],
+ eof_token: EOF@62..63 "" [Newline("\n")] [],
+}
+
+0: JS_MODULE@0..63
+ 0: (empty)
+ 1: JS_DIRECTIVE_LIST@0..0
+ 2: JS_MODULE_ITEM_LIST@0..62
+ 0: JS_VARIABLE_STATEMENT@0..10
+ 0: JS_VARIABLE_DECLARATIONS@0..9
+ 0: LET_KW@0..4 "let" [] [Whitespace(" ")]
+ 1: JS_VARIABLE_DECLARATION_LIST@4..9
+ 0: JS_VARIABLE_DECLARATION@4..9
+ 0: JS_IDENTIFIER_BINDING@4..9
+ 0: IDENT@4..9 "async" [] []
+ 1: (empty)
+ 2: (empty)
+ 3: (empty)
+ 1: SEMICOLON@9..10 ";" [] []
+ 1: JS_FUNCTION_STATEMENT@10..62
+ 0: ASYNC_KW@10..17 "async" [Newline("\n")] [Whitespace(" ")]
+ 1: FUNCTION_KW@17..26 "function" [] [Whitespace(" ")]
+ 2: (empty)
+ 3: JS_IDENTIFIER_BINDING@26..28
+ 0: IDENT@26..28 "fn" [] []
+ 4: (empty)
+ 5: JS_PARAMETERS@28..31
+ 0: L_PAREN@28..29 "(" [] []
+ 1: JS_PARAMETER_LIST@29..29
+ 2: R_PAREN@29..31 ")" [] [Whitespace(" ")]
+ 6: (empty)
+ 7: JS_FUNCTION_BODY@31..62
+ 0: L_CURLY@31..32 "{" [] []
+ 1: JS_DIRECTIVE_LIST@32..32
+ 2: JS_STATEMENT_LIST@32..60
+ 0: JS_FOR_OF_STATEMENT@32..60
+ 0: FOR_KW@32..39 "for" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")]
+ 1: AWAIT_KW@39..45 "await" [] [Whitespace(" ")]
+ 2: L_PAREN@45..46 "(" [] []
+ 3: JS_IDENTIFIER_ASSIGNMENT@46..52
+ 0: IDENT@46..52 "async" [] [Whitespace(" ")]
+ 4: OF_KW@52..55 "of" [] [Whitespace(" ")]
+ 5: JS_ARRAY_EXPRESSION@55..58
+ 0: L_BRACK@55..56 "[" [] []
+ 1: JS_ARRAY_ELEMENT_LIST@56..57
+ 0: JS_NUMBER_LITERAL_EXPRESSION@56..57
+ 0: JS_NUMBER_LITERAL@56..57 "7" [] []
+ 2: R_BRACK@57..58 "]" [] []
+ 6: R_PAREN@58..59 ")" [] []
+ 7: JS_EMPTY_STATEMENT@59..60
+ 0: SEMICOLON@59..60 ";" [] []
+ 3: R_CURLY@60..62 "}" [Newline("\n")] []
+ 3: EOF@62..63 "" [Newline("\n")] []

fix(rslint_parser): Async identifier in `for await` loop (#1963)