mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 04:43:37 -05:00
Cleanup and reordering
This commit is contained in:
@@ -1490,6 +1490,16 @@ namespace ts {
|
||||
return a === b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare equality between two strings using an ordinal comparison.
|
||||
*
|
||||
* Case-insensitive comparisons compare both strings after applying `toUpperCase` to
|
||||
* each string.
|
||||
*/
|
||||
export function equateStrings(a: string, b: string, ignoreCase: boolean) {
|
||||
return ignoreCase ? equateStringsCaseInsensitive(a, b) : equateStringsCaseSensitive(a, b);
|
||||
}
|
||||
|
||||
export function equateStringsCaseInsensitive(a: string, b: string) {
|
||||
return a === b
|
||||
|| a !== undefined
|
||||
@@ -1501,16 +1511,6 @@ namespace ts {
|
||||
return equateValues(a, b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare equality between two strings using an ordinal comparison.
|
||||
*
|
||||
* Case-insensitive comparisons compare both strings after applying `toUpperCase` to
|
||||
* each string.
|
||||
*/
|
||||
export function equateStrings(a: string, b: string, ignoreCase: boolean) {
|
||||
return ignoreCase ? equateStringsCaseInsensitive(a, b) : equateStringsCaseSensitive(a, b);
|
||||
}
|
||||
|
||||
export function getStringEqualityComparer(ignoreCase: boolean) {
|
||||
return ignoreCase ? equateStringsCaseInsensitive : equateStringsCaseSensitive;
|
||||
}
|
||||
@@ -1557,6 +1557,20 @@ namespace ts {
|
||||
return ignoreCase ? compareStringsCaseInsensitive : compareStringsCaseSensitive;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare two strings using the sort behavior of the UI locale.
|
||||
*
|
||||
* Ordering is not predictable between different host locales, but is best for displaying
|
||||
* ordered data for UI presentation. Characters with multiple unicode representations may
|
||||
* be considered equal.
|
||||
*
|
||||
* Case-insensitive comparisons compare strings that differ in only base characters or
|
||||
* accents/diacritic marks as unequal.
|
||||
*/
|
||||
export function compareStringsUI(a: string, b: string, ignoreCase: boolean) {
|
||||
return ignoreCase ? compareStringsCaseInsensitiveUI(a, b) : compareStringsCaseSensitiveUI(a, b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a string comparer for use with string collation in the UI.
|
||||
*/
|
||||
@@ -1660,24 +1674,17 @@ namespace ts {
|
||||
return comparer(a, b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare two strings using the sort behavior of the UI locale.
|
||||
*
|
||||
* Ordering is not predictable between different host locales, but is best for displaying
|
||||
* ordered data for UI presentation. Characters with multiple unicode representations may
|
||||
* be considered equal.
|
||||
*
|
||||
* Case-insensitive comparisons compare strings that differ in only base characters or
|
||||
* accents/diacritic marks as unequal.
|
||||
*/
|
||||
export function compareStringsUI(a: string, b: string, ignoreCase: boolean) {
|
||||
return ignoreCase ? compareStringsCaseInsensitiveUI(a, b) : compareStringsCaseSensitiveUI(a, b);
|
||||
}
|
||||
|
||||
export function getStringComparerUI(ignoreCase: boolean) {
|
||||
return ignoreCase ? compareStringsCaseInsensitiveUI : compareStringsCaseSensitiveUI;
|
||||
}
|
||||
|
||||
export function compareProperties<T>(a: T, b: T, key: keyof T) {
|
||||
return a === b ? Comparison.EqualTo :
|
||||
a === undefined ? Comparison.LessThan :
|
||||
b === undefined ? Comparison.GreaterThan :
|
||||
compareValues(a[key], b[key]);
|
||||
}
|
||||
|
||||
function getDiagnosticFileName(diagnostic: Diagnostic): string {
|
||||
return diagnostic.file ? diagnostic.file.fileName : undefined;
|
||||
}
|
||||
|
||||
@@ -3949,7 +3949,7 @@ namespace ts {
|
||||
trySetLanguageAndTerritory(language, /*territory*/ undefined, errors);
|
||||
}
|
||||
|
||||
// Set the locale for UI collation
|
||||
// Set the UI locale for string collation
|
||||
setUILocale(locale);
|
||||
|
||||
function trySetLanguageAndTerritory(language: string, territory: string, errors?: Push<Diagnostic>): boolean {
|
||||
|
||||
@@ -13,7 +13,6 @@ namespace ts.projectSystem {
|
||||
describe("CompileOnSave affected list", () => {
|
||||
function sendAffectedFileRequestAndCheckResult(session: server.Session, request: server.protocol.Request, expectedFileList: { projectFileName: string, files: FileOrFolder[] }[]) {
|
||||
const response = session.executeCommand(request).response as server.protocol.CompileOnSaveAffectedFileListSingleProject[];
|
||||
// File-system ordering should use a predictable order
|
||||
const comparer = getStringComparer(/*ignoreCase*/ false);
|
||||
const actualResult = response.sort((list1, list2) => comparer(list1.projectFileName, list2.projectFileName));
|
||||
expectedFileList = expectedFileList.sort((list1, list2) => comparer(list1.projectFileName, list2.projectFileName));
|
||||
|
||||
@@ -173,10 +173,10 @@ namespace ts.NavigateTo {
|
||||
return bestMatchKind;
|
||||
}
|
||||
|
||||
function compareNavigateToItems(i1: RawNavigateToItem, i2: RawNavigateToItem): number {
|
||||
function compareNavigateToItems(i1: RawNavigateToItem, i2: RawNavigateToItem) {
|
||||
// TODO(cyrusn): get the gamut of comparisons that VS already uses here.
|
||||
return i1.matchKind - i2.matchKind ||
|
||||
compareStringsCaseSensitiveUI(i1.name, i2.name);
|
||||
return compareValues(i1.matchKind, i2.matchKind)
|
||||
|| compareStringsCaseSensitiveUI(i1.name, i2.name);
|
||||
}
|
||||
|
||||
function createNavigateToItem(rawItem: RawNavigateToItem): NavigateToItem {
|
||||
|
||||
@@ -366,10 +366,9 @@ namespace ts.NavigationBar {
|
||||
children.sort(compareChildren);
|
||||
}
|
||||
|
||||
function compareChildren(child1: NavigationBarNode, child2: NavigationBarNode): number {
|
||||
const name1 = tryGetName(child1.node), name2 = tryGetName(child2.node);
|
||||
return compareStringsCaseInsensitiveUI(name1, name2)
|
||||
|| navigationBarNodeKind(child1) - navigationBarNodeKind(child2);
|
||||
function compareChildren(child1: NavigationBarNode, child2: NavigationBarNode) {
|
||||
return compareStringsCaseInsensitiveUI(tryGetName(child1.node), tryGetName(child2.node))
|
||||
|| compareValues(navigationBarNodeKind(child1), navigationBarNodeKind(child2));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1137,32 +1137,11 @@ namespace ts.refactor.extractSymbol {
|
||||
{type: type1, declaration: declaration1}: {type: Type, declaration?: Declaration},
|
||||
{type: type2, declaration: declaration2}: {type: Type, declaration?: Declaration}) {
|
||||
|
||||
if (declaration1) {
|
||||
if (declaration2) {
|
||||
const positionDiff = declaration1.pos - declaration2.pos;
|
||||
if (positionDiff !== 0) {
|
||||
return positionDiff;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return 1; // Sort undeclared type parameters to the front.
|
||||
}
|
||||
}
|
||||
else if (declaration2) {
|
||||
return -1; // Sort undeclared type parameters to the front.
|
||||
}
|
||||
|
||||
const name1 = type1.symbol ? type1.symbol.getName() : "";
|
||||
const name2 = type2.symbol ? type2.symbol.getName() : "";
|
||||
|
||||
// This is for code generation, use a predictable comparer.
|
||||
const nameDiff = compareStringsCaseSensitive(name1, name2);
|
||||
if (nameDiff !== 0) {
|
||||
return nameDiff;
|
||||
}
|
||||
|
||||
// IDs are guaranteed to be unique, so this ensures a total ordering.
|
||||
return type1.id - type2.id;
|
||||
return compareProperties(declaration1, declaration2, "pos")
|
||||
|| compareStringsCaseSensitive(
|
||||
type1.symbol ? type1.symbol.getName() : "",
|
||||
type2.symbol ? type2.symbol.getName() : "")
|
||||
|| compareValues(type1.id, type2.id);
|
||||
}
|
||||
|
||||
function getCalledExpression(scope: Node, range: TargetRange, functionNameText: string): Expression {
|
||||
|
||||
Reference in New Issue
Block a user