Skip to content

Commit 6e4b730

Browse files
authored
fix(44465): remove only unused declarations instead of the entire line (#44490)
1 parent f850470 commit 6e4b730

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

src/services/textChanges.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,9 @@ namespace ts.textChanges {
174174
return node.getStart(sourceFile);
175175
}
176176
if (leadingTriviaOption === LeadingTriviaOption.StartLine) {
177-
return getLineStartPositionForPosition(node.getStart(sourceFile), sourceFile);
177+
const startPos = node.getStart(sourceFile);
178+
const pos = getLineStartPositionForPosition(startPos, sourceFile);
179+
return rangeContainsPosition(node, pos) ? pos : startPos;
178180
}
179181
if (leadingTriviaOption === LeadingTriviaOption.JSDoc) {
180182
const JSDocComments = getJSDocCommentRanges(node, sourceFile.text);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @noUnusedLocals: true
4+
// @noUnusedParameters: true
5+
////export const a = 1; const b = 1;
6+
7+
verify.codeFix({
8+
description: "Remove unused declaration for: 'b'",
9+
newFileContent: "export const a = 1; "
10+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @noUnusedLocals: true
4+
// @noUnusedParameters: true
5+
////export function f1() {} function f2() {}
6+
7+
verify.codeFix({
8+
description: "Remove unused declaration for: 'f2'",
9+
index: 0,
10+
newFileContent: "export function f1() {} "
11+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @noUnusedLocals: true
4+
// @noUnusedParameters: true
5+
////export class c1 {} class c2 {}
6+
7+
verify.codeFix({
8+
description: "Remove unused declaration for: 'c2'",
9+
index: 0,
10+
newFileContent: "export class c1 {} "
11+
});

0 commit comments

Comments
 (0)