@@ -24,7 +24,9 @@ namespace ts {
24
24
}
25
25
26
26
// More efficient to create a collator once and use its `compare` than to call `a.localeCompare(b)` many times.
27
- export const collator : { compare ( a : string , b : string ) : number } = typeof Intl === "object" && typeof Intl . Collator === "function" ? new Intl . Collator ( ) : undefined ;
27
+ export const collator : { compare ( a : string , b : string ) : number } = typeof Intl === "object" && typeof Intl . Collator === "function" ? new Intl . Collator ( /*locales*/ undefined , { usage : "sort" , sensitivity : "accent" } ) : undefined ;
28
+ // Intl is missing in Safari, and node 0.10 treats "a" as greater than "B".
29
+ export const localeCompareIsCorrect = ts . collator && ts . collator . compare ( "a" , "B" ) < 0 ;
28
30
29
31
/** Create a MapLike with good performance. */
30
32
function createDictionaryObject < T > ( ) : MapLike < T > {
@@ -1247,9 +1249,12 @@ namespace ts {
1247
1249
if ( a === undefined ) return Comparison . LessThan ;
1248
1250
if ( b === undefined ) return Comparison . GreaterThan ;
1249
1251
if ( ignoreCase ) {
1250
- if ( collator && String . prototype . localeCompare ) {
1251
- // accent means a ≠ b, a ≠ á, a = A
1252
- const result = a . localeCompare ( b , /*locales*/ undefined , { usage : "sort" , sensitivity : "accent" } ) ;
1252
+ // Checking if "collator exists indicates that Intl is available.
1253
+ // We still have to check if "collator.compare" is correct. If it is not, use "String.localeComapre"
1254
+ if ( collator ) {
1255
+ const result = localeCompareIsCorrect ?
1256
+ collator . compare ( a , b ) :
1257
+ a . localeCompare ( b , /*locales*/ undefined , { usage : "sort" , sensitivity : "accent" } ) ; // accent means a ≠ b, a ≠ á, a = A
1253
1258
return result < 0 ? Comparison . LessThan : result > 0 ? Comparison . GreaterThan : Comparison . EqualTo ;
1254
1259
}
1255
1260
0 commit comments