@@ -356,8 +356,7 @@ module ts {
356
356
var node = < ImportDeclaration > getDeclarationOfKind ( symbol , SyntaxKind . ImportDeclaration ) ;
357
357
var target = node . externalModuleName ?
358
358
resolveExternalModuleName ( node , node . externalModuleName ) :
359
- resolveEntityName ( node , node . entityName , node . entityName . kind === SyntaxKind . QualifiedName ?
360
- SymbolFlags . Value | SymbolFlags . Type | SymbolFlags . Namespace : SymbolFlags . Namespace ) ;
359
+ getSymbolOfPartOfRightHandSideOfImport ( node . entityName , node ) ;
361
360
if ( links . target === resolvingSymbol ) {
362
361
links . target = target || unknownSymbol ;
363
362
}
@@ -371,6 +370,33 @@ module ts {
371
370
return links . target ;
372
371
}
373
372
373
+ // This function is only for imports with entity names
374
+ function getSymbolOfPartOfRightHandSideOfImport ( entityName : EntityName , importDeclaration ?: ImportDeclaration ) : Symbol {
375
+ if ( ! importDeclaration ) {
376
+ importDeclaration = getAncestor ( entityName , SyntaxKind . ImportDeclaration ) ;
377
+ Debug . assert ( importDeclaration ) ;
378
+ }
379
+ // There are three things we might try to look for. In the following examples,
380
+ // the search term is enclosed in |...|:
381
+ //
382
+ // import a = |b|; // Namespace
383
+ // import a = |b.c|; // Value, type, namespace
384
+ // import a = |b.c|.d; // Namespace
385
+ if ( entityName . kind === SyntaxKind . Identifier && isRightSideOfQualifiedNameOrPropertyAccess ( entityName ) ) {
386
+ entityName = entityName . parent ;
387
+ }
388
+ // Check for case 1 and 3 in the above example
389
+ if ( entityName . kind === SyntaxKind . Identifier || entityName . parent . kind === SyntaxKind . QualifiedName ) {
390
+ return resolveEntityName ( importDeclaration , entityName , SymbolFlags . Namespace ) ;
391
+ }
392
+ else {
393
+ // Case 2 in above example
394
+ // entityName.kind could be a QualifiedName or a Missing identifier
395
+ Debug . assert ( entityName . parent . kind === SyntaxKind . ImportDeclaration ) ;
396
+ return resolveEntityName ( importDeclaration , entityName , SymbolFlags . Value | SymbolFlags . Type | SymbolFlags . Namespace ) ;
397
+ }
398
+ }
399
+
374
400
function getFullyQualifiedName ( symbol : Symbol ) {
375
401
return symbol . parent ? getFullyQualifiedName ( symbol . parent ) + "." + symbolToString ( symbol ) : symbolToString ( symbol ) ;
376
402
}
@@ -6894,18 +6920,10 @@ module ts {
6894
6920
6895
6921
if ( isInRightSideOfImportOrExportAssignment ( node ) ) {
6896
6922
var symbol : Symbol ;
6897
- if ( node . parent . kind === SyntaxKind . ExportAssignment ) {
6898
- symbol = getSymbolInfo ( node ) ;
6899
- }
6900
- else {
6901
- // It is an import statement
6902
- if ( isRightSideOfQualifiedNameOrPropertyAccess ( node ) ) {
6903
- node = node . parent ;
6904
- }
6905
- // We include all declaration spaces for aliases. This is likely too inclusive, as the rules
6906
- // for resolving aliases are quite particular. Ideally this should reuse the logic in resolveAlias.
6907
- symbol = resolveEntityName ( node , node , SymbolFlags . Value | SymbolFlags . Type | SymbolFlags . Namespace | SymbolFlags . Import ) ;
6908
- }
6923
+ symbol = node . parent . kind === SyntaxKind . ExportAssignment
6924
+ ? getSymbolInfo ( node )
6925
+ : getSymbolOfPartOfRightHandSideOfImport ( node ) ;
6926
+
6909
6927
var declaredType = getDeclaredTypeOfSymbol ( symbol ) ;
6910
6928
return declaredType !== unknownType ? declaredType : getTypeOfSymbol ( symbol ) ;
6911
6929
}
0 commit comments