Add logic in checker for getting type of export assignments and imports

This commit is contained in:
Jason Freeman 2014-08-14 18:43:36 -07:00
parent 5574b58d64
commit 834a6f71c1
2 changed files with 35 additions and 4 deletions

View File

@ -6737,6 +6737,21 @@ module ts {
return false;
}
function isInRightSideOfImportOrExportAssignment(node: EntityName) {
while (node.parent.kind === SyntaxKind.QualifiedName) {
node = node.parent;
}
if (node.parent.kind === SyntaxKind.ImportDeclaration) {
return (<ImportDeclaration>node.parent).entityName === node;
}
if (node.parent.kind === SyntaxKind.ExportAssignment) {
return (<ExportAssignment>node.parent).exportName === node;
}
return false;
}
function isRightSideOfQualifiedNameOrPropertyAccess(node: Node) {
return (node.parent.kind === SyntaxKind.QualifiedName || node.parent.kind === SyntaxKind.PropertyAccess) &&
(<QualifiedName>node.parent).right === node;
@ -6747,6 +6762,11 @@ module ts {
return getSymbolOfNode(identifier.parent);
}
if (identifier.parent.kind === SyntaxKind.ExportAssignment) {
return resolveEntityName(/*location*/ identifier.parent.parent, identifier,
/*all meanings*/ SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Import);
}
var entityName: Node = identifier;
while (isRightSideOfQualifiedNameOrPropertyAccess(entityName))
entityName = entityName.parent;
@ -6855,13 +6875,23 @@ module ts {
return getTypeOfSymbol(symbol);
}
if (node.kind === SyntaxKind.Identifier && node.parent.kind === SyntaxKind.ExportAssignment) {
var symbol = getSymbolInfo(node);
if (isInRightSideOfImportOrExportAssignment(node)) {
var symbol: Symbol;
if (node.parent.kind === SyntaxKind.ExportAssignment) {
symbol = getSymbolInfo(node);
}
else {
// It is an import statement
while (node.kind !== SyntaxKind.ImportDeclaration) {
node = node.parent;
}
symbol = getSymbolOfNode(node);
}
var declaredType = getDeclaredTypeOfSymbol(symbol);
return declaredType !== unknownType ? declaredType : getTypeOfSymbol(symbol);
}
Debug.fail("Unhandled case in getTypeOfNode");
return unknownType;
}
function getTypeOfExpression(expr: Expression): Type {

View File

@ -77,13 +77,14 @@ class TypeWriterWalker {
var actualPos = ts.skipTrivia(this.currentSourceFile.text, node.pos);
var lineAndCharacter = this.currentSourceFile.getLineAndCharacterFromPosition(actualPos);
var name = ts.getSourceTextOfNodeFromSourceText(this.currentSourceFile.text, node);
var isUnkownType = (<ts.IntrinsicType>type).intrinsicName === "unknown";
this.results.push({
line: lineAndCharacter.line - 1,
column: lineAndCharacter.character,
syntaxKind: ts.SyntaxKind[node.kind],
identifierName: name,
type: this.checker.typeToString(type)
type: isUnkownType ? name : this.checker.typeToString(type)
});
}