Skip to content

Commit 834a6f7

Browse files
committed
Add logic in checker for getting type of export assignments and imports
1 parent 5574b58 commit 834a6f7

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

src/compiler/checker.ts

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6737,6 +6737,21 @@ module ts {
67376737
return false;
67386738
}
67396739

6740+
function isInRightSideOfImportOrExportAssignment(node: EntityName) {
6741+
while (node.parent.kind === SyntaxKind.QualifiedName) {
6742+
node = node.parent;
6743+
}
6744+
6745+
if (node.parent.kind === SyntaxKind.ImportDeclaration) {
6746+
return (<ImportDeclaration>node.parent).entityName === node;
6747+
}
6748+
if (node.parent.kind === SyntaxKind.ExportAssignment) {
6749+
return (<ExportAssignment>node.parent).exportName === node;
6750+
}
6751+
6752+
return false;
6753+
}
6754+
67406755
function isRightSideOfQualifiedNameOrPropertyAccess(node: Node) {
67416756
return (node.parent.kind === SyntaxKind.QualifiedName || node.parent.kind === SyntaxKind.PropertyAccess) &&
67426757
(<QualifiedName>node.parent).right === node;
@@ -6747,6 +6762,11 @@ module ts {
67476762
return getSymbolOfNode(identifier.parent);
67486763
}
67496764

6765+
if (identifier.parent.kind === SyntaxKind.ExportAssignment) {
6766+
return resolveEntityName(/*location*/ identifier.parent.parent, identifier,
6767+
/*all meanings*/ SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Import);
6768+
}
6769+
67506770
var entityName: Node = identifier;
67516771
while (isRightSideOfQualifiedNameOrPropertyAccess(entityName))
67526772
entityName = entityName.parent;
@@ -6855,13 +6875,23 @@ module ts {
68556875
return getTypeOfSymbol(symbol);
68566876
}
68576877

6858-
if (node.kind === SyntaxKind.Identifier && node.parent.kind === SyntaxKind.ExportAssignment) {
6859-
var symbol = getSymbolInfo(node);
6878+
if (isInRightSideOfImportOrExportAssignment(node)) {
6879+
var symbol: Symbol;
6880+
if (node.parent.kind === SyntaxKind.ExportAssignment) {
6881+
symbol = getSymbolInfo(node);
6882+
}
6883+
else {
6884+
// It is an import statement
6885+
while (node.kind !== SyntaxKind.ImportDeclaration) {
6886+
node = node.parent;
6887+
}
6888+
symbol = getSymbolOfNode(node);
6889+
}
68606890
var declaredType = getDeclaredTypeOfSymbol(symbol);
68616891
return declaredType !== unknownType ? declaredType : getTypeOfSymbol(symbol);
68626892
}
68636893

6864-
Debug.fail("Unhandled case in getTypeOfNode");
6894+
return unknownType;
68656895
}
68666896

68676897
function getTypeOfExpression(expr: Expression): Type {

src/harness/typeWriter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,14 @@ class TypeWriterWalker {
7777
var actualPos = ts.skipTrivia(this.currentSourceFile.text, node.pos);
7878
var lineAndCharacter = this.currentSourceFile.getLineAndCharacterFromPosition(actualPos);
7979
var name = ts.getSourceTextOfNodeFromSourceText(this.currentSourceFile.text, node);
80+
var isUnkownType = (<ts.IntrinsicType>type).intrinsicName === "unknown";
8081

8182
this.results.push({
8283
line: lineAndCharacter.line - 1,
8384
column: lineAndCharacter.character,
8485
syntaxKind: ts.SyntaxKind[node.kind],
8586
identifierName: name,
86-
type: this.checker.typeToString(type)
87+
type: isUnkownType ? name : this.checker.typeToString(type)
8788
});
8889
}
8990

0 commit comments

Comments
 (0)