fix(semantic): generic passed to typeof not counted as a reference (#4499)

This commit is contained in:
Dunqing 2024-07-27 12:16:25 +08:00 committed by GitHub
parent 40cafb8c61
commit ef0e953702
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 21 additions and 2 deletions

View file

@ -1787,6 +1787,11 @@ impl<'a> SemanticBuilder<'a> {
// ^^^^^^^^
self.current_reference_flag = ReferenceFlag::Read | ReferenceFlag::TSTypeQuery;
}
AstKind::TSTypeParameterInstantiation(_) => {
// type A<T> = typeof a<T>;
// ^^^ avoid treat T as a value and TSTypeQuery
self.current_reference_flag -= ReferenceFlag::Read | ReferenceFlag::TSTypeQuery;
}
AstKind::TSTypeName(_) => {
match self.nodes.parent_kind(self.current_node_id) {
Some(

View file

@ -52,7 +52,14 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/instantiation-e
"id": 4,
"name": "T",
"node": "TSTypeParameter",
"references": []
"references": [
{
"flag": "ReferenceFlag(Type)",
"id": 3,
"name": "T",
"node_id": 31
}
]
}
]
}

View file

@ -52,7 +52,14 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio
"id": 4,
"name": "T",
"node": "TSTypeParameter",
"references": []
"references": [
{
"flag": "ReferenceFlag(Type)",
"id": 3,
"name": "T",
"node_id": 33
}
]
}
]
}