MCPcopy
hub / github.com/webpack/webpack / getter

Function getter

lib/cache/getLazyHashedEtag.js:71–100  ·  view source on GitHub ↗
(obj, hashFunction = DEFAULTS.HASH_FUNCTION)

Source from the content-addressed store, hash-verified

69 * @returns {LazyHashedEtag} etag
70 */
71const getter = (obj, hashFunction = DEFAULTS.HASH_FUNCTION) => {
72 /** @type {undefined | InnerCache} */
73 let innerMap;
74 if (typeof hashFunction === "string") {
75 innerMap = mapStrings.get(hashFunction);
76 if (innerMap === undefined) {
77 const newHash = new LazyHashedEtag(obj, hashFunction);
78 /** @type {InnerCache} */
79 innerMap = new WeakMap();
80 innerMap.set(obj, newHash);
81 mapStrings.set(hashFunction, innerMap);
82 return newHash;
83 }
84 } else {
85 innerMap = mapObjects.get(hashFunction);
86 if (innerMap === undefined) {
87 const newHash = new LazyHashedEtag(obj, hashFunction);
88 /** @type {InnerCache} */
89 innerMap = new WeakMap();
90 innerMap.set(obj, newHash);
91 mapObjects.set(hashFunction, innerMap);
92 return newHash;
93 }
94 }
95 const hash = innerMap.get(obj);
96 if (hash !== undefined) return hash;
97 const newHash = new LazyHashedEtag(obj, hashFunction);
98 innerMap.set(obj, newHash);
99 return newHash;
100};
101
102module.exports = getter;

Callers 1

resultFunction · 0.85

Calls 2

getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected