Skip to content

Commit

Permalink
fix(typescript): replace assertion failures with unexpected token dia…
Browse files Browse the repository at this point in the history
…gnostics
  • Loading branch information
strager committed Dec 28, 2023
1 parent 4e488d3 commit 79478c8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/quick-lint-js/fe/parse-statement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6301,11 +6301,13 @@ void Parser::parse_and_visit_declare_statement(
this->parse_and_visit_declare_global(v, declare_context);
break;

// declare: // Label.
// declare: // Label.
// declare();
// export declare export // Invalid?
case Token_Type::colon:
case Token_Type::left_paren:
default:
QLJS_ASSERT(false);
QLJS_PARSER_UNIMPLEMENTED();
break;
}
}
Expand Down
15 changes: 15 additions & 0 deletions test/test-parse-typescript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,21 @@ TEST_F(Test_Parse_TypeScript, unicode_next_line_is_whitespace) {
typescript_options);
EXPECT_THAT(v.variable_uses, ElementsAreArray({u8"x"_sv, u8"y"_sv}));
}

// These examples used to crash with assertion failures.
TEST_F(Test_Parse_TypeScript, no_crash) {
for (String8_View code : {
u8"export declare:"_sv,
u8"export declare export"_sv,
u8"export declare()"_sv,
}) {
Spy_Visitor v;
Padded_String code_string(code);
Parser p(&code_string, &v, typescript_options);
// Should not crash:
p.parse_and_visit_module_catching_fatal_parse_errors(v);
}
}
}
}

Expand Down

0 comments on commit 79478c8

Please sign in to comment.