@@ -204,9 +204,7 @@ namespace ts.OrganizeImports {
204
204
205
205
newImportSpecifiers . push ( ...flatMap ( namedImports , i => ( i . importClause . namedBindings as NamedImports ) . elements ) ) ;
206
206
207
- const sortedImportSpecifiers = stableSort ( newImportSpecifiers , ( s1 , s2 ) =>
208
- compareIdentifiers ( s1 . propertyName || s1 . name , s2 . propertyName || s2 . name ) ||
209
- compareIdentifiers ( s1 . name , s2 . name ) ) ;
207
+ const sortedImportSpecifiers = sortSpecifiers ( newImportSpecifiers ) ;
210
208
211
209
const importDecl = defaultImports . length > 0
212
210
? defaultImports [ 0 ]
@@ -295,9 +293,7 @@ namespace ts.OrganizeImports {
295
293
const newExportSpecifiers : ExportSpecifier [ ] = [ ] ;
296
294
newExportSpecifiers . push ( ...flatMap ( namedExports , i => ( i . exportClause ) . elements ) ) ;
297
295
298
- const sortedExportSpecifiers = stableSort ( newExportSpecifiers , ( s1 , s2 ) =>
299
- compareIdentifiers ( s1 . propertyName || s1 . name , s2 . propertyName || s2 . name ) ||
300
- compareIdentifiers ( s1 . name , s2 . name ) ) ;
296
+ const sortedExportSpecifiers = sortSpecifiers ( newExportSpecifiers ) ;
301
297
302
298
const exportDecl = namedExports [ 0 ] ;
303
299
coalescedExports . push (
@@ -350,6 +346,12 @@ namespace ts.OrganizeImports {
350
346
importDeclaration . moduleSpecifier ) ;
351
347
}
352
348
349
+ function sortSpecifiers < T extends ImportOrExportSpecifier > ( specifiers : ReadonlyArray < T > ) {
350
+ return stableSort ( specifiers , ( s1 , s2 ) =>
351
+ compareIdentifiers ( s1 . propertyName || s1 . name , s2 . propertyName || s2 . name ) ||
352
+ compareIdentifiers ( s1 . name , s2 . name ) ) ;
353
+ }
354
+
353
355
/* internal */ // Exported for testing
354
356
export function compareModuleSpecifiers ( m1 : Expression , m2 : Expression ) {
355
357
const name1 = getExternalModuleName ( m1 ) ;
0 commit comments