diff --git a/src/services/importTracker.ts b/src/services/importTracker.ts index 316d3874fb40e..1ed555e91a559 100644 --- a/src/services/importTracker.ts +++ b/src/services/importTracker.ts @@ -44,9 +44,11 @@ import { isImportCall, isImportEqualsDeclaration, isImportTypeNode, + isIndexedAccessTypeNode, isInJSFile, isJSDocCallbackTag, isJSDocTypedefTag, + isLiteralTypeNode, isModuleExportsAccessExpression, isNamedExports, isNamespaceExport, @@ -355,6 +357,12 @@ function getSearchesFromDirectImports(directImports: Importer[], exportSymbol: S singleReferences.push(firstIdentifier); } } + else if ( + isIndexedAccessTypeNode(decl.parent) && isLiteralTypeNode(decl.parent.indexType) && + isStringLiteral(decl.parent.indexType.literal) && decl.parent.indexType.literal.text === symbolName(exportSymbol) + ) { + singleReferences.push(decl.parent.indexType.literal); + } else if (exportKind === ExportKind.ExportEquals) { singleReferences.push(decl.argument.literal); } diff --git a/tests/baselines/reference/findAllReferencesIndexedAccessOnImportType1.baseline.jsonc b/tests/baselines/reference/findAllReferencesIndexedAccessOnImportType1.baseline.jsonc new file mode 100644 index 0000000000000..c64aaf29a9ea1 --- /dev/null +++ b/tests/baselines/reference/findAllReferencesIndexedAccessOnImportType1.baseline.jsonc @@ -0,0 +1,109 @@ +// === findAllReferences === +// === /tests/cases/fourslash/foo.ts === +// <|export const /*FIND ALL REFS*/[|{| isWriteAccess: true, isDefinition: true |}foo|] = 1;|> + +// === /tests/cases/fourslash/imports.d.ts === +// import * as $0 from "./bar"; +// +// declare global { +// const foo: typeof import("./foo")["[|foo|]"]; +// const bar: typeof import("./bar")["bar"]; +// } +// +// export {}; + + // === Definitions === + // === /tests/cases/fourslash/foo.ts === + // <|export const /*FIND ALL REFS*/[|foo|] = 1;|> + + // === Details === + [ + { + "containerKind": "", + "containerName": "", + "kind": "const", + "name": "const foo: 1", + "displayParts": [ + { + "text": "const", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "foo", + "kind": "localName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "1", + "kind": "stringLiteral" + } + ] + } + ] + + + +// === findAllReferences === +// === /tests/cases/fourslash/bar.ts === +// <|export const /*FIND ALL REFS*/[|{| isWriteAccess: true, isDefinition: true |}bar|] = 1;|> + +// === /tests/cases/fourslash/imports.d.ts === +// import * as $0 from "./bar"; +// +// declare global { +// const foo: typeof import("./foo")["foo"]; +// const bar: typeof import("./bar")["[|[|bar|]|]"]; +// } +// +// export {}; + + // === Definitions === + // === /tests/cases/fourslash/bar.ts === + // <|export const /*FIND ALL REFS*/[|bar|] = 1;|> + + // === Details === + [ + { + "containerKind": "", + "containerName": "", + "kind": "const", + "name": "const bar: 1", + "displayParts": [ + { + "text": "const", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "bar", + "kind": "localName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "1", + "kind": "stringLiteral" + } + ] + } + ] \ No newline at end of file diff --git a/tests/cases/fourslash/findAllReferencesIndexedAccessOnImportType1.ts b/tests/cases/fourslash/findAllReferencesIndexedAccessOnImportType1.ts new file mode 100644 index 0000000000000..84e4e1cd1180c --- /dev/null +++ b/tests/cases/fourslash/findAllReferencesIndexedAccessOnImportType1.ts @@ -0,0 +1,23 @@ +/// + +// @module: commonjs + +// https://github.com/microsoft/TypeScript/issues/62541 + +// @filename: imports.d.ts +//// import * as $0 from "./bar"; +//// +//// declare global { +//// const foo: typeof import("./foo")["foo"]; +//// const bar: typeof import("./bar")["bar"]; +//// } +//// +//// export {}; + +// @filename: foo.ts +//// export const /*1*/foo = 1; + +// @filename: bar.ts +//// export const /*2*/bar = 1; + +verify.baselineFindAllReferences("1", "2");