Skip to content

Commit

Permalink
Don't coalesce or remove unused imports with invalid module specifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
amcasey committed Feb 15, 2018
1 parent 7498043 commit 0c2babc
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/services/organizeImports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ namespace ts.OrganizeImports {
compareModuleSpecifiers(group1[0].moduleSpecifier, group2[0].moduleSpecifier));

const newImportDecls = flatMap(sortedImportGroups, importGroup =>
coalesceImports(removeUnusedImports(importGroup)));
getExternalModuleName(importGroup[0].moduleSpecifier)
? coalesceImports(removeUnusedImports(importGroup))
: importGroup);

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

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

Expand Down

0 comments on commit 0c2babc

Please sign in to comment.