Skip to content

Commit

Permalink
move "Change Array by copy" proposal to stage 3
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Mar 30, 2022
1 parent 81d06dd commit a9955c5
Show file tree
Hide file tree
Showing 42 changed files with 205 additions and 152 deletions.
1 change: 1 addition & 0 deletions 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)
Expand Down
96 changes: 48 additions & 48 deletions README.md
Expand Up @@ -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)
Expand Down Expand Up @@ -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<mixed>;
toSpliced(start?: number, deleteCount?: number, ...items: Array<mixed>): Array<mixed>;
toSorted(comparefn?: (a: any, b: any) => number): Array<mixed>;
with(index: includes, value: any): Array<mixed>;
}

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)
Expand Down Expand Up @@ -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<mixed>;
toSpliced(start?: number, deleteCount?: number, ...items: Array<mixed>): Array<mixed>;
toSorted(comparefn?: (a: any, b: any) => number): Array<mixed>;
with(index: includes, value: any): Array<mixed>;
}

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
Expand Down
4 changes: 4 additions & 0 deletions packages/core-js/actual/array/index.js
Expand Up @@ -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;
4 changes: 4 additions & 0 deletions 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');
5 changes: 5 additions & 0 deletions 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');
4 changes: 4 additions & 0 deletions 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');
4 changes: 4 additions & 0 deletions packages/core-js/actual/array/virtual/index.js
Expand Up @@ -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;
4 changes: 4 additions & 0 deletions 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;
5 changes: 5 additions & 0 deletions 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;
4 changes: 4 additions & 0 deletions 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;
4 changes: 4 additions & 0 deletions 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'];
4 changes: 4 additions & 0 deletions 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');
9 changes: 9 additions & 0 deletions 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;
};
9 changes: 9 additions & 0 deletions 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;
};
9 changes: 9 additions & 0 deletions 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;
};
9 changes: 9 additions & 0 deletions 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;
};
4 changes: 4 additions & 0 deletions 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;
4 changes: 4 additions & 0 deletions 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;
1 change: 1 addition & 0 deletions packages/core-js/actual/typed-array/to-reversed.js
@@ -0,0 +1 @@
require('../../modules/esnext.typed-array.to-reversed');
2 changes: 2 additions & 0 deletions 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');
1 change: 1 addition & 0 deletions packages/core-js/actual/typed-array/to-spliced.js
@@ -0,0 +1 @@
require('../../modules/esnext.typed-array.to-spliced');
1 change: 1 addition & 0 deletions packages/core-js/actual/typed-array/with.js
@@ -0,0 +1 @@
require('../../modules/esnext.typed-array.with');
4 changes: 0 additions & 4 deletions packages/core-js/features/array/index.js
Expand Up @@ -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;
4 changes: 0 additions & 4 deletions packages/core-js/features/array/virtual/index.js
Expand Up @@ -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;
5 changes: 2 additions & 3 deletions 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;
6 changes: 2 additions & 4 deletions 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;
5 changes: 2 additions & 3 deletions 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;
5 changes: 2 additions & 3 deletions 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;
10 changes: 2 additions & 8 deletions 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;
10 changes: 2 additions & 8 deletions 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;
10 changes: 2 additions & 8 deletions 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;
10 changes: 2 additions & 8 deletions 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;
4 changes: 0 additions & 4 deletions packages/core-js/features/typed-array/index.js
Expand Up @@ -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;
4 changes: 0 additions & 4 deletions packages/core-js/features/typed-array/methods.js
Expand Up @@ -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;
4 changes: 3 additions & 1 deletion 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;
5 changes: 3 additions & 2 deletions 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;
4 changes: 3 additions & 1 deletion 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;

0 comments on commit a9955c5

Please sign in to comment.