Skip to content

Commit 9d2914a

Browse files
committed
Some more getSymbolOfNode changes
1 parent 86d3334 commit 9d2914a

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

src/compiler/checker.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,7 +1278,7 @@ namespace ts {
12781278
isInExternalModule = true;
12791279
// falls through
12801280
case SyntaxKind.ModuleDeclaration:
1281-
const moduleExports = getSymbolOfNode(location)!.exports!;
1281+
const moduleExports = getSymbolOfNode(location as ModuleDeclaration).exports!;
12821282
if (location.kind === SyntaxKind.SourceFile || isAmbientModule(location)) {
12831283

12841284
// It's an external module. First see if the module has an export default and if the local
@@ -1340,7 +1340,7 @@ namespace ts {
13401340
case SyntaxKind.ClassDeclaration:
13411341
case SyntaxKind.ClassExpression:
13421342
case SyntaxKind.InterfaceDeclaration:
1343-
if (result = lookup(getMembersOfSymbol(getSymbolOfNode(location)!), name, meaning & SymbolFlags.Type)) {
1343+
if (result = lookup(getMembersOfSymbol(getSymbolOfNode(location as ClassLikeDeclaration | InterfaceDeclaration)), name, meaning & SymbolFlags.Type)) {
13441344
if (!isTypeParameterSymbolDeclaredInContainer(result, location)) {
13451345
// ignore type parameters not declared in this container
13461346
result = undefined;
@@ -1387,7 +1387,7 @@ namespace ts {
13871387
grandparent = location.parent.parent;
13881388
if (isClassLike(grandparent) || grandparent.kind === SyntaxKind.InterfaceDeclaration) {
13891389
// A reference to this grandparent's type parameters would be an error
1390-
if (result = lookup(getSymbolOfNode(grandparent)!.members!, name, meaning & SymbolFlags.Type)) {
1390+
if (result = lookup(getSymbolOfNode(grandparent as ClassLikeDeclaration | InterfaceDeclaration).members!, name, meaning & SymbolFlags.Type)) {
13911391
error(errorLocation, Diagnostics.A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type);
13921392
return undefined;
13931393
}
@@ -2574,7 +2574,7 @@ namespace ts {
25742574
}
25752575
// falls through
25762576
case SyntaxKind.ModuleDeclaration:
2577-
if (result = callback(getSymbolOfNode(location)!.exports!)) {
2577+
if (result = callback(getSymbolOfNode(location as ModuleDeclaration).exports!)) {
25782578
return result;
25792579
}
25802580
break;
@@ -5036,7 +5036,7 @@ namespace ts {
50365036
const outerAndOwnTypeParameters = appendTypeParameters(outerTypeParameters, getEffectiveTypeParameterDeclarations(<DeclarationWithTypeParameters>node) || emptyArray);
50375037
const thisType = includeThisTypes &&
50385038
(node.kind === SyntaxKind.ClassDeclaration || node.kind === SyntaxKind.ClassExpression || node.kind === SyntaxKind.InterfaceDeclaration) &&
5039-
getDeclaredTypeOfClassOrInterface(getSymbolOfNode(node)!).thisType;
5039+
getDeclaredTypeOfClassOrInterface(getSymbolOfNode(node as ClassLikeDeclaration | InterfaceDeclaration)).thisType;
50405040
return thisType ? append(outerAndOwnTypeParameters, thisType) : outerAndOwnTypeParameters;
50415041
}
50425042
}
@@ -9088,7 +9088,7 @@ namespace ts {
90889088

90899089
function getESSymbolLikeTypeForNode(node: Node) {
90909090
if (isValidESSymbolDeclaration(node)) {
9091-
const symbol = getSymbolOfNode(node)!;
9091+
const symbol = getSymbolOfNode(node);
90929092
const links = getSymbolLinks(symbol);
90939093
return links.uniqueESSymbolType || (links.uniqueESSymbolType = createUniqueESSymbolType(symbol));
90949094
}
@@ -9101,7 +9101,7 @@ namespace ts {
91019101
if (parent && (isClassLike(parent) || parent.kind === SyntaxKind.InterfaceDeclaration)) {
91029102
if (!hasModifier(container, ModifierFlags.Static) &&
91039103
(container.kind !== SyntaxKind.Constructor || isNodeDescendantOf(node, (<ConstructorDeclaration>container).body!))) {
9104-
return getDeclaredTypeOfClassOrInterface(getSymbolOfNode(parent)!).thisType!;
9104+
return getDeclaredTypeOfClassOrInterface(getSymbolOfNode(parent as ClassLikeDeclaration | InterfaceDeclaration)).thisType!;
91059105
}
91069106
}
91079107
error(node, Diagnostics.A_this_type_is_available_only_in_a_non_static_member_of_a_class_or_interface);
@@ -17773,7 +17773,7 @@ namespace ts {
1777317773
if (node.kind === SyntaxKind.ClassDeclaration) {
1777417774
// For a class decorator, the `target` is the type of the class (e.g. the
1777517775
// "static" or "constructor" side of the class)
17776-
const classSymbol = getSymbolOfNode(node)!;
17776+
const classSymbol = getSymbolOfNode(node as ClassDeclaration);
1777717777
return getTypeOfSymbol(classSymbol);
1777817778
}
1777917779

@@ -17782,7 +17782,7 @@ namespace ts {
1778217782
// parameter's containing method.
1778317783
node = node.parent;
1778417784
if (node.kind === SyntaxKind.Constructor) {
17785-
const classSymbol = getSymbolOfNode(node)!;
17785+
const classSymbol = getSymbolOfNode(node as ConstructorDeclaration);
1778617786
return getTypeOfSymbol(classSymbol);
1778717787
}
1778817788
}
@@ -18958,7 +18958,7 @@ namespace ts {
1895818958
return unknownType;
1895918959
}
1896018960
else if (container.kind === SyntaxKind.Constructor) {
18961-
const symbol = getSymbolOfNode(container.parent)!;
18961+
const symbol = getSymbolOfNode(container.parent as ClassLikeDeclaration);
1896218962
return getTypeOfSymbol(symbol);
1896318963
}
1896418964
else {
@@ -20944,7 +20944,7 @@ namespace ts {
2094420944

2094520945
function checkTypeForDuplicateIndexSignatures(node: Node) {
2094620946
if (node.kind === SyntaxKind.InterfaceDeclaration) {
20947-
const nodeSymbol = getSymbolOfNode(node)!;
20947+
const nodeSymbol = getSymbolOfNode(node as InterfaceDeclaration);
2094820948
// in case of merging interface declaration it is possible that we'll enter this check procedure several times for every declaration
2094920949
// to prevent this run check only for the first declaration of a given kind
2095020950
if (nodeSymbol.declarations.length > 0 && nodeSymbol.declarations[0] !== node) {
@@ -24187,7 +24187,7 @@ namespace ts {
2418724187
if (isInstancePropertyWithoutInitializer(member)) {
2418824188
const propName = (<PropertyDeclaration>member).name;
2418924189
if (isIdentifier(propName)) {
24190-
const type = getTypeOfSymbol(getSymbolOfNode(member)); // TODO: GH#18217
24190+
const type = getTypeOfSymbol(getSymbolOfNode(member));
2419124191
if (!(type.flags & TypeFlags.Any || getFalsyFlags(type) & TypeFlags.Undefined)) {
2419224192
if (!constructor || !isPropertyInitializedInConstructor(propName, type, constructor)) {
2419324193
error(member.name, Diagnostics.Property_0_has_no_initializer_and_is_not_definitely_assigned_in_the_constructor, declarationNameToString(propName));
@@ -25412,13 +25412,13 @@ namespace ts {
2541225412

2541325413
switch (location.kind) {
2541425414
case SyntaxKind.ModuleDeclaration:
25415-
copySymbols(getSymbolOfNode(location)!.exports!, meaning & SymbolFlags.ModuleMember);
25415+
copySymbols(getSymbolOfNode(location as ModuleDeclaration).exports!, meaning & SymbolFlags.ModuleMember);
2541625416
break;
2541725417
case SyntaxKind.EnumDeclaration:
25418-
copySymbols(getSymbolOfNode(location)!.exports!, meaning & SymbolFlags.EnumMember);
25418+
copySymbols(getSymbolOfNode(location as EnumDeclaration).exports!, meaning & SymbolFlags.EnumMember);
2541925419
break;
2542025420
case SyntaxKind.ClassExpression:
25421-
const className = (<ClassExpression>location).name;
25421+
const className = (location as ClassExpression).name;
2542225422
if (className) {
2542325423
copySymbol(location.symbol, meaning);
2542425424
}
@@ -25432,11 +25432,11 @@ namespace ts {
2543225432
// (type parameters of classDeclaration/classExpression and interface are in member property of the symbol.
2543325433
// Note: that the memberFlags come from previous iteration.
2543425434
if (!isStatic) {
25435-
copySymbols(getMembersOfSymbol(getSymbolOfNode(location)!), meaning & SymbolFlags.Type);
25435+
copySymbols(getMembersOfSymbol(getSymbolOfNode(location as ClassDeclaration | InterfaceDeclaration)), meaning & SymbolFlags.Type);
2543625436
}
2543725437
break;
2543825438
case SyntaxKind.FunctionExpression:
25439-
const funcName = (<FunctionExpression>location).name;
25439+
const funcName = (location as FunctionExpression).name;
2544025440
if (funcName) {
2544125441
copySymbol(location.symbol, meaning);
2544225442
}
@@ -25488,7 +25488,7 @@ namespace ts {
2548825488
(<NamedDeclaration>name.parent).name === name;
2548925489
}
2549025490

25491-
function isTypeDeclaration(node: Node): boolean {
25491+
function isTypeDeclaration(node: Node): node is TypeParameterDeclaration | ClassDeclaration | InterfaceDeclaration | TypeAliasDeclaration | EnumDeclaration {
2549225492
switch (node.kind) {
2549325493
case SyntaxKind.TypeParameter:
2549425494
case SyntaxKind.ClassDeclaration:
@@ -25864,7 +25864,7 @@ namespace ts {
2586425864

2586525865
if (isTypeDeclaration(node)) {
2586625866
// In this case, we call getSymbolOfNode instead of getSymbolAtLocation because it is a declaration
25867-
const symbol = getSymbolOfNode(node)!;
25867+
const symbol = getSymbolOfNode(node);
2586825868
return getDeclaredTypeOfSymbol(symbol);
2586925869
}
2587025870

src/compiler/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ namespace ts {
10091009
&& node.parent.parent.kind === SyntaxKind.VariableStatement;
10101010
}
10111011

1012-
export function isValidESSymbolDeclaration(node: Node) {
1012+
export function isValidESSymbolDeclaration(node: Node): node is VariableDeclaration | PropertyDeclaration | SignatureDeclaration {
10131013
return isVariableDeclaration(node) ? isConst(node) && isIdentifier(node.name) && isVariableDeclarationInVariableStatement(node) :
10141014
isPropertyDeclaration(node) ? hasReadonlyModifier(node) && hasStaticModifier(node) :
10151015
isPropertySignature(node) && hasReadonlyModifier(node);

0 commit comments

Comments
 (0)