diff --git a/crates/oxc_semantic/src/builder.rs b/crates/oxc_semantic/src/builder.rs index a1715dcb1eb07..47a9f04954985 100644 --- a/crates/oxc_semantic/src/builder.rs +++ b/crates/oxc_semantic/src/builder.rs @@ -1830,6 +1830,14 @@ impl<'a> SemanticBuilder<'a> { AstKind::TSInterfaceHeritage(_) => { self.current_reference_flags = ReferenceFlags::Type; } + AstKind::TSPropertySignature(signature) => { + if signature.key.is_expression() { + // interface A { [prop]: string } + // ^^^^^ The property can reference value or [`SymbolFlags::TypeImport`] symbol + self.current_reference_flags = + ReferenceFlags::Read | ReferenceFlags::TSTypeQuery; // TODO: Should use another flag + } + } AstKind::TSTypeQuery(_) => { // type A = typeof a; // ^^^^^^^^ @@ -1962,8 +1970,10 @@ impl<'a> SemanticBuilder<'a> { } } AstKind::MemberExpression(_) + | AstKind::ExportNamedDeclaration(_) | AstKind::TSTypeQuery(_) - | AstKind::ExportNamedDeclaration(_) => { + // Clear the reference flags that are set in AstKind::PropertySignature + | AstKind::PropertyKey(_) => { self.current_reference_flags = ReferenceFlags::empty(); } AstKind::AssignmentTarget(_) => self.current_reference_flags -= ReferenceFlags::Write, diff --git a/crates/oxc_semantic/tests/fixtures/oxc/type-declarations/signatures/property-with-type-import.snap b/crates/oxc_semantic/tests/fixtures/oxc/type-declarations/signatures/property-with-type-import.snap new file mode 100644 index 0000000000000..9b43e0cc37ae2 --- /dev/null +++ b/crates/oxc_semantic/tests/fixtures/oxc/type-declarations/signatures/property-with-type-import.snap @@ -0,0 +1,64 @@ +--- +source: crates/oxc_semantic/tests/main.rs +input_file: crates/oxc_semantic/tests/fixtures/oxc/type-declarations/signatures/property-with-type-import.ts +--- +[ + { + "children": [ + { + "children": [], + "flags": "ScopeFlags(StrictMode)", + "id": 1, + "node": "TSTypeAliasDeclaration", + "symbols": [] + }, + { + "children": [], + "flags": "ScopeFlags(StrictMode)", + "id": 2, + "node": "TSInterfaceDeclaration", + "symbols": [] + } + ], + "flags": "ScopeFlags(StrictMode | Top)", + "id": 0, + "node": "Program", + "symbols": [ + { + "flags": "SymbolFlags(TypeImport)", + "id": 0, + "name": "X", + "node": "ImportDefaultSpecifier", + "references": [ + { + "flags": "ReferenceFlags(Type | TSTypeQuery)", + "id": 0, + "name": "X", + "node_id": 15 + } + ] + }, + { + "flags": "SymbolFlags(TypeAlias)", + "id": 1, + "name": "B", + "node": "TSTypeAliasDeclaration", + "references": [ + { + "flags": "ReferenceFlags(Type)", + "id": 1, + "name": "B", + "node_id": 19 + } + ] + }, + { + "flags": "SymbolFlags(Export | Interface)", + "id": 2, + "name": "A", + "node": "TSInterfaceDeclaration", + "references": [] + } + ] + } +] diff --git a/crates/oxc_semantic/tests/fixtures/oxc/type-declarations/signatures/property-with-type-import.ts b/crates/oxc_semantic/tests/fixtures/oxc/type-declarations/signatures/property-with-type-import.ts new file mode 100644 index 0000000000000..da4d768c6ba68 --- /dev/null +++ b/crates/oxc_semantic/tests/fixtures/oxc/type-declarations/signatures/property-with-type-import.ts @@ -0,0 +1,7 @@ +import type X from 'mod'; + +type B = number; + +export interface A { + [X]: B +} \ No newline at end of file diff --git a/crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaration/signatures/property-computed-name.snap b/crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaration/signatures/property-computed-name.snap index adeb38b62edf7..14f6fb3ef86e0 100644 --- a/crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaration/signatures/property-computed-name.snap +++ b/crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaration/signatures/property-computed-name.snap @@ -31,7 +31,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/type-declaratio "node": "VariableDeclarator(x)", "references": [ { - "flags": "ReferenceFlags(Read)", + "flags": "ReferenceFlags(Read | TSTypeQuery)", "id": 0, "name": "x", "node_id": 14