Skip to content

Commit 3b610c3

Browse files
authored
Add .findLast() and .findLastIndex() (#69)
* Add .findLast(), .findLastIndex(), and es2023 target Signed-off-by: mbasov2 <[email protected]> * Update baselines Signed-off-by: mbasov2 <[email protected]>
1 parent 44d6b51 commit 3b610c3

37 files changed

+1503
-48
lines changed

src/compiler/commandLineParser.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ namespace ts {
3434
["es2020", "lib.es2020.d.ts"],
3535
["es2021", "lib.es2021.d.ts"],
3636
["es2022", "lib.es2022.d.ts"],
37+
["es2023", "lib.es2023.d.ts"],
3738
["esnext", "lib.esnext.d.ts"],
3839
// Host only
3940
["dom", "lib.dom.d.ts"],
@@ -85,7 +86,8 @@ namespace ts {
8586
["es2022.object", "lib.es2022.object.d.ts"],
8687
["es2022.sharedmemory", "lib.es2022.sharedmemory.d.ts"],
8788
["es2022.string", "lib.es2022.string.d.ts"],
88-
["esnext.array", "lib.es2022.array.d.ts"],
89+
["es2023.array", "lib.es2023.array.d.ts"],
90+
["esnext.array", "lib.es2023.array.d.ts"],
8991
["esnext.symbol", "lib.es2019.symbol.d.ts"],
9092
["esnext.asynciterable", "lib.es2018.asynciterable.d.ts"],
9193
["esnext.intl", "lib.esnext.intl.d.ts"],
@@ -332,6 +334,7 @@ namespace ts {
332334
es2020: ScriptTarget.ES2020,
333335
es2021: ScriptTarget.ES2021,
334336
es2022: ScriptTarget.ES2022,
337+
es2023: ScriptTarget.ES2023,
335338
esnext: ScriptTarget.ESNext,
336339
})),
337340
affectsSourceFile: true,

src/compiler/types.ts

+13-10
Original file line numberDiff line numberDiff line change
@@ -6523,6 +6523,7 @@ namespace ts {
65236523
ES2020 = 7,
65246524
ES2021 = 8,
65256525
ES2022 = 9,
6526+
ES2023 = 10,
65266527
ESNext = 99,
65276528
JSON = 100,
65286529
Latest = ESNext,
@@ -7003,16 +7004,17 @@ namespace ts {
70037004
ContainsTypeScript = 1 << 0,
70047005
ContainsJsx = 1 << 1,
70057006
ContainsESNext = 1 << 2,
7006-
ContainsES2022 = 1 << 3,
7007-
ContainsES2021 = 1 << 4,
7008-
ContainsES2020 = 1 << 5,
7009-
ContainsES2019 = 1 << 6,
7010-
ContainsES2018 = 1 << 7,
7011-
ContainsES2017 = 1 << 8,
7012-
ContainsES2016 = 1 << 9,
7013-
ContainsES2015 = 1 << 10,
7014-
ContainsGenerator = 1 << 11,
7015-
ContainsDestructuringAssignment = 1 << 12,
7007+
ContainsES2023 = 1 << 3,
7008+
ContainsES2022 = 1 << 4,
7009+
ContainsES2021 = 1 << 5,
7010+
ContainsES2020 = 1 << 6,
7011+
ContainsES2019 = 1 << 7,
7012+
ContainsES2018 = 1 << 8,
7013+
ContainsES2017 = 1 << 9,
7014+
ContainsES2016 = 1 << 10,
7015+
ContainsES2015 = 1 << 11,
7016+
ContainsGenerator = 1 << 12,
7017+
ContainsDestructuringAssignment = 1 << 13,
70167018

70177019
// Markers
70187020
// - Flags used to indicate that a subtree contains a specific transformation.
@@ -7042,6 +7044,7 @@ namespace ts {
70427044
AssertTypeScript = ContainsTypeScript,
70437045
AssertJsx = ContainsJsx,
70447046
AssertESNext = ContainsESNext,
7047+
AssertES2023 = ContainsES2023,
70457048
AssertES2022 = ContainsES2022,
70467049
AssertES2021 = ContainsES2021,
70477050
AssertES2020 = ContainsES2020,

src/compiler/utilities.ts

+14
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,20 @@ namespace ts {
645645
BigUint64Array: ["at"],
646646
ObjectConstructor: ["hasOwn"],
647647
Error: ["cause"]
648+
},
649+
es2023: {
650+
Array: ["findLast", "findLastIndex"],
651+
Int8Array: ["findLast", "findLastIndex"],
652+
Uint8Array: ["findLast", "findLastIndex"],
653+
Uint8ClampedArray: ["findLast", "findLastIndex"],
654+
Int16Array: ["findLast", "findLastIndex"],
655+
Uint16Array: ["findLast", "findLastIndex"],
656+
Int32Array: ["findLast", "findLastIndex"],
657+
Uint32Array: ["findLast", "findLastIndex"],
658+
Float32Array: ["findLast", "findLastIndex"],
659+
Float64Array: ["findLast", "findLastIndex"],
660+
BigInt64Array: ["findLast", "findLastIndex"],
661+
BigUint64Array: ["findLast", "findLastIndex"]
648662
}
649663
};
650664
}

src/compiler/utilitiesPublic.ts

+2
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.ES2023:
18+
return "lib.es2023.full.d.ts";
1719
case ScriptTarget.ES2022:
1820
return "lib.es2022.full.d.ts";
1921
case ScriptTarget.ES2021:

src/lib/es2023.array.d.ts

+324
Large diffs are not rendered by default.

src/lib/es2023.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/// <reference lib="es2022" />
2+
/// <reference lib="es2023.array" />

src/lib/es2023.full.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// <reference lib="es2023" />
2+
/// <reference lib="dom" />
3+
/// <reference lib="webworker.importscripts" />
4+
/// <reference lib="scripthost" />
5+
/// <reference lib="dom.iterable" />

src/lib/esnext.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
/// <reference lib="es2022" />
1+
/// <reference lib="es2023" />
22
/// <reference lib="esnext.intl" />

src/lib/libs.json

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"es2020",
1111
"es2021",
1212
"es2022",
13+
"es2023",
1314
"esnext",
1415
// Host only
1516
"dom.generated",
@@ -61,6 +62,7 @@
6162
"es2022.object",
6263
"es2022.sharedmemory",
6364
"es2022.string",
65+
"es2023.array",
6466
"esnext.intl",
6567
// Default libraries
6668
"es5.full",
@@ -72,6 +74,7 @@
7274
"es2020.full",
7375
"es2021.full",
7476
"es2022.full",
77+
"es2023.full",
7578
"esnext.full"
7679
],
7780
"paths": {

src/server/protocol.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3584,6 +3584,7 @@ namespace ts.server.protocol {
35843584
ES2020 = "ES2020",
35853585
ES2021 = "ES2021",
35863586
ES2022 = "ES2022",
3587+
ES2023 = "ES2023",
35873588
ESNext = "ESNext"
35883589
}
35893590

src/testRunner/unittests/config/commandLineParsing.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ namespace ts {
211211
start: undefined,
212212
length: undefined,
213213
}, {
214-
messageText: "Argument for '--target' option must be: 'es3', 'es5', 'es6', 'es2015', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020', 'es2021', 'es2022', 'esnext'.",
214+
messageText: "Argument for '--target' option must be: 'es3', 'es5', 'es6', 'es2015', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020', 'es2021', 'es2022', 'es2023', 'esnext'.",
215215
category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category,
216216
code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code,
217217

tests/baselines/reference/api/tsserverlibrary.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -3148,6 +3148,7 @@ declare namespace ts {
31483148
ES2020 = 7,
31493149
ES2021 = 8,
31503150
ES2022 = 9,
3151+
ES2023 = 10,
31513152
ESNext = 99,
31523153
JSON = 100,
31533154
Latest = 99
@@ -9870,6 +9871,7 @@ declare namespace ts.server.protocol {
98709871
ES2020 = "ES2020",
98719872
ES2021 = "ES2021",
98729873
ES2022 = "ES2022",
9874+
ES2023 = "ES2023",
98739875
ESNext = "ESNext"
98749876
}
98759877
enum ClassificationType {

tests/baselines/reference/api/typescript.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3148,6 +3148,7 @@ declare namespace ts {
31483148
ES2020 = 7,
31493149
ES2021 = 8,
31503150
ES2022 = 9,
3151+
ES2023 = 10,
31513152
ESNext = 99,
31523153
JSON = 100,
31533154
Latest = 99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//// [callChainWithSuper.ts]
2+
// GH#34952
3+
class Base { method?() {} }
4+
class Derived extends Base {
5+
method1() { return super.method?.(); }
6+
method2() { return super["method"]?.(); }
7+
}
8+
9+
//// [callChainWithSuper.js]
10+
"use strict";
11+
// GH#34952
12+
class Base {
13+
method() { }
14+
}
15+
class Derived extends Base {
16+
method1() { return super.method?.(); }
17+
method2() { return super["method"]?.(); }
18+
}

tests/baselines/reference/callWithSpread4.symbols

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ declare const pli: {
3030

3131
(streams: ReadonlyArray<R | W | RW>): Promise<void>;
3232
>streams : Symbol(streams, Decl(callWithSpread4.ts, 5, 5))
33-
>ReadonlyArray : Symbol(ReadonlyArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2016.array.include.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --) ... and 1 more)
33+
>ReadonlyArray : Symbol(ReadonlyArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2016.array.include.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --) ... and 2 more)
3434
>R : Symbol(R, Decl(callWithSpread4.ts, 0, 0))
3535
>W : Symbol(W, Decl(callWithSpread4.ts, 0, 22))
3636
>RW : Symbol(RW, Decl(callWithSpread4.ts, 1, 22))
@@ -43,7 +43,7 @@ declare const pli: {
4343
>RW : Symbol(RW, Decl(callWithSpread4.ts, 1, 22))
4444
>W : Symbol(W, Decl(callWithSpread4.ts, 0, 22))
4545
>streams : Symbol(streams, Decl(callWithSpread4.ts, 6, 23))
46-
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 3 more)
46+
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 4 more)
4747
>RW : Symbol(RW, Decl(callWithSpread4.ts, 1, 22))
4848
>W : Symbol(W, Decl(callWithSpread4.ts, 0, 22))
4949
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))

tests/baselines/reference/dependentDestructuredVariables.symbols

+2-2
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ interface B<T> { variant: 'b', value: Array<T> }
321321
>T : Symbol(T, Decl(dependentDestructuredVariables.ts, 128, 12))
322322
>variant : Symbol(B.variant, Decl(dependentDestructuredVariables.ts, 128, 16))
323323
>value : Symbol(B.value, Decl(dependentDestructuredVariables.ts, 128, 30))
324-
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 3 more)
324+
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 4 more)
325325
>T : Symbol(T, Decl(dependentDestructuredVariables.ts, 128, 12))
326326

327327
type AB<T> = A<T> | B<T>;
@@ -342,7 +342,7 @@ declare function printValueList<T>(t: Array<T>): void;
342342
>printValueList : Symbol(printValueList, Decl(dependentDestructuredVariables.ts, 132, 43))
343343
>T : Symbol(T, Decl(dependentDestructuredVariables.ts, 134, 32))
344344
>t : Symbol(t, Decl(dependentDestructuredVariables.ts, 134, 35))
345-
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 3 more)
345+
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 4 more)
346346
>T : Symbol(T, Decl(dependentDestructuredVariables.ts, 134, 32))
347347

348348
function unrefined1<T>(ab: AB<T>): void {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//// [findLast.ts]
2+
[0].findLast((item) => item === 0);
3+
new Int8Array().findLast((item) => item === 0);
4+
new Uint8Array().findLast((item) => item === 0);
5+
new Uint8ClampedArray().findLast((item) => item === 0);
6+
new Int16Array().findLast((item) => item === 0);
7+
new Uint16Array().findLast((item) => item === 0);
8+
new Int32Array().findLast((item) => item === 0);
9+
new Uint32Array().findLast((item) => item === 0);
10+
new Float32Array().findLast((item) => item === 0);
11+
new Float64Array().findLast((item) => item === 0);
12+
new BigInt64Array().findLast((item) => item === BigInt(0));
13+
new BigUint64Array().findLast((item) => item === BigInt(0));
14+
15+
[0].findLastIndex((item) => item === 0);
16+
new Int8Array().findLastIndex((item) => item === 0);
17+
new Uint8Array().findLastIndex((item) => item === 0);
18+
new Uint8ClampedArray().findLastIndex((item) => item === 0);
19+
new Int16Array().findLastIndex((item) => item === 0);
20+
new Uint16Array().findLastIndex((item) => item === 0);
21+
new Int32Array().findLastIndex((item) => item === 0);
22+
new Uint32Array().findLastIndex((item) => item === 0);
23+
new Float32Array().findLastIndex((item) => item === 0);
24+
new Float64Array().findLastIndex((item) => item === 0);
25+
new BigInt64Array().findLastIndex((item) => item === BigInt(0));
26+
new BigUint64Array().findLastIndex((item) => item === BigInt(0));
27+
28+
29+
//// [findLast.js]
30+
[0].findLast((item) => item === 0);
31+
new Int8Array().findLast((item) => item === 0);
32+
new Uint8Array().findLast((item) => item === 0);
33+
new Uint8ClampedArray().findLast((item) => item === 0);
34+
new Int16Array().findLast((item) => item === 0);
35+
new Uint16Array().findLast((item) => item === 0);
36+
new Int32Array().findLast((item) => item === 0);
37+
new Uint32Array().findLast((item) => item === 0);
38+
new Float32Array().findLast((item) => item === 0);
39+
new Float64Array().findLast((item) => item === 0);
40+
new BigInt64Array().findLast((item) => item === BigInt(0));
41+
new BigUint64Array().findLast((item) => item === BigInt(0));
42+
[0].findLastIndex((item) => item === 0);
43+
new Int8Array().findLastIndex((item) => item === 0);
44+
new Uint8Array().findLastIndex((item) => item === 0);
45+
new Uint8ClampedArray().findLastIndex((item) => item === 0);
46+
new Int16Array().findLastIndex((item) => item === 0);
47+
new Uint16Array().findLastIndex((item) => item === 0);
48+
new Int32Array().findLastIndex((item) => item === 0);
49+
new Uint32Array().findLastIndex((item) => item === 0);
50+
new Float32Array().findLastIndex((item) => item === 0);
51+
new Float64Array().findLastIndex((item) => item === 0);
52+
new BigInt64Array().findLastIndex((item) => item === BigInt(0));
53+
new BigUint64Array().findLastIndex((item) => item === BigInt(0));

0 commit comments

Comments
 (0)