Skip to content

Commit 48971b1

Browse files
committed
refactor: use getExportsOfModule for export= namespace symbol resolution
Replace direct exports Map access with TypeScript's official API for more robust export= namespace + ES6 import support.
1 parent e97a7e9 commit 48971b1

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/services/findAllReferences.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,11 +1017,20 @@ export namespace Core {
10171017

10181018
// Handle export = namespace case where ES6 import cannot resolve the symbol
10191019
if (!symbol && isIdentifier(node) && isImportSpecifier(node.parent)) {
1020-
const importDeclaration = findAncestor(node, isImportDeclaration);
1021-
if (importDeclaration && isImportDeclaration(importDeclaration) && importDeclaration.moduleSpecifier) {
1022-
const moduleSymbol = checker.getSymbolAtLocation(importDeclaration.moduleSpecifier);
1023-
if (moduleSymbol && moduleSymbol.exports) {
1024-
symbol = moduleSymbol.exports.get(node.escapedText);
1020+
const spec = node.parent;
1021+
// Get the imported name: for 'import { foo as bar }', use 'foo'; for 'import { foo }', use 'foo'
1022+
const importedName = spec.propertyName && isIdentifier(spec.propertyName)
1023+
? spec.propertyName.escapedText
1024+
: spec.name.escapedText;
1025+
const importDecl = findAncestor(spec, isImportDeclaration);
1026+
const moduleSymbol = importDecl?.moduleSpecifier ? checker.getSymbolAtLocation(importDecl.moduleSpecifier) : undefined;
1027+
if (moduleSymbol) {
1028+
// Use TypeScript's official getExportsOfModule API for robust symbol resolution
1029+
// This handles complex export= namespace cases and internal resolution rules
1030+
const moduleExports = checker.getExportsOfModule(moduleSymbol);
1031+
const exportedSymbol = find(moduleExports, s => s.escapedName === importedName);
1032+
if (exportedSymbol) {
1033+
symbol = exportedSymbol;
10251034
}
10261035
}
10271036
}

0 commit comments

Comments
 (0)