Skip to content

Commit fd8b7f3

Browse files
author
Andy
authored
Remove redundant checks in getNameOfDeclaration (microsoft#25244)
1 parent 1cb691f commit fd8b7f3

File tree

4 files changed

+5
-10
lines changed

4 files changed

+5
-10
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8807,7 +8807,7 @@ namespace ts {
88078807
if (!(getDeclarationModifierFlagsFromSymbol(prop) & ModifierFlags.NonPublicAccessibilityModifier)) {
88088808
let type = getLateBoundSymbol(prop).nameType;
88098809
if (!type && !isKnownSymbol(prop)) {
8810-
const name = getNameOfDeclaration(prop.valueDeclaration);
8810+
const name = prop.valueDeclaration && getNameOfDeclaration(prop.valueDeclaration);
88118811
type = name && isNumericLiteral(name) ? getLiteralType(+name.text) :
88128812
name && name.kind === SyntaxKind.ComputedPropertyName && isNumericLiteral(name.expression) ? getLiteralType(+name.expression.text) :
88138813
getLiteralType(symbolName(prop));
@@ -23244,7 +23244,7 @@ namespace ts {
2324423244
}
2324523245
else {
2324623246
const parameter = local.valueDeclaration && tryGetRootParameterDeclaration(local.valueDeclaration);
23247-
const name = getNameOfDeclaration(local.valueDeclaration);
23247+
const name = local.valueDeclaration && getNameOfDeclaration(local.valueDeclaration);
2324823248
if (parameter && name) {
2324923249
if (!isParameterPropertyDeclaration(parameter) && !parameterIsThisKeyword(parameter) && !isIdentifierThatStartsWithUnderscore(name)) {
2325023250
addDiagnostic(UnusedKind.Parameter, createDiagnosticForNode(name, Diagnostics._0_is_declared_but_its_value_is_never_read, symbolName(local)));
@@ -24541,7 +24541,7 @@ namespace ts {
2454124541
}
2454224542

2454324543
const propDeclaration = prop.valueDeclaration;
24544-
const name = getNameOfDeclaration(propDeclaration);
24544+
const name = propDeclaration && getNameOfDeclaration(propDeclaration);
2454524545

2454624546
// index is numeric and property name is not valid numeric literal
2454724547
if (indexKind === IndexKind.Number && !(name ? isNumericName(name) : isNumericLiteralName(prop.escapedName))) {

src/compiler/utilities.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4875,9 +4875,6 @@ namespace ts {
48754875
}
48764876

48774877
export function getNameOfDeclaration(declaration: Declaration | Expression): DeclarationName | undefined {
4878-
if (!declaration) {
4879-
return undefined;
4880-
}
48814878
switch (declaration.kind) {
48824879
case SyntaxKind.ClassExpression:
48834880
case SyntaxKind.FunctionExpression:
@@ -4907,8 +4904,6 @@ namespace ts {
49074904
return undefined;
49084905
}
49094906
}
4910-
case SyntaxKind.JSDocCallbackTag:
4911-
return (declaration as JSDocCallbackTag).name;
49124907
case SyntaxKind.JSDocTypedefTag:
49134908
return getNameOfJSDocTypedef(declaration as JSDocTypedefTag);
49144909
case SyntaxKind.ExportAssignment: {

src/services/codefixes/inferFromUsage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace ts.codefix {
3333
const token = getTokenAtPosition(sourceFile, start);
3434
let declaration!: Declaration | undefined;
3535
const changes = textChanges.ChangeTracker.with(context, changes => { declaration = doChange(changes, sourceFile, token, errorCode, program, cancellationToken, /*markSeenseen*/ returnTrue); });
36-
const name = getNameOfDeclaration(declaration!);
36+
const name = declaration && getNameOfDeclaration(declaration);
3737
return !name || changes.length === 0 ? undefined
3838
: [createCodeFixAction(fixId, changes, [getDiagnostic(errorCode, token), name.getText(sourceFile)], fixId, Diagnostics.Infer_all_types_from_usage)];
3939
},

src/services/findAllReferences.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ namespace ts.FindAllReferences.Core {
10231023

10241024
function getReferenceForShorthandProperty({ flags, valueDeclaration }: Symbol, search: Search, state: State): void {
10251025
const shorthandValueSymbol = state.checker.getShorthandAssignmentValueSymbol(valueDeclaration)!;
1026-
const name = getNameOfDeclaration(valueDeclaration);
1026+
const name = valueDeclaration && getNameOfDeclaration(valueDeclaration);
10271027
/*
10281028
* Because in short-hand property assignment, an identifier which stored as name of the short-hand property assignment
10291029
* has two meanings: property name and property value. Therefore when we do findAllReference at the position where

0 commit comments

Comments
 (0)