Skip to content

Commit

Permalink
fix(typescript): parse 'typeof string' correctly in type
Browse files Browse the repository at this point in the history
  • Loading branch information
strager committed Dec 28, 2023
1 parent b0b3aef commit c2bcea2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
2 changes: 2 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ Semantic Versioning.
errors.
* `export default` inside a `declare module` no longer falsely reports
[E0715][] ("cannot use multiple `export default` statements in one module").
* `typeof` in types now supports variables named `boolean`, `string`, and some
other names.

## 2.18.0 (2023-11-03)

Expand Down
6 changes: 6 additions & 0 deletions src/quick-lint-js/fe/parse-type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ void Parser::parse_and_visit_typescript_type_expression_no_scope(
case Token_Type::kw_async:
case Token_Type::kw_await:
case Token_Type::kw_bigint:
case Token_Type::kw_boolean:
case Token_Type::kw_break:
case Token_Type::kw_case:
case Token_Type::kw_catch:
Expand Down Expand Up @@ -601,10 +602,12 @@ void Parser::parse_and_visit_typescript_type_expression_no_scope(
case Token_Type::kw_intrinsic:
case Token_Type::kw_is:
case Token_Type::kw_keyof:
case Token_Type::kw_let:
case Token_Type::kw_module:
case Token_Type::kw_namespace:
case Token_Type::kw_new:
case Token_Type::kw_null:
case Token_Type::kw_number:
case Token_Type::kw_object:
case Token_Type::kw_of:
case Token_Type::kw_out:
Expand All @@ -614,6 +617,8 @@ void Parser::parse_and_visit_typescript_type_expression_no_scope(
case Token_Type::kw_return:
case Token_Type::kw_satisfies:
case Token_Type::kw_set:
case Token_Type::kw_static:
case Token_Type::kw_string:
case Token_Type::kw_super:
case Token_Type::kw_switch:
case Token_Type::kw_symbol:
Expand All @@ -628,6 +633,7 @@ void Parser::parse_and_visit_typescript_type_expression_no_scope(
case Token_Type::kw_void:
case Token_Type::kw_while:
case Token_Type::kw_with:
case Token_Type::kw_yield:
v.visit_variable_use(this->peek().identifier_name());
this->skip();
break;
Expand Down
21 changes: 6 additions & 15 deletions test/test-parse-typescript-type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1433,21 +1433,12 @@ TEST_F(Test_Parse_TypeScript_Type, typeof) {
EXPECT_THAT(p.variable_uses, ElementsAreArray({u8"ns"}));
}

for (String8 keyword :
keywords - typescript_special_type_keywords -
strict_only_reserved_keywords -
Dirty_Set<String8>{
u8"this",
// This list is derived experimentally from TypeScript version
// 4.7.4. Some of these seem arbitrary. *shrug*
u8"boolean",
u8"import",
u8"let",
u8"number",
u8"static",
u8"string",
u8"yield",
}) {
for (String8 keyword : keywords - typescript_special_type_keywords -
strict_only_reserved_keywords -
Dirty_Set<String8>{
u8"import",
u8"this",
}) {
{
Padded_String code(u8"typeof " + keyword);
SCOPED_TRACE(code);
Expand Down

0 comments on commit c2bcea2

Please sign in to comment.