MCPcopy
hub / github.com/webpack/webpack / createGetCombinations

Method createGetCombinations

lib/optimize/SplitChunksPlugin.js:1059–1098  ·  view source on GitHub ↗
(
						chunkSets,
						singleChunkSets,
						chunkSetsByCount
					)

Source from the content-addressed store, hash-verified

1057 * @returns {(key: bigint | Chunk) => Combinations} combinations
1058 */
1059 const createGetCombinations = (
1060 chunkSets,
1061 singleChunkSets,
1062 chunkSetsByCount
1063 ) => {
1064 /** @type {Map<bigint | Chunk, Combinations>} */
1065 const combinationsCache = new Map();
1066
1067 return (key) => {
1068 const cacheEntry = combinationsCache.get(key);
1069 if (cacheEntry !== undefined) return cacheEntry;
1070 if (key instanceof Chunk) {
1071 const result = [key];
1072 combinationsCache.set(key, result);
1073 return result;
1074 }
1075 const chunksSet =
1076 /** @type {ChunkSet} */
1077 (chunkSets.get(key));
1078 /** @type {Combinations} */
1079 const array = [chunksSet];
1080 for (const [count, setArray] of chunkSetsByCount) {
1081 // "equal" is not needed because they would have been merge in the first step
1082 if (count < chunksSet.size) {
1083 for (const set of setArray) {
1084 if (isSubset(chunksSet, set)) {
1085 array.push(set);
1086 }
1087 }
1088 }
1089 }
1090 for (const chunk of singleChunkSets) {
1091 if (chunksSet.has(chunk)) {
1092 array.push(chunk);
1093 }
1094 }
1095 combinationsCache.set(key, array);
1096 return array;
1097 };
1098 };
1099
1100 const getCombinationsFactory = memoize(() => {
1101 const { chunkSetsInGraph, singleChunkSets } = getChunkSetsInGraph();

Callers

nothing calls this directly

Calls 5

isSubsetFunction · 0.85
getMethod · 0.45
setMethod · 0.45
pushMethod · 0.45
hasMethod · 0.45

Tested by

no test coverage detected