@@ -84,6 +84,7 @@ import {
84
84
compareComparableValues,
85
85
compareDiagnostics,
86
86
comparePaths,
87
+ compareValues,
87
88
Comparison,
88
89
CompilerOptions,
89
90
ComputedPropertyName,
@@ -5394,7 +5395,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
5394
5395
}
5395
5396
5396
5397
function createTypeofType() {
5397
- return getUnionType(map([...typeofNEFacts.keys()].sort(), getStringLiteralType));
5398
+ return getUnionType(map(__TSGO_COMPAT__ ? [...typeofNEFacts.keys()].sort() : arrayFrom(typeofNEFacts.keys() ), getStringLiteralType));
5398
5399
}
5399
5400
5400
5401
function createTypeParameter(symbol?: Symbol) {
@@ -5420,7 +5421,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
5420
5421
(result || (result = [])).push(symbol);
5421
5422
}
5422
5423
});
5423
- result?.sort(compareSymbols );
5424
+ sortSymbolsIfTSGoCompat(result );
5424
5425
return result || emptyArray;
5425
5426
}
5426
5427
@@ -17653,11 +17654,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
17653
17654
}
17654
17655
17655
17656
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;
17657
17658
}
17658
17659
17659
17660
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 );
17661
17662
if (index < 0) {
17662
17663
types.splice(~index, 0, type);
17663
17664
return true;
@@ -17678,7 +17679,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
17678
17679
if (!(getObjectFlags(type) & ObjectFlags.ContainsWideningType)) includes |= TypeFlags.IncludesNonWideningType;
17679
17680
}
17680
17681
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));
17682
17684
if (index < 0) {
17683
17685
typeSet.splice(~index, 0, type);
17684
17686
}
@@ -34717,16 +34719,17 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
34717
34719
// So the table *contains* `x` but `x` isn't actually in scope.
34718
34720
// However, resolveNameHelper will continue and call this callback again, so we'll eventually get a correct suggestion.
34719
34721
if (symbol) return symbol;
34720
- let candidates = arrayFrom(symbols.values()).sort(compareSymbols) ;
34722
+ let candidates = arrayFrom(symbols.values());
34721
34723
if (symbols === globals) {
34722
34724
const primitives = mapDefined(
34723
34725
["string", "number", "boolean", "object", "bigint", "symbol"],
34724
34726
s => symbols.has((s.charAt(0).toUpperCase() + s.slice(1)) as __String)
34725
34727
? createSymbol(SymbolFlags.TypeAlias, s as __String) as Symbol
34726
34728
: undefined,
34727
34729
);
34728
- candidates = concatenate(candidates, primitives );
34730
+ candidates = concatenate(primitives, candidates );
34729
34731
}
34732
+ sortSymbolsIfTSGoCompat(candidates);
34730
34733
return getSpellingSuggestionForName(unescapeLeadingUnderscores(name), candidates, meaning);
34731
34734
}
34732
34735
function getSuggestedSymbolForNonexistentSymbol(location: Node | undefined, outerName: __String, meaning: SymbolFlags): Symbol | undefined {
@@ -34736,7 +34739,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
34736
34739
}
34737
34740
34738
34741
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);
34740
34743
}
34741
34744
34742
34745
function getSuggestionForNonexistentIndexSignature(objectType: Type, expr: ElementAccessExpression, keyedType: Type): string | undefined {
@@ -52850,6 +52853,15 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
52850
52853
return specifier;
52851
52854
}
52852
52855
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
+
52853
52865
function compareSymbols(s1: Symbol | undefined, s2: Symbol | undefined): number {
52854
52866
if (s1 === s2) return 0;
52855
52867
if (s1 === undefined) return 1;
0 commit comments