MCPcopy
hub / github.com/webpack/webpack / memoize

Function memoize

lib/util/memoize.js:19–36  ·  view source on GitHub ↗
(fn)

Source from the content-addressed store, hash-verified

17 * @returns {FunctionReturning<T>} new function
18 */
19const memoize = (fn) => {
20 let cache = false;
21 /** @type {T | undefined} */
22 let result;
23 return () => {
24 if (cache) {
25 return /** @type {T} */ (result);
26 }
27
28 result = fn();
29 cache = true;
30 // Allow to clean up memory for fn
31 // and all dependent resources
32 /** @type {FunctionReturning<T> | undefined} */
33 (fn) = undefined;
34 return /** @type {T} */ (result);
35 };
36};
37
38module.exports = memoize;

Callers 15

RuntimePlugin.jsFile · 0.85
lazyFunctionFunction · 0.85
mergeExportsFunction · 0.85
validateFunction · 0.85
RuntimeTemplate.jsFile · 0.85
FileSystemInfo.jsFile · 0.85
ModuleTemplate.jsFile · 0.85
webpack.jsFile · 0.85
NormalModule.jsFile · 0.85
_createLoaderContextMethod · 0.85
ProgressPlugin.jsFile · 0.85

Calls 1

fnFunction · 0.70

Tested by

no test coverage detected