Skip to content

Commit c7c57f7

Browse files
committed
remove casts
1 parent eb54e77 commit c7c57f7

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

src/services/organizeImports.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -813,12 +813,16 @@ function getTopLevelExportGroups(sourceFile: SourceFile) {
813813
return flatMap(topLevelExportGroups, exportGroupDecls => groupByNewlineContiguous(sourceFile, exportGroupDecls));
814814
}
815815

816+
function getModuleNamesFromDecls(decls: readonly AnyImportOrRequireStatement[]): string[] {
817+
return decls.map(s => getExternalModuleName(getModuleSpecifierExpression(s)) || "");
818+
}
819+
816820
/** @internal */
817-
export function detectModuleSpecifierCaseBySort(importDeclsByGroup: ImportDeclaration[][], comparersToTest: Comparer<string>[]) {
821+
export function detectModuleSpecifierCaseBySort(importDeclsByGroup: (readonly AnyImportOrRequireStatement[])[], comparersToTest: Comparer<string>[]) {
818822
const moduleSpecifiersByGroup: string[][] = [];
819823
importDeclsByGroup.forEach(importGroup => {
820-
// turns importdeclbygroup into string[][] of module specifiers by group to detect sorting on module specifiers
821-
moduleSpecifiersByGroup.push(importGroup.map(i => getExternalModuleName(i.moduleSpecifier)!));
824+
// turns importDeclsByGroup into string[][] of module specifiers by group to detect sorting on module specifiers
825+
moduleSpecifiersByGroup.push(getModuleNamesFromDecls(importGroup));
822826
});
823827
return detectCaseSensitivityBySort(moduleSpecifiersByGroup, comparersToTest);
824828
}

src/services/utilities.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2623,12 +2623,7 @@ export function insertImports(changes: textChanges.ChangeTracker, sourceFile: So
26232623
const decl = isArray(imports) ? imports[0] : imports;
26242624
const importKindPredicate: (node: Node) => node is AnyImportOrRequireStatement = decl.kind === SyntaxKind.VariableStatement ? isRequireVariableStatement : isAnyImportSyntax;
26252625
const existingImportStatements = filter(sourceFile.statements, importKindPredicate);
2626-
// todo remove typecasts
2627-
const moduleSpecifiersToDetect: ImportDeclaration[][] = existingImportStatements.length > 1
2628-
? [existingImportStatements as ImportDeclaration[]]
2629-
: isArray(imports)
2630-
? [imports as ImportDeclaration[]]
2631-
: [existingImportStatements as ImportDeclaration[]];
2626+
const moduleSpecifiersToDetect = existingImportStatements.length > 1 ? [existingImportStatements] : isArray(imports) ? [imports] : [existingImportStatements];
26322627
const { comparer } = OrganizeImports.detectModuleSpecifierCaseBySort(moduleSpecifiersToDetect, OrganizeImports.getDetectionLists(preferences).comparersToTest);
26332628
const sortedNewImports = isArray(imports) ? stableSort(imports, (a, b) => OrganizeImports.compareImportsOrRequireStatements(a, b, comparer)) : [imports];
26342629
if (!existingImportStatements.length) {

0 commit comments

Comments
 (0)