Skip to content

Commit

Permalink
fix(lex): parse let f = (): RT<T>=>null;
Browse files Browse the repository at this point in the history
Test Plan:
`let f = (): RT<T>=>null;`

Fixes #1169
  • Loading branch information
vegerot committed Jan 8, 2024
1 parent b05e1cc commit 1e8190c
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/quick-lint-js/fe/lex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,12 @@ void Lexer::skip_less_less_as_less() {
void Lexer::skip_as_greater() {
switch (this->last_token_.type) {
case Token_Type::greater_equal:
this->last_token_.type = Token_Type::equal;
if (this->input_[0] == '>') {
this->last_token_.type = Token_Type::equal_greater;
this->input_ += 1;
} else {
this->last_token_.type = Token_Type::equal;
}
break;
case Token_Type::greater_greater_equal:
this->last_token_.type = Token_Type::greater_equal;
Expand Down
1 change: 1 addition & 0 deletions test/test-parse-typescript-generic-arrow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace quick_lint_js {
namespace {
class Test_Parse_TypeScript_Generic_Arrow : public Test_Parse_Expression {};


TEST_F(Test_Parse_TypeScript_Generic_Arrow, generic_arrow_function) {
{
Spy_Visitor p = test_parse_and_visit_statement(
Expand Down
69 changes: 69 additions & 0 deletions test/test-parse-typescript-generic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,75 @@ TEST_F(
}
}

TEST_F(Test_Parse_TypeScript_Generic,
greater_equal_greater_is_split_into_two_tokens) {
{
Spy_Visitor p = test_parse_and_visit_statement(
u8"let f = (): RT<T> => null;"_sv, no_diags, typescript_options);
EXPECT_THAT(p.visits, ElementsAreArray({
"visit_enter_function_scope", //
"visit_enter_type_scope", // :
"visit_variable_type_use", // RT
"visit_variable_type_use", // T
"visit_exit_type_scope", //
"visit_enter_function_scope_body", // {
"visit_exit_function_scope", // }
"visit_variable_declaration", // let f
}));
EXPECT_THAT(p.variable_declarations,
ElementsAreArray({let_init_decl(u8"f")}));
}
{
Spy_Visitor p = test_parse_and_visit_statement(
u8"let f = (): RT<T>=>null;"_sv, no_diags, typescript_options);
EXPECT_THAT(p.visits, ElementsAreArray({
"visit_enter_function_scope", //
"visit_enter_type_scope", // :
"visit_variable_type_use", // RT
"visit_variable_type_use", // T
"visit_exit_type_scope", //
"visit_enter_function_scope_body", // {
"visit_exit_function_scope", // }
"visit_variable_declaration", // let f
}));
EXPECT_THAT(p.variable_declarations,
ElementsAreArray({let_init_decl(u8"f")}));
}
{
Spy_Visitor p = test_parse_and_visit_statement(
u8"let f = (): RT<T>=> null;"_sv, no_diags, typescript_options);
EXPECT_THAT(p.visits, ElementsAreArray({
"visit_enter_function_scope", //
"visit_enter_type_scope", // :
"visit_variable_type_use", // RT
"visit_variable_type_use", // T
"visit_exit_type_scope", //
"visit_enter_function_scope_body", // {
"visit_exit_function_scope", // }
"visit_variable_declaration", // let f
}));
EXPECT_THAT(p.variable_declarations,
ElementsAreArray({let_init_decl(u8"f")}));
}
{
Spy_Visitor p = test_parse_and_visit_statement(
u8"let f = (): RT<RT<T>>=> null;"_sv, no_diags, typescript_options);
EXPECT_THAT(p.visits, ElementsAreArray({
"visit_enter_function_scope", //
"visit_enter_type_scope", // :
"visit_variable_type_use", // RT
"visit_variable_type_use", // RT
"visit_variable_type_use", // T
"visit_exit_type_scope", //
"visit_enter_function_scope_body", // {
"visit_exit_function_scope", // }
"visit_variable_declaration", // let f
}));
EXPECT_THAT(p.variable_declarations,
ElementsAreArray({let_init_decl(u8"f")}));
}
}

TEST_F(Test_Parse_TypeScript_Generic,
unambiguous_generic_arguments_are_parsed_in_javascript) {
{
Expand Down

0 comments on commit 1e8190c

Please sign in to comment.