* @param {Module} module module * @returns {void}
(module)
| 341 | * @returns {void} |
| 342 | */ |
| 343 | function inferDependencyUsage(module) { |
| 344 | const innerGraphState = states.get(module); |
| 345 | |
| 346 | if (!innerGraphState) { |
| 347 | return; |
| 348 | } |
| 349 | |
| 350 | const { innerGraph, usageCallbackMap } = innerGraphState; |
| 351 | /** @type {Map<InnerGraphKey, InnerGraphValueSet | undefined>} */ |
| 352 | const processed = new Map(); |
| 353 | // flatten graph to terminal nodes (string, undefined or true) |
| 354 | const nonTerminal = new Set(innerGraph.keys()); |
| 355 | while (nonTerminal.size > 0) { |
| 356 | for (const key of nonTerminal) { |
| 357 | if (key !== null && !key.isPure(compilation, module)) { |
| 358 | innerGraph.set(key, true); |
| 359 | nonTerminal.delete(key); |
| 360 | continue; |
| 361 | } |
| 362 | |
| 363 | /** @type {InnerGraphValue} */ |
| 364 | let newSet = new Set(); |
| 365 | let isTerminal = true; |
| 366 | const value = innerGraph.get(key); |
| 367 | let alreadyProcessed = processed.get(key); |
| 368 | if (alreadyProcessed === undefined) { |
| 369 | /** @type {InnerGraphValueSet} */ |
| 370 | alreadyProcessed = new Set(); |
| 371 | processed.set(key, alreadyProcessed); |
| 372 | } |
| 373 | if (value !== true && value !== undefined) { |
| 374 | for (const item of value) { |
| 375 | alreadyProcessed.add(item); |
| 376 | } |
| 377 | for (const item of value) { |
| 378 | if (typeof item === "string") { |
| 379 | newSet.add(item); |
| 380 | } else if (!item.isPure(compilation, module)) { |
| 381 | newSet = true; |
| 382 | break; |
| 383 | } else { |
| 384 | const itemValue = innerGraph.get(item); |
| 385 | if (itemValue === true) { |
| 386 | newSet = true; |
| 387 | break; |
| 388 | } |
| 389 | if (itemValue !== undefined) { |
| 390 | for (const i of itemValue) { |
| 391 | if (i === key) continue; |
| 392 | if (alreadyProcessed.has(i)) continue; |
| 393 | newSet.add(i); |
| 394 | if (typeof i !== "string") { |
| 395 | isTerminal = false; |
| 396 | } |
| 397 | } |
| 398 | } |
| 399 | } |
| 400 | } |