Skip to content

Commit f713571

Browse files
Merge pull request microsoft#38668 from typescript-bot/pick/38599/release-3.9
🤖 Pick PR microsoft#38599 (Fix regression organize imports dup...) into release-3.9
2 parents 5b29b14 + fefdd74 commit f713571

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

src/services/organizeImports.ts

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 0 deletions
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

Lines changed: 16 additions & 0 deletions
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",
Lines changed: 17 additions & 0 deletions
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)