Skip to content

Commit e118594

Browse files
committed
move Map upsert to stage 3
1 parent 00c7bf9 commit e118594

24 files changed

Lines changed: 96 additions & 67 deletions

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,16 @@
2121
- `Iterator.concat`
2222
- Moved to stage 3, [July 2025 TC39 meeting](https://github.com/tc39/proposals/commit/3eebab0f8594673dd08bc709d68c011016074c2e)
2323
- Added `/actual/` namespace entries, unconditional forced replacement changed to feature detection
24+
- [`Map` upsert proposal](https://github.com/tc39/proposal-upsert):
25+
- Built-ins:
26+
- `Map.prototype.getOrInsert`
27+
- `Map.prototype.getOrInsertComputed`
28+
- `WeakMap.prototype.getOrInsert`
29+
- `WeakMap.prototype.getOrInsertComputed`
30+
- Moved to stage 3, July 2025 TC39 meeting
31+
- Added `/actual/` namespace entries, unconditional forced replacement changed to feature detection
2432
- Added missing dependencies to some entries of static `Iterator` methods
33+
- Fixed [Joint Iteration proposal](https://github.com/tc39/proposal-joint-iteration) in `/stage/` entries
2534
- Compat data improvements:
2635
- [`Uint8Array` to / from base64 and hex proposal](https://github.com/tc39/proposal-arraybuffer-base64) features marked as [supported from V8 ~ Chromium 140](https://issues.chromium.org/issues/42204568#comment37)
2736
- `%TypedArray%.prototype.with` marked as fixed in Safari 26.0

README.md

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,11 @@ structuredClone(new Set([1, 2, 3])); // => new Set([1, 2, 3])
168168
- [`Math.sumPrecise`](#mathsumprecise)
169169
- [Stage 3 proposals](#stage-3-proposals)
170170
- [`Iterator` sequencing](#iterator-sequencing)
171+
- [`Map` upsert](#map-upsert)
171172
- [`JSON.parse` source text access](#jsonparse-source-text-access)
172173
- [`Symbol.metadata` for decorators metadata proposal](#symbolmetadata-for-decorators-metadata-proposal)
173174
- [Stage 2.7 proposals](#stage-27-proposals)
174175
- [Joint iteration](#joint-iteration)
175-
- [`Map` upsert](#map-upsert)
176176
- [Stage 2 proposals](#stage-2-proposals)
177177
- [`AsyncIterator` helpers](#asynciterator-helpers)
178178
- [`Iterator.range`](#iteratorrange)
@@ -2712,6 +2712,42 @@ Iterator.concat([0, 1].values(), [2, 3], function * () {
27122712
}()).toArray(); // => [0, 1, 2, 3, 4, 5]
27132713
```
27142714

2715+
##### [`Map` upsert](https://github.com/thumbsupep/proposal-upsert)[](#index)
2716+
Modules [`esnext.map.get-or-insert`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.map.get-or-insert.js), [`esnext.map.get-or-insert-computed`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.map.get-or-insert-computed.js), [`esnext.weak-map.get-or-insert`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.weak-map.get-or-insert.js) and [`esnext.weak-map.get-or-insert-computed`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.weak-map.get-or-insert-computed.js)
2717+
```ts
2718+
class Map {
2719+
getOrInsert(key: any, value: any): any;
2720+
getOrInsertComputed(key: any, (key: any) => value: any): any;
2721+
}
2722+
2723+
class WeakMap {
2724+
getOrInsert(key: any, value: any): any;
2725+
getOrInsertComputed(key: any, (key: any) => value: any): any;
2726+
}
2727+
```
2728+
[*CommonJS entry points:*](#commonjs-api)
2729+
```
2730+
core-js/proposals/map-upsert-v4
2731+
core-js(-pure)/actual|full/map/get-or-insert
2732+
core-js(-pure)/actual|full/map/get-or-insert-computed
2733+
core-js(-pure)/actual|full/weak-map/get-or-insert
2734+
core-js(-pure)/actual|full/weak-map/get-or-insert-computed
2735+
```
2736+
[*Examples*](https://tinyurl.com/2a54u5ux):
2737+
```js
2738+
const map = new Map([['a', 1]]);
2739+
2740+
map.getOrInsert('a', 2); // => 1
2741+
2742+
map.getOrInsert('b', 3); // => 3
2743+
2744+
map.getOrInsertComputed('a', key => key); // => 1
2745+
2746+
map.getOrInsertComputed('c', key => key); // => 'c'
2747+
2748+
console.log(map); // => Map { 'a': 1, 'b': 3, 'c': 'c' }
2749+
```
2750+
27152751
##### [`JSON.parse` source text access](https://github.com/tc39/proposal-json-parse-with-source)[](#index)
27162752
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).
27172753
```ts
@@ -2827,42 +2863,6 @@ Iterator.zipKeyed({
28272863
*/
28282864
```
28292865

2830-
##### [`Map` upsert](https://github.com/thumbsupep/proposal-upsert)[](#index)
2831-
Modules [`esnext.map.get-or-insert`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.map.get-or-insert.js), [`esnext.map.get-or-insert-computed`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.map.get-or-insert-computed.js), [`esnext.weak-map.get-or-insert`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.weak-map.get-or-insert.js) and [`esnext.weak-map.get-or-insert-computed`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.weak-map.get-or-insert-computed.js)
2832-
```ts
2833-
class Map {
2834-
getOrInsert(key: any, value: any): any;
2835-
getOrInsertComputed(key: any, (key: any) => value: any): any;
2836-
}
2837-
2838-
class WeakMap {
2839-
getOrInsert(key: any, value: any): any;
2840-
getOrInsertComputed(key: any, (key: any) => value: any): any;
2841-
}
2842-
```
2843-
[*CommonJS entry points:*](#commonjs-api)
2844-
```
2845-
core-js/proposals/map-upsert-v4
2846-
core-js(-pure)/full/map/get-or-insert
2847-
core-js(-pure)/full/map/get-or-insert-computed
2848-
core-js(-pure)/full/weak-map/get-or-insert
2849-
core-js(-pure)/full/weak-map/get-or-insert-computed
2850-
```
2851-
[*Examples*](https://tinyurl.com/2a54u5ux):
2852-
```js
2853-
const map = new Map([['a', 1]]);
2854-
2855-
map.getOrInsert('a', 2); // => 1
2856-
2857-
map.getOrInsert('b', 3); // => 3
2858-
2859-
map.getOrInsertComputed('a', key => key); // => 1
2860-
2861-
map.getOrInsertComputed('c', key => key); // => 'c'
2862-
2863-
console.log(map); // => Map { 'a': 1, 'b': 3, 'c': 'c' }
2864-
```
2865-
28662866
#### Stage 2 proposals[](#index)
28672867
[*CommonJS entry points:*](#commonjs-api)
28682868
```
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
'use strict';
2+
require('../../modules/es.map');
3+
require('../../modules/esnext.map.get-or-insert-computed');
4+
var entryUnbind = require('../../internals/entry-unbind');
5+
6+
module.exports = entryUnbind('Map', 'getOrInsertComputed');
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
'use strict';
2+
require('../../modules/es.map');
3+
require('../../modules/esnext.map.get-or-insert');
4+
var entryUnbind = require('../../internals/entry-unbind');
5+
6+
module.exports = entryUnbind('Map', 'getOrInsert');
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22
var parent = require('../../stable/map');
3+
require('../../modules/esnext.map.get-or-insert');
4+
require('../../modules/esnext.map.get-or-insert-computed');
35
require('../../modules/esnext.map.group-by');
46

57
module.exports = parent;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
'use strict';
2+
require('../../modules/es.weak-map');
3+
require('../../modules/esnext.weak-map.get-or-insert-computed');
4+
var entryUnbind = require('../../internals/entry-unbind');
5+
6+
module.exports = entryUnbind('WeakMap', 'getOrInsertComputed');
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
'use strict';
2+
require('../../modules/es.weak-map');
3+
require('../../modules/esnext.weak-map.get-or-insert');
4+
var entryUnbind = require('../../internals/entry-unbind');
5+
6+
module.exports = entryUnbind('WeakMap', 'getOrInsert');
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
'use strict';
22
var parent = require('../../stable/weak-map');
3+
require('../../modules/esnext.weak-map.get-or-insert');
4+
require('../../modules/esnext.weak-map.get-or-insert-computed');
35

46
module.exports = parent;
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
'use strict';
2-
require('../../modules/es.map');
3-
require('../../modules/esnext.map.get-or-insert-computed');
4-
var entryUnbind = require('../../internals/entry-unbind');
2+
var parent = require('../../actual/map/get-or-insert-computed');
53

6-
module.exports = entryUnbind('Map', 'getOrInsertComputed');
4+
module.exports = parent;
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
'use strict';
2-
require('../../modules/es.map');
3-
require('../../modules/esnext.map.get-or-insert');
4-
var entryUnbind = require('../../internals/entry-unbind');
2+
var parent = require('../../actual/map/get-or-insert');
53

6-
module.exports = entryUnbind('Map', 'getOrInsert');
4+
module.exports = parent;

0 commit comments

Comments
 (0)