Skip to content

Commit 45d9eb5

Browse files
committed
place first import after header
1 parent 6247364 commit 45d9eb5

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

src/services/textChanges.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,8 @@ namespace ts.textChanges {
384384
}
385385
}
386386

387-
public insertNodeBefore(sourceFile: SourceFile, before: Node, newNode: Node, blankLineBetween = false): void {
388-
this.insertNodeAt(sourceFile, getAdjustedStartPosition(sourceFile, before, {}), newNode, this.getOptionsForInsertNodeBefore(before, newNode, blankLineBetween));
387+
public insertNodeBefore(sourceFile: SourceFile, before: Node, newNode: Node, blankLineBetween = false, options = {}): void {
388+
this.insertNodeAt(sourceFile, getAdjustedStartPosition(sourceFile, before, options), newNode, this.getOptionsForInsertNodeBefore(before, newNode, blankLineBetween));
389389
}
390390

391391
public insertModifierBefore(sourceFile: SourceFile, modifier: SyntaxKind, before: Node): void {

src/services/utilities.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1913,7 +1913,9 @@ namespace ts {
19131913
for (const newImport of sortedNewImports) {
19141914
const insertionIndex = OrganizeImports.getImportDeclarationInsertionIndex(existingImportStatements, newImport);
19151915
if (insertionIndex === 0) {
1916-
changes.insertNodeBefore(sourceFile, existingImportStatements[0], newImport, /*blankLineBetween*/ false);
1916+
changes.insertNodeBefore(sourceFile, existingImportStatements[0], newImport, /*blankLineBetween*/ false, {
1917+
leadingTriviaOption: textChanges.LeadingTriviaOption.Exclude,
1918+
});
19171919
}
19181920
else {
19191921
const prevImport = existingImportStatements[insertionIndex - 1];
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @Filename: /a.ts
4+
////export const foo = 0;
5+
6+
// @Filename: /b.ts
7+
////export const bar = 0;
8+
9+
// @Filename: /c.ts
10+
/////*--------------------
11+
//// * Copyright Header
12+
//// *--------------------*/
13+
////
14+
////import { bar } from "./b";
15+
////foo;
16+
17+
goTo.file("/c.ts");
18+
verify.importFixAtPosition([
19+
`/*--------------------
20+
* Copyright Header
21+
*--------------------*/
22+
23+
import { foo } from "./a";
24+
import { bar } from "./b";
25+
foo;`,
26+
]);

0 commit comments

Comments
 (0)