From efbc2ffe6a1ee5ec38a4396305561d6515d0943e Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Fri, 30 Aug 2024 17:21:18 +0800 Subject: node fixes, updates --- node_modules/webpack/lib/util/memoize.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 node_modules/webpack/lib/util/memoize.js (limited to 'node_modules/webpack/lib/util/memoize.js') diff --git a/node_modules/webpack/lib/util/memoize.js b/node_modules/webpack/lib/util/memoize.js new file mode 100644 index 00000000..c79d1fd8 --- /dev/null +++ b/node_modules/webpack/lib/util/memoize.js @@ -0,0 +1,32 @@ +/* + MIT License http://www.opensource.org/licenses/mit-license.php +*/ + +"use strict"; + +/** @template T @typedef {function(): T} FunctionReturning */ + +/** + * @template T + * @param {FunctionReturning} fn memorized function + * @returns {FunctionReturning} new function + */ +const memoize = fn => { + let cache = false; + /** @type {T | undefined} */ + let result; + return () => { + if (cache) { + return /** @type {T} */ (result); + } + + result = fn(); + cache = true; + // Allow to clean up memory for fn + // and all dependent resources + fn = undefined; + return /** @type {T} */ (result); + }; +}; + +module.exports = memoize; -- cgit v1.2.3