@@ -84,6 +84,7 @@ import {
8484 compareComparableValues,
8585 compareDiagnostics,
8686 comparePaths,
87+ compareValues,
8788 Comparison,
8889 CompilerOptions,
8990 ComputedPropertyName,
@@ -5394,7 +5395,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
53945395 }
53955396
53965397 function createTypeofType() {
5397- return getUnionType(map([...typeofNEFacts.keys()].sort(), getStringLiteralType));
5398+ return getUnionType(map(__TSGO_COMPAT__ ? [...typeofNEFacts.keys()].sort() : arrayFrom(typeofNEFacts.keys() ), getStringLiteralType));
53985399 }
53995400
54005401 function createTypeParameter(symbol?: Symbol) {
@@ -5420,7 +5421,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
54205421 (result || (result = [])).push(symbol);
54215422 }
54225423 });
5423- result?.sort(compareSymbols );
5424+ sortSymbolsIfTSGoCompat(result );
54245425 return result || emptyArray;
54255426 }
54265427
@@ -17653,11 +17654,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1765317654 }
1765417655
1765517656 function containsType(types: readonly Type[], type: Type): boolean {
17656- return binarySearch(types, type, identity, compareTypes) >= 0;
17657+ return __TSGO_COMPAT__ ? binarySearch(types, type, identity, compareTypes) >= 0 : binarySearch(types, type, getTypeId, compareValues ) >= 0;
1765717658 }
1765817659
1765917660 function insertType(types: Type[], type: Type): boolean {
17660- const index = binarySearch(types, type, identity, compareTypes);
17661+ const index = __TSGO_COMPAT__ ? binarySearch(types, type, identity, compareTypes) : binarySearch(types, type, getTypeId, compareValues );
1766117662 if (index < 0) {
1766217663 types.splice(~index, 0, type);
1766317664 return true;
@@ -17678,7 +17679,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1767817679 if (!(getObjectFlags(type) & ObjectFlags.ContainsWideningType)) includes |= TypeFlags.IncludesNonWideningType;
1767917680 }
1768017681 else {
17681- const index = binarySearch(typeSet, type, identity, compareTypes);
17682+ const len = typeSet.length;
17683+ const index = __TSGO_COMPAT__ ? binarySearch(typeSet, type, identity, compareTypes) : (len && type.id > typeSet[len - 1].id ? ~len : binarySearch(typeSet, type, getTypeId, compareValues));
1768217684 if (index < 0) {
1768317685 typeSet.splice(~index, 0, type);
1768417686 }
@@ -34717,16 +34719,17 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3471734719 // So the table *contains* `x` but `x` isn't actually in scope.
3471834720 // However, resolveNameHelper will continue and call this callback again, so we'll eventually get a correct suggestion.
3471934721 if (symbol) return symbol;
34720- let candidates = arrayFrom(symbols.values()).sort(compareSymbols) ;
34722+ let candidates = arrayFrom(symbols.values());
3472134723 if (symbols === globals) {
3472234724 const primitives = mapDefined(
3472334725 ["string", "number", "boolean", "object", "bigint", "symbol"],
3472434726 s => symbols.has((s.charAt(0).toUpperCase() + s.slice(1)) as __String)
3472534727 ? createSymbol(SymbolFlags.TypeAlias, s as __String) as Symbol
3472634728 : undefined,
3472734729 );
34728- candidates = concatenate(candidates, primitives );
34730+ candidates = concatenate(primitives, candidates );
3472934731 }
34732+ sortSymbolsIfTSGoCompat(candidates);
3473034733 return getSpellingSuggestionForName(unescapeLeadingUnderscores(name), candidates, meaning);
3473134734 }
3473234735 function getSuggestedSymbolForNonexistentSymbol(location: Node | undefined, outerName: __String, meaning: SymbolFlags): Symbol | undefined {
@@ -34736,7 +34739,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3473634739 }
3473734740
3473834741 function getSuggestedSymbolForNonexistentModule(name: Identifier, targetModule: Symbol): Symbol | undefined {
34739- return targetModule.exports && getSpellingSuggestionForName(idText(name), getExportsOfModuleAsArray(targetModule).sort(compareSymbols ), SymbolFlags.ModuleMember); // eslint-disable-line local/no-array-mutating-method-expressions
34742+ return targetModule.exports && getSpellingSuggestionForName(idText(name), sortSymbolsIfTSGoCompat( getExportsOfModuleAsArray(targetModule)), SymbolFlags.ModuleMember);
3474034743 }
3474134744
3474234745 function getSuggestionForNonexistentIndexSignature(objectType: Type, expr: ElementAccessExpression, keyedType: Type): string | undefined {
@@ -52850,6 +52853,15 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
5285052853 return specifier;
5285152854 }
5285252855
52856+ function sortSymbolsIfTSGoCompat(array: Symbol[]): Symbol[];
52857+ function sortSymbolsIfTSGoCompat(array: Symbol[] | undefined): Symbol[] | undefined;
52858+ function sortSymbolsIfTSGoCompat(array: Symbol[] | undefined): Symbol[] | undefined {
52859+ if (__TSGO_COMPAT__ && array) {
52860+ return array.sort(compareSymbols);
52861+ }
52862+ return array;
52863+ }
52864+
5285352865 function compareSymbols(s1: Symbol | undefined, s2: Symbol | undefined): number {
5285452866 if (s1 === s2) return 0;
5285552867 if (s1 === undefined) return 1;
0 commit comments