Skip to content

Commit 17b01bc

Browse files
saschanazorta
authored andcommitted
Add target: "es2022" (microsoft#46291)
* Add `target: "es2022"` * Add Object.hasOwn * formatToParts is es2018 * ref update * optional parameter * Revert "optional parameter" This reverts commit e67d6e5. * undefined * error cause * Lint fix Co-authored-by: Orta <[email protected]>
1 parent a628e68 commit 17b01bc

File tree

57 files changed

+973
-47
lines changed

Some content is hidden

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

57 files changed

+973
-47
lines changed

src/compiler/commandLineParser.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ namespace ts {
2929
["es2019", "lib.es2019.d.ts"],
3030
["es2020", "lib.es2020.d.ts"],
3131
["es2021", "lib.es2021.d.ts"],
32+
["es2022", "lib.es2022.d.ts"],
3233
["esnext", "lib.esnext.d.ts"],
3334
// Host only
3435
["dom", "lib.dom.d.ts"],
@@ -72,12 +73,16 @@ namespace ts {
7273
["es2021.string", "lib.es2021.string.d.ts"],
7374
["es2021.weakref", "lib.es2021.weakref.d.ts"],
7475
["es2021.intl", "lib.es2021.intl.d.ts"],
75-
["esnext.array", "lib.es2019.array.d.ts"],
76+
["es2022.array", "lib.es2022.array.d.ts"],
77+
["es2022.error", "lib.es2022.error.d.ts"],
78+
["es2022.object", "lib.es2022.object.d.ts"],
79+
["es2022.string", "lib.es2022.string.d.ts"],
80+
["esnext.array", "lib.es2022.array.d.ts"],
7681
["esnext.symbol", "lib.es2019.symbol.d.ts"],
7782
["esnext.asynciterable", "lib.es2018.asynciterable.d.ts"],
7883
["esnext.intl", "lib.esnext.intl.d.ts"],
7984
["esnext.bigint", "lib.es2020.bigint.d.ts"],
80-
["esnext.string", "lib.es2021.string.d.ts"],
85+
["esnext.string", "lib.es2022.string.d.ts"],
8186
["esnext.promise", "lib.es2021.promise.d.ts"],
8287
["esnext.weakref", "lib.es2021.weakref.d.ts"]
8388
];
@@ -314,6 +319,7 @@ namespace ts {
314319
es2019: ScriptTarget.ES2019,
315320
es2020: ScriptTarget.ES2020,
316321
es2021: ScriptTarget.ES2021,
322+
es2022: ScriptTarget.ES2022,
317323
esnext: ScriptTarget.ESNext,
318324
})),
319325
affectsSourceFile: true,

src/compiler/types.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6268,6 +6268,7 @@ namespace ts {
62686268
ES2019 = 6,
62696269
ES2020 = 7,
62706270
ES2021 = 8,
6271+
ES2022 = 9,
62716272
ESNext = 99,
62726273
JSON = 100,
62736274
Latest = ESNext,
@@ -6725,15 +6726,16 @@ namespace ts {
67256726
ContainsTypeScript = 1 << 0,
67266727
ContainsJsx = 1 << 1,
67276728
ContainsESNext = 1 << 2,
6728-
ContainsES2021 = 1 << 3,
6729-
ContainsES2020 = 1 << 4,
6730-
ContainsES2019 = 1 << 5,
6731-
ContainsES2018 = 1 << 6,
6732-
ContainsES2017 = 1 << 7,
6733-
ContainsES2016 = 1 << 8,
6734-
ContainsES2015 = 1 << 9,
6735-
ContainsGenerator = 1 << 10,
6736-
ContainsDestructuringAssignment = 1 << 11,
6729+
ContainsES2022 = 1 << 3,
6730+
ContainsES2021 = 1 << 4,
6731+
ContainsES2020 = 1 << 5,
6732+
ContainsES2019 = 1 << 6,
6733+
ContainsES2018 = 1 << 7,
6734+
ContainsES2017 = 1 << 8,
6735+
ContainsES2016 = 1 << 9,
6736+
ContainsES2015 = 1 << 10,
6737+
ContainsGenerator = 1 << 11,
6738+
ContainsDestructuringAssignment = 1 << 12,
67376739

67386740
// Markers
67396741
// - Flags used to indicate that a subtree contains a specific transformation.
@@ -6762,6 +6764,7 @@ namespace ts {
67626764
AssertTypeScript = ContainsTypeScript,
67636765
AssertJsx = ContainsJsx,
67646766
AssertESNext = ContainsESNext,
6767+
AssertES2022 = ContainsES2022,
67656768
AssertES2021 = ContainsES2021,
67666769
AssertES2020 = ContainsES2020,
67676770
AssertES2019 = ContainsES2019,

src/compiler/utilities.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,7 @@ namespace ts {
606606
AsyncIterableIterator: emptyArray,
607607
AsyncGenerator: emptyArray,
608608
AsyncGeneratorFunction: emptyArray,
609+
NumberFormat: ["formatToParts"]
609610
},
610611
es2019: {
611612
Array: ["flat", "flatMap"],
@@ -627,8 +628,21 @@ namespace ts {
627628
PromiseConstructor: ["any"],
628629
String: ["replaceAll"]
629630
},
630-
esnext: {
631-
NumberFormat: ["formatToParts"]
631+
es2022: {
632+
Array: ["at"],
633+
String: ["at"],
634+
Int8Array: ["at"],
635+
Uint8Array: ["at"],
636+
Uint8ClampedArray: ["at"],
637+
Int16Array: ["at"],
638+
Uint16Array: ["at"],
639+
Int32Array: ["at"],
640+
Uint32Array: ["at"],
641+
Float32Array: ["at"],
642+
Float64Array: ["at"],
643+
BigInt64Array: ["at"],
644+
BigUint64Array: ["at"],
645+
ObjectConstructor: ["hasOwn"]
632646
}
633647
};
634648
}

src/compiler/utilitiesPublic.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ namespace ts {
1414
switch (getEmitScriptTarget(options)) {
1515
case ScriptTarget.ESNext:
1616
return "lib.esnext.full.d.ts";
17+
case ScriptTarget.ES2022:
18+
return "lib.es2022.full.d.ts";
1719
case ScriptTarget.ES2021:
1820
return "lib.es2021.full.d.ts";
1921
case ScriptTarget.ES2020:

src/lib/es2022.array.d.ts

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
interface Array<T> {
2+
/**
3+
* Returns the item located at the specified index.
4+
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
5+
*/
6+
at(index: number): T | undefined;
7+
}
8+
9+
interface ReadonlyArray<T> {
10+
/**
11+
* Returns the item located at the specified index.
12+
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
13+
*/
14+
at(index: number): T | undefined;
15+
}
16+
17+
interface Int8Array {
18+
/**
19+
* Returns the item located at the specified index.
20+
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
21+
*/
22+
at(index: number): number | undefined;
23+
}
24+
25+
interface Uint8Array {
26+
/**
27+
* Returns the item located at the specified index.
28+
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
29+
*/
30+
at(index: number): number | undefined;
31+
}
32+
33+
interface Uint8ClampedArray {
34+
/**
35+
* Returns the item located at the specified index.
36+
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
37+
*/
38+
at(index: number): number | undefined;
39+
}
40+
41+
interface Int16Array {
42+
/**
43+
* Returns the item located at the specified index.
44+
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
45+
*/
46+
at(index: number): number | undefined;
47+
}
48+
49+
interface Uint16Array {
50+
/**
51+
* Returns the item located at the specified index.
52+
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
53+
*/
54+
at(index: number): number | undefined;
55+
}
56+
57+
interface Int32Array {
58+
/**
59+
* Returns the item located at the specified index.
60+
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
61+
*/
62+
at(index: number): number | undefined;
63+
}
64+
65+
interface Uint32Array {
66+
/**
67+
* Returns the item located at the specified index.
68+
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
69+
*/
70+
at(index: number): number | undefined;
71+
}
72+
73+
interface Float32Array {
74+
/**
75+
* Returns the item located at the specified index.
76+
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
77+
*/
78+
at(index: number): number | undefined;
79+
}
80+
81+
interface Float64Array {
82+
/**
83+
* Returns the item located at the specified index.
84+
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
85+
*/
86+
at(index: number): number | undefined;
87+
}
88+
89+
interface BigInt64Array {
90+
/**
91+
* Returns the item located at the specified index.
92+
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
93+
*/
94+
at(index: number): number | undefined;
95+
}
96+
97+
interface BigUint64Array {
98+
/**
99+
* Returns the item located at the specified index.
100+
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
101+
*/
102+
at(index: number): number | undefined;
103+
}

src/lib/es2022.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// <reference lib="es2021" />
2+
/// <reference lib="es2022.array" />
3+
/// <reference lib="es2022.error" />
4+
/// <reference lib="es2022.object" />
5+
/// <reference lib="es2022.string" />

src/lib/es2022.error.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
interface ErrorOptions {
2+
cause?: Error;
3+
}
4+
5+
interface ErrorConstructor {
6+
new(message?: string, options?: ErrorOptions): Error;
7+
(message?: string, options?: ErrorOptions): Error;
8+
}

src/lib/es2022.full.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// <reference lib="es2022" />
2+
/// <reference lib="dom" />
3+
/// <reference lib="webworker.importscripts" />
4+
/// <reference lib="scripthost" />
5+
/// <reference lib="dom.iterable" />

src/lib/es2022.object.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
interface Object {
2+
/**
3+
* Determines whether an object has a property with the specified name.
4+
* @param o An object.
5+
* @param v A property name.
6+
*/
7+
hasOwn(o: object, v: PropertyKey): boolean;
8+
}

src/lib/es2022.string.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
interface String {
2+
/**
3+
* Returns a new String consisting of the single UTF-16 code unit located at the specified index.
4+
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item.
5+
*/
6+
at(index: number): string | undefined;
7+
}

0 commit comments

Comments
 (0)