Special case arrow functions with only parameter unused

Fixes GH #18274
This commit is contained in:
Andrew Casey 2018-01-10 18:28:47 -08:00
parent 1dcc83e6d2
commit e354754b2a

View file

@ -121,9 +121,20 @@ namespace ts.codefix {
break;
case SyntaxKind.Parameter:
const functionDeclaration = <FunctionDeclaration>parent.parent;
if (functionDeclaration.parameters.length === 1) {
changes.deleteNode(sourceFile, parent);
const oldFunction = parent.parent;
if (isArrowFunction(oldFunction) && oldFunction.parameters.length === 1) {
const newFunction = updateArrowFunction(
oldFunction,
oldFunction.modifiers,
oldFunction.typeParameters,
/*parameters*/ undefined,
oldFunction.type,
oldFunction.equalsGreaterThanToken,
oldFunction.body);
suppressLeadingAndTrailingTrivia(newFunction);
changes.replaceRange(sourceFile, { pos: oldFunction.getStart(), end: oldFunction.end }, newFunction);
}
else {
changes.deleteNodeInList(sourceFile, parent);