Skip to content

Commit c3c44dc

Browse files
committed
Some renaming and added comments as per feedback
1 parent 1939c7f commit c3c44dc

4 files changed

Lines changed: 30 additions & 18 deletions

File tree

src/compiler/checker.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ module ts {
9393
getIndexTypeOfType,
9494
getReturnTypeOfSignature,
9595
getSymbolsInScope,
96-
getSymbolInfoOfLocation,
96+
getSymbolAtLocation,
9797
getShorthandAssignmentValueSymbol,
98-
getTypeOfLocation,
98+
getTypeAtLocation,
9999
typeToString,
100100
getSymbolDisplayBuilder,
101101
symbolToString,
@@ -4398,18 +4398,30 @@ module ts {
43984398
ts.forEach(containerNodes, node => { getTypeOfNode(node); });
43994399
}
44004400

4401-
function getSymbolInfoOfLocation(node: Node): Symbol {
4401+
function getSymbolAtLocation(node: Node): Symbol {
44024402
resolveLocation(node);
44034403
return getSymbolInfo(node);
44044404
}
44054405

4406-
function getTypeOfLocation(node: Node): Type {
4406+
function getTypeAtLocation(node: Node): Type {
44074407
resolveLocation(node);
44084408
return getTypeOfNode(node);
44094409
}
44104410

44114411
function getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type {
44124412
resolveLocation(node);
4413+
// Get the narrowed type of symbol at given location instead of just getting
4414+
// the type of the symbol.
4415+
// eg.
4416+
// function foo(a: string | number) {
4417+
// if (typeof a === "string") {
4418+
// a/**/
4419+
// }
4420+
// }
4421+
// getTypeOfSymbol for a would return type of parameter symbol string | number
4422+
// Unless we provide location /**/, checker wouldn't know how to narrow the type
4423+
// By using getNarrowedTypeOfSymbol would return string since it would be able to narrow
4424+
// it by typeguard in the if true condition
44134425
return getNarrowedTypeOfSymbol(symbol, node);
44144426
}
44154427

src/compiler/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -891,9 +891,9 @@ module ts {
891891
getIndexTypeOfType(type: Type, kind: IndexKind): Type;
892892
getReturnTypeOfSignature(signature: Signature): Type;
893893
getSymbolsInScope(location: Node, meaning: SymbolFlags): Symbol[];
894-
getSymbolInfoOfLocation(node: Node): Symbol;
894+
getSymbolAtLocation(node: Node): Symbol;
895895
getShorthandAssignmentValueSymbol(location: Node): Symbol;
896-
getTypeOfLocation(node: Node): Type;
896+
getTypeAtLocation(node: Node): Type;
897897
typeToString(type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): string;
898898
symbolToString(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): string;
899899
getSymbolDisplayBuilder(): SymbolDisplayBuilder;

src/services/services.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2428,7 +2428,7 @@ module ts {
24282428
isMemberCompletion = true;
24292429

24302430
if (node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.QualifiedName || node.kind === SyntaxKind.PropertyAccessExpression) {
2431-
var symbol = typeInfoResolver.getSymbolInfoOfLocation(node);
2431+
var symbol = typeInfoResolver.getSymbolAtLocation(node);
24322432

24332433
// This is an alias, follow what it aliases
24342434
if (symbol && symbol.flags & SymbolFlags.Import) {
@@ -2445,7 +2445,7 @@ module ts {
24452445
}
24462446
}
24472447

2448-
var type = typeInfoResolver.getTypeOfLocation(node);
2448+
var type = typeInfoResolver.getTypeAtLocation(node);
24492449
if (type) {
24502450
// Filter private properties
24512451
forEach(type.getApparentProperties(), symbol => {
@@ -3089,7 +3089,7 @@ module ts {
30893089
displayParts.push(punctuationPart(SyntaxKind.CloseParenToken));
30903090
}
30913091
else {
3092-
var internalAliasSymbol = typeResolver.getSymbolInfoOfLocation(importDeclaration.moduleReference);
3092+
var internalAliasSymbol = typeResolver.getSymbolAtLocation(importDeclaration.moduleReference);
30933093
if (internalAliasSymbol) {
30943094
displayParts.push(spacePart());
30953095
displayParts.push(operatorPart(SyntaxKind.EqualsToken));
@@ -3199,7 +3199,7 @@ module ts {
31993199
return undefined;
32003200
}
32013201

3202-
var symbol = typeInfoResolver.getSymbolInfoOfLocation(node);
3202+
var symbol = typeInfoResolver.getSymbolAtLocation(node);
32033203
if (!symbol) {
32043204
// Try getting just type at this position and show
32053205
switch (node.kind) {
@@ -3209,7 +3209,7 @@ module ts {
32093209
case SyntaxKind.ThisKeyword:
32103210
case SyntaxKind.SuperKeyword:
32113211
// For the identifiers/this/super etc get the type at position
3212-
var type = typeInfoResolver.getTypeOfLocation(node);
3212+
var type = typeInfoResolver.getTypeAtLocation(node);
32133213
if (type) {
32143214
return {
32153215
kind: ScriptElementKind.unknown,
@@ -3326,7 +3326,7 @@ module ts {
33263326
return undefined;
33273327
}
33283328

3329-
var symbol = typeInfoResolver.getSymbolInfoOfLocation(node);
3329+
var symbol = typeInfoResolver.getSymbolAtLocation(node);
33303330

33313331
// Could not find a symbol e.g. node is string or number keyword,
33323332
// or the symbol was an internal symbol and does not have a declaration e.g. undefined symbol
@@ -3958,7 +3958,7 @@ module ts {
39583958
return getReferencesForSuperKeyword(node);
39593959
}
39603960

3961-
var symbol = typeInfoResolver.getSymbolInfoOfLocation(node);
3961+
var symbol = typeInfoResolver.getSymbolAtLocation(node);
39623962

39633963
// Could not find a symbol e.g. unknown identifier
39643964
if (!symbol) {
@@ -4210,7 +4210,7 @@ module ts {
42104210
return;
42114211
}
42124212

4213-
var referenceSymbol = typeInfoResolver.getSymbolInfoOfLocation(referenceLocation);
4213+
var referenceSymbol = typeInfoResolver.getSymbolAtLocation(referenceLocation);
42144214
if (referenceSymbol) {
42154215
var referenceSymbolDeclaration = referenceSymbol.valueDeclaration;
42164216
var shorthandValueSymbol = typeInfoResolver.getShorthandAssignmentValueSymbol(referenceSymbolDeclaration);
@@ -4443,7 +4443,7 @@ module ts {
44434443

44444444
function getPropertySymbolFromTypeReference(typeReference: TypeReferenceNode) {
44454445
if (typeReference) {
4446-
var type = typeInfoResolver.getTypeOfLocation(typeReference);
4446+
var type = typeInfoResolver.getTypeAtLocation(typeReference);
44474447
if (type) {
44484448
var propertySymbol = typeInfoResolver.getPropertyOfType(type, propertyName);
44494449
if (propertySymbol) {
@@ -4967,7 +4967,7 @@ module ts {
49674967
// Only walk into nodes that intersect the requested span.
49684968
if (node && span.intersectsWith(node.getStart(), node.getWidth())) {
49694969
if (node.kind === SyntaxKind.Identifier && node.getWidth() > 0) {
4970-
var symbol = typeInfoResolver.getSymbolInfoOfLocation(node);
4970+
var symbol = typeInfoResolver.getSymbolAtLocation(node);
49714971
if (symbol) {
49724972
var type = classifySymbol(symbol, getMeaningFromLocation(node));
49734973
if (type) {
@@ -5396,7 +5396,7 @@ module ts {
53965396

53975397
// Can only rename an identifier.
53985398
if (node && node.kind === SyntaxKind.Identifier) {
5399-
var symbol = typeInfoResolver.getSymbolInfoOfLocation(node);
5399+
var symbol = typeInfoResolver.getSymbolAtLocation(node);
54005400

54015401
// Only allow a symbol to be renamed if it actually has at least one declaration.
54025402
if (symbol && symbol.getDeclarations() && symbol.getDeclarations().length > 0) {

src/services/signatureHelp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ module ts.SignatureHelp {
457457

458458
var invocation = argumentListInfo.invocation;
459459
var callTarget = getInvokedExpression(invocation)
460-
var callTargetSymbol = typeInfoResolver.getSymbolInfoOfLocation(callTarget);
460+
var callTargetSymbol = typeInfoResolver.getSymbolAtLocation(callTarget);
461461
var callTargetDisplayParts = callTargetSymbol && symbolToDisplayParts(typeInfoResolver, callTargetSymbol, /*enclosingDeclaration*/ undefined, /*meaning*/ undefined);
462462
var items: SignatureHelpItem[] = map(candidates, candidateSignature => {
463463
var signatureHelpParameters: SignatureHelpParameter[];

0 commit comments

Comments
 (0)