diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index eb23835ffc4..c593da7a440 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8807,7 +8807,7 @@ namespace ts { if (!(getDeclarationModifierFlagsFromSymbol(prop) & ModifierFlags.NonPublicAccessibilityModifier)) { let type = getLateBoundSymbol(prop).nameType; if (!type && !isKnownSymbol(prop)) { - const name = getNameOfDeclaration(prop.valueDeclaration); + const name = prop.valueDeclaration && getNameOfDeclaration(prop.valueDeclaration); type = name && isNumericLiteral(name) ? getLiteralType(+name.text) : name && name.kind === SyntaxKind.ComputedPropertyName && isNumericLiteral(name.expression) ? getLiteralType(+name.expression.text) : getLiteralType(symbolName(prop)); @@ -23244,7 +23244,7 @@ namespace ts { } else { const parameter = local.valueDeclaration && tryGetRootParameterDeclaration(local.valueDeclaration); - const name = getNameOfDeclaration(local.valueDeclaration); + const name = local.valueDeclaration && getNameOfDeclaration(local.valueDeclaration); if (parameter && name) { if (!isParameterPropertyDeclaration(parameter) && !parameterIsThisKeyword(parameter) && !isIdentifierThatStartsWithUnderscore(name)) { addDiagnostic(UnusedKind.Parameter, createDiagnosticForNode(name, Diagnostics._0_is_declared_but_its_value_is_never_read, symbolName(local))); @@ -24541,7 +24541,7 @@ namespace ts { } const propDeclaration = prop.valueDeclaration; - const name = getNameOfDeclaration(propDeclaration); + const name = propDeclaration && getNameOfDeclaration(propDeclaration); // index is numeric and property name is not valid numeric literal if (indexKind === IndexKind.Number && !(name ? isNumericName(name) : isNumericLiteralName(prop.escapedName))) { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 9c933b44d01..e3c0fd87606 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -4875,9 +4875,6 @@ namespace ts { } export function getNameOfDeclaration(declaration: Declaration | Expression): DeclarationName | undefined { - if (!declaration) { - return undefined; - } switch (declaration.kind) { case SyntaxKind.ClassExpression: case SyntaxKind.FunctionExpression: @@ -4907,8 +4904,6 @@ namespace ts { return undefined; } } - case SyntaxKind.JSDocCallbackTag: - return (declaration as JSDocCallbackTag).name; case SyntaxKind.JSDocTypedefTag: return getNameOfJSDocTypedef(declaration as JSDocTypedefTag); case SyntaxKind.ExportAssignment: { diff --git a/src/services/codefixes/inferFromUsage.ts b/src/services/codefixes/inferFromUsage.ts index cadb6d232d8..81f6fc1b6b5 100644 --- a/src/services/codefixes/inferFromUsage.ts +++ b/src/services/codefixes/inferFromUsage.ts @@ -33,7 +33,7 @@ namespace ts.codefix { const token = getTokenAtPosition(sourceFile, start); let declaration!: Declaration | undefined; const changes = textChanges.ChangeTracker.with(context, changes => { declaration = doChange(changes, sourceFile, token, errorCode, program, cancellationToken, /*markSeenseen*/ returnTrue); }); - const name = getNameOfDeclaration(declaration!); + const name = declaration && getNameOfDeclaration(declaration); return !name || changes.length === 0 ? undefined : [createCodeFixAction(fixId, changes, [getDiagnostic(errorCode, token), name.getText(sourceFile)], fixId, Diagnostics.Infer_all_types_from_usage)]; }, diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index 53d7a4f7ad1..e0ce611af2e 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -1023,7 +1023,7 @@ namespace ts.FindAllReferences.Core { function getReferenceForShorthandProperty({ flags, valueDeclaration }: Symbol, search: Search, state: State): void { const shorthandValueSymbol = state.checker.getShorthandAssignmentValueSymbol(valueDeclaration)!; - const name = getNameOfDeclaration(valueDeclaration); + const name = valueDeclaration && getNameOfDeclaration(valueDeclaration); /* * Because in short-hand property assignment, an identifier which stored as name of the short-hand property assignment * has two meanings: property name and property value. Therefore when we do findAllReference at the position where