Remove redundant checks in getNameOfDeclaration (#25244)

This commit is contained in:
Andy 2018-06-27 13:56:31 -07:00 committed by GitHub
parent 1cb691f52d
commit fd8b7f3da5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 5 additions and 10 deletions

View File

@ -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))) {

View File

@ -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: {

View File

@ -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)];
},

View File

@ -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