@@ -586,25 +586,28 @@ namespace ts.FindAllReferences.Core {
586
586
}
587
587
else {
588
588
const search = state . createSearch ( node , symbol , /*comingFrom*/ undefined , { allSearchSymbols : node ? populateSearchSymbolSet ( symbol , node , checker , ! ! options . isForRename , ! ! options . providePrefixAndSuffixTextForRename , ! ! options . implementations ) : [ symbol ] } ) ;
589
-
590
- // Try to get the smallest valid scope that we can limit our search to;
591
- // otherwise we'll need to search globally (i.e. include each file).
592
- const scope = getSymbolScope ( symbol ) ;
593
- if ( scope ) {
594
- getReferencesInContainer ( scope , scope . getSourceFile ( ) , search , state , /*addReferencesHere*/ ! ( isSourceFile ( scope ) && ! contains ( sourceFiles , scope ) ) ) ;
595
- }
596
- else {
597
- // Global search
598
- for ( const sourceFile of state . sourceFiles ) {
599
- state . cancellationToken . throwIfCancellationRequested ( ) ;
600
- searchForName ( sourceFile , search , state ) ;
601
- }
602
- }
589
+ getReferencesInContainerOrFiles ( symbol , state , search ) ;
603
590
}
604
591
605
592
return result ;
606
593
}
607
594
595
+ function getReferencesInContainerOrFiles ( symbol : Symbol , state : State , search : Search ) : void {
596
+ // Try to get the smallest valid scope that we can limit our search to;
597
+ // otherwise we'll need to search globally (i.e. include each file).
598
+ const scope = getSymbolScope ( symbol ) ;
599
+ if ( scope ) {
600
+ getReferencesInContainer ( scope , scope . getSourceFile ( ) , search , state , /*addReferencesHere*/ ! ( isSourceFile ( scope ) && ! contains ( state . sourceFiles , scope ) ) ) ;
601
+ }
602
+ else {
603
+ // Global search
604
+ for ( const sourceFile of state . sourceFiles ) {
605
+ state . cancellationToken . throwIfCancellationRequested ( ) ;
606
+ searchForName ( sourceFile , search , state ) ;
607
+ }
608
+ }
609
+ }
610
+
608
611
function getSpecialSearchKind ( node : Node ) : SpecialSearchKind {
609
612
switch ( node . kind ) {
610
613
case SyntaxKind . ConstructorKeyword :
@@ -707,7 +710,6 @@ namespace ts.FindAllReferences.Core {
707
710
constructor (
708
711
readonly sourceFiles : ReadonlyArray < SourceFile > ,
709
712
readonly sourceFilesSet : ReadonlyMap < true > ,
710
- /** True if we're searching for constructor references. */
711
713
readonly specialSearchKind : SpecialSearchKind ,
712
714
readonly checker : TypeChecker ,
713
715
readonly cancellationToken : CancellationToken ,
@@ -1293,6 +1295,7 @@ namespace ts.FindAllReferences.Core {
1293
1295
const classExtending = tryGetClassByExtendingIdentifier ( referenceLocation ) ;
1294
1296
if ( classExtending ) {
1295
1297
findSuperConstructorAccesses ( classExtending , pusher ( ) ) ;
1298
+ findInheritedConstructorReferences ( classExtending , state ) ;
1296
1299
}
1297
1300
}
1298
1301
}
@@ -1325,35 +1328,44 @@ namespace ts.FindAllReferences.Core {
1325
1328
* Reference the constructor and all calls to `new this()`.
1326
1329
*/
1327
1330
function findOwnConstructorReferences ( classSymbol : Symbol , sourceFile : SourceFile , addNode : ( node : Node ) => void ) : void {
1328
- for ( const decl of classSymbol . members ! . get ( InternalSymbolName . Constructor ) ! . declarations ) {
1329
- const ctrKeyword = findChildOfKind ( decl , SyntaxKind . ConstructorKeyword , sourceFile ) ! ;
1330
- Debug . assert ( decl . kind === SyntaxKind . Constructor && ! ! ctrKeyword ) ;
1331
- addNode ( ctrKeyword ) ;
1332
- }
1333
-
1334
- classSymbol . exports ! . forEach ( member => {
1335
- const decl = member . valueDeclaration ;
1336
- if ( decl && decl . kind === SyntaxKind . MethodDeclaration ) {
1337
- const body = ( < MethodDeclaration > decl ) . body ;
1338
- if ( body ) {
1339
- forEachDescendantOfKind ( body , SyntaxKind . ThisKeyword , thisKeyword => {
1340
- if ( isNewExpressionTarget ( thisKeyword ) ) {
1341
- addNode ( thisKeyword ) ;
1342
- }
1343
- } ) ;
1344
- }
1331
+ const constructorSymbol = getClassConstructorSymbol ( classSymbol ) ;
1332
+ if ( constructorSymbol ) {
1333
+ for ( const decl of constructorSymbol . declarations ) {
1334
+ const ctrKeyword = findChildOfKind ( decl , SyntaxKind . ConstructorKeyword , sourceFile ) ! ;
1335
+ Debug . assert ( decl . kind === SyntaxKind . Constructor && ! ! ctrKeyword ) ;
1336
+ addNode ( ctrKeyword ) ;
1345
1337
}
1346
- } ) ;
1338
+ }
1339
+
1340
+ if ( classSymbol . exports ) {
1341
+ classSymbol . exports . forEach ( member => {
1342
+ const decl = member . valueDeclaration ;
1343
+ if ( decl && decl . kind === SyntaxKind . MethodDeclaration ) {
1344
+ const body = ( < MethodDeclaration > decl ) . body ;
1345
+ if ( body ) {
1346
+ forEachDescendantOfKind ( body , SyntaxKind . ThisKeyword , thisKeyword => {
1347
+ if ( isNewExpressionTarget ( thisKeyword ) ) {
1348
+ addNode ( thisKeyword ) ;
1349
+ }
1350
+ } ) ;
1351
+ }
1352
+ }
1353
+ } ) ;
1354
+ }
1355
+ }
1356
+
1357
+ function getClassConstructorSymbol ( classSymbol : Symbol ) : Symbol | undefined {
1358
+ return classSymbol . members && classSymbol . members . get ( InternalSymbolName . Constructor ) ;
1347
1359
}
1348
1360
1349
1361
/** Find references to `super` in the constructor of an extending class. */
1350
- function findSuperConstructorAccesses ( cls : ClassLikeDeclaration , addNode : ( node : Node ) => void ) : void {
1351
- const ctr = cls . symbol . members ! . get ( InternalSymbolName . Constructor ) ;
1352
- if ( ! ctr ) {
1362
+ function findSuperConstructorAccesses ( classDeclaration : ClassLikeDeclaration , addNode : ( node : Node ) => void ) : void {
1363
+ const constructor = getClassConstructorSymbol ( classDeclaration . symbol ) ;
1364
+ if ( ! constructor ) {
1353
1365
return ;
1354
1366
}
1355
1367
1356
- for ( const decl of ctr . declarations ) {
1368
+ for ( const decl of constructor . declarations ) {
1357
1369
Debug . assert ( decl . kind === SyntaxKind . Constructor ) ;
1358
1370
const body = ( < ConstructorDeclaration > decl ) . body ;
1359
1371
if ( body ) {
@@ -1366,6 +1378,17 @@ namespace ts.FindAllReferences.Core {
1366
1378
}
1367
1379
}
1368
1380
1381
+ function hasOwnConstructor ( classDeclaration : ClassLikeDeclaration ) : boolean {
1382
+ return ! ! getClassConstructorSymbol ( classDeclaration . symbol ) ;
1383
+ }
1384
+
1385
+ function findInheritedConstructorReferences ( classDeclaration : ClassLikeDeclaration , state : State ) : void {
1386
+ if ( hasOwnConstructor ( classDeclaration ) ) return ;
1387
+ const classSymbol = classDeclaration . symbol ;
1388
+ const search = state . createSearch ( /*location*/ undefined , classSymbol , /*comingFrom*/ undefined ) ;
1389
+ getReferencesInContainerOrFiles ( classSymbol , state , search ) ;
1390
+ }
1391
+
1369
1392
function addImplementationReferences ( refNode : Node , addReference : ( node : Node ) => void , state : State ) : void {
1370
1393
// Check if we found a function/propertyAssignment/method with an implementation or initializer
1371
1394
if ( isDeclarationName ( refNode ) && isImplementation ( refNode . parent ) ) {
0 commit comments