@@ -5624,8 +5624,14 @@ namespace ts {
5624
5624
} ;
5625
5625
}
5626
5626
5627
- function getImportOrExportSpecifierForPropertyNameSymbol ( symbol : Symbol , location : Node ) : ImportOrExportSpecifier {
5627
+ function getAliasSymbolForPropertyNameSymbol ( symbol : Symbol , location : Node ) : Symbol {
5628
5628
if ( symbol . flags & SymbolFlags . Alias ) {
5629
+ // Default import get alias
5630
+ const defaultImport = getDeclarationOfKind ( symbol , SyntaxKind . ImportClause ) ;
5631
+ if ( defaultImport ) {
5632
+ return typeChecker . getAliasedSymbol ( symbol ) ;
5633
+ }
5634
+
5629
5635
const importOrExportSpecifier = < ImportOrExportSpecifier > forEach ( symbol . declarations ,
5630
5636
declaration => ( declaration . kind === SyntaxKind . ImportSpecifier ||
5631
5637
declaration . kind === SyntaxKind . ExportSpecifier ) ? declaration : undefined ) ;
@@ -5634,7 +5640,22 @@ namespace ts {
5634
5640
( ! importOrExportSpecifier . propertyName ||
5635
5641
// export {a as class } where a is location
5636
5642
importOrExportSpecifier . propertyName === location ) ) {
5637
- return importOrExportSpecifier ;
5643
+ // If Import specifier -> get alias
5644
+ // else Export specifier -> get local target
5645
+ return importOrExportSpecifier . kind === SyntaxKind . ImportSpecifier ?
5646
+ typeChecker . getAliasedSymbol ( symbol ) :
5647
+ typeChecker . getExportSpecifierLocalTargetSymbol ( importOrExportSpecifier ) ;
5648
+ }
5649
+ }
5650
+ return undefined ;
5651
+ }
5652
+
5653
+ function getPropertySymbolOfDestructuringAssignment ( location : Node ) {
5654
+ if ( isArrayLiteralOrObjectLiteralDestructuringPattern ( location . parent . parent ) ) {
5655
+ // Do work to determine if this is a property symbol corresponding to the search symbol
5656
+ const typeOfObjectLiteral = typeChecker . getTypeOfArrayLiteralOrObjectLiteralDestructuringAssignment ( < Expression > location . parent . parent ) ;
5657
+ if ( typeOfObjectLiteral ) {
5658
+ return typeChecker . getPropertyOfType ( typeOfObjectLiteral , ( < Identifier > location ) . text ) ;
5638
5659
}
5639
5660
}
5640
5661
return undefined ;
@@ -6105,12 +6126,9 @@ namespace ts {
6105
6126
// If the location is name of property symbol from object literal destructuring pattern
6106
6127
// Search the property symbol
6107
6128
// for ( { property: p2 } of elems) { }
6108
- if ( isNameOfPropertyAssignment ( location ) &&
6109
- location . parent . kind !== SyntaxKind . ShorthandPropertyAssignment &&
6110
- isArrayLiteralOrObjectLiteralDestructuringPattern ( location . parent . parent ) ) {
6111
- const typeOfObjectLiteral = typeChecker . getTypeOfArrayLiteralOrObjectLiteralDestructuringAssignment ( < Expression > location . parent . parent ) ;
6112
- if ( typeOfObjectLiteral ) {
6113
- const propertySymbol = typeChecker . getPropertyOfType ( typeOfObjectLiteral , ( < Identifier > location ) . text ) ;
6129
+ if ( isNameOfPropertyAssignment ( location ) && location . parent . kind !== SyntaxKind . ShorthandPropertyAssignment ) {
6130
+ const propertySymbol = getPropertySymbolOfDestructuringAssignment ( location ) ;
6131
+ if ( propertySymbol ) {
6114
6132
result . push ( propertySymbol ) ;
6115
6133
}
6116
6134
}
@@ -6126,12 +6144,9 @@ namespace ts {
6126
6144
//// export {a as somethingElse}
6127
6145
//// We want the *local* declaration of 'a' as declared in the import,
6128
6146
//// *not* as declared within "mod" (or farther)
6129
- const importOrExportSpecifier = getImportOrExportSpecifierForPropertyNameSymbol ( symbol , location ) ;
6130
- if ( importOrExportSpecifier || getDeclarationOfKind ( symbol , SyntaxKind . ImportClause ) ) {
6131
- result = result . concat ( populateSearchSymbolSet (
6132
- ! importOrExportSpecifier || importOrExportSpecifier . kind === SyntaxKind . ImportSpecifier ?
6133
- typeChecker . getAliasedSymbol ( symbol ) :
6134
- typeChecker . getExportSpecifierLocalTargetSymbol ( importOrExportSpecifier ) , location ) ) ;
6147
+ const aliasSymbol = getAliasSymbolForPropertyNameSymbol ( symbol , location ) ;
6148
+ if ( aliasSymbol ) {
6149
+ result = result . concat ( populateSearchSymbolSet ( aliasSymbol , location ) ) ;
6135
6150
}
6136
6151
6137
6152
// If the location is in a context sensitive location (i.e. in an object literal) try
@@ -6257,15 +6272,11 @@ namespace ts {
6257
6272
6258
6273
// If the reference symbol is an alias, check if what it is aliasing is one of the search
6259
6274
// symbols but by looking up for related symbol of this alias so it can handle multiple level of indirectness.
6260
- const importOrExportSpecifier = getImportOrExportSpecifierForPropertyNameSymbol ( referenceSymbol , referenceLocation ) ;
6261
- if ( importOrExportSpecifier || getDeclarationOfKind ( referenceSymbol , SyntaxKind . ImportClause ) ) {
6262
- const aliasedSymbol = ! importOrExportSpecifier || importOrExportSpecifier . kind === SyntaxKind . ImportSpecifier ?
6263
- typeChecker . getAliasedSymbol ( referenceSymbol ) :
6264
- typeChecker . getExportSpecifierLocalTargetSymbol ( importOrExportSpecifier ) ;
6265
- return getRelatedSymbol ( searchSymbols , aliasedSymbol , referenceLocation ) ;
6275
+ const aliasSymbol = getAliasSymbolForPropertyNameSymbol ( referenceSymbol , referenceLocation ) ;
6276
+ if ( aliasSymbol ) {
6277
+ return getRelatedSymbol ( searchSymbols , aliasSymbol , referenceLocation ) ;
6266
6278
}
6267
6279
6268
-
6269
6280
// If the reference location is in an object literal, try to get the contextual type for the
6270
6281
// object literal, lookup the property symbol in the contextual type, and use this symbol to
6271
6282
// compare to our searchSymbol
@@ -6282,15 +6293,9 @@ namespace ts {
6282
6293
// Get the property symbol from the object literal's type and look if thats the search symbol
6283
6294
// In below eg. get 'property' from type of elems iterating type
6284
6295
// for ( { property: p2 } of elems) { }
6285
- if ( isArrayLiteralOrObjectLiteralDestructuringPattern ( referenceLocation . parent . parent ) ) {
6286
- // Do work to determine if this is a property symbol corresponding to the search symbol
6287
- const typeOfObjectLiteral = typeChecker . getTypeOfArrayLiteralOrObjectLiteralDestructuringAssignment ( < Expression > referenceLocation . parent . parent ) ;
6288
- if ( typeOfObjectLiteral ) {
6289
- const propertySymbol = typeChecker . getPropertyOfType ( typeOfObjectLiteral , ( < Identifier > referenceLocation ) . text ) ;
6290
- if ( searchSymbols . indexOf ( propertySymbol ) >= 0 ) {
6291
- return propertySymbol ;
6292
- }
6293
- }
6296
+ const propertySymbol = getPropertySymbolOfDestructuringAssignment ( referenceLocation ) ;
6297
+ if ( propertySymbol && searchSymbols . indexOf ( propertySymbol ) >= 0 ) {
6298
+ return propertySymbol ;
6294
6299
}
6295
6300
}
6296
6301
0 commit comments