mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
Fix regression organize imports duplicates comments (#38599)
* delete import comments on organize imports * add unit test * accept new baseline * respond to review comment
This commit is contained in:
parent
1cbe7ef000
commit
1a15717bc4
@ -76,7 +76,7 @@ namespace ts.OrganizeImports {
|
||||
|
||||
// Delete any subsequent imports.
|
||||
for (let i = 1; i < oldImportDecls.length; i++) {
|
||||
changeTracker.delete(sourceFile, oldImportDecls[i]);
|
||||
changeTracker.deleteNode(sourceFile, oldImportDecls[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -286,6 +286,10 @@ namespace ts.textChanges {
|
||||
this.deletedNodes.push({ sourceFile, node });
|
||||
}
|
||||
|
||||
public deleteNode(sourceFile: SourceFile, node: Node, options: ConfigurableStartEnd = { leadingTriviaOption: LeadingTriviaOption.IncludeAll }): void {
|
||||
this.deleteRange(sourceFile, getAdjustedRange(sourceFile, node, node, options));
|
||||
}
|
||||
|
||||
public deleteModifier(sourceFile: SourceFile, modifier: Modifier): void {
|
||||
this.deleteRange(sourceFile, { pos: modifier.getStart(sourceFile), end: skipTrivia(sourceFile.text, modifier.end, /*stopAfterLineBreak*/ true) });
|
||||
}
|
||||
|
||||
@ -592,6 +592,22 @@ import "lib1";
|
||||
{ path: "/lib1.ts", content: "" },
|
||||
{ path: "/lib2.ts", content: "" });
|
||||
|
||||
testOrganizeImports("SortComments",
|
||||
{
|
||||
path: "/test.ts",
|
||||
content: `
|
||||
// Header
|
||||
import "lib3";
|
||||
// Comment2
|
||||
import "lib2";
|
||||
// Comment1
|
||||
import "lib1";
|
||||
`,
|
||||
},
|
||||
{ path: "/lib1.ts", content: "" },
|
||||
{ path: "/lib2.ts", content: "" },
|
||||
{ path: "/lib3.ts", content: "" });
|
||||
|
||||
testOrganizeImports("AmbientModule",
|
||||
{
|
||||
path: "/test.ts",
|
||||
|
||||
17
tests/baselines/reference/organizeImports/SortComments.ts
Normal file
17
tests/baselines/reference/organizeImports/SortComments.ts
Normal file
@ -0,0 +1,17 @@
|
||||
// ==ORIGINAL==
|
||||
|
||||
// Header
|
||||
import "lib3";
|
||||
// Comment2
|
||||
import "lib2";
|
||||
// Comment1
|
||||
import "lib1";
|
||||
|
||||
// ==ORGANIZED==
|
||||
|
||||
// Header
|
||||
// Comment1
|
||||
import "lib1";
|
||||
// Comment2
|
||||
import "lib2";
|
||||
import "lib3";
|
||||
Loading…
x
Reference in New Issue
Block a user