fix(57497): "Remove unused declaration" does not work on overloaded function declarations (#57517)

This commit is contained in:
Oleksandr T
2024-04-19 11:28:00 -07:00
committed by GitHub
parent c0ac582284
commit 93451e8dd9
2 changed files with 33 additions and 0 deletions
@@ -27,6 +27,7 @@ import {
isComputedPropertyName,
isDeclarationWithTypeParameterChildren,
isExpressionStatement,
isFunctionDeclaration,
isIdentifier,
isImportClause,
isImportDeclaration,
@@ -129,6 +130,10 @@ registerCodeFix({
];
}
if (isIdentifier(token) && isFunctionDeclaration(token.parent)) {
return [createDeleteFix(textChanges.ChangeTracker.with(context, t => deleteFunctionLikeDeclaration(t, sourceFile, token.parent as FunctionLikeDeclaration)), [Diagnostics.Remove_unused_declaration_for_Colon_0, token.getText(sourceFile)])];
}
const result: CodeFixAction[] = [];
if (token.kind === SyntaxKind.InferKeyword) {
const changes = textChanges.ChangeTracker.with(context, t => changeInferToUnknown(t, sourceFile, token));
@@ -431,3 +436,12 @@ function mayDeleteExpression(node: Node) {
return ((isBinaryExpression(node.parent) && node.parent.left === node) ||
((isPostfixUnaryExpression(node.parent) || isPrefixUnaryExpression(node.parent)) && node.parent.operand === node)) && isExpressionStatement(node.parent.parent);
}
function deleteFunctionLikeDeclaration(changes: textChanges.ChangeTracker, sourceFile: SourceFile, node: FunctionLikeDeclaration) {
const declarations = node.symbol.declarations;
if (declarations) {
for (const declaration of declarations) {
changes.delete(sourceFile, declaration);
}
}
}