Skip to content

Commit 1c56b98

Browse files
committed
Fix findAllReferences for export= namespace with ES6 imports
1 parent 7956c00 commit 1c56b98

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/services/findAllReferences.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ import {
135135
isIdentifier,
136136
isIdentifierPart,
137137
isImportMeta,
138+
isImportDeclaration,
138139
isImportOrExportSpecifier,
139140
isImportSpecifier,
140141
isImportTypeNode,
@@ -1012,7 +1013,18 @@ export namespace Core {
10121013

10131014
const checker = program.getTypeChecker();
10141015
// constructors should use the class symbol, detected by name, if present
1015-
const symbol = checker.getSymbolAtLocation(isConstructorDeclaration(node) && node.parent.name || node);
1016+
let symbol = checker.getSymbolAtLocation(isConstructorDeclaration(node) && node.parent.name || node);
1017+
1018+
// Handle export = namespace case where ES6 import cannot resolve the symbol
1019+
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);
1025+
}
1026+
}
1027+
}
10161028

10171029
// Could not find a symbol e.g. unknown identifier
10181030
if (!symbol) {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @module: commonjs
4+
5+
// @Filename: /mod.d.ts
6+
////export = React;
7+
////
8+
////declare namespace React {
9+
//// function /*1*/lazy(): void;
10+
////}
11+
12+
// @Filename: /index.ts
13+
////import { /*2*/lazy } from "./mod"
14+
/////*3*/lazy();
15+
16+
verify.baselineFindAllReferences("1", "2", "3");

0 commit comments

Comments
 (0)