diff --git a/crates/rslint_parser/src/syntax/function.rs b/crates/rslint_parser/src/syntax/function.rs index 0e07d4240a1..40d4e5e54ca 100644 --- a/crates/rslint_parser/src/syntax/function.rs +++ b/crates/rslint_parser/src/syntax/function.rs @@ -750,12 +750,19 @@ fn parse_arrow_function_with_single_parameter(p: &mut Parser) -> ParsedSyntax { } fn is_arrow_function_with_single_parameter(p: &mut Parser) -> bool { - if p.at(T![async]) && !p.has_nth_preceding_line_break(1) { - is_nth_at_identifier_binding(p, 1) - && p.nth_at(2, T![=>]) + // a => ... + if p.nth_at(1, T![=>]) { + // test single_parameter_arrow_function_with_parameter_named_async + // let id = async => async; + is_at_identifier_binding(p) && !p.has_nth_preceding_line_break(1) + } + // async ident => ... + else { + p.at(T![async]) + && !p.has_nth_preceding_line_break(1) + && is_nth_at_identifier_binding(p, 1) && !p.has_nth_preceding_line_break(2) - } else { - is_at_identifier_binding(p) && p.nth_at(1, T![=>]) && !p.has_nth_preceding_line_break(1) + && p.nth_at(2, T![=>]) } } diff --git a/crates/rslint_parser/test_data/inline/ok/single_parameter_arrow_function_with_parameter_named_async.js b/crates/rslint_parser/test_data/inline/ok/single_parameter_arrow_function_with_parameter_named_async.js new file mode 100644 index 00000000000..5f3cefcdfec --- /dev/null +++ b/crates/rslint_parser/test_data/inline/ok/single_parameter_arrow_function_with_parameter_named_async.js @@ -0,0 +1 @@ +let id = async => async; diff --git a/crates/rslint_parser/test_data/inline/ok/single_parameter_arrow_function_with_parameter_named_async.rast b/crates/rslint_parser/test_data/inline/ok/single_parameter_arrow_function_with_parameter_named_async.rast new file mode 100644 index 00000000000..2fb34d571bd --- /dev/null +++ b/crates/rslint_parser/test_data/inline/ok/single_parameter_arrow_function_with_parameter_named_async.rast @@ -0,0 +1,65 @@ +JsModule { + interpreter_token: missing (optional), + directives: JsDirectiveList [], + items: JsModuleItemList [ + JsVariableStatement { + declaration: JsVariableDeclaration { + kind: LET_KW@0..4 "let" [] [Whitespace(" ")], + declarators: JsVariableDeclaratorList [ + JsVariableDeclarator { + id: JsIdentifierBinding { + name_token: IDENT@4..7 "id" [] [Whitespace(" ")], + }, + variable_annotation: missing (optional), + initializer: JsInitializerClause { + eq_token: EQ@7..9 "=" [] [Whitespace(" ")], + expression: JsArrowFunctionExpression { + async_token: missing (optional), + type_parameters: missing (optional), + parameters: JsIdentifierBinding { + name_token: IDENT@9..15 "async" [] [Whitespace(" ")], + }, + return_type_annotation: missing (optional), + fat_arrow_token: FAT_ARROW@15..18 "=>" [] [Whitespace(" ")], + body: JsIdentifierExpression { + name: JsReferenceIdentifier { + value_token: IDENT@18..23 "async" [] [], + }, + }, + }, + }, + }, + ], + }, + semicolon_token: SEMICOLON@23..24 ";" [] [], + }, + ], + eof_token: EOF@24..25 "" [Newline("\n")] [], +} + +0: JS_MODULE@0..25 + 0: (empty) + 1: JS_DIRECTIVE_LIST@0..0 + 2: JS_MODULE_ITEM_LIST@0..24 + 0: JS_VARIABLE_STATEMENT@0..24 + 0: JS_VARIABLE_DECLARATION@0..23 + 0: LET_KW@0..4 "let" [] [Whitespace(" ")] + 1: JS_VARIABLE_DECLARATOR_LIST@4..23 + 0: JS_VARIABLE_DECLARATOR@4..23 + 0: JS_IDENTIFIER_BINDING@4..7 + 0: IDENT@4..7 "id" [] [Whitespace(" ")] + 1: (empty) + 2: JS_INITIALIZER_CLAUSE@7..23 + 0: EQ@7..9 "=" [] [Whitespace(" ")] + 1: JS_ARROW_FUNCTION_EXPRESSION@9..23 + 0: (empty) + 1: (empty) + 2: JS_IDENTIFIER_BINDING@9..15 + 0: IDENT@9..15 "async" [] [Whitespace(" ")] + 3: (empty) + 4: FAT_ARROW@15..18 "=>" [] [Whitespace(" ")] + 5: JS_IDENTIFIER_EXPRESSION@18..23 + 0: JS_REFERENCE_IDENTIFIER@18..23 + 0: IDENT@18..23 "async" [] [] + 1: SEMICOLON@23..24 ";" [] [] + 3: EOF@24..25 "" [Newline("\n")] []