Skip to content

Add .findLast() and .findLastIndex() #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace ts {
["es2020", "lib.es2020.d.ts"],
["es2021", "lib.es2021.d.ts"],
["es2022", "lib.es2022.d.ts"],
["es2023", "lib.es2023.d.ts"],
["esnext", "lib.esnext.d.ts"],
// Host only
["dom", "lib.dom.d.ts"],
Expand Down Expand Up @@ -85,7 +86,8 @@ namespace ts {
["es2022.object", "lib.es2022.object.d.ts"],
["es2022.sharedmemory", "lib.es2022.sharedmemory.d.ts"],
["es2022.string", "lib.es2022.string.d.ts"],
["esnext.array", "lib.es2022.array.d.ts"],
["es2023.array", "lib.es2023.array.d.ts"],
["esnext.array", "lib.es2023.array.d.ts"],
["esnext.symbol", "lib.es2019.symbol.d.ts"],
["esnext.asynciterable", "lib.es2018.asynciterable.d.ts"],
["esnext.intl", "lib.esnext.intl.d.ts"],
Expand Down Expand Up @@ -332,6 +334,7 @@ namespace ts {
es2020: ScriptTarget.ES2020,
es2021: ScriptTarget.ES2021,
es2022: ScriptTarget.ES2022,
es2023: ScriptTarget.ES2023,
esnext: ScriptTarget.ESNext,
})),
affectsSourceFile: true,
Expand Down
23 changes: 13 additions & 10 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6523,6 +6523,7 @@ namespace ts {
ES2020 = 7,
ES2021 = 8,
ES2022 = 9,
ES2023 = 10,
ESNext = 99,
JSON = 100,
Latest = ESNext,
Expand Down Expand Up @@ -7003,16 +7004,17 @@ namespace ts {
ContainsTypeScript = 1 << 0,
ContainsJsx = 1 << 1,
ContainsESNext = 1 << 2,
ContainsES2022 = 1 << 3,
ContainsES2021 = 1 << 4,
ContainsES2020 = 1 << 5,
ContainsES2019 = 1 << 6,
ContainsES2018 = 1 << 7,
ContainsES2017 = 1 << 8,
ContainsES2016 = 1 << 9,
ContainsES2015 = 1 << 10,
ContainsGenerator = 1 << 11,
ContainsDestructuringAssignment = 1 << 12,
ContainsES2023 = 1 << 3,
ContainsES2022 = 1 << 4,
ContainsES2021 = 1 << 5,
ContainsES2020 = 1 << 6,
ContainsES2019 = 1 << 7,
ContainsES2018 = 1 << 8,
ContainsES2017 = 1 << 9,
ContainsES2016 = 1 << 10,
ContainsES2015 = 1 << 11,
ContainsGenerator = 1 << 12,
ContainsDestructuringAssignment = 1 << 13,

// Markers
// - Flags used to indicate that a subtree contains a specific transformation.
Expand Down Expand Up @@ -7042,6 +7044,7 @@ namespace ts {
AssertTypeScript = ContainsTypeScript,
AssertJsx = ContainsJsx,
AssertESNext = ContainsESNext,
AssertES2023 = ContainsES2023,
AssertES2022 = ContainsES2022,
AssertES2021 = ContainsES2021,
AssertES2020 = ContainsES2020,
Expand Down
14 changes: 14 additions & 0 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,20 @@ namespace ts {
BigUint64Array: ["at"],
ObjectConstructor: ["hasOwn"],
Error: ["cause"]
},
es2023: {
Array: ["findLast", "findLastIndex"],
Int8Array: ["findLast", "findLastIndex"],
Uint8Array: ["findLast", "findLastIndex"],
Uint8ClampedArray: ["findLast", "findLastIndex"],
Int16Array: ["findLast", "findLastIndex"],
Uint16Array: ["findLast", "findLastIndex"],
Int32Array: ["findLast", "findLastIndex"],
Uint32Array: ["findLast", "findLastIndex"],
Float32Array: ["findLast", "findLastIndex"],
Float64Array: ["findLast", "findLastIndex"],
BigInt64Array: ["findLast", "findLastIndex"],
BigUint64Array: ["findLast", "findLastIndex"]
}
};
}
Expand Down
2 changes: 2 additions & 0 deletions src/compiler/utilitiesPublic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace ts {
switch (getEmitScriptTarget(options)) {
case ScriptTarget.ESNext:
return "lib.esnext.full.d.ts";
case ScriptTarget.ES2023:
return "lib.es2023.full.d.ts";
case ScriptTarget.ES2022:
return "lib.es2022.full.d.ts";
case ScriptTarget.ES2021:
Expand Down
324 changes: 324 additions & 0 deletions src/lib/es2023.array.d.ts

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/lib/es2023.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// <reference lib="es2022" />
/// <reference lib="es2023.array" />
5 changes: 5 additions & 0 deletions src/lib/es2023.full.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference lib="es2023" />
/// <reference lib="dom" />
/// <reference lib="webworker.importscripts" />
/// <reference lib="scripthost" />
/// <reference lib="dom.iterable" />
2 changes: 1 addition & 1 deletion src/lib/esnext.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/// <reference lib="es2022" />
/// <reference lib="es2023" />
/// <reference lib="esnext.intl" />
3 changes: 3 additions & 0 deletions src/lib/libs.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"es2020",
"es2021",
"es2022",
"es2023",
"esnext",
// Host only
"dom.generated",
Expand Down Expand Up @@ -61,6 +62,7 @@
"es2022.object",
"es2022.sharedmemory",
"es2022.string",
"es2023.array",
"esnext.intl",
// Default libraries
"es5.full",
Expand All @@ -72,6 +74,7 @@
"es2020.full",
"es2021.full",
"es2022.full",
"es2023.full",
"esnext.full"
],
"paths": {
Expand Down
1 change: 1 addition & 0 deletions src/server/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3584,6 +3584,7 @@ namespace ts.server.protocol {
ES2020 = "ES2020",
ES2021 = "ES2021",
ES2022 = "ES2022",
ES2023 = "ES2023",
ESNext = "ESNext"
}

Expand Down
2 changes: 1 addition & 1 deletion src/testRunner/unittests/config/commandLineParsing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ namespace ts {
start: undefined,
length: undefined,
}, {
messageText: "Argument for '--target' option must be: 'es3', 'es5', 'es6', 'es2015', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020', 'es2021', 'es2022', 'esnext'.",
messageText: "Argument for '--target' option must be: 'es3', 'es5', 'es6', 'es2015', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020', 'es2021', 'es2022', 'es2023', 'esnext'.",
category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category,
code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code,

Expand Down
2 changes: 2 additions & 0 deletions tests/baselines/reference/api/tsserverlibrary.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3148,6 +3148,7 @@ declare namespace ts {
ES2020 = 7,
ES2021 = 8,
ES2022 = 9,
ES2023 = 10,
ESNext = 99,
JSON = 100,
Latest = 99
Expand Down Expand Up @@ -9870,6 +9871,7 @@ declare namespace ts.server.protocol {
ES2020 = "ES2020",
ES2021 = "ES2021",
ES2022 = "ES2022",
ES2023 = "ES2023",
ESNext = "ESNext"
}
enum ClassificationType {
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/api/typescript.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3148,6 +3148,7 @@ declare namespace ts {
ES2020 = 7,
ES2021 = 8,
ES2022 = 9,
ES2023 = 10,
ESNext = 99,
JSON = 100,
Latest = 99
Expand Down
18 changes: 18 additions & 0 deletions tests/baselines/reference/callChainWithSuper(target=es2023).js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//// [callChainWithSuper.ts]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this test relevant to your changes?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it was created because the es2023 target was added (filename is callChainWithSuper(target=es2023).js). This file was added for the es2022 target as well.

// GH#34952
class Base { method?() {} }
class Derived extends Base {
method1() { return super.method?.(); }
method2() { return super["method"]?.(); }
}

//// [callChainWithSuper.js]
"use strict";
// GH#34952
class Base {
method() { }
}
class Derived extends Base {
method1() { return super.method?.(); }
method2() { return super["method"]?.(); }
}
4 changes: 2 additions & 2 deletions tests/baselines/reference/callWithSpread4.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ declare const pli: {

(streams: ReadonlyArray<R | W | RW>): Promise<void>;
>streams : Symbol(streams, Decl(callWithSpread4.ts, 5, 5))
>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)
>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)
>R : Symbol(R, Decl(callWithSpread4.ts, 0, 0))
>W : Symbol(W, Decl(callWithSpread4.ts, 0, 22))
>RW : Symbol(RW, Decl(callWithSpread4.ts, 1, 22))
Expand All @@ -43,7 +43,7 @@ declare const pli: {
>RW : Symbol(RW, Decl(callWithSpread4.ts, 1, 22))
>W : Symbol(W, Decl(callWithSpread4.ts, 0, 22))
>streams : Symbol(streams, Decl(callWithSpread4.ts, 6, 23))
>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)
>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)
>RW : Symbol(RW, Decl(callWithSpread4.ts, 1, 22))
>W : Symbol(W, Decl(callWithSpread4.ts, 0, 22))
>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, --, --))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ interface B<T> { variant: 'b', value: Array<T> }
>T : Symbol(T, Decl(dependentDestructuredVariables.ts, 128, 12))
>variant : Symbol(B.variant, Decl(dependentDestructuredVariables.ts, 128, 16))
>value : Symbol(B.value, Decl(dependentDestructuredVariables.ts, 128, 30))
>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)
>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)
>T : Symbol(T, Decl(dependentDestructuredVariables.ts, 128, 12))

type AB<T> = A<T> | B<T>;
Expand All @@ -342,7 +342,7 @@ declare function printValueList<T>(t: Array<T>): void;
>printValueList : Symbol(printValueList, Decl(dependentDestructuredVariables.ts, 132, 43))
>T : Symbol(T, Decl(dependentDestructuredVariables.ts, 134, 32))
>t : Symbol(t, Decl(dependentDestructuredVariables.ts, 134, 35))
>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)
>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)
>T : Symbol(T, Decl(dependentDestructuredVariables.ts, 134, 32))

function unrefined1<T>(ab: AB<T>): void {
Expand Down
53 changes: 53 additions & 0 deletions tests/baselines/reference/findLast(target=es2023).js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//// [findLast.ts]
[0].findLast((item) => item === 0);
new Int8Array().findLast((item) => item === 0);
new Uint8Array().findLast((item) => item === 0);
new Uint8ClampedArray().findLast((item) => item === 0);
new Int16Array().findLast((item) => item === 0);
new Uint16Array().findLast((item) => item === 0);
new Int32Array().findLast((item) => item === 0);
new Uint32Array().findLast((item) => item === 0);
new Float32Array().findLast((item) => item === 0);
new Float64Array().findLast((item) => item === 0);
new BigInt64Array().findLast((item) => item === BigInt(0));
new BigUint64Array().findLast((item) => item === BigInt(0));

[0].findLastIndex((item) => item === 0);
new Int8Array().findLastIndex((item) => item === 0);
new Uint8Array().findLastIndex((item) => item === 0);
new Uint8ClampedArray().findLastIndex((item) => item === 0);
new Int16Array().findLastIndex((item) => item === 0);
new Uint16Array().findLastIndex((item) => item === 0);
new Int32Array().findLastIndex((item) => item === 0);
new Uint32Array().findLastIndex((item) => item === 0);
new Float32Array().findLastIndex((item) => item === 0);
new Float64Array().findLastIndex((item) => item === 0);
new BigInt64Array().findLastIndex((item) => item === BigInt(0));
new BigUint64Array().findLastIndex((item) => item === BigInt(0));


//// [findLast.js]
[0].findLast((item) => item === 0);
new Int8Array().findLast((item) => item === 0);
new Uint8Array().findLast((item) => item === 0);
new Uint8ClampedArray().findLast((item) => item === 0);
new Int16Array().findLast((item) => item === 0);
new Uint16Array().findLast((item) => item === 0);
new Int32Array().findLast((item) => item === 0);
new Uint32Array().findLast((item) => item === 0);
new Float32Array().findLast((item) => item === 0);
new Float64Array().findLast((item) => item === 0);
new BigInt64Array().findLast((item) => item === BigInt(0));
new BigUint64Array().findLast((item) => item === BigInt(0));
[0].findLastIndex((item) => item === 0);
new Int8Array().findLastIndex((item) => item === 0);
new Uint8Array().findLastIndex((item) => item === 0);
new Uint8ClampedArray().findLastIndex((item) => item === 0);
new Int16Array().findLastIndex((item) => item === 0);
new Uint16Array().findLastIndex((item) => item === 0);
new Int32Array().findLastIndex((item) => item === 0);
new Uint32Array().findLastIndex((item) => item === 0);
new Float32Array().findLastIndex((item) => item === 0);
new Float64Array().findLastIndex((item) => item === 0);
new BigInt64Array().findLastIndex((item) => item === BigInt(0));
new BigUint64Array().findLastIndex((item) => item === BigInt(0));
Loading