Skip to content

Commit e018d8c

Browse files
Add proposal-upsert methods to lib.esnext.collection (#62612)
Co-authored-by: Jake Bailey <5341706+jakebailey@users.noreply.github.com>
1 parent 0208948 commit e018d8c

File tree

103 files changed

+1836
-835
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+1836
-835
lines changed

src/compiler/commandLineParser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,12 @@ const libEntries: [string, string][] = [
245245
["esnext.object", "lib.es2024.object.d.ts"],
246246
["esnext.regexp", "lib.es2024.regexp.d.ts"],
247247
["esnext.string", "lib.es2024.string.d.ts"],
248-
["esnext.collection", "lib.es2025.collection.d.ts"],
249248
["esnext.float16", "lib.es2025.float16.d.ts"],
250249
["esnext.iterator", "lib.es2025.iterator.d.ts"],
251250
["esnext.promise", "lib.es2025.promise.d.ts"],
252251
// ESNext By-feature options
253252
["esnext.array", "lib.esnext.array.d.ts"],
253+
["esnext.collection", "lib.esnext.collection.d.ts"],
254254
["esnext.decorators", "lib.esnext.decorators.d.ts"],
255255
["esnext.disposable", "lib.esnext.disposable.d.ts"],
256256
["esnext.error", "lib.esnext.error.d.ts"],

src/compiler/utilities.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,6 +1580,10 @@ export const getScriptTargetFeatures: () => ScriptTargetFeatures = /* @__PURE__
15801580
"keys",
15811581
"values",
15821582
],
1583+
esnext: [
1584+
"getOrInsert",
1585+
"getOrInsertComputed",
1586+
],
15831587
})),
15841588
MapConstructor: new Map(Object.entries({
15851589
es2024: [
@@ -1637,6 +1641,10 @@ export const getScriptTargetFeatures: () => ScriptTargetFeatures = /* @__PURE__
16371641
"keys",
16381642
"values",
16391643
],
1644+
esnext: [
1645+
"getOrInsert",
1646+
"getOrInsertComputed",
1647+
],
16401648
})),
16411649
WeakSet: new Map(Object.entries({
16421650
es2015: [

src/lib/esnext.collection.d.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/// <reference lib="es2025.collection" />
2+
3+
interface Map<K, V> {
4+
/**
5+
* Returns a specified element from the Map object.
6+
* If no element is associated with the specified key, a new element with the value `defaultValue` will be inserted into the Map and returned.
7+
* @returns The element associated with the specified key, which will be `defaultValue` if no element previously existed.
8+
*/
9+
getOrInsert(key: K, defaultValue: V): V;
10+
/**
11+
* Returns a specified element from the Map object.
12+
* If no element is associated with the specified key, the result of passing the specified key to the `callback` function will be inserted into the Map and returned.
13+
* @returns The element associated with the specific key, which will be the newly computed value if no element previously existed.
14+
*/
15+
getOrInsertComputed(key: K, callback: (key: K) => V): V;
16+
}
17+
18+
interface WeakMap<K extends WeakKey, V> {
19+
/**
20+
* Returns a specified element from the WeakMap object.
21+
* If no element is associated with the specified key, a new element with the value `defaultValue` will be inserted into the WeakMap and returned.
22+
* @returns The element associated with the specified key, which will be `defaultValue` if no element previously existed.
23+
*/
24+
getOrInsert(key: K, defaultValue: V): V;
25+
/**
26+
* Returns a specified element from the WeakMap object.
27+
* If no element is associated with the specified key, the result of passing the specified key to the `callback` function will be inserted into the WeakMap and returned.
28+
* @returns The element associated with the specific key, which will be the newly computed value if no element previously existed.
29+
*/
30+
getOrInsertComputed(key: K, callback: (key: K) => V): V;
31+
}

src/lib/esnext.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/// <reference lib="es2025" />
22
/// <reference lib="esnext.intl" />
3+
/// <reference lib="esnext.collection" />
34
/// <reference lib="esnext.decorators" />
45
/// <reference lib="esnext.disposable" />
56
/// <reference lib="esnext.array" />

src/lib/libs.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
"es2025.promise",
8888
"es2025.regexp",
8989
"esnext.array",
90+
"esnext.collection",
9091
"esnext.decorators",
9192
"esnext.disposable",
9293
"esnext.error",

tests/baselines/reference/acceptSymbolAsWeakType.symbols

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ ws.delete(s);
3030

3131
const wm = new WeakMap([[s, false]]);
3232
>wm : Symbol(wm, Decl(acceptSymbolAsWeakType.ts, 7, 5))
33-
>WeakMap : Symbol(WeakMap, Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
33+
>WeakMap : Symbol(WeakMap, Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.esnext.collection.d.ts, --, --))
3434
>s : Symbol(s, Decl(acceptSymbolAsWeakType.ts, 0, 5))
3535

3636
wm.set(s, true);

tests/baselines/reference/awaitUsingDeclarationsWithIteratorObject.symbols

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ async function f() {
5555
await using it5 = new Map<string, string>().entries();
5656
>it5 : Symbol(it5, Decl(awaitUsingDeclarationsWithIteratorObject.ts, 15, 15))
5757
>new Map<string, string>().entries : Symbol(Map.entries, Decl(lib.es2015.iterable.d.ts, --, --))
58-
>Map : Symbol(Map, Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
58+
>Map : Symbol(Map, Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.esnext.collection.d.ts, --, --))
5959
>entries : Symbol(Map.entries, Decl(lib.es2015.iterable.d.ts, --, --))
6060

6161
await using it6 = new Set<string>().keys();

tests/baselines/reference/builtinIteratorReturn(strictbuiltiniteratorreturn=false).symbols

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ declare const array: number[];
66

77
declare const map: Map<string, number>;
88
>map : Symbol(map, Decl(builtinIteratorReturn.ts, 1, 13))
9-
>Map : Symbol(Map, Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
9+
>Map : Symbol(Map, Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.esnext.collection.d.ts, --, --))
1010

1111
declare const set: Set<number>;
1212
>set : Symbol(set, Decl(builtinIteratorReturn.ts, 2, 13))

tests/baselines/reference/builtinIteratorReturn(strictbuiltiniteratorreturn=true).symbols

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ declare const array: number[];
66

77
declare const map: Map<string, number>;
88
>map : Symbol(map, Decl(builtinIteratorReturn.ts, 1, 13))
9-
>Map : Symbol(Map, Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
9+
>Map : Symbol(Map, Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.esnext.collection.d.ts, --, --))
1010

1111
declare const set: Set<number>;
1212
>set : Symbol(set, Decl(builtinIteratorReturn.ts, 2, 13))

tests/baselines/reference/config/commandLineParsing/parseCommandLine/Parse --lib option with extra comma.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)