(set, getKey)
| 45 | * @returns {ReadonlyMap<T, ReadonlyArray<ModuleGraphConnection>>} mapped by key |
| 46 | */ |
| 47 | const 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. |
no test coverage detected