Skip to content

Commit 5b4dfcc

Browse files
author
Kanchalai Tanglertsampan
committed
Address PR: remove locales and options; use accent as default
1 parent c03b04b commit 5b4dfcc

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

src/compiler/core.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ namespace ts {
2323
// More efficient to create a collator once and use its `compare` than to call `a.localeCompare(b)` many times.
2424
export const collator: { compare(a: string, b: string): number } = typeof Intl === "object" && typeof Intl.Collator === "function" ? new Intl.Collator() : undefined;
2525

26-
// This means "compare in a case insensitive manner but consider accentsor other diacritic marks"
27-
// (e.g. a ≠ b, a ≠ á, a = A)
28-
const accentSensitivity: Intl.CollatorOptions = { usage: "sort", sensitivity: "accent" };
29-
3026
/**
3127
* Use this function instead of calling "String.prototype.localeCompre". This function will preform appropriate check to make sure that
3228
* "typeof Intl" is correct as there are reported issues #11110 nad #11339.
@@ -1033,13 +1029,14 @@ namespace ts {
10331029
return a < b ? Comparison.LessThan : Comparison.GreaterThan;
10341030
}
10351031

1036-
export function compareStrings(a: string, b: string, locales?: string | string[], options?: Intl.CollatorOptions): Comparison {
1032+
export function compareStrings(a: string, b: string, ignoreCase?: boolean): Comparison {
10371033
if (a === b) return Comparison.EqualTo;
10381034
if (a === undefined) return Comparison.LessThan;
10391035
if (b === undefined) return Comparison.GreaterThan;
1040-
if (options) {
1036+
if (ignoreCase) {
10411037
if (collator && String.prototype.localeCompare) {
1042-
const result = a.localeCompare(b, locales, options);
1038+
// accent means a ≠ b, a ≠ á, a = A
1039+
const result = a.localeCompare(b, /*locales*/ undefined, { usage: "sort", sensitivity: "accent" });
10431040
return result < 0 ? Comparison.LessThan : result > 0 ? Comparison.GreaterThan : Comparison.EqualTo;
10441041
}
10451042

@@ -1052,7 +1049,7 @@ namespace ts {
10521049
}
10531050

10541051
export function compareStringsCaseInsensitive(a: string, b: string) {
1055-
return compareStrings(a, b, /*locales*/ undefined, accentSensitivity);
1052+
return compareStrings(a, b, /*ignoreCase*/ true);
10561053
}
10571054

10581055
function getDiagnosticFileName(diagnostic: Diagnostic): string {
@@ -1422,8 +1419,7 @@ namespace ts {
14221419
const bComponents = getNormalizedPathComponents(b, currentDirectory);
14231420
const sharedLength = Math.min(aComponents.length, bComponents.length);
14241421
for (let i = 0; i < sharedLength; i++) {
1425-
const result = compareStrings(aComponents[i], bComponents[i],
1426-
/*locales*/ undefined, /*options*/ ignoreCase ? accentSensitivity : undefined);
1422+
const result = compareStrings(aComponents[i], bComponents[i], ignoreCase);
14271423
if (result !== Comparison.EqualTo) {
14281424
return result;
14291425
}
@@ -1445,8 +1441,7 @@ namespace ts {
14451441
}
14461442

14471443
for (let i = 0; i < parentComponents.length; i++) {
1448-
const result = compareStrings(parentComponents[i], childComponents[i],
1449-
/*locales*/ undefined, /*options*/ ignoreCase ? accentSensitivity : undefined);
1444+
const result = compareStrings(parentComponents[i], childComponents[i], ignoreCase);
14501445
if (result !== Comparison.EqualTo) {
14511446
return false;
14521447
}

src/services/navigateTo.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ namespace ts.NavigateTo {
66
const patternMatcher = createPatternMatcher(searchValue);
77
let rawItems: RawNavigateToItem[] = [];
88

9-
// This means "compare in a case insensitive manner."
10-
const baseSensitivity: Intl.CollatorOptions = { sensitivity: "base" };
11-
129
// Search the declarations in all files and output matched NavigateToItem into array of NavigateToItem[]
1310
forEach(sourceFiles, sourceFile => {
1411
cancellationToken.throwIfCancellationRequested();
@@ -188,7 +185,7 @@ namespace ts.NavigateTo {
188185
// We first sort case insensitively. So "Aaa" will come before "bar".
189186
// Then we sort case sensitively, so "aaa" will come before "Aaa".
190187
return i1.matchKind - i2.matchKind ||
191-
ts.compareStrings(i1.name, i2.name, /*locales*/ undefined, /*options*/ baseSensitivity) ||
188+
ts.compareStringsCaseInsensitive(i1.name, i2.name) ||
192189
ts.compareStrings(i1.name, i2.name);
193190
}
194191

0 commit comments

Comments
 (0)