|
6 | 6 |
|
7 | 7 | const Queue = require("../util/Queue");
|
8 | 8 |
|
9 |
| -const hasModule = (chunk, module, checkedChunks) => { |
10 |
| - if(chunk.containsModule(module)) return [chunk]; |
11 |
| - if(chunk.getNumberOfParents() === 0) return false; |
12 |
| - return allHaveModule(chunk.getParents().filter((c) => { |
13 |
| - return !checkedChunks.has(c); |
14 |
| - }), module, checkedChunks); |
15 |
| -}; |
16 |
| - |
17 |
| -const allHaveModule = (someChunks, module, checkedChunks) => { |
18 |
| - if(!checkedChunks) checkedChunks = new Set(); |
19 |
| - var chunks = new Set(); |
20 |
| - for(var i = 0; i < someChunks.length; i++) { |
21 |
| - checkedChunks.add(someChunks[i]); |
22 |
| - var subChunks = hasModule(someChunks[i], module, checkedChunks); |
23 |
| - if(!subChunks) return false; |
| 9 | +const getParentChunksWithModule = (currentChunk, module) => { |
| 10 | + const chunks = []; |
| 11 | + const stack = new Set(currentChunk.parentsIterable); |
24 | 12 |
|
25 |
| - for(var index = 0; index < subChunks.length; index++) { |
26 |
| - var item = subChunks[index]; |
27 |
| - |
28 |
| - chunks.add(item); |
| 13 | + for(const chunk of stack) { |
| 14 | + if(chunk.containsModule(module)) { |
| 15 | + chunks.push(chunk); |
| 16 | + } else { |
| 17 | + for(const parent of chunk.parentsIterable) { |
| 18 | + stack.add(parent); |
| 19 | + } |
29 | 20 | }
|
30 | 21 | }
|
| 22 | + |
31 | 23 | return chunks;
|
32 | 24 | };
|
33 | 25 |
|
@@ -93,8 +85,7 @@ class RemoveParentModulesPlugin {
|
93 | 85 | toRemove.add(m);
|
94 | 86 | }
|
95 | 87 | for(const module of toRemove) {
|
96 |
| - const parentChunksWithModule = allHaveModule(chunk.getParents(), module); |
97 |
| - module.rewriteChunkInReasons(chunk, Array.from(parentChunksWithModule)); |
| 88 | + module.rewriteChunkInReasons(chunk, getParentChunksWithModule(chunk, module)); |
98 | 89 | chunk.removeModule(module);
|
99 | 90 | }
|
100 | 91 | }
|
|
0 commit comments