Skip to content

Commit

Permalink
move new Set methods to stable ES
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Apr 8, 2024
1 parent 5e703c4 commit 559081f
Show file tree
Hide file tree
Showing 57 changed files with 337 additions and 207 deletions.
78 changes: 41 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ structuredClone(new Set([1, 2, 3])); // => new Set([1, 2, 3])
- [`Symbol.prototype.description`](#symbolprototypedescription)
- [Well-formed `JSON.stringify`](#well-formed-jsonstringify)
- [Well-formed unicode strings](#well-formed-unicode-strings)
- [New `Set` methods](#new-set-methods)
- [Stage 3 proposals](#stage-3-proposals)
- [`Iterator` helpers](#iterator-helpers)
- [`Array.fromAsync`](#arrayfromasync)
- [New `Set` methods](#new-set-methods)
- [`JSON.parse` source text access](#jsonparse-source-text-access)
- [`Float16` methods](#float16-methods)
- [Explicit resource management](#explicit-resource-management)
Expand Down Expand Up @@ -1499,7 +1499,7 @@ map.get(1); // => [1, 3, 5]
map.get(0); // => [2, 4]
```
#### Set[⬆](#index)
Module [`es.set`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.set.js).
Modules [`es.set`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.set.js), [`es.set.difference.v2`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.set.difference.v2.js), [`es.set.intersection.v2`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.set.intersection.v2.js), [`es.set.is-disjoint-from.v2`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.set.is-disjoint-from.v2.js), [`es.set.is-subset-of.v2`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.set.is-subset-of.v2.js), [`es.set.is-superset-of.v2`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.set.is-superset-of.v2.js), [`es.set.symmetric-difference.v2`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.set.symmetric-difference.v2.js), [`es.set.union.v2`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.set.union.v2.js)
```js
class Set {
constructor(iterable?: Iterable<value>): Set;
Expand All @@ -1511,15 +1511,29 @@ class Set {
values(): Iterator<value>;
keys(): Iterator<value>;
entries(): Iterator<[value, value]>;
difference(other: SetLike<mixed>): Set;
intersection(other: SetLike<mixed>): Set;
isDisjointFrom(other: SetLike<mixed>): boolean;
isSubsetOf(other: SetLike<mixed>): boolean;
isSupersetOf(other: SetLike<mixed>): boolean;
symmetricDifference(other: SetLike<mixed>): Set;
union(other: SetLike<mixed>): Set;
@@iterator(): Iterator<value>;
readonly attribute size: number;
}
```
[*CommonJS entry points:*](#commonjs-api)
```
core-js(-pure)/es|stable|actual|full/set
core-js(-pure)/es|stable|actual|full/set/difference
core-js(-pure)/es|stable|actual|full/set/intersection
core-js(-pure)/es|stable|actual|full/set/is-disjoint-from
core-js(-pure)/es|stable|actual|full/set/is-subset-of
core-js(-pure)/es|stable|actual|full/set/is-superset-of
core-js(-pure)/es|stable|actual|full/set/symmetric-difference
core-js(-pure)/es|stable|actual|full/set/union
```
[*Examples*](https://goo.gl/bmhLwg):
[*Examples*](https://tinyurl.com/2dy5t9ey):
```js
let set = new Set(['a', 'b', 'a', 'c']);
set.add('d').add('b').add('e');
Expand All @@ -1542,6 +1556,14 @@ for (let [key, value] of set.entries()) {
console.log(key); // => 1, 2, 3
console.log(value); // => 1, 2, 3
}

new Set([1, 2, 3]).union(new Set([3, 4, 5])); // => Set {1, 2, 3, 4, 5}
new Set([1, 2, 3]).intersection(new Set([3, 4, 5])); // => Set {3}
new Set([1, 2, 3]).difference(new Set([3, 4, 5])); // => Set {1, 2}
new Set([1, 2, 3]).symmetricDifference(new Set([3, 4, 5])); // => Set {1, 2, 4, 5}
new Set([1, 2, 3]).isDisjointFrom(new Set([4, 5, 6])); // => true
new Set([1, 2, 3]).isSubsetOf(new Set([5, 4, 3, 2, 1])); // => true
new Set([5, 4, 3, 2, 1]).isSupersetOf(new Set([1, 2, 3])); // => true
```
#### WeakMap[⬆](#index)
Module [`es.weak-map`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.weak-map.js).
Expand Down Expand Up @@ -2236,6 +2258,22 @@ class String {
```js
core-js/proposals/well-formed-unicode-strings
```
##### [New `Set` methods](https://github.com/tc39/proposal-set-methods)[⬆](#index)
```js
class Set {
difference(other: SetLike<mixed>): Set;
intersection(other: SetLike<mixed>): Set;
isDisjointFrom(other: SetLike<mixed>): boolean;
isSubsetOf(other: SetLike<mixed>): boolean;
isSupersetOf(other: SetLike<mixed>): boolean;
symmetricDifference(other: SetLike<mixed>): Set;
union(other: SetLike<mixed>): Set;
}
```
[*CommonJS entry points:*](#commonjs-api)
```js
core-js/proposals/set-methods-v2
```

#### Stage 3 proposals[⬆](#index)

Expand Down Expand Up @@ -2314,40 +2352,6 @@ core-js(-pure)/actual|full/array/from-async
```js
await Array.fromAsync((async function * (){ yield * [1, 2, 3] })(), i => i * i); // => [1, 4, 9]
```
##### [New `Set` methods](https://github.com/tc39/proposal-set-methods)[⬆](#index)
Modules [`esnext.set.difference.v2`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.set.difference.v2.js), [`esnext.set.intersection.v2`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.set.intersection.v2.js), [`esnext.set.is-disjoint-from.v2`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.set.is-disjoint-from.v2.js), [`esnext.set.is-subset-of.v2`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.set.is-subset-of.v2.js), [`esnext.set.is-superset-of.v2`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.set.is-superset-of.v2.js), [`esnext.set.symmetric-difference.v2`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.set.symmetric-difference.v2.js), [`esnext.set.union.v2`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.set.union.v2.js)
```js
class Set {
difference(other: SetLike<mixed>): Set;
intersection(other: SetLike<mixed>): Set;
isDisjointFrom(other: SetLike<mixed>): boolean;
isSubsetOf(other: SetLike<mixed>): boolean;
isSupersetOf(other: SetLike<mixed>): boolean;
symmetricDifference(other: SetLike<mixed>): Set;
union(other: SetLike<mixed>): Set;
}
```
[*CommonJS entry points:*](#commonjs-api)
```js
core-js/proposals/set-methods-v2
core-js(-pure)/actual|full/set/difference
core-js(-pure)/actual|full/set/intersection
core-js(-pure)/actual|full/set/is-disjoint-from
core-js(-pure)/actual|full/set/is-subset-of
core-js(-pure)/actual|full/set/is-superset-of
core-js(-pure)/actual|full/set/symmetric-difference
core-js(-pure)/actual|full/set/union
```
[*Examples*](https://tinyurl.com/2henaoac):
```js
new Set([1, 2, 3]).union(new Set([3, 4, 5])); // => Set {1, 2, 3, 4, 5}
new Set([1, 2, 3]).intersection(new Set([3, 4, 5])); // => Set {3}
new Set([1, 2, 3]).difference(new Set([3, 4, 5])); // => Set {1, 2}
new Set([1, 2, 3]).symmetricDifference(new Set([3, 4, 5])); // => Set {1, 2, 4, 5}
new Set([1, 2, 3]).isDisjointFrom(new Set([4, 5, 6])); // => true
new Set([1, 2, 3]).isSubsetOf(new Set([5, 4, 3, 2, 1])); // => true
new Set([5, 4, 3, 2, 1]).isSupersetOf(new Set([1, 2, 3])); // => true
```

##### [`JSON.parse` source text access](https://github.com/tc39/proposal-json-parse-with-source)[⬆](#index)
Modules [`esnext.json.is-raw-json`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.json.is-raw-json.js), [`esnext.json.parse`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.json.parse.js), [`esnext.json.raw-json`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.json.raw-json.js).
Expand Down
147 changes: 84 additions & 63 deletions packages/core-js-compat/src/data.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1348,6 +1348,69 @@ export const data = {
rhino: '1.7.13',
safari: '10.0',
},
'es.set.difference.v2': {
bun: '1.1.1',
// v8 ~ Chrome 122 do not properly work with set-like objects
// https://bugs.chromium.org/p/v8/issues/detail?id=14559
chrome: '123',
// safari do not properly work with set-like objects
// https://bugs.webkit.org/show_bug.cgi?id=267494
// safari: '17.0',
},
'es.set.intersection.v2': {
bun: '1.1.1',
// v8 ~ Chrome 122 do not properly work with set-like objects
// https://bugs.chromium.org/p/v8/issues/detail?id=14559
chrome: '123',
// safari do not properly work with set-like objects
// https://bugs.webkit.org/show_bug.cgi?id=267494
// safari: '17.0',
},
'es.set.is-disjoint-from.v2': {
bun: '1.1.1',
// v8 ~ Chrome 122 do not properly work with set-like objects
// https://bugs.chromium.org/p/v8/issues/detail?id=14559
chrome: '123',
// safari do not properly work with set-like objects
// https://bugs.webkit.org/show_bug.cgi?id=267494
// safari: '17.0',
},
'es.set.is-subset-of.v2': {
bun: '1.1.1',
// v8 ~ Chrome 122 do not properly work with set-like objects
// https://bugs.chromium.org/p/v8/issues/detail?id=14559
chrome: '123',
// safari do not properly work with set-like objects
// https://bugs.webkit.org/show_bug.cgi?id=267494
// safari: '17.0',
},
'es.set.is-superset-of.v2': {
bun: '1.1.1',
// v8 ~ Chrome 122 do not properly work with set-like objects
// https://bugs.chromium.org/p/v8/issues/detail?id=14559
chrome: '123',
// safari do not properly work with set-like objects
// https://bugs.webkit.org/show_bug.cgi?id=267494
// safari: '17.0',
},
'es.set.symmetric-difference.v2': {
bun: '1.1.1',
// v8 ~ Chrome 122 do not properly work with set-like objects
// https://bugs.chromium.org/p/v8/issues/detail?id=14559
chrome: '123',
// safari do not properly work with set-like objects
// https://bugs.webkit.org/show_bug.cgi?id=267494
// safari: '17.0',
},
'es.set.union.v2': {
bun: '1.1.1',
// v8 ~ Chrome 122 do not properly work with set-like objects
// https://bugs.chromium.org/p/v8/issues/detail?id=14559
chrome: '123',
// safari do not properly work with set-like objects
// https://bugs.webkit.org/show_bug.cgi?id=267494
// safari: '17.0',
},
'es.string.at-alternative': {
chrome: '92',
firefox: '90',
Expand Down Expand Up @@ -2261,15 +2324,8 @@ export const data = {
},
'esnext.set.delete-all': {
},
'esnext.set.difference.v2': {
// v8 ~ Chrome 122 do not properly work with set-like objects
// https://bugs.chromium.org/p/v8/issues/detail?id=14559
chrome: '123',
bun: '1.1.1',
// safari do not properly work with set-like objects
// https://bugs.webkit.org/show_bug.cgi?id=267494
// safari: '17.0',
},
// TODO: Remove from `core-js@4`
'esnext.set.difference.v2': null,
// TODO: Remove from `core-js@4`
'esnext.set.difference': {
},
Expand All @@ -2281,51 +2337,23 @@ export const data = {
},
'esnext.set.from': {
},
'esnext.set.intersection.v2': {
// v8 ~ Chrome 122 do not properly work with set-like objects
// https://bugs.chromium.org/p/v8/issues/detail?id=14559
chrome: '123',
bun: '1.1.1',
// safari do not properly work with set-like objects
// https://bugs.webkit.org/show_bug.cgi?id=267494
// safari: '17.0',
},
// TODO: Remove from `core-js@4`
'esnext.set.intersection.v2': null,
// TODO: Remove from `core-js@4`
'esnext.set.intersection': {
},
'esnext.set.is-disjoint-from.v2': {
// v8 ~ Chrome 122 do not properly work with set-like objects
// https://bugs.chromium.org/p/v8/issues/detail?id=14559
chrome: '123',
bun: '1.1.1',
// safari do not properly work with set-like objects
// https://bugs.webkit.org/show_bug.cgi?id=267494
// safari: '17.0',
},
// TODO: Remove from `core-js@4`
'esnext.set.is-disjoint-from.v2': null,
// TODO: Remove from `core-js@4`
'esnext.set.is-disjoint-from': {
},
'esnext.set.is-subset-of.v2': {
// v8 ~ Chrome 122 do not properly work with set-like objects
// https://bugs.chromium.org/p/v8/issues/detail?id=14559
chrome: '123',
bun: '1.1.1',
// safari do not properly work with set-like objects
// https://bugs.webkit.org/show_bug.cgi?id=267494
// safari: '17.0',
},
// TODO: Remove from `core-js@4`
'esnext.set.is-subset-of.v2': null,
// TODO: Remove from `core-js@4`
'esnext.set.is-subset-of': {
},
'esnext.set.is-superset-of.v2': {
// v8 ~ Chrome 122 do not properly work with set-like objects
// https://bugs.chromium.org/p/v8/issues/detail?id=14559
chrome: '123',
bun: '1.1.1',
// safari do not properly work with set-like objects
// https://bugs.webkit.org/show_bug.cgi?id=267494
// safari: '17.0',
},
// TODO: Remove from `core-js@4`
'esnext.set.is-superset-of.v2': null,
// TODO: Remove from `core-js@4`
'esnext.set.is-superset-of': {
},
Expand All @@ -2339,27 +2367,13 @@ export const data = {
},
'esnext.set.some': {
},
'esnext.set.symmetric-difference.v2': {
// v8 ~ Chrome 122 do not properly work with set-like objects
// https://bugs.chromium.org/p/v8/issues/detail?id=14559
chrome: '123',
bun: '1.1.1',
// safari do not properly work with set-like objects
// https://bugs.webkit.org/show_bug.cgi?id=267494
// safari: '17.0',
},
// TODO: Remove from `core-js@4`
'esnext.set.symmetric-difference.v2': null,
// TODO: Remove from `core-js@4`
'esnext.set.symmetric-difference': {
},
'esnext.set.union.v2': {
// v8 ~ Chrome 122 do not properly work with set-like objects
// https://bugs.chromium.org/p/v8/issues/detail?id=14559
chrome: '123',
bun: '1.1.1',
// safari do not properly work with set-like objects
// https://bugs.webkit.org/show_bug.cgi?id=267494
// safari: '17.0',
},
// TODO: Remove from `core-js@4`
'esnext.set.union.v2': null,
// TODO: Remove from `core-js@4`
'esnext.set.union': {
},
Expand Down Expand Up @@ -2727,6 +2741,13 @@ export const renamed = new Map([
['esnext.promise.all-settled', 'es.promise.all-settled'],
['esnext.promise.any', 'es.promise.any'],
['esnext.promise.with-resolvers', 'es.promise.with-resolvers'],
['esnext.set.difference.v2', 'es.set.difference.v2'],
['esnext.set.intersection.v2', 'es.set.intersection.v2'],
['esnext.set.is-disjoint-from.v2', 'es.set.is-disjoint-from.v2'],
['esnext.set.is-subset-of.v2', 'es.set.is-subset-of.v2'],
['esnext.set.is-superset-of.v2', 'es.set.is-superset-of.v2'],
['esnext.set.symmetric-difference.v2', 'es.set.symmetric-difference.v2'],
['esnext.set.union.v2', 'es.set.union.v2'],
['esnext.string.is-well-formed', 'es.string.is-well-formed'],
['esnext.string.match-all', 'es.string.match-all'],
['esnext.string.replace-all', 'es.string.replace-all'],
Expand Down
7 changes: 7 additions & 0 deletions packages/core-js-compat/src/modules-by-versions.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,13 @@ export default {
'es.array-buffer.transfer-to-fixed-length',
],
3.37: [
'es.set.difference.v2',
'es.set.intersection.v2',
'es.set.is-disjoint-from.v2',
'es.set.is-subset-of.v2',
'es.set.is-superset-of.v2',
'es.set.symmetric-difference.v2',
'es.set.union.v2',
'web.url.parse',
],
};
5 changes: 2 additions & 3 deletions packages/core-js/actual/set/difference.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';
require('../../modules/es.set');
var parent = require('../../stable/set/difference');
require('../../modules/esnext.set.difference.v2');
var entryUnbind = require('../../internals/entry-unbind');

module.exports = entryUnbind('Set', 'difference');
module.exports = parent;
5 changes: 2 additions & 3 deletions packages/core-js/actual/set/intersection.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';
require('../../modules/es.set');
var parent = require('../../stable/set/intersection');
require('../../modules/esnext.set.intersection.v2');
var entryUnbind = require('../../internals/entry-unbind');

module.exports = entryUnbind('Set', 'intersection');
module.exports = parent;
5 changes: 2 additions & 3 deletions packages/core-js/actual/set/is-disjoint-from.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';
require('../../modules/es.set');
var parent = require('../../stable/set/is-disjoint-from');
require('../../modules/esnext.set.is-disjoint-from.v2');
var entryUnbind = require('../../internals/entry-unbind');

module.exports = entryUnbind('Set', 'isDisjointFrom');
module.exports = parent;
5 changes: 2 additions & 3 deletions packages/core-js/actual/set/is-subset-of.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';
require('../../modules/es.set');
var parent = require('../../stable/set/is-subset-of');
require('../../modules/esnext.set.is-subset-of.v2');
var entryUnbind = require('../../internals/entry-unbind');

module.exports = entryUnbind('Set', 'isSubsetOf');
module.exports = parent;
5 changes: 2 additions & 3 deletions packages/core-js/actual/set/is-superset-of.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';
require('../../modules/es.set');
var parent = require('../../stable/set/is-superset-of');
require('../../modules/esnext.set.is-superset-of.v2');
var entryUnbind = require('../../internals/entry-unbind');

module.exports = entryUnbind('Set', 'isSupersetOf');
module.exports = parent;
5 changes: 2 additions & 3 deletions packages/core-js/actual/set/symmetric-difference.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';
require('../../modules/es.set');
var parent = require('../../stable/set/symmetric-difference');
require('../../modules/esnext.set.symmetric-difference.v2');
var entryUnbind = require('../../internals/entry-unbind');

module.exports = entryUnbind('Set', 'symmetricDifference');
module.exports = parent;
Loading

0 comments on commit 559081f

Please sign in to comment.