mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
Add logic in checker for getting type of export assignments and imports
This commit is contained in:
parent
5574b58d64
commit
834a6f71c1
@ -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 {
|
||||
|
||||
@ -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)
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user