Skip to content

Commit

Permalink
fix(typescript): fix parsing of 'import("mod").C<<T>() => null>'
Browse files Browse the repository at this point in the history
Split the '<<' token into two '<' tokens to match TypeScript's
behavior.
  • Loading branch information
strager committed Dec 13, 2023
1 parent 7776927 commit c609b39
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ Semantic Versioning.
an arrow function parameter list.
* Fixed a crash if certain diagnostics are reported after a TypeScript
interface. (Implemented by [Rui Serra][].)
* `import("modulename").Class<<T>(params) => ReturnType>` in a type is now
parsed correctly.

## 2.18.0 (2023-11-03)

Expand Down
3 changes: 2 additions & 1 deletion src/quick-lint-js/fe/parse-type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,8 @@ void Parser::parse_and_visit_typescript_type_expression(
break;
}
}
if (this->peek().type == Token_Type::less) {
if (this->peek().type == Token_Type::less ||
this->peek().type == Token_Type::less_less) {
this->parse_and_visit_typescript_generic_arguments(v);
}
maybe_parse_dots_after_generic_arguments();
Expand Down
12 changes: 12 additions & 0 deletions test/test-parse-typescript-type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2065,6 +2065,18 @@ TEST_F(Test_Parse_TypeScript_Type, imported_type) {
}));
}

{
Spy_Visitor p = test_parse_and_visit_typescript_type_expression(
u8"import('mymod').MyClass<<T>() => ReturnType>"_sv, no_diags,
typescript_options);
EXPECT_THAT(p.visits, ElementsAreArray({
"visit_enter_function_scope", //
"visit_variable_declaration", // T
"visit_variable_type_use", // ReturnType
"visit_exit_function_scope", //
}));
}

test_parse_and_visit_typescript_type_expression(
u8"import('mymod').MyClass<T>.prop"_sv, //
u8" ^^^^ Diag_Dot_Not_Allowed_After_Generic_Arguments_In_Type.property_name\n"_diag
Expand Down

0 comments on commit c609b39

Please sign in to comment.