Skip to content

Commit

Permalink
Introduce ES2024 target and fix some types (#58573)
Browse files Browse the repository at this point in the history
Co-authored-by: indrajitbnikam <[email protected]>
Co-authored-by: Ron Buckton <[email protected]>
  • Loading branch information
3 people authored Sep 27, 2024
1 parent 52c59db commit 9d98874
Show file tree
Hide file tree
Showing 148 changed files with 4,315 additions and 2,804 deletions.
22 changes: 16 additions & 6 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ export const inverseJsxOptionMap: Map<string, string> = new Map(mapIterator(jsxO
// augmented in another lib.
// NOTE: We must reevaluate the target for upcoming features when each successive TC39 edition is ratified in
// June of each year. This includes changes to `LanguageFeatureMinimumTarget`, `ScriptTarget`,
// transformers/esnext.ts, commandLineParser.ts, and the contents of each lib/esnext.*.d.ts file.
// `ScriptTargetFeatures` transformers/esnext.ts, compiler/commandLineParser.ts and the contents of each
// lib/esnext.*.d.ts file.
const libEntries: [string, string][] = [
// JavaScript only
["es5", "lib.es5.d.ts"],
Expand All @@ -161,6 +162,7 @@ const libEntries: [string, string][] = [
["es2021", "lib.es2021.d.ts"],
["es2022", "lib.es2022.d.ts"],
["es2023", "lib.es2023.d.ts"],
["es2024", "lib.es2024.d.ts"],
["esnext", "lib.esnext.d.ts"],
// Host only
["dom", "lib.dom.d.ts"],
Expand All @@ -183,6 +185,7 @@ const libEntries: [string, string][] = [
["es2015.symbol.wellknown", "lib.es2015.symbol.wellknown.d.ts"],
["es2016.array.include", "lib.es2016.array.include.d.ts"],
["es2016.intl", "lib.es2016.intl.d.ts"],
["es2017.arraybuffer", "lib.es2017.arraybuffer.d.ts"],
["es2017.date", "lib.es2017.date.d.ts"],
["es2017.object", "lib.es2017.object.d.ts"],
["es2017.sharedmemory", "lib.es2017.sharedmemory.d.ts"],
Expand Down Expand Up @@ -215,12 +218,18 @@ const libEntries: [string, string][] = [
["es2022.error", "lib.es2022.error.d.ts"],
["es2022.intl", "lib.es2022.intl.d.ts"],
["es2022.object", "lib.es2022.object.d.ts"],
["es2022.sharedmemory", "lib.es2022.sharedmemory.d.ts"],
["es2022.string", "lib.es2022.string.d.ts"],
["es2022.regexp", "lib.es2022.regexp.d.ts"],
["es2023.array", "lib.es2023.array.d.ts"],
["es2023.collection", "lib.es2023.collection.d.ts"],
["es2023.intl", "lib.es2023.intl.d.ts"],
["es2024.arraybuffer", "lib.es2024.arraybuffer.d.ts"],
["es2024.collection", "lib.es2024.collection.d.ts"],
["es2024.object", "lib.es2024.object.d.ts"],
["es2024.promise", "lib.es2024.promise.d.ts"],
["es2024.regexp", "lib.es2024.regexp.d.ts"],
["es2024.sharedmemory", "lib.es2024.sharedmemory.d.ts"],
["es2024.string", "lib.es2024.string.d.ts"],
["esnext.array", "lib.es2023.array.d.ts"],
["esnext.collection", "lib.esnext.collection.d.ts"],
["esnext.symbol", "lib.es2019.symbol.d.ts"],
Expand All @@ -229,13 +238,13 @@ const libEntries: [string, string][] = [
["esnext.disposable", "lib.esnext.disposable.d.ts"],
["esnext.bigint", "lib.es2020.bigint.d.ts"],
["esnext.string", "lib.es2022.string.d.ts"],
["esnext.promise", "lib.esnext.promise.d.ts"],
["esnext.promise", "lib.es2024.promise.d.ts"],
["esnext.weakref", "lib.es2021.weakref.d.ts"],
["esnext.decorators", "lib.esnext.decorators.d.ts"],
["esnext.object", "lib.esnext.object.d.ts"],
["esnext.object", "lib.es2024.object.d.ts"],
["esnext.array", "lib.esnext.array.d.ts"],
["esnext.regexp", "lib.esnext.regexp.d.ts"],
["esnext.string", "lib.esnext.string.d.ts"],
["esnext.regexp", "lib.es2024.regexp.d.ts"],
["esnext.string", "lib.es2024.string.d.ts"],
["esnext.iterator", "lib.esnext.iterator.d.ts"],
["decorators", "lib.decorators.d.ts"],
["decorators.legacy", "lib.decorators.legacy.d.ts"],
Expand Down Expand Up @@ -558,6 +567,7 @@ export const targetOptionDeclaration: CommandLineOptionOfCustomType = {
es2021: ScriptTarget.ES2021,
es2022: ScriptTarget.ES2022,
es2023: ScriptTarget.ES2023,
es2024: ScriptTarget.ES2024,
esnext: ScriptTarget.ESNext,
})),
affectsSourceFile: true,
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/transformers/esnext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ const enum UsingKind {
export function transformESNext(context: TransformationContext): (x: SourceFile | Bundle) => SourceFile | Bundle {
// NOTE: We must reevaluate the target for upcoming features when each successive TC39 edition is ratified in
// June of each year. This includes changes to `LanguageFeatureMinimumTarget`, `ScriptTarget`,
// transformers/esnext.ts, commandLineParser.ts, and the contents of each lib/esnext.*.d.ts file.
// `ScriptTargetFeatures` transformers/esnext.ts, compiler/commandLineParser.ts and the contents of each
// lib/esnext.*.d.ts file.

const {
factory,
Expand Down
18 changes: 11 additions & 7 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7577,7 +7577,8 @@ export const enum ScriptKind {

// NOTE: We must reevaluate the target for upcoming features when each successive TC39 edition is ratified in
// June of each year. This includes changes to `LanguageFeatureMinimumTarget`, `ScriptTarget`,
// transformers/esnext.ts, commandLineParser.ts, and the contents of each lib/esnext.*.d.ts file.
// `ScriptTargetFeatures` transformers/esnext.ts, compiler/commandLineParser.ts and the contents of each
// lib/esnext.*.d.ts file.
export const enum ScriptTarget {
/** @deprecated */
ES3 = 0,
Expand All @@ -7591,6 +7592,7 @@ export const enum ScriptTarget {
ES2021 = 8,
ES2022 = 9,
ES2023 = 10,
ES2024 = 11,
ESNext = 99,
JSON = 100,
Latest = ESNext,
Expand Down Expand Up @@ -8379,13 +8381,15 @@ export type LanugageFeatures =
| "RegularExpressionFlagsHasIndices"
// ES2023 Features
| "ShebangComments"
// ES2024 Features
| "RegularExpressionFlagsUnicodeSets"
// Upcoming Features
// NOTE: We must reevaluate the target for upcoming features when each successive TC39 edition is ratified in
// June of each year. This includes changes to `LanguageFeatureMinimumTarget`, `ScriptTarget`,
// transformers/esnext.ts, commandLineParser.ts, and the contents of each lib/esnext.*.d.ts file.
| "UsingAndAwaitUsing"
| "ClassAndClassElementDecorators" // `using x = y`, `await using x = y`
| "RegularExpressionFlagsUnicodeSets" // `@dec class C {}`, `class C { @dec m() {} }`
// `ScriptTargetFeatures` transformers/esnext.ts, compiler/commandLineParser.ts and the contents of each
// lib/esnext.*.d.ts file.
| "UsingAndAwaitUsing" // `using x = y`, `await using x = y`
| "ClassAndClassElementDecorators" // `@dec class C {}`, `class C { @dec m() {} }`
;

/**
Expand Down Expand Up @@ -8424,10 +8428,10 @@ export const LanguageFeatureMinimumTarget: Record<LanugageFeatures, ScriptTarget
ClassFields: ScriptTarget.ES2022,
PrivateNamesAndClassStaticBlocks: ScriptTarget.ES2022,
RegularExpressionFlagsHasIndices: ScriptTarget.ES2022,
ShebangComments: ScriptTarget.ESNext,
ShebangComments: ScriptTarget.ES2023,
RegularExpressionFlagsUnicodeSets: ScriptTarget.ES2024,
UsingAndAwaitUsing: ScriptTarget.ESNext,
ClassAndClassElementDecorators: ScriptTarget.ESNext,
RegularExpressionFlagsUnicodeSets: ScriptTarget.ESNext,
};

// dprint-ignore
Expand Down
72 changes: 69 additions & 3 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1367,6 +1367,10 @@ export function getInternalEmitFlags(node: Node): InternalEmitFlags {
/** @internal */
export type ScriptTargetFeatures = ReadonlyMap<string, ReadonlyMap<string, string[]>>;

// NOTE: We must reevaluate the target for upcoming features when each successive TC39 edition is ratified in
// June of each year. This includes changes to `LanguageFeatureMinimumTarget`, `ScriptTarget`,
// `ScriptTargetFeatures` transformers/esnext.ts, compiler/commandLineParser.ts and the contents of each
// lib/esnext.*.d.ts file.
/** @internal */
export const getScriptTargetFeatures: () => ScriptTargetFeatures = /* @__PURE__ */ memoize((): ScriptTargetFeatures =>
new Map(Object.entries({
Expand Down Expand Up @@ -1405,11 +1409,45 @@ export const getScriptTargetFeatures: () => ScriptTargetFeatures = /* @__PURE__
AsyncIterator: new Map(Object.entries({
es2015: emptyArray,
})),
ArrayBuffer: new Map(Object.entries({
es2024: [
"maxByteLength",
"resizable",
"resize",
"detached",
"transfer",
"transferToFixedLength",
],
})),
Atomics: new Map(Object.entries({
es2017: emptyArray,
es2017: [
"add",
"and",
"compareExchange",
"exchange",
"isLockFree",
"load",
"or",
"store",
"sub",
"wait",
"notify",
"xor",
],
es2024: [
"waitAsync",
],
})),
SharedArrayBuffer: new Map(Object.entries({
es2017: emptyArray,
es2017: [
"byteLength",
"slice",
],
es2024: [
"growable",
"maxByteLength",
"grow",
],
})),
AsyncIterable: new Map(Object.entries({
es2018: emptyArray,
Expand All @@ -1432,6 +1470,9 @@ export const getScriptTargetFeatures: () => ScriptTargetFeatures = /* @__PURE__
es2018: [
"dotAll",
],
es2024: [
"unicodeSets",
],
})),
Reflect: new Map(Object.entries({
es2015: [
Expand Down Expand Up @@ -1478,6 +1519,9 @@ export const getScriptTargetFeatures: () => ScriptTargetFeatures = /* @__PURE__
es2022: [
"hasOwn",
],
es2024: [
"groupBy",
],
})),
NumberConstructor: new Map(Object.entries({
es2015: [
Expand Down Expand Up @@ -1517,12 +1561,26 @@ export const getScriptTargetFeatures: () => ScriptTargetFeatures = /* @__PURE__
"values",
],
})),
MapConstructor: new Map(Object.entries({
es2024: [
"groupBy",
],
})),
Set: new Map(Object.entries({
es2015: [
"entries",
"keys",
"values",
],
esnext: [
"union",
"intersection",
"difference",
"symmetricDifference",
"isSubsetOf",
"isSupersetOf",
"isDisjointFrom",
],
})),
PromiseConstructor: new Map(Object.entries({
es2015: [
Expand All @@ -1537,6 +1595,9 @@ export const getScriptTargetFeatures: () => ScriptTargetFeatures = /* @__PURE__
es2021: [
"any",
],
es2024: [
"withResolvers",
],
})),
Symbol: new Map(Object.entries({
es2015: [
Expand Down Expand Up @@ -1602,7 +1663,7 @@ export const getScriptTargetFeatures: () => ScriptTargetFeatures = /* @__PURE__
es2022: [
"at",
],
esnext: [
es2024: [
"isWellFormed",
"toWellFormed",
],
Expand Down Expand Up @@ -1648,6 +1709,11 @@ export const getScriptTargetFeatures: () => ScriptTargetFeatures = /* @__PURE__
es2020: [
"matchAll",
],
esnext: [
"metadata",
"dispose",
"asyncDispose",
],
})),
DataView: new Map(Object.entries({
es2020: [
Expand Down
2 changes: 1 addition & 1 deletion src/lib/es2016.intl.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ declare namespace Intl {
* the canonical locale names. Duplicates will be omitted and elements
* will be validated as structurally valid language tags.
*
* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/getCanonicalLocales)
* [MDN](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl/getCanonicalLocales)
*
* @param locale A list of String values for which to get the canonical locale names
* @returns An array containing the canonical and validated locale names.
Expand Down
3 changes: 3 additions & 0 deletions src/lib/es2017.arraybuffer.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
interface ArrayBufferConstructor {
new (): ArrayBuffer;
}
5 changes: 3 additions & 2 deletions src/lib/es2017.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/// <reference lib="es2016" />
/// <reference lib="es2017.arraybuffer" />
/// <reference lib="es2017.date" />
/// <reference lib="es2017.intl" />
/// <reference lib="es2017.object" />
/// <reference lib="es2017.sharedmemory" />
/// <reference lib="es2017.string" />
/// <reference lib="es2017.intl" />
/// <reference lib="es2017.typedarrays" />
/// <reference lib="es2017.date" />
4 changes: 2 additions & 2 deletions src/lib/es2017.sharedmemory.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ interface SharedArrayBuffer {
/**
* Returns a section of an SharedArrayBuffer.
*/
slice(begin: number, end?: number): SharedArrayBuffer;
slice(begin?: number, end?: number): SharedArrayBuffer;
readonly [Symbol.species]: SharedArrayBuffer;
readonly [Symbol.toStringTag]: "SharedArrayBuffer";
}

interface SharedArrayBufferConstructor {
readonly prototype: SharedArrayBuffer;
new (byteLength: number): SharedArrayBuffer;
new (byteLength?: number): SharedArrayBuffer;
}
declare var SharedArrayBuffer: SharedArrayBufferConstructor;

Expand Down
2 changes: 1 addition & 1 deletion src/lib/es2020.bigint.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

interface BigIntToLocaleStringOptions {
/**
* The locale matching algorithm to use.The default is "best fit". For information about this option, see the {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_negotiation Intl page}.
* The locale matching algorithm to use.The default is "best fit". For information about this option, see the {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_negotiation Intl page}.
*/
localeMatcher?: string;
/**
Expand Down
Loading

0 comments on commit 9d98874

Please sign in to comment.