* 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)
| 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. |