@@ -21,7 +21,9 @@ namespace ts {
21
21
const createObject = Object . create ;
22
22
23
23
// More efficient to create a collator once and use its `compare` than to call `a.localeCompare(b)` many times.
24
- export const collator : { compare ( a : string , b : string ) : number } = typeof Intl === "object" && typeof Intl . Collator === "function" ? new Intl . Collator ( ) : undefined ;
24
+ 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 ;
25
+ // Intl is missing in Safari, and node 0.10 treats "a" as greater than "B".
26
+ export const localeCompareIsCorrect = ts . collator && ts . collator . compare ( "a" , "B" ) < 0 ;
25
27
26
28
export function createMap < T > ( template ?: MapLike < T > ) : Map < T > {
27
29
const map : Map < T > = createObject ( null ) ; // tslint:disable-line:no-null-keyword
@@ -1050,9 +1052,12 @@ namespace ts {
1050
1052
if ( a === undefined ) return Comparison . LessThan ;
1051
1053
if ( b === undefined ) return Comparison . GreaterThan ;
1052
1054
if ( ignoreCase ) {
1053
- if ( collator && String . prototype . localeCompare ) {
1054
- // accent means a ≠ b, a ≠ á, a = A
1055
- const result = a . localeCompare ( b , /*locales*/ undefined , { usage : "sort" , sensitivity : "accent" } ) ;
1055
+ // Checking if "collator exists indicates that Intl is available.
1056
+ // We still have to check if "collator.compare" is correct. If it is not, use "String.localeComapre"
1057
+ if ( collator ) {
1058
+ const result = localeCompareIsCorrect ?
1059
+ collator . compare ( a , b ) :
1060
+ a . localeCompare ( b , /*locales*/ undefined , { usage : "sort" , sensitivity : "accent" } ) ; // accent means a ≠ b, a ≠ á, a = A
1056
1061
return result < 0 ? Comparison . LessThan : result > 0 ? Comparison . GreaterThan : Comparison . EqualTo ;
1057
1062
}
1058
1063
0 commit comments