Skip to content

Commit fefdd74

Browse files
Jesse Trinitytypescript-bot
Jesse Trinity
authored andcommitted
Cherry-pick PR microsoft#38599 into release-3.9
Component commits: 428f5a1 delete import comments on organize imports 8003791 add unit test 26eaf70 accept new baseline 81d1732 respond to review comment
1 parent 8037e26 commit fefdd74

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

src/services/organizeImports.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ namespace ts.OrganizeImports {
7676

7777
// Delete any subsequent imports.
7878
for (let i = 1; i < oldImportDecls.length; i++) {
79-
changeTracker.delete(sourceFile, oldImportDecls[i]);
79+
changeTracker.deleteNode(sourceFile, oldImportDecls[i]);
8080
}
8181
}
8282
}

src/services/textChanges.ts

+4
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,10 @@ namespace ts.textChanges {
286286
this.deletedNodes.push({ sourceFile, node });
287287
}
288288

289+
public deleteNode(sourceFile: SourceFile, node: Node, options: ConfigurableStartEnd = { leadingTriviaOption: LeadingTriviaOption.IncludeAll }): void {
290+
this.deleteRange(sourceFile, getAdjustedRange(sourceFile, node, node, options));
291+
}
292+
289293
public deleteModifier(sourceFile: SourceFile, modifier: Modifier): void {
290294
this.deleteRange(sourceFile, { pos: modifier.getStart(sourceFile), end: skipTrivia(sourceFile.text, modifier.end, /*stopAfterLineBreak*/ true) });
291295
}

src/testRunner/unittests/services/organizeImports.ts

+16
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,22 @@ import "lib1";
592592
{ path: "/lib1.ts", content: "" },
593593
{ path: "/lib2.ts", content: "" });
594594

595+
testOrganizeImports("SortComments",
596+
{
597+
path: "/test.ts",
598+
content: `
599+
// Header
600+
import "lib3";
601+
// Comment2
602+
import "lib2";
603+
// Comment1
604+
import "lib1";
605+
`,
606+
},
607+
{ path: "/lib1.ts", content: "" },
608+
{ path: "/lib2.ts", content: "" },
609+
{ path: "/lib3.ts", content: "" });
610+
595611
testOrganizeImports("AmbientModule",
596612
{
597613
path: "/test.ts",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// ==ORIGINAL==
2+
3+
// Header
4+
import "lib3";
5+
// Comment2
6+
import "lib2";
7+
// Comment1
8+
import "lib1";
9+
10+
// ==ORGANIZED==
11+
12+
// Header
13+
// Comment1
14+
import "lib1";
15+
// Comment2
16+
import "lib2";
17+
import "lib3";

0 commit comments

Comments
 (0)