* Assigns depth values to the provided modules. * @param {Module[] | Set<Module>} modules modules to assign depth * @returns {void}
(modules)
| 4529 | * @returns {void} |
| 4530 | */ |
| 4531 | assignDepths(modules) { |
| 4532 | const moduleGraph = this.moduleGraph; |
| 4533 | |
| 4534 | /** @type {Set<Module>} */ |
| 4535 | const queue = new Set(modules); |
| 4536 | // Track these in local variables so that queue only has one data type |
| 4537 | let nextDepthAt = queue.size; |
| 4538 | let depth = 0; |
| 4539 | |
| 4540 | let i = 0; |
| 4541 | for (const module of queue) { |
| 4542 | moduleGraph.setDepth(module, depth); |
| 4543 | // Some of these results come from cache, which speeds this up |
| 4544 | const connections = moduleGraph.getOutgoingConnectionsByModule(module); |
| 4545 | // connections will be undefined if there are no outgoing connections |
| 4546 | if (connections) { |
| 4547 | for (const refModule of connections.keys()) { |
| 4548 | if (refModule) queue.add(refModule); |
| 4549 | } |
| 4550 | } |
| 4551 | i++; |
| 4552 | // Since this is a breadth-first search, all modules added to the queue |
| 4553 | // while at depth N will be depth N+1 |
| 4554 | if (i >= nextDepthAt) { |
| 4555 | depth++; |
| 4556 | nextDepthAt = queue.size; |
| 4557 | } |
| 4558 | } |
| 4559 | } |
| 4560 | |
| 4561 | /** |
| 4562 | * Gets dependency referenced exports. |
no test coverage detected