@@ -4614,7 +4614,6 @@ namespace ts {
4614
4614
let symbolKind = getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar ( symbol , symbolFlags , location ) ;
4615
4615
let hasAddedSymbolInfo : boolean ;
4616
4616
const isThisExpression = location . kind === SyntaxKind . ThisKeyword && isExpression ( location ) ;
4617
- const isConstructor = location . kind === SyntaxKind . ConstructorKeyword ;
4618
4617
let type : Type ;
4619
4618
4620
4619
// Class at constructor site need to be shown as constructor apart from property,method, vars
@@ -4625,12 +4624,7 @@ namespace ts {
4625
4624
}
4626
4625
4627
4626
let signature : Signature ;
4628
- type = isThisExpression
4629
- ? typeChecker . getTypeAtLocation ( location )
4630
- : isConstructor
4631
- // For constructor, get type of the class.
4632
- ? typeChecker . getTypeOfSymbolAtLocation ( symbol . parent , location )
4633
- : typeChecker . getTypeOfSymbolAtLocation ( symbol , location ) ;
4627
+ type = isThisExpression ? typeChecker . getTypeAtLocation ( location ) : typeChecker . getTypeOfSymbolAtLocation ( symbol , location ) ;
4634
4628
if ( type ) {
4635
4629
if ( location . parent && location . parent . kind === SyntaxKind . PropertyAccessExpression ) {
4636
4630
const right = ( < PropertyAccessExpression > location . parent ) . name ;
@@ -6067,11 +6061,9 @@ namespace ts {
6067
6061
return getReferencesForSuperKeyword ( node ) ;
6068
6062
}
6069
6063
6070
- const isConstructor = node . kind === SyntaxKind . ConstructorKeyword ;
6071
-
6072
6064
// `getSymbolAtLocation` normally returns the symbol of the class when given the constructor keyword,
6073
6065
// so we have to specify that we want the constructor symbol.
6074
- let symbol = isConstructor ? node . parent . symbol : typeChecker . getSymbolAtLocation ( node ) ;
6066
+ const symbol = typeChecker . getSymbolAtLocation ( node ) ;
6075
6067
6076
6068
if ( ! symbol && node . kind === SyntaxKind . StringLiteral ) {
6077
6069
return getReferencesForStringLiteral ( < StringLiteral > node , sourceFiles ) ;
@@ -6097,8 +6089,7 @@ namespace ts {
6097
6089
6098
6090
// Get the text to search for.
6099
6091
// Note: if this is an external module symbol, the name doesn't include quotes.
6100
- const nameSymbol = isConstructor ? symbol . parent : symbol ; // A constructor is referenced using the name of its class.
6101
- const declaredName = stripQuotes ( getDeclaredName ( typeChecker , nameSymbol , node ) ) ;
6092
+ const declaredName = stripQuotes ( getDeclaredName ( typeChecker , symbol , node ) ) ;
6102
6093
6103
6094
// Try to get the smallest valid scope that we can limit our search to;
6104
6095
// otherwise we'll need to search globally (i.e. include each file).
@@ -6112,7 +6103,7 @@ namespace ts {
6112
6103
getReferencesInNode ( scope , symbol , declaredName , node , searchMeaning , findInStrings , findInComments , result , symbolToIndex ) ;
6113
6104
}
6114
6105
else {
6115
- const internedName = isConstructor ? declaredName : getInternedName ( symbol , node , declarations ) ;
6106
+ const internedName = getInternedName ( symbol , node , declarations ) ;
6116
6107
for ( const sourceFile of sourceFiles ) {
6117
6108
cancellationToken . throwIfCancellationRequested ( ) ;
6118
6109
@@ -6145,7 +6136,7 @@ namespace ts {
6145
6136
} ;
6146
6137
}
6147
6138
6148
- function getAliasSymbolForPropertyNameSymbol ( symbol : Symbol , location : Node ) : Symbol {
6139
+ function getAliasSymbolForPropertyNameSymbol ( symbol : Symbol , location : Node ) : Symbol | undefined {
6149
6140
if ( symbol . flags & SymbolFlags . Alias ) {
6150
6141
// Default import get alias
6151
6142
const defaultImport = getDeclarationOfKind ( symbol , SyntaxKind . ImportClause ) ;
@@ -6171,6 +6162,10 @@ namespace ts {
6171
6162
return undefined ;
6172
6163
}
6173
6164
6165
+ function followAliasIfNecessary ( symbol : Symbol , location : Node ) : Symbol {
6166
+ return getAliasSymbolForPropertyNameSymbol ( symbol , location ) || symbol ;
6167
+ }
6168
+
6174
6169
function getPropertySymbolOfDestructuringAssignment ( location : Node ) {
6175
6170
return isArrayLiteralOrObjectLiteralDestructuringPattern ( location . parent . parent ) &&
6176
6171
typeChecker . getPropertySymbolOfDestructuringAssignment ( < Identifier > location ) ;
@@ -6434,7 +6429,8 @@ namespace ts {
6434
6429
if ( referenceSymbol ) {
6435
6430
const referenceSymbolDeclaration = referenceSymbol . valueDeclaration ;
6436
6431
const shorthandValueSymbol = typeChecker . getShorthandAssignmentValueSymbol ( referenceSymbolDeclaration ) ;
6437
- const relatedSymbol = getRelatedSymbol ( searchSymbols , referenceSymbol , referenceLocation ) ;
6432
+ const relatedSymbol = getRelatedSymbol ( searchSymbols , referenceSymbol , referenceLocation ,
6433
+ /*searchLocationIsConstructor*/ searchLocation . kind === SyntaxKind . ConstructorKeyword ) ;
6438
6434
6439
6435
if ( relatedSymbol ) {
6440
6436
const referencedSymbol = getReferencedSymbol ( relatedSymbol ) ;
@@ -6461,23 +6457,19 @@ namespace ts {
6461
6457
6462
6458
/** Adds references when a constructor is used with `new this()` in its own class and `super()` calls in subclasses. */
6463
6459
function findAdditionalConstructorReferences ( referenceSymbol : Symbol , referenceLocation : Node ) : void {
6464
- const searchClassSymbol = searchSymbol . parent ;
6465
- Debug . assert ( isClassLike ( searchClassSymbol . valueDeclaration ) ) ;
6460
+ Debug . assert ( isClassLike ( searchSymbol . valueDeclaration ) ) ;
6466
6461
6467
6462
const referenceClass = referenceLocation . parent ;
6468
- if ( referenceSymbol === searchClassSymbol && isClassLike ( referenceClass ) ) {
6463
+ if ( referenceSymbol === searchSymbol && isClassLike ( referenceClass ) ) {
6464
+ Debug . assert ( referenceClass . name === referenceLocation ) ;
6469
6465
// This is the class declaration containing the constructor.
6470
- const calls = findOwnConstructorCalls ( referenceSymbol , < ClassLikeDeclaration > referenceClass ) ;
6471
- addReferences ( calls ) ;
6466
+ addReferences ( findOwnConstructorCalls ( referenceSymbol , referenceClass ) ) ;
6472
6467
}
6473
6468
else {
6474
6469
// If this class appears in `extends C`, then the extending class' "super" calls are references.
6475
6470
const classExtending = tryGetClassExtendingIdentifier ( referenceLocation ) ;
6476
- if ( classExtending && isClassLike ( classExtending ) ) {
6477
- if ( getRelatedSymbol ( [ searchClassSymbol ] , referenceSymbol , referenceLocation ) ) {
6478
- const supers = superConstructorAccesses ( classExtending ) ;
6479
- addReferences ( supers ) ;
6480
- }
6471
+ if ( classExtending && isClassLike ( classExtending ) && followAliasIfNecessary ( referenceSymbol , referenceLocation ) === searchSymbol ) {
6472
+ addReferences ( superConstructorAccesses ( classExtending ) ) ;
6481
6473
}
6482
6474
}
6483
6475
}
@@ -6915,21 +6907,17 @@ namespace ts {
6915
6907
}
6916
6908
}
6917
6909
6918
- function getRelatedSymbol ( searchSymbols : Symbol [ ] , referenceSymbol : Symbol , referenceLocation : Node ) : Symbol | undefined {
6910
+ function getRelatedSymbol ( searchSymbols : Symbol [ ] , referenceSymbol : Symbol , referenceLocation : Node , searchLocationIsConstructor : boolean ) : Symbol | undefined {
6919
6911
if ( contains ( searchSymbols , referenceSymbol ) ) {
6920
- return referenceSymbol ;
6912
+ // If we are searching for constructor uses, they must be 'new' expressions.
6913
+ return ! ( searchLocationIsConstructor && ! isNewExpressionTarget ( referenceLocation ) ) && referenceSymbol ;
6921
6914
}
6922
6915
6923
6916
// If the reference symbol is an alias, check if what it is aliasing is one of the search
6924
6917
// symbols but by looking up for related symbol of this alias so it can handle multiple level of indirectness.
6925
6918
const aliasSymbol = getAliasSymbolForPropertyNameSymbol ( referenceSymbol , referenceLocation ) ;
6926
6919
if ( aliasSymbol ) {
6927
- return getRelatedSymbol ( searchSymbols , aliasSymbol , referenceLocation ) ;
6928
- }
6929
-
6930
- // If we are in a constructor and we didn't find the symbol yet, we should try looking for the constructor instead.
6931
- if ( isNewExpressionTarget ( referenceLocation ) && referenceSymbol . members && referenceSymbol . members [ "__constructor" ] ) {
6932
- return getRelatedSymbol ( searchSymbols , referenceSymbol . members [ "__constructor" ] , referenceLocation . parent ) ;
6920
+ return getRelatedSymbol ( searchSymbols , aliasSymbol , referenceLocation , searchLocationIsConstructor ) ;
6933
6921
}
6934
6922
6935
6923
// If the reference location is in an object literal, try to get the contextual type for the
0 commit comments