From 2be6bd7806ba6b54eb3da9de82a1bc5817a2ae24 Mon Sep 17 00:00:00 2001 From: Daniel Nalborczyk Date: Thu, 30 Dec 2021 12:49:34 -0500 Subject: [PATCH] feat: add support for Array.prototype.findLast,findLastIndex --- src/ast/nodes/shared/ArrayPrototype.ts | 2 ++ .../builtin-prototypes/array-expression/_expected.js | 8 ++++++++ .../builtin-prototypes/array-expression/main.js | 12 ++++++++++++ 3 files changed, 22 insertions(+) diff --git a/src/ast/nodes/shared/ArrayPrototype.ts b/src/ast/nodes/shared/ArrayPrototype.ts index 65efb82ea17..a1a1d3d6912 100644 --- a/src/ast/nodes/shared/ArrayPrototype.ts +++ b/src/ast/nodes/shared/ArrayPrototype.ts @@ -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, diff --git a/test/form/samples/builtin-prototypes/array-expression/_expected.js b/test/form/samples/builtin-prototypes/array-expression/_expected.js index f6f62d2d5fe..4fea44f0ad9 100644 --- a/test/form/samples/builtin-prototypes/array-expression/_expected.js +++ b/test/form/samples/builtin-prototypes/array-expression/_expected.js @@ -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))); diff --git a/test/form/samples/builtin-prototypes/array-expression/main.js b/test/form/samples/builtin-prototypes/array-expression/main.js index ae082e12d64..3cf1b47ca43 100644 --- a/test/form/samples/builtin-prototypes/array-expression/main.js +++ b/test/form/samples/builtin-prototypes/array-expression/main.js @@ -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() {} }];