mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
fix(57497): "Remove unused declaration" does not work on overloaded function declarations (#57517)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user