MCPcopy
hub / github.com/webpack/webpack / getConnectionsByKey

Function getConnectionsByKey

lib/ModuleGraph.js:47–73  ·  lib/ModuleGraph.js::getConnectionsByKey
(set, getKey)

Source from the content-addressed store, hash-verified

45 * @returns {ReadonlyMap<T, ReadonlyArray<ModuleGraphConnection>>} mapped by key
46 */
47const getConnectionsByKey = (set, getKey) => {
48 /** @type {Map<T, ModuleGraphConnection[]>} */
49 const map = new Map();
50 /** @type {T | 0} */
51 let lastKey = 0;
52 /** @type {ModuleGraphConnection[] | undefined} */
53 let lastList;
54 for (const connection of set) {
55 const key = getKey(connection);
56 if (lastKey === key) {
57 /** @type {ModuleGraphConnection[]} */
58 (lastList).push(connection);
59 } else {
60 lastKey = key;
61 const list = map.get(key);
62 if (list !== undefined) {
63 lastList = list;
64 list.push(connection);
65 } else {
66 const list = [connection];
67 lastList = list;
68 map.set(key, list);
69 }
70 }
71 }
72 return map;
73};
74
75/**
76 * Gets connections by origin module.

Callers 2

getConnectionsByModuleFunction · 0.85

Calls 3

pushMethod · 0.45
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected