MCPcopy
hub / github.com/webpack/webpack / provide

Method provide

lib/util/WeakTupleMap.js:120–131  ·  view source on GitHub ↗

* Returns an existing value for the tuple or computes, stores, and returns a * new one when the tuple is missing. * @param {[...K, (...args: K) => V]} args tuple * @returns {V} the value

(...args)

Source from the content-addressed store, hash-verified

118 * @returns {V} the value
119 */
120 provide(...args) {
121 /** @type {WeakTupleMap<K, V>} */
122 let node = this;
123 for (let i = 0; i < args.length - 1; i++) {
124 node = node._get(/** @type {ArrayElement<K>} */ (args[i]));
125 }
126 if (node._hasValue()) return /** @type {V} */ (node._getValue());
127 const fn = /** @type {(...args: K) => V} */ (args[args.length - 1]);
128 const newValue = fn(.../** @type {K} */ (args.slice(0, -1)));
129 node._setValue(newValue);
130 return newValue;
131 }
132
133 /**
134 * Memoizes `compute(thisArg, ...args)` under the tuple key `[compute,

Callers

nothing calls this directly

Calls 6

_getMethod · 0.80
_hasValueMethod · 0.80
_getValueMethod · 0.80
sliceMethod · 0.80
_setValueMethod · 0.80
fnFunction · 0.70

Tested by

no test coverage detected