MCPcopy
hub / github.com/webpack/webpack / getModulesArrayBounds

Method getModulesArrayBounds

lib/Template.js:283–305  ·  view source on GitHub ↗

* Gets modules array bounds. * @param {WithId[]} modules a collection of modules to get array bounds for * @returns {[number, number] | false} returns the upper and lower array bounds * or false if not every module has a number based id

(modules)

Source from the content-addressed store, hash-verified

281 * or false if not every module has a number based id
282 */
283 static getModulesArrayBounds(modules) {
284 let maxId = -Infinity;
285 let minId = Infinity;
286 for (const module of modules) {
287 const moduleId = module.id;
288 if (typeof moduleId !== "number") return false;
289 if (maxId < moduleId) maxId = moduleId;
290 if (minId > moduleId) minId = moduleId;
291 }
292 if (minId < 16 + String(minId).length) {
293 // add minId x ',' instead of 'Array(minId).concat(…)'
294 minId = 0;
295 }
296 // start with -1 because the first module needs no comma
297 let objectOverhead = -1;
298 for (const module of modules) {
299 // module id + colon + comma
300 objectOverhead += `${module.id}`.length + 2;
301 }
302 // number of commas, or when starting non-zero the length of Array(minId).concat()
303 const arrayOverhead = minId === 0 ? maxId : 16 + `${minId}`.length + maxId;
304 return arrayOverhead < objectOverhead ? [minId, maxId] : false;
305 }
306
307 /**
308 * Renders chunk modules.

Callers 1

renderChunkModulesMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected