tc39 / proposal-upsert

ECMAScript Proposal, specs, and reference implementation for Map.prototype.upsert
https://tc39.es/proposal-upsert/
MIT License
202 stars 14 forks source link

The spec draft text of all methods looks incorrect #62

Closed zloirock closed 4 weeks ago

zloirock commented 4 weeks ago

Image

Since steps 3.b and 3.c in the loop and they work with existent entry, in case the first map entry key is not something that we search, the value of this entry will be replaced to passed.

Something like

let map = new Map([['a', 1]]);
// map.getOrInsert('b', 2):
(() => {
  for (let [key, value] of map) {
    if (key === 'b') return value;
    map.set(key, 2);
    return 2;
  }
})();
console.log(map); // => Map { 'a': 2 }
dminor commented 4 weeks ago

Yes, that was my mistake. We have https://github.com/tc39/proposal-upsert/pull/61 open to fix this up, if you have some time, please have a quick look and see if this addresses your concerns.

zloirock commented 4 weeks ago

Sorry, I missed this PR. It seems it's fixed here.