Skip to content

Commit

Permalink
fix(fe): commit transaction after parsing Typescript type, interface …
Browse files Browse the repository at this point in the history
…or namespace (#1112)

Fixes #1108 

`Parser::parse_and_visit_typescript_interface_or_namespace_or_type_statement` starts a [lexer transaction](https://github.com/quick-lint/quick-lint-js/blob/ad585501000607aa309c4199ee3ce497e3374ee3/src/quick-lint-js/fe/parse-statement.cpp#L785), but that transaction wasn't committed if the statement was parsed cleanly.
  • Loading branch information
ruipserra authored Dec 6, 2023
1 parent ad58550 commit 088573b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/quick-lint-js/fe/parse-statement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,7 @@ Parser::parse_and_visit_typescript_interface_or_namespace_or_type_statement(
default:
QLJS_UNREACHABLE();
}
this->lexer_.commit_transaction(std::move(transaction));
return Parse_Possible_Label_Result::parsed_not_as_a_label;

// type++; // Expression.
Expand Down
23 changes: 23 additions & 0 deletions test/test-parse-typescript-interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1494,6 +1494,29 @@ TEST_F(Test_Parse_TypeScript_Interface,
u8" \\u{63}onstructor();}"_sv,
no_diags, typescript_options);
}

TEST_F(Test_Parse_TypeScript_Interface,
parser_is_left_in_consistent_state_after_parsing_interface) {
{
Test_Parser p(
u8"interface I {}\n"
u8"let a = \"",
typescript_options, capture_diags);
p.parse_and_visit_statement();
p.parse_and_visit_statement();
EXPECT_THAT(p.visits, ElementsAreArray({
"visit_variable_declaration", // I
"visit_enter_interface_scope", // {
"visit_exit_interface_scope", // }
"visit_variable_declaration", // a
}));
assert_diagnostics(
p.code, p.errors,
{
u8" ^^ Diag_Unclosed_String_Literal"_diag,
});
}
}
}
}

Expand Down

0 comments on commit 088573b

Please sign in to comment.