Skip to content

Commit 8da951c

Browse files
authored
Fixed "Delete all unused declarations" to delete self-referential functions (#60888)
1 parent 0745e6a commit 8da951c

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/services/codefixes/fixUnusedIdentifier.ts

+3
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ registerCodeFix({
200200
else if (canDeleteEntireVariableStatement(sourceFile, token)) {
201201
deleteEntireVariableStatement(changes, sourceFile, token.parent as VariableDeclarationList);
202202
}
203+
else if (isIdentifier(token) && isFunctionDeclaration(token.parent)) {
204+
deleteFunctionLikeDeclaration(changes, sourceFile, token.parent as FunctionLikeDeclaration);
205+
}
203206
else {
204207
tryDeleteDeclaration(sourceFile, token, changes, checker, sourceFiles, program, cancellationToken, /*isFixAll*/ true);
205208
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
//// function fibonacci(n: number): number {
4+
//// if (n <= 1) {
5+
//// return n;
6+
//// }
7+
//// return fibonacci(n - 1) + fibonacci(n - 2);
8+
//// }
9+
////
10+
//// function other() {}
11+
////
12+
//// export {};
13+
14+
verify.codeFixAll({
15+
fixId: "unusedIdentifier_delete",
16+
fixAllDescription: ts.Diagnostics.Delete_all_unused_declarations.message,
17+
newFileContent: "\n\nexport {};",
18+
});

0 commit comments

Comments
 (0)