fixUnusedIdentifier: fix "Remove variable statement" codefix (#24497)

* fixUnusedIdentifier: fix "Remove variable statement" codefix

* Add test for a single "Remove variable statement" codefix in a file
This commit is contained in:
Vyacheslav Pukhanov 2018-05-31 00:51:08 +03:00 committed by Andy
parent cdfa63aa40
commit 75f20f9b65
2 changed files with 15 additions and 1 deletions

View File

@ -29,7 +29,7 @@ namespace ts.codefix {
}
const delVar = textChanges.ChangeTracker.with(context, t => tryDeleteFullVariableStatement(t, sourceFile, startToken, /*deleted*/ undefined));
if (delVar.length) {
return [createCodeFixAction(fixName, delDestructure, Diagnostics.Remove_variable_statement, fixIdDelete, Diagnostics.Delete_all_unused_declarations)];
return [createCodeFixAction(fixName, delVar, Diagnostics.Remove_variable_statement, fixIdDelete, Diagnostics.Delete_all_unused_declarations)];
}
const token = getToken(sourceFile, textSpanEnd(context.span));

View File

@ -0,0 +1,14 @@
/// <reference path='fourslash.ts' />
// @noUnusedLocals: true
////function f() {
//// let a = 1, b = 2, c = 3;
////}
verify.codeFix({
description: "Remove variable statement",
newFileContent:
`function f() {
}`,
});