Skip to content

Commit c0ed26e

Browse files
committed
Simplify comparers
1 parent 130c407 commit c0ed26e

10 files changed

Lines changed: 162 additions & 255 deletions

File tree

src/compiler/core.ts

Lines changed: 148 additions & 240 deletions
Large diffs are not rendered by default.

src/compiler/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6069,7 +6069,7 @@ namespace ts {
60696069
const checkJsDirectiveMatchResult = checkJsDirectiveRegEx.exec(comment);
60706070
if (checkJsDirectiveMatchResult) {
60716071
checkJsDirective = {
6072-
enabled: StringCollator.ordinalCaseInsensitive.equate(checkJsDirectiveMatchResult[1], "@ts-check"),
6072+
enabled: equateStringsCaseInsensitive(checkJsDirectiveMatchResult[1], "@ts-check"),
60736073
end: range.end,
60746074
pos: range.pos
60756075
};

src/compiler/program.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,12 +1103,12 @@ namespace ts {
11031103
// otherwise, using options specified in '--lib' instead of '--target' default library file
11041104

11051105
// File-system ordering should use a predictable order
1106-
const collator = StringCollator.getPathCollator(!host.useCaseSensitiveFileNames());
1106+
const equalityComparer = getStringEqualityComparer(!host.useCaseSensitiveFileNames());
11071107
if (!options.lib) {
1108-
return collator.equate(file.fileName, getDefaultLibraryFileName());
1108+
return equalityComparer(file.fileName, getDefaultLibraryFileName());
11091109
}
11101110
else {
1111-
return forEach(options.lib, libFileName => collator.equate(file.fileName, combinePaths(defaultLibraryPath, libFileName)));
1111+
return forEach(options.lib, libFileName => equalityComparer(file.fileName, combinePaths(defaultLibraryPath, libFileName)));
11121112
}
11131113
}
11141114

src/compiler/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3950,7 +3950,7 @@ namespace ts {
39503950
}
39513951

39523952
// Set the locale for UI collation
3953-
StringCollator.uiLocale = locale;
3953+
setUILocale(locale);
39543954

39553955
function trySetLanguageAndTerritory(language: string, territory: string, errors?: Push<Diagnostic>): boolean {
39563956
const compilerFilePath = normalizePath(sys.getExecutingFilePath());

src/harness/harness.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1699,8 +1699,8 @@ namespace Harness {
16991699
export function *iterateOutputs(outputFiles: Harness.Compiler.GeneratedFile[]): IterableIterator<[string, string]> {
17001700
// Collect, test, and sort the fileNames
17011701
// As this uses the file system, use a predictable order
1702-
const collator = ts.StringCollator.getPathCollator(/*ignoreCase*/ false);
1703-
outputFiles.sort((a, b) => collator.compare(cleanName(a.fileName), cleanName(b.fileName)));
1702+
const comparer = ts.getStringComparer(/*ignoreCase*/ false);
1703+
outputFiles.sort((a, b) => comparer(cleanName(a.fileName), cleanName(b.fileName)));
17041704
const dupeCase = ts.createMap<number>();
17051705
// Yield them
17061706
for (const outputFile of outputFiles) {

src/harness/unittests/compileOnSave.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ namespace ts.projectSystem {
1414
function sendAffectedFileRequestAndCheckResult(session: server.Session, request: server.protocol.Request, expectedFileList: { projectFileName: string, files: FileOrFolder[] }[]) {
1515
const response = session.executeCommand(request).response as server.protocol.CompileOnSaveAffectedFileListSingleProject[];
1616
// File-system ordering should use a predictable order
17-
const collator = StringCollator.getPathCollator(/*ignoreCase*/ false);
18-
const actualResult = response.sort((list1, list2) => collator.compare(list1.projectFileName, list2.projectFileName));
19-
expectedFileList = expectedFileList.sort((list1, list2) => collator.compare(list1.projectFileName, list2.projectFileName));
17+
const comparer = getStringComparer(/*ignoreCase*/ false);
18+
const actualResult = response.sort((list1, list2) => comparer(list1.projectFileName, list2.projectFileName));
19+
expectedFileList = expectedFileList.sort((list1, list2) => comparer(list1.projectFileName, list2.projectFileName));
2020

2121
assert.equal(actualResult.length, expectedFileList.length, `Actual result project number is different from the expected project number`);
2222

src/server/session.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,15 +1186,14 @@ namespace ts.server {
11861186

11871187
const completions = project.getLanguageService().getCompletionsAtPosition(file, position);
11881188
if (simplifiedResult) {
1189-
const comparer = StringCollator.uiCaseSensitive.compare;
11901189
return mapDefined<CompletionEntry, protocol.CompletionEntry>(completions && completions.entries, entry => {
11911190
if (completions.isMemberCompletion || (entry.name.toLowerCase().indexOf(prefix.toLowerCase()) === 0)) {
11921191
const { name, kind, kindModifiers, sortText, replacementSpan, hasAction } = entry;
11931192
const convertedSpan = replacementSpan ? this.decorateSpan(replacementSpan, scriptInfo) : undefined;
11941193
// Use `hasAction || undefined` to avoid serializing `false`.
11951194
return { name, kind, kindModifiers, sortText, replacementSpan: convertedSpan, hasAction: hasAction || undefined };
11961195
}
1197-
}).sort((a, b) => comparer(a.name, b.name));
1196+
}).sort((a, b) => compareStringsCaseSensitiveUI(a.name, b.name));
11981197
}
11991198
else {
12001199
return completions;

src/services/navigateTo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ namespace ts.NavigateTo {
176176
function compareNavigateToItems(i1: RawNavigateToItem, i2: RawNavigateToItem): number {
177177
// TODO(cyrusn): get the gamut of comparisons that VS already uses here.
178178
return i1.matchKind - i2.matchKind ||
179-
StringCollator.uiCaseSensitive.compare(i1.name, i2.name);
179+
compareStringsCaseSensitiveUI(i1.name, i2.name);
180180
}
181181

182182
function createNavigateToItem(rawItem: RawNavigateToItem): NavigateToItem {

src/services/navigationBar.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ namespace ts.NavigationBar {
368368

369369
function compareChildren(child1: NavigationBarNode, child2: NavigationBarNode): number {
370370
const name1 = tryGetName(child1.node), name2 = tryGetName(child2.node);
371-
return StringCollator.uiCaseInsensitive.compare(name1, name2)
371+
return compareStringsCaseInsensitiveUI(name1, name2)
372372
|| navigationBarNodeKind(child1) - navigationBarNodeKind(child2);
373373
}
374374

src/services/refactors/extractSymbol.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1156,7 +1156,7 @@ namespace ts.refactor.extractSymbol {
11561156
const name2 = type2.symbol ? type2.symbol.getName() : "";
11571157

11581158
// This is for code generation, use a predictable comparer.
1159-
const nameDiff = StringCollator.invariantCaseSensitive.compare(name1, name2);
1159+
const nameDiff = compareStringsCaseSensitive(name1, name2);
11601160
if (nameDiff !== 0) {
11611161
return nameDiff;
11621162
}

0 commit comments

Comments
 (0)