MCPcopy
hub / github.com/rollup/rollup / getOrCreate

Function getOrCreate

src/utils/getOrCreate.ts:7–19  ·  view source on GitHub ↗
(
	map: Map<K, V> | WeakMap<K, V>,
	key: K,
	init: () => V
)

Source from the content-addressed store, hash-verified

5): V;
6export function getOrCreate<K, V>(map: Map<K, V>, key: K, init: () => V): V;
7export function getOrCreate<K extends object, V>(
8 map: Map<K, V> | WeakMap<K, V>,
9 key: K,
10 init: () => V
11): V {
12 const existing = map.get(key);
13 if (existing !== undefined) {
14 return existing;
15 }
16 const value = init();
17 map.set(key, value);
18 return value;
19}
20
21export function getNewSet<T>() {
22 return new Set<T>();

Callers 15

addFunction · 0.90
UNRESOLVED_IMPORTFunction · 0.90
nestFunction · 0.90
getImportSpecifiersMethod · 0.90
getReexportSpecifiersMethod · 0.90
FileEmitterClass · 0.90
analyzeModuleGraphFunction · 0.90

Calls 2

getMethod · 0.80
setMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…