Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
243 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/core-js-pure/override/modules/esnext.typed-array.group-by.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// empty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
require('../../modules/esnext.array.group-by'); | ||
var entryUnbind = require('../../internals/entry-unbind'); | ||
|
||
module.exports = entryUnbind('Array', 'groupBy'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
require('../../../modules/esnext.array.group-by'); | ||
var entryVirtual = require('../../../internals/entry-virtual'); | ||
|
||
module.exports = entryVirtual('Array').groupBy; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
var groupBy = require('../array/virtual/group-by'); | ||
|
||
var ArrayPrototype = Array.prototype; | ||
|
||
module.exports = function (it) { | ||
var own = it.groupBy; | ||
return it === ArrayPrototype || (it instanceof Array && own === ArrayPrototype.groupBy) ? groupBy : own; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require('../../modules/esnext.typed-array.group-by'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
var bind = require('../internals/function-bind-context'); | ||
var has = require('../internals/has'); | ||
var IndexedObject = require('../internals/indexed-object'); | ||
var toObject = require('../internals/to-object'); | ||
var toLength = require('../internals/to-length'); | ||
var toPrimitive = require('../internals/to-primitive'); | ||
var objectCreate = require('../internals/object-create'); | ||
|
||
var push = [].push; | ||
|
||
module.exports = function ($this, callbackfn, that, specificCreate) { | ||
var O = toObject($this); | ||
var self = IndexedObject(O); | ||
var boundFunction = bind(callbackfn, that, 3); | ||
var target = objectCreate(null); | ||
var length = toLength(self.length); | ||
var index = 0; | ||
var value, result, array; | ||
for (;length > index; index++) { | ||
value = self[index]; | ||
result = toPrimitive(boundFunction(value, index, O), 'string'); | ||
if (has(target, result)) array = target[result]; | ||
else target[result] = array = specificCreate ? specificCreate($this, 0) : []; | ||
push.call(array, value); | ||
} return target; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
var $ = require('../internals/export'); | ||
var $groupBy = require('../internals/array-group-by'); | ||
var arraySpeciesCreate = require('../internals/array-species-create'); | ||
var addToUnscopables = require('../internals/add-to-unscopables'); | ||
|
||
// `Array.prototype.groupBy` method | ||
// https://github.com/tc39/proposal-array-grouping | ||
$({ target: 'Array', proto: true }, { | ||
groupBy: function groupBy(callbackfn /* , thisArg */) { | ||
return $groupBy(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined, arraySpeciesCreate); | ||
} | ||
}); | ||
|
||
addToUnscopables('groupBy'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict'; | ||
var ArrayBufferViewCore = require('../internals/array-buffer-view-core'); | ||
var $groupBy = require('../internals/array-group-by'); | ||
var speciesConstructor = require('../internals/species-constructor'); | ||
|
||
var aTypedArray = ArrayBufferViewCore.aTypedArray; | ||
var aTypedArrayConstructor = ArrayBufferViewCore.aTypedArrayConstructor; | ||
var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod; | ||
|
||
// `%TypedArray%.prototype.groupBy` method | ||
// https://github.com/tc39/proposal-array-grouping | ||
exportTypedArrayMethod('groupBy', function groupBy(callbackfn /* , thisArg */) { | ||
var result = $groupBy(aTypedArray(this), callbackfn, arguments.length > 1 ? arguments[1] : undefined); | ||
var TypedArray = aTypedArrayConstructor(speciesConstructor(this, this.constructor)); | ||
var key, array, typedArray, index, length; | ||
for (key in result) { | ||
array = result[key]; | ||
length = array.length; | ||
result[key] = typedArray = new TypedArray(length); | ||
for (index = 0; index < length; index++) typedArray[index] = array[index]; | ||
} return result; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// https://github.com/tc39/proposal-array-grouping | ||
require('../modules/esnext.array.group-by'); | ||
require('../modules/esnext.typed-array.group-by'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { STRICT } from '../helpers/constants'; | ||
|
||
import Symbol from 'core-js-pure/features/symbol'; | ||
import groupBy from 'core-js-pure/features/array/group-by'; | ||
import getPrototypeOf from 'core-js-pure/features/object/get-prototype-of'; | ||
|
||
QUnit.test('Array#groupBy', assert => { | ||
assert.isFunction(groupBy); | ||
let array = [1]; | ||
const context = {}; | ||
groupBy(array, function (value, key, that) { | ||
assert.same(arguments.length, 3, 'correct number of callback arguments'); | ||
assert.same(value, 1, 'correct value in callback'); | ||
assert.same(key, 0, 'correct index in callback'); | ||
assert.same(that, array, 'correct link to array in callback'); | ||
assert.same(this, context, 'correct callback context'); | ||
}, context); | ||
assert.same(getPrototypeOf(groupBy([], it => it)), null, 'null proto'); | ||
assert.deepEqual(groupBy([1, 2, 3], it => it % 2), { 1: [1, 3], 0: [2] }, '#1'); | ||
assert.deepEqual( | ||
groupBy([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], it => `i${ it % 5 }`), | ||
{ i1: [1, 6, 11], i2: [2, 7, 12], i3: [3, 8], i4: [4, 9], i0: [5, 10] }, | ||
'#2', | ||
); | ||
assert.deepEqual(groupBy(Array(3), it => it), { undefined: [undefined, undefined, undefined] }, '#3'); | ||
if (STRICT) { | ||
assert.throws(() => groupBy(null, () => { /* empty */ }), TypeError); | ||
assert.throws(() => groupBy(undefined, () => { /* empty */ }), TypeError); | ||
} | ||
array = [1]; | ||
// eslint-disable-next-line object-shorthand -- constructor | ||
array.constructor = { [Symbol.species]: function () { | ||
return { foo: 1 }; | ||
} }; | ||
assert.same(groupBy(array, Boolean).true.foo, 1, '@@species'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { STRICT } from '../helpers/constants'; | ||
|
||
const { getPrototypeOf } = Object; | ||
|
||
QUnit.test('Array#groupBy', assert => { | ||
const { groupBy } = Array.prototype; | ||
assert.isFunction(groupBy); | ||
assert.arity(groupBy, 1); | ||
assert.name(groupBy, 'groupBy'); | ||
assert.looksNative(groupBy); | ||
assert.nonEnumerable(Array.prototype, 'groupBy'); | ||
let array = [1]; | ||
const context = {}; | ||
array.groupBy(function (value, key, that) { | ||
assert.same(arguments.length, 3, 'correct number of callback arguments'); | ||
assert.same(value, 1, 'correct value in callback'); | ||
assert.same(key, 0, 'correct index in callback'); | ||
assert.same(that, array, 'correct link to array in callback'); | ||
assert.same(this, context, 'correct callback context'); | ||
}, context); | ||
assert.same(getPrototypeOf([].groupBy(it => it)), null, 'null proto'); | ||
assert.deepEqual([1, 2, 3].groupBy(it => it % 2), { 1: [1, 3], 0: [2] }, '#1'); | ||
assert.deepEqual( | ||
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12].groupBy(it => `i${ it % 5 }`), | ||
{ i1: [1, 6, 11], i2: [2, 7, 12], i3: [3, 8], i4: [4, 9], i0: [5, 10] }, | ||
'#2', | ||
); | ||
assert.deepEqual(Array(3).groupBy(it => it), { undefined: [undefined, undefined, undefined] }, '#3'); | ||
if (STRICT) { | ||
assert.throws(() => groupBy.call(null, () => { /* empty */ }), TypeError); | ||
assert.throws(() => groupBy.call(undefined, () => { /* empty */ }), TypeError); | ||
} | ||
array = [1]; | ||
// eslint-disable-next-line object-shorthand -- constructor | ||
array.constructor = { [Symbol.species]: function () { | ||
return { foo: 1 }; | ||
} }; | ||
assert.same(array.groupBy(Boolean).true.foo, 1, '@@species'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { DESCRIPTORS, GLOBAL, TYPED_ARRAYS } from '../helpers/constants'; | ||
|
||
const { getPrototypeOf } = Object; | ||
|
||
if (DESCRIPTORS) QUnit.test('%TypedArrayPrototype%.groupBy', assert => { | ||
// we can't implement %TypedArrayPrototype% in all engines, so run all tests for each typed array constructor | ||
for (const name in TYPED_ARRAYS) { | ||
const TypedArray = GLOBAL[name]; | ||
const { groupBy } = TypedArray.prototype; | ||
assert.isFunction(groupBy, `${ name }::groupBy is function`); | ||
assert.arity(groupBy, 1, `${ name }::groupBy arity is 1`); | ||
assert.name(groupBy, 'groupBy', `${ name }::groupBy name is 'groupBy'`); | ||
assert.looksNative(groupBy, `${ name }::groupBy looks native`); | ||
const array = new TypedArray([1]); | ||
const context = {}; | ||
array.groupBy(function (value, key, that) { | ||
assert.same(arguments.length, 3, 'correct number of callback arguments'); | ||
assert.same(value, 1, 'correct value in callback'); | ||
assert.same(key, 0, 'correct index in callback'); | ||
assert.same(that, array, 'correct link to array in callback'); | ||
assert.same(this, context, 'correct callback context'); | ||
}, context); | ||
|
||
assert.same(getPrototypeOf(new TypedArray([1]).groupBy(it => it)), null, 'null proto'); | ||
assert.ok(new TypedArray([1]).groupBy(it => it)[1] instanceof TypedArray, 'instance'); | ||
assert.deepEqual( | ||
new TypedArray([1, 2, 3]).groupBy(it => it % 2), | ||
{ 1: new TypedArray([1, 3]), 0: new TypedArray([2]) }, | ||
'#1', | ||
); | ||
assert.deepEqual(new TypedArray([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]).groupBy(it => `i${ it % 5 }`), { | ||
i1: new TypedArray([1, 6, 11]), | ||
i2: new TypedArray([2, 7, 12]), | ||
i3: new TypedArray([3, 8]), | ||
i4: new TypedArray([4, 9]), | ||
i0: new TypedArray([5, 10]), | ||
}, '#2'); | ||
|
||
assert.throws(() => groupBy.call([0], () => { /* empty */ }), "isn't generic"); | ||
} | ||
}); | ||
|