Skip to content

Commit

Permalink
Cherry-pick PR #40273 into release-4.0 (#40303)
Browse files Browse the repository at this point in the history
Component commits:
2c0e01a Fix misplaced comma in auto imported specifier

Co-authored-by: Andrew Branch <andrew@wheream.io>
  • Loading branch information
TypeScript Bot and andrewbranch authored Sep 15, 2020
1 parent 3e7a8e7 commit 65b84e7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/services/codefixes/importFixes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ namespace ts.codefix {
}
else if (existingSpecifiers?.length) {
for (const spec of newSpecifiers) {
changes.insertNodeAtEndOfList(sourceFile, existingSpecifiers, spec);
changes.insertNodeInListAfter(sourceFile, last(existingSpecifiers), spec, existingSpecifiers);
}
}
else {
Expand Down
24 changes: 24 additions & 0 deletions tests/cases/fourslash/importNameCodeFix_trailingComma.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/// <reference path="fourslash.ts" />

// Bug #40219 only happens when existing import specifiers are unsorted.

// @Filename: index.ts
//// import {
//// T2,
//// T1,
//// } from "./types";
////
//// const x: T3/**/

// @Filename: types.ts
//// export type T1 = 0;
//// export type T2 = 0;
//// export type T3 = 0;

verify.importFixAtPosition([`import {
T2,
T1,
T3,
} from "./types";
const x: T3`]);

0 comments on commit 65b84e7

Please sign in to comment.