diff --git a/crates/oxc_semantic/src/builder.rs b/crates/oxc_semantic/src/builder.rs index b6211dea1..0c17738e7 100644 --- a/crates/oxc_semantic/src/builder.rs +++ b/crates/oxc_semantic/src/builder.rs @@ -436,6 +436,7 @@ 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. @@ -443,6 +444,15 @@ impl<'a> SemanticBuilder<'a> { *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 diff --git a/crates/oxc_semantic/tests/fixtures/typescript-eslint/import/type-default-value.snap b/crates/oxc_semantic/tests/fixtures/typescript-eslint/import/type-default-value.snap index 61035781c..5e76a73d3 100644 --- a/crates/oxc_semantic/tests/fixtures/typescript-eslint/import/type-default-value.snap +++ b/crates/oxc_semantic/tests/fixtures/typescript-eslint/import/type-default-value.snap @@ -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)", diff --git a/crates/oxc_semantic/tests/fixtures/typescript-eslint/import/type-inline-value.snap b/crates/oxc_semantic/tests/fixtures/typescript-eslint/import/type-inline-value.snap index bfa74a794..8558f7674 100644 --- a/crates/oxc_semantic/tests/fixtures/typescript-eslint/import/type-inline-value.snap +++ b/crates/oxc_semantic/tests/fixtures/typescript-eslint/import/type-inline-value.snap @@ -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)", diff --git a/crates/oxc_semantic/tests/fixtures/typescript-eslint/import/type-named-value.snap b/crates/oxc_semantic/tests/fixtures/typescript-eslint/import/type-named-value.snap index 989e6b9f6..400b586b4 100644 --- a/crates/oxc_semantic/tests/fixtures/typescript-eslint/import/type-named-value.snap +++ b/crates/oxc_semantic/tests/fixtures/typescript-eslint/import/type-named-value.snap @@ -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)",