mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-09 16:39:46 -05:00
Support resolution of any part of the RHS of an import
This commit is contained in:
@@ -356,8 +356,7 @@ module ts {
|
||||
var node = <ImportDeclaration>getDeclarationOfKind(symbol, SyntaxKind.ImportDeclaration);
|
||||
var target = node.externalModuleName ?
|
||||
resolveExternalModuleName(node, node.externalModuleName) :
|
||||
resolveEntityName(node, node.entityName, node.entityName.kind === SyntaxKind.QualifiedName ?
|
||||
SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace : SymbolFlags.Namespace);
|
||||
getSymbolOfPartOfRightHandSideOfImport(node.entityName, node);
|
||||
if (links.target === resolvingSymbol) {
|
||||
links.target = target || unknownSymbol;
|
||||
}
|
||||
@@ -371,6 +370,33 @@ module ts {
|
||||
return links.target;
|
||||
}
|
||||
|
||||
// This function is only for imports with entity names
|
||||
function getSymbolOfPartOfRightHandSideOfImport(entityName: EntityName, importDeclaration?: ImportDeclaration): Symbol {
|
||||
if (!importDeclaration) {
|
||||
importDeclaration = getAncestor(entityName, SyntaxKind.ImportDeclaration);
|
||||
Debug.assert(importDeclaration);
|
||||
}
|
||||
// There are three things we might try to look for. In the following examples,
|
||||
// the search term is enclosed in |...|:
|
||||
//
|
||||
// import a = |b|; // Namespace
|
||||
// import a = |b.c|; // Value, type, namespace
|
||||
// import a = |b.c|.d; // Namespace
|
||||
if (entityName.kind === SyntaxKind.Identifier && isRightSideOfQualifiedNameOrPropertyAccess(entityName)) {
|
||||
entityName = entityName.parent;
|
||||
}
|
||||
// Check for case 1 and 3 in the above example
|
||||
if (entityName.kind === SyntaxKind.Identifier || entityName.parent.kind === SyntaxKind.QualifiedName) {
|
||||
return resolveEntityName(importDeclaration, entityName, SymbolFlags.Namespace);
|
||||
}
|
||||
else {
|
||||
// Case 2 in above example
|
||||
// entityName.kind could be a QualifiedName or a Missing identifier
|
||||
Debug.assert(entityName.parent.kind === SyntaxKind.ImportDeclaration);
|
||||
return resolveEntityName(importDeclaration, entityName, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace);
|
||||
}
|
||||
}
|
||||
|
||||
function getFullyQualifiedName(symbol: Symbol) {
|
||||
return symbol.parent ? getFullyQualifiedName(symbol.parent) + "." + symbolToString(symbol) : symbolToString(symbol);
|
||||
}
|
||||
@@ -6894,18 +6920,10 @@ module ts {
|
||||
|
||||
if (isInRightSideOfImportOrExportAssignment(node)) {
|
||||
var symbol: Symbol;
|
||||
if (node.parent.kind === SyntaxKind.ExportAssignment) {
|
||||
symbol = getSymbolInfo(node);
|
||||
}
|
||||
else {
|
||||
// It is an import statement
|
||||
if (isRightSideOfQualifiedNameOrPropertyAccess(node)) {
|
||||
node = node.parent;
|
||||
}
|
||||
// We include all declaration spaces for aliases. This is likely too inclusive, as the rules
|
||||
// for resolving aliases are quite particular. Ideally this should reuse the logic in resolveAlias.
|
||||
symbol = resolveEntityName(node, node, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Import);
|
||||
}
|
||||
symbol = node.parent.kind === SyntaxKind.ExportAssignment
|
||||
? getSymbolInfo(node)
|
||||
: getSymbolOfPartOfRightHandSideOfImport(node);
|
||||
|
||||
var declaredType = getDeclaredTypeOfSymbol(symbol);
|
||||
return declaredType !== unknownType ? declaredType : getTypeOfSymbol(symbol);
|
||||
}
|
||||
|
||||
@@ -19,11 +19,11 @@ module B {
|
||||
|
||||
import Y = A; // Alias only for module A
|
||||
>Y : typeof A
|
||||
>A : A
|
||||
>A : typeof A
|
||||
|
||||
import Z = A.X; // Alias for both type and member A.X
|
||||
>Z : X
|
||||
>A : A
|
||||
>A : typeof A
|
||||
>X : X
|
||||
|
||||
var v: Z = Z;
|
||||
|
||||
@@ -15,6 +15,6 @@ module B {
|
||||
|
||||
import Y = A;
|
||||
>Y : Y
|
||||
>A : number
|
||||
>A : A
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user