Skip to content

Commit

Permalink
feat: add Array.prototype.groupBy/groupByToMap (#4360)
Browse files Browse the repository at this point in the history
Co-authored-by: Lukas Taegert-Atkinson <lukastaegert@users.noreply.github.com>
  • Loading branch information
dnalborczyk and lukastaegert authored Jan 29, 2022
1 parent 042933a commit 5364114
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
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ export const ARRAY_PROTOTYPE = new ObjectEntity(
flat: METHOD_DEOPTS_SELF_RETURNS_NEW_ARRAY,
flatMap: METHOD_CALLS_ARG_DEOPTS_SELF_RETURNS_NEW_ARRAY,
forEach: METHOD_CALLS_ARG_DEOPTS_SELF_RETURNS_UNKNOWN,
groupBy: METHOD_CALLS_ARG_DEOPTS_SELF_RETURNS_UNKNOWN,
groupByToMap: METHOD_CALLS_ARG_DEOPTS_SELF_RETURNS_UNKNOWN,
includes: METHOD_RETURNS_BOOLEAN,
indexOf: METHOD_RETURNS_NUMBER,
join: METHOD_RETURNS_STRING,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ _flatMapArray[0].effect();
const _forEachArray = [{ effect() {} }];
_forEachArray.forEach(element => (element.effect = () => console.log(1)));
_forEachArray[0].effect();
[1].groupBy(() => console.log(1) || true);
const _groupByArray = [{ effect() {} }];
_groupByArray.groupBy((_, element) => (element.effect = () => console.log(1)));
_groupByArray[0].effect();
[1].groupByToMap(() => console.log(1) || true);
const _groupByToMapArray = [{ effect() {} }];
_groupByToMapArray.groupBy((_, element) => (element.effect = () => console.log(1)));
_groupByToMapArray[0].effect();
[1].map(() => console.log(1) || 1);
const _mapArray = [{ effect() {} }];
_mapArray.map(element => (element.effect = () => console.log(1)));
Expand Down
12 changes: 12 additions & 0 deletions test/form/samples/builtin-prototypes/array-expression/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ const _forEachArray = [{ effect() {} }];
_forEachArray.forEach(element => (element.effect = () => console.log(1)));
_forEachArray[0].effect();

const _groupBy = [1].groupBy(() => true);
const _groupByEffect = [1].groupBy(() => console.log(1) || true);
const _groupByArray = [{ effect() {} }];
_groupByArray.groupBy((_, element) => (element.effect = () => console.log(1)));
_groupByArray[0].effect();

const _groupByToMap = [1].groupByToMap(() => true);
const _groupByToMapEffect = [1].groupByToMap(() => console.log(1) || true);
const _groupByToMapArray = [{ effect() {} }];
_groupByToMapArray.groupBy((_, element) => (element.effect = () => console.log(1)));
_groupByToMapArray[0].effect();

const _map = [1].map(() => 1).join(',');
const _mapEffect = [1].map(() => console.log(1) || 1);
const _mapArray = [{ effect() {} }];
Expand Down

0 comments on commit 5364114

Please sign in to comment.