Skip to content

Commit

Permalink
feat: add support for Array.prototype.findLast,findLastIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
dnalborczyk committed Dec 30, 2021
1 parent 7f55571 commit 2be6bd7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/ast/nodes/shared/ArrayPrototype.ts
Expand Up @@ -128,6 +128,8 @@ export const ARRAY_PROTOTYPE = new ObjectEntity(
filter: METHOD_CALLS_ARG_DEOPTS_SELF_RETURNS_NEW_ARRAY,
find: METHOD_CALLS_ARG_DEOPTS_SELF_RETURNS_UNKNOWN,
findIndex: METHOD_CALLS_ARG_DEOPTS_SELF_RETURNS_NUMBER,
findLast: METHOD_CALLS_ARG_DEOPTS_SELF_RETURNS_UNKNOWN,
findLastIndex: METHOD_CALLS_ARG_DEOPTS_SELF_RETURNS_NUMBER,
flat: METHOD_DEOPTS_SELF_RETURNS_NEW_ARRAY,
flatMap: METHOD_CALLS_ARG_DEOPTS_SELF_RETURNS_NEW_ARRAY,
forEach: METHOD_CALLS_ARG_DEOPTS_SELF_RETURNS_UNKNOWN,
Expand Down
Expand Up @@ -35,10 +35,18 @@ _filterArray[0].effect();
const _findArray = [{ effect() {} }];
_findArray.find(element => (element.effect = () => console.log(1)));
_findArray[0].effect();
[1].findLast(() => console.log(1) || true);
const _findLastArray = [{ effect() {} }];
_findLastArray.findLast(element => (element.effect = () => console.log(1)));
_findLastArray[0].effect();
[1].findIndex(() => console.log(1) || true);
const _findIndexArray = [{ effect() {} }];
_findIndexArray.findIndex(element => (element.effect = () => console.log(1)));
_findIndexArray[0].effect();
[1].findLastIndex(() => console.log(1) || true);
const _findLastIndexArray = [{ effect() {} }];
_findLastIndexArray.findLastIndex(element => (element.effect = () => console.log(1)));
_findLastIndexArray[0].effect();
[1].flatMap(() => console.log(1) || 1);
const _flatMapArray = [{ effect() {} }];
_flatMapArray.flatMap(element => (element.effect = () => console.log(1)));
Expand Down
12 changes: 12 additions & 0 deletions test/form/samples/builtin-prototypes/array-expression/main.js
Expand Up @@ -74,12 +74,24 @@ const _findArray = [{ effect() {} }];
_findArray.find(element => (element.effect = () => console.log(1)));
_findArray[0].effect();

const _findLast = [1].findLast(() => true);
const _findLastEffect = [1].findLast(() => console.log(1) || true);
const _findLastArray = [{ effect() {} }];
_findLastArray.findLast(element => (element.effect = () => console.log(1)));
_findLastArray[0].effect();

const _findIndex = [1].findIndex(() => true).toPrecision(1);
const _findIndexEffect = [1].findIndex(() => console.log(1) || true);
const _findIndexArray = [{ effect() {} }];
_findIndexArray.findIndex(element => (element.effect = () => console.log(1)));
_findIndexArray[0].effect();

const _findLastIndex = [1].findLastIndex(() => true).toPrecision(1);
const _findLastIndexEffect = [1].findLastIndex(() => console.log(1) || true);
const _findLastIndexArray = [{ effect() {} }];
_findLastIndexArray.findLastIndex(element => (element.effect = () => console.log(1)));
_findLastIndexArray[0].effect();

const _flatMap = [1].flatMap(() => 1).join(',');
const _flatMapEffect = [1].flatMap(() => console.log(1) || 1);
const _flatMapArray = [{ effect() {} }];
Expand Down

0 comments on commit 2be6bd7

Please sign in to comment.