@@ -265,14 +265,17 @@ function mutateRanksToAlphabetize(imported, alphabetizeOptions) {
265
265
if ( ! Array . isArray ( acc [ importedItem . rank ] ) ) {
266
266
acc [ importedItem . rank ] = [ ] ;
267
267
}
268
- acc [ importedItem . rank ] . push ( ` ${ importedItem . value } - ${ importedItem . node . importKind } ` ) ;
268
+ acc [ importedItem . rank ] . push ( importedItem ) ;
269
269
return acc ;
270
270
} , { } ) ;
271
271
272
272
const groupRanks = Object . keys ( groupedByRanks ) ;
273
273
274
274
const sorterFn = getSorter ( alphabetizeOptions . order === 'asc' ) ;
275
- const comparator = alphabetizeOptions . caseInsensitive ? ( a , b ) => sorterFn ( String ( a ) . toLowerCase ( ) , String ( b ) . toLowerCase ( ) ) : ( a , b ) => sorterFn ( a , b ) ;
275
+ const comparator = alphabetizeOptions . caseInsensitive
276
+ ? ( a , b ) => sorterFn ( String ( a . value ) . toLowerCase ( ) , String ( b . value ) . toLowerCase ( ) )
277
+ : ( a , b ) => sorterFn ( a . value , b . value ) ;
278
+
276
279
// sort imports locally within their group
277
280
groupRanks . forEach ( function ( groupRank ) {
278
281
groupedByRanks [ groupRank ] . sort ( comparator ) ;
@@ -281,16 +284,16 @@ function mutateRanksToAlphabetize(imported, alphabetizeOptions) {
281
284
// assign globally unique rank to each import
282
285
let newRank = 0 ;
283
286
const alphabetizedRanks = groupRanks . sort ( ) . reduce ( function ( acc , groupRank ) {
284
- groupedByRanks [ groupRank ] . forEach ( function ( importedItemName ) {
285
- acc [ importedItemName ] = parseInt ( groupRank , 10 ) + newRank ;
287
+ groupedByRanks [ groupRank ] . forEach ( function ( importedItem ) {
288
+ acc [ ` ${ importedItem . value } | ${ importedItem . node . importKind } ` ] = parseInt ( groupRank , 10 ) + newRank ;
286
289
newRank += 1 ;
287
290
} ) ;
288
291
return acc ;
289
292
} , { } ) ;
290
293
291
294
// mutate the original group-rank with alphabetized-rank
292
295
imported . forEach ( function ( importedItem ) {
293
- importedItem . rank = alphabetizedRanks [ `${ importedItem . value } - ${ importedItem . node . importKind } ` ] ;
296
+ importedItem . rank = alphabetizedRanks [ `${ importedItem . value } | ${ importedItem . node . importKind } ` ] ;
294
297
} ) ;
295
298
}
296
299
0 commit comments