@@ -24,7 +24,9 @@ namespace ts {
2424 }
2525
2626 // 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 ;
2830
2931 /** Create a MapLike with good performance. */
3032 function createDictionaryObject < T > ( ) : MapLike < T > {
@@ -1247,9 +1249,12 @@ namespace ts {
12471249 if ( a === undefined ) return Comparison . LessThan ;
12481250 if ( b === undefined ) return Comparison . GreaterThan ;
12491251 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
12531258 return result < 0 ? Comparison . LessThan : result > 0 ? Comparison . GreaterThan : Comparison . EqualTo ;
12541259 }
12551260
0 commit comments