Skip to content

Commit 7281bb7

Browse files
committed
Stop deleting empty named import lists
Fixes microsoft#23892
1 parent 2be6aaf commit 7281bb7

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

src/harness/unittests/organizeImports.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,15 @@ D();
243243
import { F1, F2 } from "lib";
244244
import * as NS from "lib";
245245
import D from "lib";
246+
`,
247+
},
248+
libFile);
249+
250+
testOrganizeImports("Unused_Empty",
251+
{
252+
path: "/test.ts",
253+
content: `
254+
import { } from "lib";
246255
`,
247256
},
248257
libFile);

src/services/organizeImports.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,9 @@ namespace ts.OrganizeImports {
198198
: namedImports[0];
199199

200200
const newNamedImports = sortedImportSpecifiers.length === 0
201-
? undefined
201+
? newDefaultImport
202+
? undefined
203+
: createNamedImports(emptyArray)
202204
: namedImports.length === 0
203205
? createNamedImports(sortedImportSpecifiers)
204206
: updateNamedImports(namedImports[0].importClause.namedBindings as NamedImports, sortedImportSpecifiers);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// ==ORIGINAL==
2+
3+
import { } from "lib";
4+
5+
// ==ORGANIZED==
6+
7+
import { } from "lib";

0 commit comments

Comments
 (0)