mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
place first import after header
This commit is contained in:
@@ -384,8 +384,8 @@ namespace ts.textChanges {
|
||||
}
|
||||
}
|
||||
|
||||
public insertNodeBefore(sourceFile: SourceFile, before: Node, newNode: Node, blankLineBetween = false): void {
|
||||
this.insertNodeAt(sourceFile, getAdjustedStartPosition(sourceFile, before, {}), newNode, this.getOptionsForInsertNodeBefore(before, newNode, blankLineBetween));
|
||||
public insertNodeBefore(sourceFile: SourceFile, before: Node, newNode: Node, blankLineBetween = false, options = {}): void {
|
||||
this.insertNodeAt(sourceFile, getAdjustedStartPosition(sourceFile, before, options), newNode, this.getOptionsForInsertNodeBefore(before, newNode, blankLineBetween));
|
||||
}
|
||||
|
||||
public insertModifierBefore(sourceFile: SourceFile, modifier: SyntaxKind, before: Node): void {
|
||||
|
||||
@@ -1913,7 +1913,9 @@ namespace ts {
|
||||
for (const newImport of sortedNewImports) {
|
||||
const insertionIndex = OrganizeImports.getImportDeclarationInsertionIndex(existingImportStatements, newImport);
|
||||
if (insertionIndex === 0) {
|
||||
changes.insertNodeBefore(sourceFile, existingImportStatements[0], newImport, /*blankLineBetween*/ false);
|
||||
changes.insertNodeBefore(sourceFile, existingImportStatements[0], newImport, /*blankLineBetween*/ false, {
|
||||
leadingTriviaOption: textChanges.LeadingTriviaOption.Exclude,
|
||||
});
|
||||
}
|
||||
else {
|
||||
const prevImport = existingImportStatements[insertionIndex - 1];
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
// @Filename: /a.ts
|
||||
////export const foo = 0;
|
||||
|
||||
// @Filename: /b.ts
|
||||
////export const bar = 0;
|
||||
|
||||
// @Filename: /c.ts
|
||||
/////*--------------------
|
||||
//// * Copyright Header
|
||||
//// *--------------------*/
|
||||
////
|
||||
////import { bar } from "./b";
|
||||
////foo;
|
||||
|
||||
goTo.file("/c.ts");
|
||||
verify.importFixAtPosition([
|
||||
`/*--------------------
|
||||
* Copyright Header
|
||||
*--------------------*/
|
||||
|
||||
import { foo } from "./a";
|
||||
import { bar } from "./b";
|
||||
foo;`,
|
||||
]);
|
||||
Reference in New Issue
Block a user