Skip to content

Commit 49e78f6

Browse files
author
Andy
authored
findAllRefs: Fix bug for export not at top-level of a module/namespace (#21846)
1 parent 425a418 commit 49e78f6

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/services/importTracker.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,9 @@ namespace ts.FindAllReferences {
606606
}
607607

608608
export function getExportInfo(exportSymbol: Symbol, exportKind: ExportKind, checker: TypeChecker): ExportInfo | undefined {
609-
const exportingModuleSymbol = checker.getMergedSymbol(exportSymbol.parent); // Need to get merged symbol in case there's an augmentation.
609+
const moduleSymbol = exportSymbol.parent;
610+
if (!moduleSymbol) return undefined; // This can happen if an `export` is not at the top-level (which is a compile error).
611+
const exportingModuleSymbol = checker.getMergedSymbol(moduleSymbol); // Need to get merged symbol in case there's an augmentation.
610612
// `export` may appear in a namespace. In that case, just rely on global search.
611613
return isExternalModuleSymbol(exportingModuleSymbol) ? { exportingModuleSymbol, exportKind } : undefined;
612614
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////{
4+
//// export const [|{| "isWriteAccess": true, "isDefinition": true |}x|] = 0;
5+
//// [|x|];
6+
////}
7+
8+
verify.singleReferenceGroup("const x: 0");

0 commit comments

Comments
 (0)