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

Method provide

lib/util/runtime.js:547–582  ·  view source on GitHub ↗

* Returns the new value. * @param {RuntimeSpec} runtime the runtimes * @param {() => R} computer function to compute the value * @returns {R} the new value

(runtime, computer)

Source from the content-addressed store, hash-verified

545 * @returns {R} the new value
546 */
547 provide(runtime, computer) {
548 switch (this._mode) {
549 case 0:
550 this._mode = 1;
551 this._singleRuntime = runtime;
552 return (this._singleValue = computer());
553 case 1: {
554 if (runtimeEqual(this._singleRuntime, runtime)) {
555 return /** @type {R} */ (this._singleValue);
556 }
557 this._mode = 2;
558 this._map = new Map();
559 this._map.set(
560 getRuntimeKey(this._singleRuntime),
561 /** @type {R} */
562 (this._singleValue)
563 );
564 this._singleRuntime = undefined;
565 this._singleValue = undefined;
566 const newValue = computer();
567 this._map.set(getRuntimeKey(runtime), newValue);
568 return newValue;
569 }
570 default: {
571 const key = getRuntimeKey(runtime);
572 const value =
573 /** @type {RuntimeSpecMapInnerMap<R>} */
574 (this._map).get(key);
575 if (value !== undefined) return value;
576 const newValue = computer();
577 /** @type {RuntimeSpecMapInnerMap<R>} */
578 (this._map).set(key, newValue);
579 return newValue;
580 }
581 }
582 }
583
584 /**
585 * Processes the provided runtime.

Callers

nothing calls this directly

Calls 4

runtimeEqualFunction · 0.85
getRuntimeKeyFunction · 0.85
setMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected