Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 342ba2c

Browse files
authored
feat: add support for Array.prototype.findLast,findLastIndex (#4332)
1 parent 3943111 commit 342ba2c

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

src/ast/nodes/shared/ArrayPrototype.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ export const ARRAY_PROTOTYPE = new ObjectEntity(
128128
filter: METHOD_CALLS_ARG_DEOPTS_SELF_RETURNS_NEW_ARRAY,
129129
find: METHOD_CALLS_ARG_DEOPTS_SELF_RETURNS_UNKNOWN,
130130
findIndex: METHOD_CALLS_ARG_DEOPTS_SELF_RETURNS_NUMBER,
131+
findLast: METHOD_CALLS_ARG_DEOPTS_SELF_RETURNS_UNKNOWN,
132+
findLastIndex: METHOD_CALLS_ARG_DEOPTS_SELF_RETURNS_NUMBER,
131133
flat: METHOD_DEOPTS_SELF_RETURNS_NEW_ARRAY,
132134
flatMap: METHOD_CALLS_ARG_DEOPTS_SELF_RETURNS_NEW_ARRAY,
133135
forEach: METHOD_CALLS_ARG_DEOPTS_SELF_RETURNS_UNKNOWN,

test/form/samples/builtin-prototypes/array-expression/_expected.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,18 @@ _filterArray[0].effect();
3535
const _findArray = [{ effect() {} }];
3636
_findArray.find(element => (element.effect = () => console.log(1)));
3737
_findArray[0].effect();
38+
[1].findLast(() => console.log(1) || true);
39+
const _findLastArray = [{ effect() {} }];
40+
_findLastArray.findLast(element => (element.effect = () => console.log(1)));
41+
_findLastArray[0].effect();
3842
[1].findIndex(() => console.log(1) || true);
3943
const _findIndexArray = [{ effect() {} }];
4044
_findIndexArray.findIndex(element => (element.effect = () => console.log(1)));
4145
_findIndexArray[0].effect();
46+
[1].findLastIndex(() => console.log(1) || true);
47+
const _findLastIndexArray = [{ effect() {} }];
48+
_findLastIndexArray.findLastIndex(element => (element.effect = () => console.log(1)));
49+
_findLastIndexArray[0].effect();
4250
[1].flatMap(() => console.log(1) || 1);
4351
const _flatMapArray = [{ effect() {} }];
4452
_flatMapArray.flatMap(element => (element.effect = () => console.log(1)));

test/form/samples/builtin-prototypes/array-expression/main.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,24 @@ const _findArray = [{ effect() {} }];
7474
_findArray.find(element => (element.effect = () => console.log(1)));
7575
_findArray[0].effect();
7676

77+
const _findLast = [1].findLast(() => true);
78+
const _findLastEffect = [1].findLast(() => console.log(1) || true);
79+
const _findLastArray = [{ effect() {} }];
80+
_findLastArray.findLast(element => (element.effect = () => console.log(1)));
81+
_findLastArray[0].effect();
82+
7783
const _findIndex = [1].findIndex(() => true).toPrecision(1);
7884
const _findIndexEffect = [1].findIndex(() => console.log(1) || true);
7985
const _findIndexArray = [{ effect() {} }];
8086
_findIndexArray.findIndex(element => (element.effect = () => console.log(1)));
8187
_findIndexArray[0].effect();
8288

89+
const _findLastIndex = [1].findLastIndex(() => true).toPrecision(1);
90+
const _findLastIndexEffect = [1].findLastIndex(() => console.log(1) || true);
91+
const _findLastIndexArray = [{ effect() {} }];
92+
_findLastIndexArray.findLastIndex(element => (element.effect = () => console.log(1)));
93+
_findLastIndexArray[0].effect();
94+
8395
const _flatMap = [1].flatMap(() => 1).join(',');
8496
const _flatMapEffect = [1].flatMap(() => console.log(1) || 1);
8597
const _flatMapArray = [{ effect() {} }];

0 commit comments

Comments
 (0)