Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions crates/oxc_semantic/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,13 +436,23 @@ impl<'a> SemanticBuilder<'a> {
references.retain(|(id, flag)| {
if flag.is_type() && symbol_flag.can_be_referenced_by_type()
|| flag.is_value() && symbol_flag.can_be_referenced_by_value()
|| flag.is_ts_type_query() && symbol_flag.is_import()
{
// The non type-only ExportSpecifier can reference a type/value symbol,
// If the symbol is a value symbol and reference flag is not type-only, remove the type flag.
if symbol_flag.is_value() && !flag.is_type_only() {
*self.symbols.references[*id].flag_mut() -= ReferenceFlag::Type;
}

// import type { T } from './mod'; type A = typeof T
// ^ can reference type-only import
// If symbol is type-import, we need to replace the ReferenceFlag::Value with ReferenceFlag::Type
if flag.is_ts_type_query() && symbol_flag.is_type_import() {
let reference_flag = self.symbols.references[*id].flag_mut();
*reference_flag -= ReferenceFlag::Value;
*reference_flag |= ReferenceFlag::Type;
}

self.symbols.references[*id].set_symbol_id(symbol_id);
resolved_references.push(*id);
false
Expand Down Expand Up @@ -1787,6 +1797,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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/import/type-def
"id": 0,
"name": "foo",
"node": "ImportDefaultSpecifier",
"references": []
"references": [
{
"flag": "ReferenceFlag(Type | TSTypeQuery)",
"id": 0,
"name": "foo",
"node_id": 10
}
]
},
{
"flag": "SymbolFlags(TypeAlias)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/import/type-inl
"id": 0,
"name": "foo",
"node": "ImportSpecifier",
"references": []
"references": [
{
"flag": "ReferenceFlag(Type | TSTypeQuery)",
"id": 0,
"name": "foo",
"node_id": 11
}
]
},
{
"flag": "SymbolFlags(TypeAlias)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/import/type-nam
"id": 0,
"name": "foo",
"node": "ImportSpecifier",
"references": []
"references": [
{
"flag": "ReferenceFlag(Type | TSTypeQuery)",
"id": 0,
"name": "foo",
"node_id": 11
}
]
},
{
"flag": "SymbolFlags(TypeAlias)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
}
]
}
Expand Down