Skip to content

Commit 0c2babc

Browse files
committed
Don't coalesce or remove unused imports with invalid module specifiers
1 parent 7498043 commit 0c2babc

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/services/organizeImports.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ namespace ts.OrganizeImports {
2020
compareModuleSpecifiers(group1[0].moduleSpecifier, group2[0].moduleSpecifier));
2121

2222
const newImportDecls = flatMap(sortedImportGroups, importGroup =>
23-
coalesceImports(removeUnusedImports(importGroup)));
23+
getExternalModuleName(importGroup[0].moduleSpecifier)
24+
? coalesceImports(removeUnusedImports(importGroup))
25+
: importGroup);
2426

2527
const changeTracker = textChanges.ChangeTracker.fromContext({ host, formatContext });
2628

@@ -60,7 +62,7 @@ namespace ts.OrganizeImports {
6062
* @param importGroup a list of ImportDeclarations, all with the same module name.
6163
*/
6264
export function coalesceImports(importGroup: ReadonlyArray<ImportDeclaration>) {
63-
if (importGroup.length === 0 || getExternalModuleName(importGroup[0].moduleSpecifier) === undefined) {
65+
if (importGroup.length === 0) {
6466
return importGroup;
6567
}
6668

0 commit comments

Comments
 (0)