@@ -387,6 +387,7 @@ namespace ts.FindAllReferences {
387
387
symbol : Symbol ;
388
388
exportInfo : ExportInfo ;
389
389
}
390
+
390
391
/**
391
392
* Given a local reference, we might notice that it's an import/export and recursively search for references of that.
392
393
* If at an import, look locally for the symbol it imports.
@@ -398,7 +399,7 @@ namespace ts.FindAllReferences {
398
399
return comingFromExport ? getExport ( ) : getExport ( ) || getImport ( ) ;
399
400
400
401
function getExport ( ) : ExportedSymbol | ImportedSymbol | undefined {
401
- const { parent } = node ;
402
+ const parent = node . parent ! ;
402
403
if ( symbol . flags & SymbolFlags . Export ) {
403
404
if ( parent . kind === SyntaxKind . PropertyAccessExpression ) {
404
405
// When accessing an export of a JS module, there's no alias. The symbol will still be flagged as an export even though we're at the use.
@@ -414,8 +415,8 @@ namespace ts.FindAllReferences {
414
415
}
415
416
}
416
417
else {
417
- const exportNode = parent . kind === SyntaxKind . VariableDeclaration ? getAncestor ( parent , SyntaxKind . VariableStatement ) : parent ;
418
- if ( hasModifier ( exportNode , ModifierFlags . Export ) ) {
418
+ const exportNode = getExportNode ( parent ) ;
419
+ if ( exportNode && hasModifier ( exportNode , ModifierFlags . Export ) ) {
419
420
if ( exportNode . kind === SyntaxKind . ImportEqualsDeclaration && ( exportNode as ImportEqualsDeclaration ) . moduleReference === node ) {
420
421
// We're at `Y` in `export import X = Y`. This is not the exported symbol, the left-hand-side is. So treat this as an import statement.
421
422
if ( comingFromExport ) {
@@ -492,6 +493,16 @@ namespace ts.FindAllReferences {
492
493
}
493
494
}
494
495
496
+ // If a reference is a variable declaration, the exported node would be the variable statement.
497
+ function getExportNode ( parent : Node ) : Node | undefined {
498
+ if ( parent . kind === SyntaxKind . VariableDeclaration ) {
499
+ const p = parent as ts . VariableDeclaration ;
500
+ return p . parent . kind === ts . SyntaxKind . CatchClause ? undefined : p . parent . parent . kind === SyntaxKind . VariableStatement ? p . parent . parent : undefined ;
501
+ } else {
502
+ return parent ;
503
+ }
504
+ }
505
+
495
506
function isNodeImport ( node : Node ) : { isNamedImport : boolean } | undefined {
496
507
const { parent } = node ;
497
508
switch ( parent . kind ) {
0 commit comments