@@ -242,10 +242,18 @@ function makeOutOfOrderReport(context, imported) {
242242 reportOutOfOrder ( context , imported , outOfOrder , 'before' ) ;
243243}
244244
245- function getSorter ( ascending ) {
246- const multiplier = ascending ? 1 : - 1 ;
245+ function getSorter ( ascending , caseInsensitive ) {
246+ const multiplier = ( ascending ? 1 : - 1 ) ;
247+ const collate = caseInsensitive
248+ ? caseInsensitive === 'invert'
249+ ? swapCase
250+ : ( s ) => String ( s ) . toLowerCase ( )
251+ : ( s ) => s ;
247252
248253 return function importsSorter ( importA , importB ) {
254+ importA = collate ( importA ) ;
255+ importB = collate ( importB ) ;
256+
249257 let result ;
250258
251259 if ( importA < importB ) {
@@ -281,13 +289,9 @@ function mutateRanksToAlphabetize(imported, alphabetizeOptions) {
281289 const groupRanks = Object . keys ( groupedByRanks ) ;
282290
283291 const sorterFn = getSorter ( alphabetizeOptions . order === 'asc' ) ;
284- const comparator =
285- alphabetizeOptions . caseInsensitive === 'invert' ? ( a , b ) => sorterFn ( swapCase ( String ( a ) ) , swapCase ( String ( b ) ) )
286- : alphabetizeOptions . caseInsensitive ? ( a , b ) => sorterFn ( String ( a ) . toLowerCase ( ) , String ( b ) . toLowerCase ( ) )
287- : ( a , b ) => sorterFn ( a , b ) ;
288292 // sort imports locally within their group
289293 groupRanks . forEach ( function ( groupRank ) {
290- groupedByRanks [ groupRank ] . sort ( comparator ) ;
294+ groupedByRanks [ groupRank ] . sort ( sorterFn ) ;
291295 } ) ;
292296
293297 // assign globally unique rank to each import
0 commit comments