Skip to content

Commit e354754

Browse files
committed
Special case arrow functions with only parameter unused
Fixes GH microsoft#18274
1 parent 1dcc83e commit e354754

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

src/services/codefixes/fixUnusedIdentifier.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,20 @@ namespace ts.codefix {
121121
break;
122122

123123
case SyntaxKind.Parameter:
124-
const functionDeclaration = <FunctionDeclaration>parent.parent;
125-
if (functionDeclaration.parameters.length === 1) {
126-
changes.deleteNode(sourceFile, parent);
124+
const oldFunction = parent.parent;
125+
if (isArrowFunction(oldFunction) && oldFunction.parameters.length === 1) {
126+
const newFunction = updateArrowFunction(
127+
oldFunction,
128+
oldFunction.modifiers,
129+
oldFunction.typeParameters,
130+
/*parameters*/ undefined,
131+
oldFunction.type,
132+
oldFunction.equalsGreaterThanToken,
133+
oldFunction.body);
134+
135+
suppressLeadingAndTrailingTrivia(newFunction);
136+
137+
changes.replaceRange(sourceFile, { pos: oldFunction.getStart(), end: oldFunction.end }, newFunction);
127138
}
128139
else {
129140
changes.deleteNodeInList(sourceFile, parent);

0 commit comments

Comments
 (0)