Skip to content

Commit e2303b1

Browse files
committed
Clean up the language service aliases to check functions
1 parent 3b78377 commit e2303b1

File tree

1 file changed

+24
-35
lines changed

1 file changed

+24
-35
lines changed

src/compiler/checker.ts

Lines changed: 24 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,20 @@ namespace ts {
5959
isArgumentsSymbol: symbol => symbol === argumentsSymbol,
6060
getDiagnostics,
6161
getGlobalDiagnostics,
62-
getTypeOfSymbolAtLocation,
62+
63+
// Get the narrowed type of symbol at given location instead of just getting
64+
// the type of the symbol.
65+
// eg.
66+
// function foo(a: string | number) {
67+
// if (typeof a === "string") {
68+
// a/**/
69+
// }
70+
// }
71+
// getTypeOfSymbol for a would return type of parameter symbol string | number
72+
// Unless we provide location /**/, checker wouldn't know how to narrow the type
73+
// By using getNarrowedTypeOfSymbol would return string since it would be able to narrow
74+
// it by typeguard in the if true condition
75+
getTypeOfSymbolAtLocation: getNarrowedTypeOfSymbol,
6376
getDeclaredTypeOfSymbol,
6477
getPropertiesOfType,
6578
getPropertyOfType,
@@ -69,7 +82,7 @@ namespace ts {
6982
getSymbolsInScope,
7083
getSymbolAtLocation,
7184
getShorthandAssignmentValueSymbol,
72-
getTypeAtLocation,
85+
getTypeAtLocation: getTypeOfNode,
7386
typeToString,
7487
getSymbolDisplayBuilder,
7588
symbolToString,
@@ -4226,7 +4239,7 @@ namespace ts {
42264239
// Callers should first ensure this by calling isTypeNode
42274240
case SyntaxKind.Identifier:
42284241
case SyntaxKind.QualifiedName:
4229-
let symbol = getSymbolInfo(node);
4242+
let symbol = getSymbolAtLocation(node);
42304243
return symbol && getDeclaredTypeOfSymbol(symbol);
42314244
default:
42324245
return unknownType;
@@ -5883,30 +5896,6 @@ namespace ts {
58835896
}
58845897
}
58855898

5886-
function getSymbolAtLocation(node: Node): Symbol {
5887-
return getSymbolInfo(node);
5888-
}
5889-
5890-
function getTypeAtLocation(node: Node): Type {
5891-
return getTypeOfNode(node);
5892-
}
5893-
5894-
function getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type {
5895-
// Get the narrowed type of symbol at given location instead of just getting
5896-
// the type of the symbol.
5897-
// eg.
5898-
// function foo(a: string | number) {
5899-
// if (typeof a === "string") {
5900-
// a/**/
5901-
// }
5902-
// }
5903-
// getTypeOfSymbol for a would return type of parameter symbol string | number
5904-
// Unless we provide location /**/, checker wouldn't know how to narrow the type
5905-
// By using getNarrowedTypeOfSymbol would return string since it would be able to narrow
5906-
// it by typeguard in the if true condition
5907-
return getNarrowedTypeOfSymbol(symbol, node);
5908-
}
5909-
59105899
// Get the narrowed type of a given symbol at a given location
59115900
function getNarrowedTypeOfSymbol(symbol: Symbol, node: Node) {
59125901
let type = getTypeOfSymbol(symbol);
@@ -10136,7 +10125,7 @@ namespace ts {
1013610125
}
1013710126
else {
1013810127
checkTypeAssignableTo(typePredicate.type,
10139-
getTypeAtLocation(node.parameters[typePredicate.parameterIndex]),
10128+
getTypeOfNode(node.parameters[typePredicate.parameterIndex]),
1014010129
typePredicateNode.type);
1014110130
}
1014210131
}
@@ -13758,7 +13747,7 @@ namespace ts {
1375813747
return undefined;
1375913748
}
1376013749

13761-
function getSymbolInfo(node: Node) {
13750+
function getSymbolAtLocation(node: Node) {
1376213751
if (isInsideWithStatementBody(node)) {
1376313752
// We cannot answer semantic questions within a with block, do not proceed any further
1376413753
return undefined;
@@ -13778,7 +13767,7 @@ namespace ts {
1377813767
else if (node.parent.kind === SyntaxKind.BindingElement &&
1377913768
node.parent.parent.kind === SyntaxKind.ObjectBindingPattern &&
1378013769
node === (<BindingElement>node.parent).propertyName) {
13781-
let typeOfPattern = getTypeAtLocation(node.parent.parent);
13770+
let typeOfPattern = getTypeOfNode(node.parent.parent);
1378213771
let propertyDeclaration = typeOfPattern && getPropertyOfType(typeOfPattern, (<Identifier>node).text);
1378313772

1378413773
if (propertyDeclaration) {
@@ -13861,24 +13850,24 @@ namespace ts {
1386113850
}
1386213851

1386313852
if (isTypeDeclaration(node)) {
13864-
// In this case, we call getSymbolOfNode instead of getSymbolInfo because it is a declaration
13853+
// In this case, we call getSymbolOfNode instead of getSymbolAtLocation because it is a declaration
1386513854
let symbol = getSymbolOfNode(node);
1386613855
return getDeclaredTypeOfSymbol(symbol);
1386713856
}
1386813857

1386913858
if (isTypeDeclarationName(node)) {
13870-
let symbol = getSymbolInfo(node);
13859+
let symbol = getSymbolAtLocation(node);
1387113860
return symbol && getDeclaredTypeOfSymbol(symbol);
1387213861
}
1387313862

1387413863
if (isDeclaration(node)) {
13875-
// In this case, we call getSymbolOfNode instead of getSymbolInfo because it is a declaration
13864+
// In this case, we call getSymbolOfNode instead of getSymbolAtLocation because it is a declaration
1387613865
let symbol = getSymbolOfNode(node);
1387713866
return getTypeOfSymbol(symbol);
1387813867
}
1387913868

1388013869
if (isDeclarationName(node)) {
13881-
let symbol = getSymbolInfo(node);
13870+
let symbol = getSymbolAtLocation(node);
1388213871
return symbol && getTypeOfSymbol(symbol);
1388313872
}
1388413873

@@ -13887,7 +13876,7 @@ namespace ts {
1388713876
}
1388813877

1388913878
if (isInRightSideOfImportOrExportAssignment(<Identifier>node)) {
13890-
let symbol = getSymbolInfo(node);
13879+
let symbol = getSymbolAtLocation(node);
1389113880
let declaredType = symbol && getDeclaredTypeOfSymbol(symbol);
1389213881
return declaredType !== unknownType ? declaredType : getTypeOfSymbol(symbol);
1389313882
}

0 commit comments

Comments
 (0)