From a9955c57c3db5b8b3f2c3c59fc3e7921a98d781b Mon Sep 17 00:00:00 2001 From: Denis Pushkarev Date: Thu, 31 Mar 2022 02:49:16 +0700 Subject: [PATCH] move "Change `Array` by copy" proposal to stage 3 https://github.com/babel/proposals/issues/81#issuecomment-1083449843 --- CHANGELOG.md | 1 + README.md | 96 +++++++++---------- packages/core-js/actual/array/index.js | 4 + packages/core-js/actual/array/to-reversed.js | 4 + packages/core-js/actual/array/to-sorted.js | 5 + packages/core-js/actual/array/to-spliced.js | 4 + .../core-js/actual/array/virtual/index.js | 4 + .../actual/array/virtual/to-reversed.js | 4 + .../core-js/actual/array/virtual/to-sorted.js | 5 + .../actual/array/virtual/to-spliced.js | 4 + packages/core-js/actual/array/virtual/with.js | 4 + packages/core-js/actual/array/with.js | 4 + .../core-js/actual/instance/to-reversed.js | 9 ++ packages/core-js/actual/instance/to-sorted.js | 9 ++ .../core-js/actual/instance/to-spliced.js | 9 ++ packages/core-js/actual/instance/with.js | 9 ++ packages/core-js/actual/typed-array/index.js | 4 + .../core-js/actual/typed-array/methods.js | 4 + .../core-js/actual/typed-array/to-reversed.js | 1 + .../core-js/actual/typed-array/to-sorted.js | 2 + .../core-js/actual/typed-array/to-spliced.js | 1 + packages/core-js/actual/typed-array/with.js | 1 + packages/core-js/features/array/index.js | 4 - .../core-js/features/array/virtual/index.js | 4 - .../features/array/virtual/to-reversed.js | 5 +- .../features/array/virtual/to-sorted.js | 6 +- .../features/array/virtual/to-spliced.js | 5 +- .../core-js/features/array/virtual/with.js | 5 +- .../core-js/features/instance/to-reversed.js | 10 +- .../core-js/features/instance/to-sorted.js | 10 +- .../core-js/features/instance/to-spliced.js | 10 +- packages/core-js/features/instance/with.js | 10 +- .../core-js/features/typed-array/index.js | 4 - .../core-js/features/typed-array/methods.js | 4 - .../features/typed-array/to-reversed.js | 4 +- .../core-js/features/typed-array/to-sorted.js | 5 +- .../features/typed-array/to-spliced.js | 4 +- packages/core-js/features/typed-array/with.js | 4 +- .../core-js/modules/es.typed-array.sort.js | 1 - packages/core-js/stage/2.js | 1 - packages/core-js/stage/3.js | 1 + tests/commonjs.mjs | 72 +++++++------- 42 files changed, 205 insertions(+), 152 deletions(-) create mode 100644 packages/core-js/actual/array/to-reversed.js create mode 100644 packages/core-js/actual/array/to-sorted.js create mode 100644 packages/core-js/actual/array/to-spliced.js create mode 100644 packages/core-js/actual/array/virtual/to-reversed.js create mode 100644 packages/core-js/actual/array/virtual/to-sorted.js create mode 100644 packages/core-js/actual/array/virtual/to-spliced.js create mode 100644 packages/core-js/actual/array/virtual/with.js create mode 100644 packages/core-js/actual/array/with.js create mode 100644 packages/core-js/actual/instance/to-reversed.js create mode 100644 packages/core-js/actual/instance/to-sorted.js create mode 100644 packages/core-js/actual/instance/to-spliced.js create mode 100644 packages/core-js/actual/instance/with.js create mode 100644 packages/core-js/actual/typed-array/to-reversed.js create mode 100644 packages/core-js/actual/typed-array/to-sorted.js create mode 100644 packages/core-js/actual/typed-array/to-spliced.js create mode 100644 packages/core-js/actual/typed-array/with.js diff --git a/CHANGELOG.md b/CHANGELOG.md index d524d4da3f4c..ef45bb9b573e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## Changelog ##### Unreleased +- [Change `Array` by copy proposal](https://github.com/tc39/proposal-change-array-by-copy) moved to stage 3 - Stabilized proposals are filtered out from the `core-js-compat` / `core-js-builder` / `core-js-bundle` output. That mean that if the output contains, for example, `es.object.has-own`, the legacy shortcut to it, `esnext.object.has-own`, will not be added. - Fixed work of non-standard V8 `Error` features with wrapped `Error` constructors, [#1061](https://github.com/zloirock/core-js/issues/1061) - `null` and `undefined` allowed as the second argument of `structuredClone`, [#1056](https://github.com/zloirock/core-js/issues/1056) diff --git a/README.md b/README.md index 6453587e58f7..a879a2241692 100644 --- a/README.md +++ b/README.md @@ -127,11 +127,11 @@ queueMicrotask(() => console.log('called as microtask')); - [Stage 3 proposals](#stage-3-proposals) - [`Array` grouping](#array-grouping) - [`Array` find from last](#array-find-from-last) + - [Change `Array` by copy](#change-array-by-copy) - [Stage 2 proposals](#stage-2-proposals) - [`Iterator` helpers](#iterator-helpers) - [New `Set` methods](#new-set-methods) - [`Map.prototype.emplace`](#mapprototypeemplace) - - [Change `Array` by copy](#change-array-by-copy) - [`Array.fromAsync`](#arrayfromasync) - [`Array.isTemplateObject`](#arrayistemplateobject) - [`Symbol.{ asyncDispose, dispose }` for `using` statement](#symbol-asyncdispose-dispose--for-using-statement) @@ -2115,6 +2115,53 @@ core-js/actual|features/typed-array/find-last-index [1, 2, 3, 4].findLast(it => it % 2); // => 3 [1, 2, 3, 4].findLastIndex(it => it % 2); // => 2 ```` +##### [Change `Array` by copy](https://github.com/tc39/proposal-change-array-by-copy)[⬆](#index) +Modules [`esnext.array.to-reversed`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.array.to-reversed.js), [`esnext.array.to-sorted`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.array.to-sorted.js), [`esnext.array.to-spliced`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.array.to-spliced.js), [`esnext.array.with`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.array.with.js), [`esnext.typed-array.to-reversed`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.typed-array.to-reversed.js), [`esnext.typed-array.to-sorted`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.typed-array.to-sorted.js), [`esnext.typed-array.to-spliced`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.typed-array.to-spliced.js), [`esnext.typed-array.with`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.typed-array.with.js). +```js +class Array { + toReversed(): Array; + toSpliced(start?: number, deleteCount?: number, ...items: Array): Array; + toSorted(comparefn?: (a: any, b: any) => number): Array; + with(index: includes, value: any): Array; +} + +class %TypedArray% { + toReversed(): %TypedArray%; + toSpliced(start?: number, deleteCount?: number, ...items: %TypedArray%): %TypedArray%; + toSorted(comparefn?: (a: any, b: any) => number): %TypedArray%; + with(index: includes, value: any): %TypedArray%; +} +``` +[*CommonJS entry points:*](#commonjs-api) +``` +core-js/proposals/change-array-by-copy +core-js(-pure)/actual|features/array(/virtual)/to-reversed +core-js(-pure)/actual|features/array(/virtual)/to-sorted +core-js(-pure)/actual|features/array(/virtual)/to-spliced +core-js(-pure)/actual|features/array(/virtual)/with +core-js/actual|features/typed-array/to-reversed +core-js/actual|features/typed-array/to-sorted +core-js/actual|features/typed-array/to-spliced +core-js/actual|features/typed-array/with +``` +[*Examples*](t.ly/wcvY): +```js +const sequence = [1, 2, 3]; +sequence.toReversed(); // => [3, 2, 1] +sequence; // => [1, 2, 3] + +const array = [1, 2, 3, 4]; +array.toSpliced(1, 2, 5, 6, 7); // => [1, 5, 6, 7, 4] +array; // => [1, 2, 3, 4] + +const outOfOrder = [3, 1, 2]; +outOfOrder.toSorted(); // => [1, 2, 3] +outOfOrder; // => [3, 1, 2] + +const correctionNeeded = [1, 1, 3]; +correctionNeeded.with(1, 2); // => [1, 2, 3] +correctionNeeded; // => [1, 1, 3] +```` #### Stage 2 proposals[⬆](#index) [*CommonJS entry points:*](#commonjs-api) @@ -2288,53 +2335,6 @@ map.emplace('b', { update: it => it ** 2, insert: () => 3}); // => 3 console.log(map); // => Map { 'a': 4, 'b': 3 } ``` -##### [Change `Array` by copy](https://github.com/tc39/proposal-change-array-by-copy)[⬆](#index) -Modules [`esnext.array.to-reversed`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.array.to-reversed.js), [`esnext.array.to-sorted`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.array.to-sorted.js), [`esnext.array.to-spliced`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.array.to-spliced.js), [`esnext.array.with`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.array.with.js), [`esnext.typed-array.to-reversed`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.typed-array.to-reversed.js), [`esnext.typed-array.to-sorted`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.typed-array.to-sorted.js), [`esnext.typed-array.to-spliced`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.typed-array.to-spliced.js), [`esnext.typed-array.with`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.typed-array.with.js). -```js -class Array { - toReversed(): Array; - toSpliced(start?: number, deleteCount?: number, ...items: Array): Array; - toSorted(comparefn?: (a: any, b: any) => number): Array; - with(index: includes, value: any): Array; -} - -class %TypedArray% { - toReversed(): %TypedArray%; - toSpliced(start?: number, deleteCount?: number, ...items: %TypedArray%): %TypedArray%; - toSorted(comparefn?: (a: any, b: any) => number): %TypedArray%; - with(index: includes, value: any): %TypedArray%; -} -``` -[*CommonJS entry points:*](#commonjs-api) -``` -core-js/proposals/change-array-by-copy -core-js(-pure)/features/array(/virtual)/to-reversed -core-js(-pure)/features/array(/virtual)/to-sorted -core-js(-pure)/features/array(/virtual)/to-spliced -core-js(-pure)/features/array(/virtual)/with -core-js/features/typed-array/to-reversed -core-js/features/typed-array/to-sorted -core-js/features/typed-array/to-spliced -core-js/features/typed-array/with -``` -[*Examples*](t.ly/wcvY): -```js -const sequence = [1, 2, 3]; -sequence.toReversed(); // => [3, 2, 1] -sequence; // => [1, 2, 3] - -const array = [1, 2, 3, 4]; -array.toSpliced(1, 2, 5, 6, 7); // => [1, 5, 6, 7, 4] -array; // => [1, 2, 3, 4] - -const outOfOrder = [3, 1, 2]; -outOfOrder.toSorted(); // => [1, 2, 3] -outOfOrder; // => [3, 1, 2] - -const correctionNeeded = [1, 1, 3]; -correctionNeeded.with(1, 2); // => [1, 2, 3] -correctionNeeded; // => [1, 1, 3] -```` ##### [`Array.fromAsync`](https://github.com/tc39/proposal-array-from-async)[⬆](#index) Modules [`esnext.array.from-async`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.array.from-async.js). ```js diff --git a/packages/core-js/actual/array/index.js b/packages/core-js/actual/array/index.js index 70b5bcf0de4d..230426a722e9 100644 --- a/packages/core-js/actual/array/index.js +++ b/packages/core-js/actual/array/index.js @@ -5,5 +5,9 @@ require('../../modules/esnext.array.find-last'); require('../../modules/esnext.array.find-last-index'); require('../../modules/esnext.array.group-by'); require('../../modules/esnext.array.group-by-to-map'); +require('../../modules/esnext.array.to-reversed'); +require('../../modules/esnext.array.to-sorted'); +require('../../modules/esnext.array.to-spliced'); +require('../../modules/esnext.array.with'); module.exports = parent; diff --git a/packages/core-js/actual/array/to-reversed.js b/packages/core-js/actual/array/to-reversed.js new file mode 100644 index 000000000000..f144b53a141e --- /dev/null +++ b/packages/core-js/actual/array/to-reversed.js @@ -0,0 +1,4 @@ +require('../../modules/esnext.array.to-reversed'); +var entryUnbind = require('../../internals/entry-unbind'); + +module.exports = entryUnbind('Array', 'toReversed'); diff --git a/packages/core-js/actual/array/to-sorted.js b/packages/core-js/actual/array/to-sorted.js new file mode 100644 index 000000000000..42ac4ee45721 --- /dev/null +++ b/packages/core-js/actual/array/to-sorted.js @@ -0,0 +1,5 @@ +require('../../modules/es.array.sort'); +require('../../modules/esnext.array.to-sorted'); +var entryUnbind = require('../../internals/entry-unbind'); + +module.exports = entryUnbind('Array', 'toSorted'); diff --git a/packages/core-js/actual/array/to-spliced.js b/packages/core-js/actual/array/to-spliced.js new file mode 100644 index 000000000000..9f03e3b06cb1 --- /dev/null +++ b/packages/core-js/actual/array/to-spliced.js @@ -0,0 +1,4 @@ +require('../../modules/esnext.array.to-spliced'); +var entryUnbind = require('../../internals/entry-unbind'); + +module.exports = entryUnbind('Array', 'toSpliced'); diff --git a/packages/core-js/actual/array/virtual/index.js b/packages/core-js/actual/array/virtual/index.js index 778f564bd0b5..a0f9910fd585 100644 --- a/packages/core-js/actual/array/virtual/index.js +++ b/packages/core-js/actual/array/virtual/index.js @@ -5,5 +5,9 @@ require('../../../modules/esnext.array.find-last'); require('../../../modules/esnext.array.find-last-index'); require('../../../modules/esnext.array.group-by'); require('../../../modules/esnext.array.group-by-to-map'); +require('../../../modules/esnext.array.to-reversed'); +require('../../../modules/esnext.array.to-sorted'); +require('../../../modules/esnext.array.to-spliced'); +require('../../../modules/esnext.array.with'); module.exports = parent; diff --git a/packages/core-js/actual/array/virtual/to-reversed.js b/packages/core-js/actual/array/virtual/to-reversed.js new file mode 100644 index 000000000000..be5ac5d7d880 --- /dev/null +++ b/packages/core-js/actual/array/virtual/to-reversed.js @@ -0,0 +1,4 @@ +require('../../../modules/esnext.array.to-reversed'); +var entryVirtual = require('../../../internals/entry-virtual'); + +module.exports = entryVirtual('Array').toReversed; diff --git a/packages/core-js/actual/array/virtual/to-sorted.js b/packages/core-js/actual/array/virtual/to-sorted.js new file mode 100644 index 000000000000..3406f1919fbc --- /dev/null +++ b/packages/core-js/actual/array/virtual/to-sorted.js @@ -0,0 +1,5 @@ +require('../../../modules/es.array.sort'); +require('../../../modules/esnext.array.to-sorted'); +var entryVirtual = require('../../../internals/entry-virtual'); + +module.exports = entryVirtual('Array').toSorted; diff --git a/packages/core-js/actual/array/virtual/to-spliced.js b/packages/core-js/actual/array/virtual/to-spliced.js new file mode 100644 index 000000000000..863743314516 --- /dev/null +++ b/packages/core-js/actual/array/virtual/to-spliced.js @@ -0,0 +1,4 @@ +require('../../../modules/esnext.array.to-spliced'); +var entryVirtual = require('../../../internals/entry-virtual'); + +module.exports = entryVirtual('Array').toSpliced; diff --git a/packages/core-js/actual/array/virtual/with.js b/packages/core-js/actual/array/virtual/with.js new file mode 100644 index 000000000000..6df870aeb2ff --- /dev/null +++ b/packages/core-js/actual/array/virtual/with.js @@ -0,0 +1,4 @@ +require('../../../modules/esnext.array.with'); +var entryVirtual = require('../../../internals/entry-virtual'); + +module.exports = entryVirtual('Array')['with']; diff --git a/packages/core-js/actual/array/with.js b/packages/core-js/actual/array/with.js new file mode 100644 index 000000000000..3591eaceeaf5 --- /dev/null +++ b/packages/core-js/actual/array/with.js @@ -0,0 +1,4 @@ +require('../../modules/esnext.array.with'); +var entryUnbind = require('../../internals/entry-unbind'); + +module.exports = entryUnbind('Array', 'with'); diff --git a/packages/core-js/actual/instance/to-reversed.js b/packages/core-js/actual/instance/to-reversed.js new file mode 100644 index 000000000000..5ef01827bea4 --- /dev/null +++ b/packages/core-js/actual/instance/to-reversed.js @@ -0,0 +1,9 @@ +var isPrototypeOf = require('../../internals/object-is-prototype-of'); +var method = require('../array/virtual/to-reversed'); + +var ArrayPrototype = Array.prototype; + +module.exports = function (it) { + var own = it.toReversed; + return (it === ArrayPrototype || (isPrototypeOf(ArrayPrototype, it) && own === ArrayPrototype.toReversed)) ? method : own; +}; diff --git a/packages/core-js/actual/instance/to-sorted.js b/packages/core-js/actual/instance/to-sorted.js new file mode 100644 index 000000000000..7110c9bc770c --- /dev/null +++ b/packages/core-js/actual/instance/to-sorted.js @@ -0,0 +1,9 @@ +var isPrototypeOf = require('../../internals/object-is-prototype-of'); +var method = require('../array/virtual/to-sorted'); + +var ArrayPrototype = Array.prototype; + +module.exports = function (it) { + var own = it.toSorted; + return (it === ArrayPrototype || (isPrototypeOf(ArrayPrototype, it) && own === ArrayPrototype.toSorted)) ? method : own; +}; diff --git a/packages/core-js/actual/instance/to-spliced.js b/packages/core-js/actual/instance/to-spliced.js new file mode 100644 index 000000000000..b1044cbf0feb --- /dev/null +++ b/packages/core-js/actual/instance/to-spliced.js @@ -0,0 +1,9 @@ +var isPrototypeOf = require('../../internals/object-is-prototype-of'); +var method = require('../array/virtual/to-spliced'); + +var ArrayPrototype = Array.prototype; + +module.exports = function (it) { + var own = it.toSpliced; + return (it === ArrayPrototype || (isPrototypeOf(ArrayPrototype, it) && own === ArrayPrototype.toSpliced)) ? method : own; +}; diff --git a/packages/core-js/actual/instance/with.js b/packages/core-js/actual/instance/with.js new file mode 100644 index 000000000000..d5e7c3b08178 --- /dev/null +++ b/packages/core-js/actual/instance/with.js @@ -0,0 +1,9 @@ +var isPrototypeOf = require('../../internals/object-is-prototype-of'); +var method = require('../array/virtual/with'); + +var ArrayPrototype = Array.prototype; + +module.exports = function (it) { + var own = it['with']; + return (it === ArrayPrototype || (isPrototypeOf(ArrayPrototype, it) && own === ArrayPrototype['with'])) ? method : own; +}; diff --git a/packages/core-js/actual/typed-array/index.js b/packages/core-js/actual/typed-array/index.js index 6464ab3d020b..3b7407810891 100644 --- a/packages/core-js/actual/typed-array/index.js +++ b/packages/core-js/actual/typed-array/index.js @@ -1,5 +1,9 @@ var parent = require('../../stable/typed-array'); require('../../modules/esnext.typed-array.find-last'); require('../../modules/esnext.typed-array.find-last-index'); +require('../../modules/esnext.typed-array.to-reversed'); +require('../../modules/esnext.typed-array.to-sorted'); +require('../../modules/esnext.typed-array.to-spliced'); +require('../../modules/esnext.typed-array.with'); module.exports = parent; diff --git a/packages/core-js/actual/typed-array/methods.js b/packages/core-js/actual/typed-array/methods.js index c29084c00906..218358f49de9 100644 --- a/packages/core-js/actual/typed-array/methods.js +++ b/packages/core-js/actual/typed-array/methods.js @@ -1,5 +1,9 @@ var parent = require('../../stable/typed-array/methods'); require('../../modules/esnext.typed-array.find-last'); require('../../modules/esnext.typed-array.find-last-index'); +require('../../modules/esnext.typed-array.to-reversed'); +require('../../modules/esnext.typed-array.to-sorted'); +require('../../modules/esnext.typed-array.to-spliced'); +require('../../modules/esnext.typed-array.with'); module.exports = parent; diff --git a/packages/core-js/actual/typed-array/to-reversed.js b/packages/core-js/actual/typed-array/to-reversed.js new file mode 100644 index 000000000000..28cbd6cbeb32 --- /dev/null +++ b/packages/core-js/actual/typed-array/to-reversed.js @@ -0,0 +1 @@ +require('../../modules/esnext.typed-array.to-reversed'); diff --git a/packages/core-js/actual/typed-array/to-sorted.js b/packages/core-js/actual/typed-array/to-sorted.js new file mode 100644 index 000000000000..644f0fe564e6 --- /dev/null +++ b/packages/core-js/actual/typed-array/to-sorted.js @@ -0,0 +1,2 @@ +require('../../modules/es.typed-array.sort'); +require('../../modules/esnext.typed-array.to-sorted'); diff --git a/packages/core-js/actual/typed-array/to-spliced.js b/packages/core-js/actual/typed-array/to-spliced.js new file mode 100644 index 000000000000..44ae5c2f6f32 --- /dev/null +++ b/packages/core-js/actual/typed-array/to-spliced.js @@ -0,0 +1 @@ +require('../../modules/esnext.typed-array.to-spliced'); diff --git a/packages/core-js/actual/typed-array/with.js b/packages/core-js/actual/typed-array/with.js new file mode 100644 index 000000000000..7908e59f7e47 --- /dev/null +++ b/packages/core-js/actual/typed-array/with.js @@ -0,0 +1 @@ +require('../../modules/esnext.typed-array.with'); diff --git a/packages/core-js/features/array/index.js b/packages/core-js/features/array/index.js index 976b45b001a7..d2095de4296d 100644 --- a/packages/core-js/features/array/index.js +++ b/packages/core-js/features/array/index.js @@ -9,10 +9,6 @@ require('../../modules/esnext.array.filter-reject'); require('../../modules/esnext.array.is-template-object'); require('../../modules/esnext.array.last-item'); require('../../modules/esnext.array.last-index'); -require('../../modules/esnext.array.to-reversed'); -require('../../modules/esnext.array.to-sorted'); -require('../../modules/esnext.array.to-spliced'); require('../../modules/esnext.array.unique-by'); -require('../../modules/esnext.array.with'); module.exports = parent; diff --git a/packages/core-js/features/array/virtual/index.js b/packages/core-js/features/array/virtual/index.js index e73cdd431846..ac11ac5015a3 100644 --- a/packages/core-js/features/array/virtual/index.js +++ b/packages/core-js/features/array/virtual/index.js @@ -4,10 +4,6 @@ require('../../../modules/esnext.array.at'); // TODO: Remove from `core-js@4` require('../../../modules/esnext.array.filter-out'); require('../../../modules/esnext.array.filter-reject'); -require('../../../modules/esnext.array.to-reversed'); -require('../../../modules/esnext.array.to-sorted'); -require('../../../modules/esnext.array.to-spliced'); require('../../../modules/esnext.array.unique-by'); -require('../../../modules/esnext.array.with'); module.exports = parent; diff --git a/packages/core-js/features/array/virtual/to-reversed.js b/packages/core-js/features/array/virtual/to-reversed.js index be5ac5d7d880..a6d254444437 100644 --- a/packages/core-js/features/array/virtual/to-reversed.js +++ b/packages/core-js/features/array/virtual/to-reversed.js @@ -1,4 +1,3 @@ -require('../../../modules/esnext.array.to-reversed'); -var entryVirtual = require('../../../internals/entry-virtual'); +var parent = require('../../../actual/array/virtual/to-reversed'); -module.exports = entryVirtual('Array').toReversed; +module.exports = parent; diff --git a/packages/core-js/features/array/virtual/to-sorted.js b/packages/core-js/features/array/virtual/to-sorted.js index 3406f1919fbc..57c6b9c284e1 100644 --- a/packages/core-js/features/array/virtual/to-sorted.js +++ b/packages/core-js/features/array/virtual/to-sorted.js @@ -1,5 +1,3 @@ -require('../../../modules/es.array.sort'); -require('../../../modules/esnext.array.to-sorted'); -var entryVirtual = require('../../../internals/entry-virtual'); +var parent = require('../../../actual/array/virtual/to-sorted'); -module.exports = entryVirtual('Array').toSorted; +module.exports = parent; diff --git a/packages/core-js/features/array/virtual/to-spliced.js b/packages/core-js/features/array/virtual/to-spliced.js index 863743314516..03b9f9c493d8 100644 --- a/packages/core-js/features/array/virtual/to-spliced.js +++ b/packages/core-js/features/array/virtual/to-spliced.js @@ -1,4 +1,3 @@ -require('../../../modules/esnext.array.to-spliced'); -var entryVirtual = require('../../../internals/entry-virtual'); +var parent = require('../../../actual/array/virtual/to-spliced'); -module.exports = entryVirtual('Array').toSpliced; +module.exports = parent; diff --git a/packages/core-js/features/array/virtual/with.js b/packages/core-js/features/array/virtual/with.js index 6df870aeb2ff..28302725f11a 100644 --- a/packages/core-js/features/array/virtual/with.js +++ b/packages/core-js/features/array/virtual/with.js @@ -1,4 +1,3 @@ -require('../../../modules/esnext.array.with'); -var entryVirtual = require('../../../internals/entry-virtual'); +var parent = require('../../../actual/array/virtual/with'); -module.exports = entryVirtual('Array')['with']; +module.exports = parent; diff --git a/packages/core-js/features/instance/to-reversed.js b/packages/core-js/features/instance/to-reversed.js index 5ef01827bea4..d96d7ae911b4 100644 --- a/packages/core-js/features/instance/to-reversed.js +++ b/packages/core-js/features/instance/to-reversed.js @@ -1,9 +1,3 @@ -var isPrototypeOf = require('../../internals/object-is-prototype-of'); -var method = require('../array/virtual/to-reversed'); +var parent = require('../../actual/instance/to-reversed'); -var ArrayPrototype = Array.prototype; - -module.exports = function (it) { - var own = it.toReversed; - return (it === ArrayPrototype || (isPrototypeOf(ArrayPrototype, it) && own === ArrayPrototype.toReversed)) ? method : own; -}; +module.exports = parent; diff --git a/packages/core-js/features/instance/to-sorted.js b/packages/core-js/features/instance/to-sorted.js index 7110c9bc770c..f4030f665277 100644 --- a/packages/core-js/features/instance/to-sorted.js +++ b/packages/core-js/features/instance/to-sorted.js @@ -1,9 +1,3 @@ -var isPrototypeOf = require('../../internals/object-is-prototype-of'); -var method = require('../array/virtual/to-sorted'); +var parent = require('../../actual/instance/to-sorted'); -var ArrayPrototype = Array.prototype; - -module.exports = function (it) { - var own = it.toSorted; - return (it === ArrayPrototype || (isPrototypeOf(ArrayPrototype, it) && own === ArrayPrototype.toSorted)) ? method : own; -}; +module.exports = parent; diff --git a/packages/core-js/features/instance/to-spliced.js b/packages/core-js/features/instance/to-spliced.js index b1044cbf0feb..790dc8769b45 100644 --- a/packages/core-js/features/instance/to-spliced.js +++ b/packages/core-js/features/instance/to-spliced.js @@ -1,9 +1,3 @@ -var isPrototypeOf = require('../../internals/object-is-prototype-of'); -var method = require('../array/virtual/to-spliced'); +var parent = require('../../actual/instance/to-spliced'); -var ArrayPrototype = Array.prototype; - -module.exports = function (it) { - var own = it.toSpliced; - return (it === ArrayPrototype || (isPrototypeOf(ArrayPrototype, it) && own === ArrayPrototype.toSpliced)) ? method : own; -}; +module.exports = parent; diff --git a/packages/core-js/features/instance/with.js b/packages/core-js/features/instance/with.js index d5e7c3b08178..3efbe64d1374 100644 --- a/packages/core-js/features/instance/with.js +++ b/packages/core-js/features/instance/with.js @@ -1,9 +1,3 @@ -var isPrototypeOf = require('../../internals/object-is-prototype-of'); -var method = require('../array/virtual/with'); +var parent = require('../../actual/instance/with'); -var ArrayPrototype = Array.prototype; - -module.exports = function (it) { - var own = it['with']; - return (it === ArrayPrototype || (isPrototypeOf(ArrayPrototype, it) && own === ArrayPrototype['with'])) ? method : own; -}; +module.exports = parent; diff --git a/packages/core-js/features/typed-array/index.js b/packages/core-js/features/typed-array/index.js index cdd64b6f49d8..9ccac8df0fad 100644 --- a/packages/core-js/features/typed-array/index.js +++ b/packages/core-js/features/typed-array/index.js @@ -8,10 +8,6 @@ require('../../modules/esnext.typed-array.at'); require('../../modules/esnext.typed-array.filter-out'); require('../../modules/esnext.typed-array.filter-reject'); require('../../modules/esnext.typed-array.group-by'); -require('../../modules/esnext.typed-array.to-reversed'); -require('../../modules/esnext.typed-array.to-sorted'); -require('../../modules/esnext.typed-array.to-spliced'); require('../../modules/esnext.typed-array.unique-by'); -require('../../modules/esnext.typed-array.with'); module.exports = parent; diff --git a/packages/core-js/features/typed-array/methods.js b/packages/core-js/features/typed-array/methods.js index d745611ebbe6..85f43408fae1 100644 --- a/packages/core-js/features/typed-array/methods.js +++ b/packages/core-js/features/typed-array/methods.js @@ -8,10 +8,6 @@ require('../../modules/esnext.typed-array.at'); require('../../modules/esnext.typed-array.filter-out'); require('../../modules/esnext.typed-array.filter-reject'); require('../../modules/esnext.typed-array.group-by'); -require('../../modules/esnext.typed-array.to-reversed'); -require('../../modules/esnext.typed-array.to-sorted'); -require('../../modules/esnext.typed-array.to-spliced'); require('../../modules/esnext.typed-array.unique-by'); -require('../../modules/esnext.typed-array.with'); module.exports = parent; diff --git a/packages/core-js/features/typed-array/to-reversed.js b/packages/core-js/features/typed-array/to-reversed.js index 28cbd6cbeb32..8cd94d6dca28 100644 --- a/packages/core-js/features/typed-array/to-reversed.js +++ b/packages/core-js/features/typed-array/to-reversed.js @@ -1 +1,3 @@ -require('../../modules/esnext.typed-array.to-reversed'); +var parent = require('../../actual/typed-array/to-reversed'); + +module.exports = parent; diff --git a/packages/core-js/features/typed-array/to-sorted.js b/packages/core-js/features/typed-array/to-sorted.js index 644f0fe564e6..f7fb29207b3a 100644 --- a/packages/core-js/features/typed-array/to-sorted.js +++ b/packages/core-js/features/typed-array/to-sorted.js @@ -1,2 +1,3 @@ -require('../../modules/es.typed-array.sort'); -require('../../modules/esnext.typed-array.to-sorted'); +var parent = require('../../actual/typed-array/to-sorted'); + +module.exports = parent; diff --git a/packages/core-js/features/typed-array/to-spliced.js b/packages/core-js/features/typed-array/to-spliced.js index 44ae5c2f6f32..b9407b1931bc 100644 --- a/packages/core-js/features/typed-array/to-spliced.js +++ b/packages/core-js/features/typed-array/to-spliced.js @@ -1 +1,3 @@ -require('../../modules/esnext.typed-array.to-spliced'); +var parent = require('../../actual/typed-array/to-spliced'); + +module.exports = parent; diff --git a/packages/core-js/features/typed-array/with.js b/packages/core-js/features/typed-array/with.js index 7908e59f7e47..a216b67de6d6 100644 --- a/packages/core-js/features/typed-array/with.js +++ b/packages/core-js/features/typed-array/with.js @@ -1 +1,3 @@ -require('../../modules/esnext.typed-array.with'); +var parent = require('../../actual/typed-array/with'); + +module.exports = parent; diff --git a/packages/core-js/modules/es.typed-array.sort.js b/packages/core-js/modules/es.typed-array.sort.js index 05ae6d9edf9e..00ffb5750668 100644 --- a/packages/core-js/modules/es.typed-array.sort.js +++ b/packages/core-js/modules/es.typed-array.sort.js @@ -10,7 +10,6 @@ var IE_OR_EDGE = require('../internals/engine-is-ie-or-edge'); var V8 = require('../internals/engine-v8-version'); var WEBKIT = require('../internals/engine-webkit-version'); -var Array = global.Array; var aTypedArray = ArrayBufferViewCore.aTypedArray; var exportTypedArrayMethod = ArrayBufferViewCore.exportTypedArrayMethod; var Uint16Array = global.Uint16Array; diff --git a/packages/core-js/stage/2.js b/packages/core-js/stage/2.js index f4e9a03ee1c7..1d5fcbd79583 100644 --- a/packages/core-js/stage/2.js +++ b/packages/core-js/stage/2.js @@ -1,6 +1,5 @@ require('../proposals/array-from-async'); require('../proposals/array-is-template-object'); -require('../proposals/change-array-by-copy'); require('../proposals/decorators'); require('../proposals/iterator-helpers'); require('../proposals/map-upsert'); diff --git a/packages/core-js/stage/3.js b/packages/core-js/stage/3.js index a6145a9ec407..9becd5aa7080 100644 --- a/packages/core-js/stage/3.js +++ b/packages/core-js/stage/3.js @@ -1,5 +1,6 @@ require('../proposals/array-find-from-last'); require('../proposals/array-grouping'); +require('../proposals/change-array-by-copy'); var parent = require('./4'); module.exports = parent; diff --git a/tests/commonjs.mjs b/tests/commonjs.mjs index e6b210e550b8..7dbb56a294c4 100644 --- a/tests/commonjs.mjs +++ b/tests/commonjs.mjs @@ -567,10 +567,18 @@ for (PATH of ['core-js-pure', 'core-js']) { ok(load(NS, 'array/find-last-index')([1, 2, 3], it => it % 2) === 2); ok(typeof load(NS, 'array/group-by') == 'function'); ok(typeof load(NS, 'array/group-by-to-map') == 'function'); + ok(load(NS, 'array/with')([1, 2, 3], 1, 4)); + ok(load(NS, 'array/to-reversed')([1, 2, 3])[0] === 3); + ok(load(NS, 'array/to-sorted')([3, 2, 1])[0] === 1); + ok(load(NS, 'array/to-spliced')([3, 2, 1], 1, 1, 4, 5).length === 4); ok(load(NS, 'array/virtual/find-last').call([1, 2, 3], it => it % 2) === 3); ok(load(NS, 'array/virtual/find-last-index').call([1, 2, 3], it => it % 2) === 2); ok(typeof load(NS, 'array/virtual/group-by') == 'function'); ok(typeof load(NS, 'array/virtual/group-by-to-map') == 'function'); + ok(load(NS, 'array/virtual/with').call([1, 2, 3], 1, 4)); + ok(load(NS, 'array/virtual/to-reversed').call([1, 2, 3])[0] === 3); + ok(load(NS, 'array/virtual/to-sorted').call([3, 2, 1])[0] === 1); + ok(load(NS, 'array/virtual/to-spliced').call([3, 2, 1], 1, 1, 4, 5).length === 4); const instanceFindLastIndex = load(NS, 'instance/find-last-index'); ok(typeof instanceFindLastIndex == 'function'); @@ -595,6 +603,30 @@ for (PATH of ['core-js-pure', 'core-js']) { ok(instanceGroupByToMap({}) === undefined); ok(typeof instanceGroupByToMap([]) == 'function'); ok(instanceGroupByToMap([]).call([1, 2, 3], it => it % 2).get(1).length === 2); + + const instanceToReversed = load(NS, 'instance/to-reversed'); + ok(typeof instanceToReversed == 'function'); + ok(instanceToReversed({}) === undefined); + ok(typeof instanceToReversed([]) == 'function'); + ok(instanceToReversed([]).call([1, 2, 3])[0] === 3); + + const instanceToSorted = load(NS, 'instance/to-sorted'); + ok(typeof instanceToSorted == 'function'); + ok(instanceToSorted({}) === undefined); + ok(typeof instanceToSorted([]) == 'function'); + ok(instanceToSorted([]).call([3, 2, 1])[0] === 1); + + const instanceToSpliced = load(NS, 'instance/to-spliced'); + ok(typeof instanceToSpliced == 'function'); + ok(instanceToSpliced({}) === undefined); + ok(typeof instanceToSpliced([]) == 'function'); + ok(instanceToSpliced([]).call([3, 2, 1], 1, 1, 4, 5).length === 4); + + const instanceWith = load(NS, 'instance/with'); + ok(typeof instanceWith == 'function'); + ok(instanceWith({}) === undefined); + ok(typeof instanceWith([]) == 'function'); + ok(instanceWith([]).call([1, 2, 3], 1, 4)[1] === 4); } { @@ -611,17 +643,9 @@ for (PATH of ['core-js-pure', 'core-js']) { load(NS, 'array/last-item'); load(NS, 'array/last-index'); ok(typeof load(NS, 'array/unique-by') == 'function'); - ok(load(NS, 'array/with')([1, 2, 3], 1, 4)); - ok(load(NS, 'array/to-reversed')([1, 2, 3])[0] === 3); - ok(load(NS, 'array/to-sorted')([3, 2, 1])[0] === 1); - ok(load(NS, 'array/to-spliced')([3, 2, 1], 1, 1, 4, 5).length === 4); ok(typeof load(NS, 'array/virtual/filter-out') == 'function'); ok(typeof load(NS, 'array/virtual/filter-reject') == 'function'); ok(typeof load(NS, 'array/virtual/unique-by') == 'function'); - ok(load(NS, 'array/virtual/with').call([1, 2, 3], 1, 4)); - ok(load(NS, 'array/virtual/to-reversed').call([1, 2, 3])[0] === 3); - ok(load(NS, 'array/virtual/to-sorted').call([3, 2, 1])[0] === 1); - ok(load(NS, 'array/virtual/to-spliced').call([3, 2, 1], 1, 1, 4, 5).length === 4); ok(typeof load(NS, 'async-iterator') == 'function'); ok(typeof load(NS, 'async-iterator/as-indexed-pairs') == 'function'); ok(typeof load(NS, 'async-iterator/drop') == 'function'); @@ -764,24 +788,6 @@ for (PATH of ['core-js-pure', 'core-js']) { ok(typeof instanceFilterReject([]) == 'function'); ok(instanceFilterReject([]).call([1, 2, 3], it => it % 2).length === 1); - const instanceToReversed = load(NS, 'instance/to-reversed'); - ok(typeof instanceToReversed == 'function'); - ok(instanceToReversed({}) === undefined); - ok(typeof instanceToReversed([]) == 'function'); - ok(instanceToReversed([]).call([1, 2, 3])[0] === 3); - - const instanceToSorted = load(NS, 'instance/to-sorted'); - ok(typeof instanceToSorted == 'function'); - ok(instanceToSorted({}) === undefined); - ok(typeof instanceToSorted([]) == 'function'); - ok(instanceToSorted([]).call([3, 2, 1])[0] === 1); - - const instanceToSpliced = load(NS, 'instance/to-spliced'); - ok(typeof instanceToSpliced == 'function'); - ok(instanceToSpliced({}) === undefined); - ok(typeof instanceToSpliced([]) == 'function'); - ok(instanceToSpliced([]).call([3, 2, 1], 1, 1, 4, 5).length === 4); - const instanceUniqueBy = load(NS, 'instance/unique-by'); ok(typeof instanceUniqueBy == 'function'); ok(instanceUniqueBy({}) === undefined); @@ -793,12 +799,6 @@ for (PATH of ['core-js-pure', 'core-js']) { ok(instanceUnThis({}) === undefined); ok(typeof instanceUnThis([].slice) == 'function'); ok(instanceUnThis([].slice).call([].slice)([1, 2, 3], 1)[0] === 2); - - const instanceWith = load(NS, 'instance/with'); - ok(typeof instanceWith == 'function'); - ok(instanceWith({}) === undefined); - ok(typeof instanceWith([]) == 'function'); - ok(instanceWith([]).call([1, 2, 3], 1, 4)[1] === 4); } load('proposals/accessible-object-hasownproperty'); @@ -941,6 +941,10 @@ for (const NS of ['es', 'stable', 'actual', 'features']) { for (const NS of ['actual', 'features']) { load(NS, 'typed-array/find-last'); load(NS, 'typed-array/find-last-index'); + load(NS, 'typed-array/to-reversed'); + load(NS, 'typed-array/to-sorted'); + load(NS, 'typed-array/to-spliced'); + load(NS, 'typed-array/with'); } { @@ -951,10 +955,6 @@ for (const NS of ['actual', 'features']) { load(NS, 'typed-array/filter-reject'); load(NS, 'typed-array/group-by'); load(NS, 'typed-array/unique-by'); - load(NS, 'typed-array/with'); - load(NS, 'typed-array/to-reversed'); - load(NS, 'typed-array/to-sorted'); - load(NS, 'typed-array/to-spliced'); } load('modules/esnext.string.at-alternative');