Skip to content

Commit 1dcae83

Browse files
committed
Merge branch 'main' into tsgo-port
2 parents 991c55d + 87aa917 commit 1dcae83

File tree

3,321 files changed

+82537
-45334
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

3,321 files changed

+82537
-45334
lines changed

src/compiler/checker.ts

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,6 @@ import {
10841084
tryGetModuleSpecifierFromDeclaration,
10851085
tryGetPropertyAccessOrIdentifierToString,
10861086
TryStatement,
1087-
TSGO_COMPAT,
10881087
TupleType,
10891088
TupleTypeNode,
10901089
TupleTypeReference,
@@ -1507,8 +1506,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
15071506

15081507
var scanner: Scanner | undefined;
15091508

1510-
var fileIndexMap = new Map(host.getSourceFiles().map((file, i) => [file, i]));
1511-
15121509
var Symbol = objectAllocator.getSymbolConstructor();
15131510
var Type = objectAllocator.getTypeConstructor();
15141511
var Signature = objectAllocator.getSignatureConstructor();
@@ -1545,6 +1542,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
15451542
var useUnknownInCatchVariables = getStrictOptionValue(compilerOptions, "useUnknownInCatchVariables");
15461543
var exactOptionalPropertyTypes = compilerOptions.exactOptionalPropertyTypes;
15471544
var noUncheckedSideEffectImports = compilerOptions.noUncheckedSideEffectImports !== false;
1545+
var stableTypeOrdering = compilerOptions.stableTypeOrdering !== false;
1546+
1547+
var fileIndexMap = stableTypeOrdering ? new Map(host.getSourceFiles().map((file, i) => [file, i])) : undefined;
15481548

15491549
var checkBinaryExpression = createCheckBinaryExpression();
15501550
var emitResolver = createResolver();
@@ -5561,7 +5561,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
55615561
}
55625562

55635563
function createTypeofType() {
5564-
return getUnionType(map(TSGO_COMPAT ? [...typeofNEFacts.keys()].sort() : arrayFrom(typeofNEFacts.keys()), getStringLiteralType));
5564+
return getUnionType(map(stableTypeOrdering ? [...typeofNEFacts.keys()].sort() : arrayFrom(typeofNEFacts.keys()), getStringLiteralType));
55655565
}
55665566

55675567
function createTypeParameter(symbol?: Symbol) {
@@ -5581,14 +5581,14 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
55815581
}
55825582

55835583
function getNamedMembers(members: SymbolTable, container: Symbol | undefined): Symbol[] {
5584-
if (!TSGO_COMPAT) {
5584+
if (!stableTypeOrdering) {
55855585
let result: Symbol[] | undefined;
55865586
members.forEach((symbol, id) => {
55875587
if (isNamedMember(symbol, id)) {
5588-
(result || (result = [])).push(symbol);
5588+
(result ??= []).push(symbol);
55895589
}
55905590
});
5591-
return result || emptyArray;
5591+
return result ?? emptyArray;
55925592
}
55935593

55945594
if (members.size === 0) {
@@ -5616,12 +5616,16 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
56165616

56175617
contained?.sort(compareSymbols);
56185618
nonContained?.sort(compareSymbols);
5619-
return concatenate(contained, nonContained) || emptyArray;
5619+
return concatenate(contained, nonContained) ?? emptyArray;
56205620

56215621
function isDeclarationContainedBy(symbol: Symbol, container: Symbol): boolean {
56225622
const declaration = symbol.valueDeclaration;
5623-
if (declaration) {
5624-
return some(container.declarations, d => containedBy(declaration, d));
5623+
if (declaration && container.declarations) {
5624+
for (const d of container.declarations) {
5625+
if (containedBy(declaration, d)) {
5626+
return true;
5627+
}
5628+
}
56255629
}
56265630
return false;
56275631

@@ -6629,9 +6633,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
66296633
cb: (context: NodeBuilderContext) => T,
66306634
out?: WriterContextOut,
66316635
): T | undefined {
6632-
const moduleResolverHost = tracker?.trackSymbol ? tracker.moduleResolverHost :
6633-
(internalFlags || InternalNodeBuilderFlags.None) & InternalNodeBuilderFlags.DoNotIncludeSymbolChain ? createBasicNodeBuilderModuleSpecifierResolutionHost(host) :
6634-
undefined;
6636+
const moduleResolverHost = tracker?.moduleResolverHost ?? createBasicNodeBuilderModuleSpecifierResolutionHost(host);
66356637
flags = flags || NodeBuilderFlags.None;
66366638
const maxTruncationLength = maximumLength ||
66376639
(flags & NodeBuilderFlags.NoTruncation ? noTruncationMaximumTruncationLength : defaultMaximumTruncationLength);
@@ -18064,11 +18066,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1806418066
}
1806518067

1806618068
function containsType(types: readonly Type[], type: Type): boolean {
18067-
return TSGO_COMPAT ? binarySearch(types, type, identity, compareTypes) >= 0 : binarySearch(types, type, getTypeId, compareValues) >= 0;
18069+
return stableTypeOrdering ? binarySearch(types, type, identity, compareTypes) >= 0 : binarySearch(types, type, getTypeId, compareValues) >= 0;
1806818070
}
1806918071

1807018072
function insertType(types: Type[], type: Type): boolean {
18071-
const index = TSGO_COMPAT ? binarySearch(types, type, identity, compareTypes) : binarySearch(types, type, getTypeId, compareValues);
18073+
const index = stableTypeOrdering ? binarySearch(types, type, identity, compareTypes) : binarySearch(types, type, getTypeId, compareValues);
1807218074
if (index < 0) {
1807318075
types.splice(~index, 0, type);
1807418076
return true;
@@ -18090,7 +18092,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1809018092
}
1809118093
else {
1809218094
const len = typeSet.length;
18093-
const index = TSGO_COMPAT ? binarySearch(typeSet, type, identity, compareTypes) : (len && type.id > typeSet[len - 1].id ? ~len : binarySearch(typeSet, type, getTypeId, compareValues));
18095+
const index = stableTypeOrdering ? binarySearch(typeSet, type, identity, compareTypes) : (len && type.id > typeSet[len - 1].id ? ~len : binarySearch(typeSet, type, getTypeId, compareValues));
1809418096
if (index < 0) {
1809518097
typeSet.splice(~index, 0, type);
1809618098
}
@@ -53795,7 +53797,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
5379553797
function sortSymbolsIfTSGoCompat(array: Symbol[]): Symbol[];
5379653798
function sortSymbolsIfTSGoCompat(array: Symbol[] | undefined): Symbol[] | undefined;
5379753799
function sortSymbolsIfTSGoCompat(array: Symbol[] | undefined): Symbol[] | undefined {
53798-
if (TSGO_COMPAT && array) {
53800+
if (stableTypeOrdering && array) {
5379953801
return array.sort(compareSymbols); // eslint-disable-line local/no-array-mutating-method-expressions
5380053802
}
5380153803
return array;
@@ -53827,8 +53829,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
5382753829
const s1 = getSourceFileOfNode(n1);
5382853830
const s2 = getSourceFileOfNode(n2);
5382953831
if (s1 !== s2) {
53830-
const f1 = fileIndexMap.get(s1)!;
53831-
const f2 = fileIndexMap.get(s2)!;
53832+
const f1 = fileIndexMap!.get(s1)!;
53833+
const f2 = fileIndexMap!.get(s2)!;
5383253834
// Order by index of file in the containing program
5383353835
return f1 - f2;
5383453836
}
@@ -53983,7 +53985,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
5398353985
if (c !== 0) {
5398453986
return c;
5398553987
}
53986-
c = (t1 as IndexType).flags - (t2 as IndexType).flags;
53988+
c = (t1 as IndexType).indexFlags - (t2 as IndexType).indexFlags;
5398753989
if (c !== 0) {
5398853990
return c;
5398953991
}

src/compiler/commandLineParser.ts

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,12 @@ const jsxOptionMap = new Map(Object.entries({
141141
export const inverseJsxOptionMap: Map<string, string> = new Map(mapIterator(jsxOptionMap.entries(), ([key, value]: [string, JsxEmit]) => ["" + value, key] as const));
142142

143143
// NOTE: The order here is important to default lib ordering as entries will have the same
144-
// order in the generated program (see `getDefaultLibPriority` in program.ts). This
144+
// order in the generated program (see `getDefaultLibFilePriority` in program.ts). This
145145
// order also affects overload resolution when a type declared in one lib is
146146
// augmented in another lib.
147147
// NOTE: We must reevaluate the target for upcoming features when each successive TC39 edition is ratified in
148148
// June of each year. This includes changes to `LanguageFeatureMinimumTarget`, `ScriptTarget`,
149-
// `ScriptTargetFeatures` transformers/esnext.ts, compiler/commandLineParser.ts,
149+
// `ScriptTargetFeatures`, `CommandLineOptionOfCustomType`, transformers/esnext.ts, compiler/commandLineParser.ts,
150150
// compiler/utilitiesPublic.ts, and the contents of each lib/esnext.*.d.ts file.
151151
const libEntries: [string, string][] = [
152152
// JavaScript only
@@ -163,6 +163,7 @@ const libEntries: [string, string][] = [
163163
["es2022", "lib.es2022.d.ts"],
164164
["es2023", "lib.es2023.d.ts"],
165165
["es2024", "lib.es2024.d.ts"],
166+
["es2025", "lib.es2025.d.ts"],
166167
["esnext", "lib.esnext.d.ts"],
167168
// Host only
168169
["dom", "lib.dom.d.ts"],
@@ -173,7 +174,7 @@ const libEntries: [string, string][] = [
173174
["webworker.iterable", "lib.webworker.iterable.d.ts"],
174175
["webworker.asynciterable", "lib.webworker.asynciterable.d.ts"],
175176
["scripthost", "lib.scripthost.d.ts"],
176-
// ES2015 Or ESNext By-feature options
177+
// ES2015 and later By-feature options
177178
["es2015.core", "lib.es2015.core.d.ts"],
178179
["es2015.collection", "lib.es2015.collection.d.ts"],
179180
["es2015.generator", "lib.es2015.generator.d.ts"],
@@ -230,27 +231,35 @@ const libEntries: [string, string][] = [
230231
["es2024.regexp", "lib.es2024.regexp.d.ts"],
231232
["es2024.sharedmemory", "lib.es2024.sharedmemory.d.ts"],
232233
["es2024.string", "lib.es2024.string.d.ts"],
233-
["esnext.array", "lib.es2023.array.d.ts"],
234-
["esnext.collection", "lib.esnext.collection.d.ts"],
235-
["esnext.symbol", "lib.es2019.symbol.d.ts"],
234+
["es2025.collection", "lib.es2025.collection.d.ts"],
235+
["es2025.float16", "lib.es2025.float16.d.ts"],
236+
["es2025.intl", "lib.es2025.intl.d.ts"],
237+
["es2025.iterator", "lib.es2025.iterator.d.ts"],
238+
["es2025.promise", "lib.es2025.promise.d.ts"],
239+
["es2025.regexp", "lib.es2025.regexp.d.ts"],
240+
// Fallback for backward compatibility
236241
["esnext.asynciterable", "lib.es2018.asynciterable.d.ts"],
237-
["esnext.intl", "lib.esnext.intl.d.ts"],
238-
["esnext.disposable", "lib.esnext.disposable.d.ts"],
242+
["esnext.symbol", "lib.es2019.symbol.d.ts"],
239243
["esnext.bigint", "lib.es2020.bigint.d.ts"],
240-
["esnext.string", "lib.es2022.string.d.ts"],
241-
["esnext.promise", "lib.es2024.promise.d.ts"],
242244
["esnext.weakref", "lib.es2021.weakref.d.ts"],
243-
["esnext.decorators", "lib.esnext.decorators.d.ts"],
244245
["esnext.object", "lib.es2024.object.d.ts"],
245-
["esnext.array", "lib.esnext.array.d.ts"],
246246
["esnext.regexp", "lib.es2024.regexp.d.ts"],
247247
["esnext.string", "lib.es2024.string.d.ts"],
248-
["esnext.iterator", "lib.esnext.iterator.d.ts"],
249-
["esnext.promise", "lib.esnext.promise.d.ts"],
250-
["esnext.float16", "lib.esnext.float16.d.ts"],
251-
["esnext.typedarrays", "lib.esnext.typedarrays.d.ts"],
248+
["esnext.float16", "lib.es2025.float16.d.ts"],
249+
["esnext.iterator", "lib.es2025.iterator.d.ts"],
250+
["esnext.promise", "lib.es2025.promise.d.ts"],
251+
// ESNext By-feature options
252+
["esnext.array", "lib.esnext.array.d.ts"],
253+
["esnext.collection", "lib.esnext.collection.d.ts"],
254+
["esnext.date", "lib.esnext.date.d.ts"],
255+
["esnext.decorators", "lib.esnext.decorators.d.ts"],
256+
["esnext.disposable", "lib.esnext.disposable.d.ts"],
252257
["esnext.error", "lib.esnext.error.d.ts"],
258+
["esnext.intl", "lib.esnext.intl.d.ts"],
253259
["esnext.sharedmemory", "lib.esnext.sharedmemory.d.ts"],
260+
["esnext.temporal", "lib.esnext.temporal.d.ts"],
261+
["esnext.typedarrays", "lib.esnext.typedarrays.d.ts"],
262+
// Decorators
254263
["decorators", "lib.decorators.d.ts"],
255264
["decorators.legacy", "lib.decorators.legacy.d.ts"],
256265
];
@@ -555,6 +564,10 @@ export const commonOptionsWithBuild: CommandLineOption[] = [
555564
},
556565
];
557566

567+
// NOTE: We must reevaluate the target for upcoming features when each successive TC39 edition is ratified in
568+
// June of each year. This includes changes to `LanguageFeatureMinimumTarget`, `ScriptTarget`,
569+
// `ScriptTargetFeatures`, `CommandLineOptionOfCustomType`, transformers/esnext.ts, compiler/commandLineParser.ts,
570+
// compiler/utilitiesPublic.ts, and the contents of each lib/esnext.*.d.ts file.
558571
/** @internal */
559572
export const targetOptionDeclaration: CommandLineOptionOfCustomType = {
560573
name: "target",
@@ -573,6 +586,7 @@ export const targetOptionDeclaration: CommandLineOptionOfCustomType = {
573586
es2022: ScriptTarget.ES2022,
574587
es2023: ScriptTarget.ES2023,
575588
es2024: ScriptTarget.ES2024,
589+
es2025: ScriptTarget.ES2025,
576590
esnext: ScriptTarget.ESNext,
577591
})),
578592
affectsSourceFile: true,
@@ -961,6 +975,16 @@ const commandOptionsWithoutBuild: CommandLineOption[] = [
961975
description: Diagnostics.Built_in_iterators_are_instantiated_with_a_TReturn_type_of_undefined_instead_of_any,
962976
defaultValueDescription: Diagnostics.true_unless_strict_is_false,
963977
},
978+
{
979+
name: "stableTypeOrdering",
980+
type: "boolean",
981+
affectsSemanticDiagnostics: true,
982+
affectsBuildInfo: true,
983+
showInHelp: false,
984+
category: Diagnostics.Type_Checking,
985+
description: Diagnostics.Ensure_types_are_ordered_stably_and_deterministically_across_compilations,
986+
defaultValueDescription: true,
987+
},
964988
{
965989
name: "noImplicitThis",
966990
type: "boolean",

src/compiler/corePublic.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ export const versionMajorMinor = "6.0";
55
/** The version of the TypeScript compiler release */
66
export const version: string = `${versionMajorMinor}.0-dev`;
77

8-
const tsgoCompatEnv = typeof process !== "undefined" && process.env ? process.env.TSGO_COMPAT : undefined;
9-
10-
/** @internal */
11-
export const TSGO_COMPAT: boolean = tsgoCompatEnv ? tsgoCompatEnv === "true" : true;
12-
138
/**
149
* Type of objects whose values are all of the same type.
1510
* The `in` and `for-in` operators can *not* be safely used,

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6589,6 +6589,10 @@
65896589
"category": "Message",
65906590
"code": 6808
65916591
},
6592+
"Ensure types are ordered stably and deterministically across compilations.": {
6593+
"category": "Message",
6594+
"code": 6809
6595+
},
65926596

65936597
"one of:": {
65946598
"category": "Message",

src/compiler/executeCommandLine.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,11 @@ function shouldBePretty(sys: System, options: CompilerOptions | BuildOptions) {
174174
}
175175

176176
function getOptionsForHelp(commandLine: ParsedCommandLine) {
177+
const helpOptions = filter(optionDeclarations.concat(tscBuildOption), option => option.showInHelp !== false);
177178
// Sort our options by their names, (e.g. "--noImplicitAny" comes before "--watch")
178179
return !!commandLine.options.all ?
179-
toSorted(optionDeclarations.concat(tscBuildOption), (a, b) => compareStringsCaseInsensitive(a.name, b.name)) :
180-
filter(optionDeclarations.concat(tscBuildOption), v => !!v.showInSimplifiedHelpView);
180+
toSorted(helpOptions, (a, b) => compareStringsCaseInsensitive(a.name, b.name)) :
181+
filter(helpOptions, v => !!v.showInSimplifiedHelpView);
181182
}
182183

183184
function printVersion(sys: System) {
@@ -512,16 +513,16 @@ function printEasyHelp(sys: System, simpleOptions: readonly CommandLineOption[])
512513
function printAllHelp(sys: System, compilerOptions: readonly CommandLineOption[], buildOptions: readonly CommandLineOption[], watchOptions: readonly CommandLineOption[]) {
513514
let output: string[] = [...getHeader(sys, `${getDiagnosticText(Diagnostics.tsc_Colon_The_TypeScript_Compiler)} - ${getDiagnosticText(Diagnostics.Version_0, version)}`)];
514515
output = [...output, ...generateSectionOptionsOutput(sys, getDiagnosticText(Diagnostics.ALL_COMPILER_OPTIONS), compilerOptions, /*subCategory*/ true, /*beforeOptionsDescription*/ undefined, formatMessage(Diagnostics.You_can_learn_about_all_of_the_compiler_options_at_0, "https://aka.ms/tsc"))];
515-
output = [...output, ...generateSectionOptionsOutput(sys, getDiagnosticText(Diagnostics.WATCH_OPTIONS), watchOptions, /*subCategory*/ false, getDiagnosticText(Diagnostics.Including_watch_w_will_start_watching_the_current_project_for_the_file_changes_Once_set_you_can_config_watch_mode_with_Colon))];
516-
output = [...output, ...generateSectionOptionsOutput(sys, getDiagnosticText(Diagnostics.BUILD_OPTIONS), filter(buildOptions, option => option !== tscBuildOption), /*subCategory*/ false, formatMessage(Diagnostics.Using_build_b_will_make_tsc_behave_more_like_a_build_orchestrator_than_a_compiler_This_is_used_to_trigger_building_composite_projects_which_you_can_learn_more_about_at_0, "https://aka.ms/tsc-composite-builds"))];
516+
output = [...output, ...generateSectionOptionsOutput(sys, getDiagnosticText(Diagnostics.WATCH_OPTIONS), filter(watchOptions, option => option.showInHelp !== false), /*subCategory*/ false, getDiagnosticText(Diagnostics.Including_watch_w_will_start_watching_the_current_project_for_the_file_changes_Once_set_you_can_config_watch_mode_with_Colon))];
517+
output = [...output, ...generateSectionOptionsOutput(sys, getDiagnosticText(Diagnostics.BUILD_OPTIONS), filter(buildOptions, option => option !== tscBuildOption && option.showInHelp !== false), /*subCategory*/ false, formatMessage(Diagnostics.Using_build_b_will_make_tsc_behave_more_like_a_build_orchestrator_than_a_compiler_This_is_used_to_trigger_building_composite_projects_which_you_can_learn_more_about_at_0, "https://aka.ms/tsc-composite-builds"))];
517518
for (const line of output) {
518519
sys.write(line);
519520
}
520521
}
521522

522523
function printBuildHelp(sys: System, buildOptions: readonly CommandLineOption[]) {
523524
let output: string[] = [...getHeader(sys, `${getDiagnosticText(Diagnostics.tsc_Colon_The_TypeScript_Compiler)} - ${getDiagnosticText(Diagnostics.Version_0, version)}`)];
524-
output = [...output, ...generateSectionOptionsOutput(sys, getDiagnosticText(Diagnostics.BUILD_OPTIONS), filter(buildOptions, option => option !== tscBuildOption), /*subCategory*/ false, formatMessage(Diagnostics.Using_build_b_will_make_tsc_behave_more_like_a_build_orchestrator_than_a_compiler_This_is_used_to_trigger_building_composite_projects_which_you_can_learn_more_about_at_0, "https://aka.ms/tsc-composite-builds"))];
525+
output = [...output, ...generateSectionOptionsOutput(sys, getDiagnosticText(Diagnostics.BUILD_OPTIONS), filter(buildOptions, option => option !== tscBuildOption && option.showInHelp !== false), /*subCategory*/ false, formatMessage(Diagnostics.Using_build_b_will_make_tsc_behave_more_like_a_build_orchestrator_than_a_compiler_This_is_used_to_trigger_building_composite_projects_which_you_can_learn_more_about_at_0, "https://aka.ms/tsc-composite-builds"))];
525526
for (const line of output) {
526527
sys.write(line);
527528
}

src/compiler/transformers/esnext.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ const enum UsingKind {
7171
export function transformESNext(context: TransformationContext): (x: SourceFile | Bundle) => SourceFile | Bundle {
7272
// NOTE: We must reevaluate the target for upcoming features when each successive TC39 edition is ratified in
7373
// June of each year. This includes changes to `LanguageFeatureMinimumTarget`, `ScriptTarget`,
74-
// `ScriptTargetFeatures` transformers/esnext.ts, compiler/commandLineParser.ts,
74+
// `ScriptTargetFeatures`, `CommandLineOptionOfCustomType`, transformers/esnext.ts, compiler/commandLineParser.ts,
7575
// compiler/utilitiesPublic.ts, and the contents of each lib/esnext.*.d.ts file.
7676

7777
const {

0 commit comments

Comments
 (0)