mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-05 04:25:39 -05:00
fix(41621): fixUnusedIdentifier - allow deleting prefix/postfix unary operators (#41624)
This commit is contained in:
@@ -225,7 +225,7 @@ namespace ts.codefix {
|
||||
if (isIdentifier(token)) {
|
||||
FindAllReferences.Core.eachSymbolReferenceInFile(token, checker, sourceFile, (ref: Node) => {
|
||||
if (isPropertyAccessExpression(ref.parent) && ref.parent.name === ref) ref = ref.parent;
|
||||
if (!isFixAll && isBinaryExpression(ref.parent) && isExpressionStatement(ref.parent.parent) && ref.parent.left === ref) {
|
||||
if (!isFixAll && mayDeleteExpression(ref)) {
|
||||
changes.delete(sourceFile, ref.parent.parent);
|
||||
}
|
||||
});
|
||||
@@ -332,4 +332,9 @@ namespace ts.codefix {
|
||||
parameters.slice(index + 1).every(p => isIdentifier(p.name) && !p.symbol.isReferenced) :
|
||||
index === parameters.length - 1;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
////function fn() {
|
||||
//// let x = 1;
|
||||
//// x++;
|
||||
////}
|
||||
|
||||
verify.codeFix({
|
||||
description: "Remove unused declaration for: 'x'",
|
||||
newFileContent:
|
||||
`function fn() {
|
||||
}`
|
||||
});
|
||||
@@ -0,0 +1,14 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
////function fn() {
|
||||
//// let x = 1;
|
||||
//// x--;
|
||||
////}
|
||||
|
||||
verify.codeFix({
|
||||
description: "Remove unused declaration for: 'x'",
|
||||
newFileContent:
|
||||
`function fn() {
|
||||
}`
|
||||
});
|
||||
@@ -0,0 +1,14 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
////function fn() {
|
||||
//// let x = 1;
|
||||
//// ++x;
|
||||
////}
|
||||
|
||||
verify.codeFix({
|
||||
description: "Remove unused declaration for: 'x'",
|
||||
newFileContent:
|
||||
`function fn() {
|
||||
}`
|
||||
});
|
||||
@@ -0,0 +1,14 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
////function fn() {
|
||||
//// let x = 1;
|
||||
//// --x;
|
||||
////}
|
||||
|
||||
verify.codeFix({
|
||||
description: "Remove unused declaration for: 'x'",
|
||||
newFileContent:
|
||||
`function fn() {
|
||||
}`
|
||||
});
|
||||
Reference in New Issue
Block a user