webpack 5.57.1 → 5.58.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of webpack might be problematic. Click here for more details.

@@ -33,8 +33,6 @@ class AsyncDependenciesBlock extends DependenciesBlock {
33
33
  this.groupOptions = groupOptions;
34
34
  this.loc = loc;
35
35
  this.request = request;
36
- /** @type {DependenciesBlock} */
37
- this.parent = undefined;
38
36
  this._stringifiedGroupOptions = undefined;
39
37
  }
40
38
 
@@ -0,0 +1,187 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+
6
+ "use strict";
7
+
8
+ const SortableSet = require("./util/SortableSet");
9
+
10
+ /** @typedef {import("./Chunk")} Chunk */
11
+
12
+ /**
13
+ * @template T
14
+ * @param {SortableSet<T>} set the set
15
+ * @returns {T[]} set as array
16
+ */
17
+ const getArray = set => {
18
+ return Array.from(set);
19
+ };
20
+
21
+ let debugId = 1;
22
+
23
+ class ChunkCombination {
24
+ constructor() {
25
+ this.debugId = debugId++;
26
+ this.size = 0;
27
+ /**
28
+ * (do not modify)
29
+ * @type {SortableSet<Chunk>}
30
+ */
31
+ this._chunks = new SortableSet();
32
+ /** @type {ChunkCombination} */
33
+ this._parent = undefined;
34
+ this._lastChunk = undefined;
35
+ /** @type {WeakMap<Chunk, ChunkCombination>} */
36
+ this._addMap = new WeakMap();
37
+ /** @type {WeakMap<Chunk, ChunkCombination>} */
38
+ this._removeCache = new WeakMap();
39
+ }
40
+
41
+ /**
42
+ * @returns {Iterable<Chunk>} iterable of chunks
43
+ */
44
+ get chunksIterable() {
45
+ return this._chunks;
46
+ }
47
+
48
+ /**
49
+ * @param {Chunk} chunk chunk to add
50
+ * @returns {ChunkCombination} new chunk combination
51
+ */
52
+ with(chunk) {
53
+ if (this._chunks.has(chunk)) return this;
54
+ let next = this._addMap.get(chunk);
55
+ if (next !== undefined) return next;
56
+ // must insert chunks in order to maintain order-independent identity of ChunkCombination
57
+ if (!this._parent || this._lastChunk.debugId < chunk.debugId) {
58
+ next = new ChunkCombination();
59
+ for (const chunk of this._chunks) {
60
+ next._chunks.add(chunk);
61
+ }
62
+ next._chunks.add(chunk);
63
+ next._removeCache.set(chunk, this);
64
+ next.size = this.size + 1;
65
+ next._parent = this;
66
+ next._lastChunk = chunk;
67
+ } else {
68
+ next = this._parent.with(chunk).with(this._lastChunk);
69
+ }
70
+ this._addMap.set(chunk, next);
71
+ return next;
72
+ }
73
+
74
+ /**
75
+ * @param {Chunk} chunk chunk to remove
76
+ * @returns {ChunkCombination} new chunk combination
77
+ */
78
+ without(chunk) {
79
+ if (!this._chunks.has(chunk)) return this;
80
+ let next = this._removeCache.get(chunk);
81
+ if (next !== undefined) return next;
82
+ const stack = [this._lastChunk];
83
+ let current = this._parent;
84
+ while (current._lastChunk !== chunk) {
85
+ stack.push(current._lastChunk);
86
+ current = current._parent;
87
+ }
88
+ next = current._parent;
89
+ while (stack.length) next = next.with(stack.pop());
90
+ this._removeCache.set(chunk, next);
91
+ return next;
92
+ }
93
+
94
+ withAll(other) {
95
+ if (other.size === 0) return this;
96
+ if (this.size === 0) return other;
97
+ const stack = [];
98
+ /** @type {ChunkCombination} */
99
+ let current = this;
100
+ for (;;) {
101
+ if (current._lastChunk.debugId < other._lastChunk.debugId) {
102
+ stack.push(other._lastChunk);
103
+ other = other._parent;
104
+ if (other.size === 0) {
105
+ while (stack.length) current = current.with(stack.pop());
106
+ return current;
107
+ }
108
+ } else {
109
+ stack.push(current._lastChunk);
110
+ current = current._parent;
111
+ if (current.size === 0) {
112
+ while (stack.length) other = other.with(stack.pop());
113
+ return other;
114
+ }
115
+ }
116
+ }
117
+ }
118
+
119
+ hasSharedChunks(other) {
120
+ if (this.size > other.size) {
121
+ const chunks = this._chunks;
122
+ for (const chunk of other._chunks) {
123
+ if (chunks.has(chunk)) return true;
124
+ }
125
+ } else {
126
+ const chunks = other._chunks;
127
+ for (const chunk of this._chunks) {
128
+ if (chunks.has(chunk)) return true;
129
+ }
130
+ }
131
+ return false;
132
+ }
133
+
134
+ /**
135
+ * @param {ChunkCombination} other other combination
136
+ * @returns {boolean} true, when other is a subset of this combination
137
+ */
138
+ isSubset(other) {
139
+ // TODO: This could be more efficient when using the debugId order of the combinations
140
+ /** @type {ChunkCombination} */
141
+ let current = this;
142
+ let otherSize = other.size;
143
+ let currentSize = current.size;
144
+ if (otherSize === 0) return true;
145
+ for (;;) {
146
+ if (currentSize === 0) return false;
147
+ if (otherSize === 1) {
148
+ if (currentSize === 1) {
149
+ return current._lastChunk === other._lastChunk;
150
+ } else {
151
+ return current._chunks.has(other._lastChunk);
152
+ }
153
+ }
154
+ if (otherSize * 8 < currentSize) {
155
+ // go for the Set access when current >> other
156
+ const chunks = current._chunks;
157
+ for (const item of other._chunks) {
158
+ if (!chunks.has(item)) return false;
159
+ }
160
+ return true;
161
+ }
162
+ const otherId = other._lastChunk.debugId;
163
+ // skip over nodes in current that have higher ids
164
+ while (otherId < current._lastChunk.debugId) {
165
+ current = current._parent;
166
+ currentSize--;
167
+ if (currentSize === 0) return false;
168
+ }
169
+ if (otherId > current._lastChunk.debugId) {
170
+ return false;
171
+ }
172
+ other = other._parent;
173
+ otherSize--;
174
+ if (otherSize === 0) return true;
175
+ current = current._parent;
176
+ currentSize--;
177
+ }
178
+ }
179
+
180
+ getChunks() {
181
+ return this._chunks.getFromUnorderedCache(getArray);
182
+ }
183
+ }
184
+
185
+ ChunkCombination.empty = new ChunkCombination();
186
+
187
+ module.exports = ChunkCombination;
package/lib/ChunkGraph.js CHANGED
@@ -6,6 +6,7 @@
6
6
  "use strict";
7
7
 
8
8
  const util = require("util");
9
+ const ChunkCombination = require("./ChunkCombination");
9
10
  const Entrypoint = require("./Entrypoint");
10
11
  const ModuleGraphConnection = require("./ModuleGraphConnection");
11
12
  const { first } = require("./util/SetHelpers");
@@ -40,6 +41,8 @@ const {
40
41
  /** @type {ReadonlySet<string>} */
41
42
  const EMPTY_SET = new Set();
42
43
 
44
+ const EMPTY_RUNTIME_SPEC_SET = new RuntimeSpecSet();
45
+
43
46
  const ZERO_BIG_INT = BigInt(0);
44
47
 
45
48
  const compareModuleIterables = compareIterables(compareModulesByIdentifier);
@@ -177,8 +180,7 @@ const isAvailableChunk = (a, b) => {
177
180
 
178
181
  class ChunkGraphModule {
179
182
  constructor() {
180
- /** @type {SortableSet<Chunk>} */
181
- this.chunks = new SortableSet();
183
+ this.chunkCombination = ChunkCombination.empty;
182
184
  /** @type {Set<Chunk> | undefined} */
183
185
  this.entryInChunks = undefined;
184
186
  /** @type {Set<Chunk> | undefined} */
@@ -235,16 +237,6 @@ class ChunkGraph {
235
237
  this._hashFunction = hashFunction;
236
238
 
237
239
  this._getGraphRoots = this._getGraphRoots.bind(this);
238
-
239
- // Caching
240
- this._cacheChunkGraphModuleKey1 = undefined;
241
- this._cacheChunkGraphModuleValue1 = undefined;
242
- this._cacheChunkGraphModuleKey2 = undefined;
243
- this._cacheChunkGraphModuleValue2 = undefined;
244
- this._cacheChunkGraphChunkKey1 = undefined;
245
- this._cacheChunkGraphChunkValue1 = undefined;
246
- this._cacheChunkGraphChunkKey2 = undefined;
247
- this._cacheChunkGraphChunkValue2 = undefined;
248
240
  }
249
241
 
250
242
  /**
@@ -253,19 +245,11 @@ class ChunkGraph {
253
245
  * @returns {ChunkGraphModule} internal module
254
246
  */
255
247
  _getChunkGraphModule(module) {
256
- if (this._cacheChunkGraphModuleKey1 === module)
257
- return this._cacheChunkGraphModuleValue1;
258
- if (this._cacheChunkGraphModuleKey2 === module)
259
- return this._cacheChunkGraphModuleValue2;
260
248
  let cgm = this._modules.get(module);
261
249
  if (cgm === undefined) {
262
250
  cgm = new ChunkGraphModule();
263
251
  this._modules.set(module, cgm);
264
252
  }
265
- this._cacheChunkGraphModuleKey2 = this._cacheChunkGraphModuleKey1;
266
- this._cacheChunkGraphModuleValue2 = this._cacheChunkGraphModuleValue1;
267
- this._cacheChunkGraphModuleKey1 = module;
268
- this._cacheChunkGraphModuleValue1 = cgm;
269
253
  return cgm;
270
254
  }
271
255
 
@@ -275,19 +259,11 @@ class ChunkGraph {
275
259
  * @returns {ChunkGraphChunk} internal chunk
276
260
  */
277
261
  _getChunkGraphChunk(chunk) {
278
- if (this._cacheChunkGraphChunkKey1 === chunk)
279
- return this._cacheChunkGraphChunkValue1;
280
- if (this._cacheChunkGraphChunkKey2 === chunk)
281
- return this._cacheChunkGraphChunkValue2;
282
262
  let cgc = this._chunks.get(chunk);
283
263
  if (cgc === undefined) {
284
264
  cgc = new ChunkGraphChunk();
285
265
  this._chunks.set(chunk, cgc);
286
266
  }
287
- this._cacheChunkGraphChunkKey2 = this._cacheChunkGraphChunkKey1;
288
- this._cacheChunkGraphChunkValue2 = this._cacheChunkGraphChunkValue1;
289
- this._cacheChunkGraphChunkKey1 = chunk;
290
- this._cacheChunkGraphChunkValue1 = cgc;
291
267
  return cgc;
292
268
  }
293
269
 
@@ -327,7 +303,7 @@ class ChunkGraph {
327
303
  connectChunkAndModule(chunk, module) {
328
304
  const cgm = this._getChunkGraphModule(module);
329
305
  const cgc = this._getChunkGraphChunk(chunk);
330
- cgm.chunks.add(chunk);
306
+ cgm.chunkCombination = cgm.chunkCombination.with(chunk);
331
307
  cgc.modules.add(module);
332
308
  }
333
309
 
@@ -340,7 +316,7 @@ class ChunkGraph {
340
316
  const cgm = this._getChunkGraphModule(module);
341
317
  const cgc = this._getChunkGraphChunk(chunk);
342
318
  cgc.modules.delete(module);
343
- cgm.chunks.delete(chunk);
319
+ cgm.chunkCombination = cgm.chunkCombination.without(chunk);
344
320
  }
345
321
 
346
322
  /**
@@ -351,7 +327,7 @@ class ChunkGraph {
351
327
  const cgc = this._getChunkGraphChunk(chunk);
352
328
  for (const module of cgc.modules) {
353
329
  const cgm = this._getChunkGraphModule(module);
354
- cgm.chunks.delete(chunk);
330
+ cgm.chunkCombination = cgm.chunkCombination.without(chunk);
355
331
  }
356
332
  cgc.modules.clear();
357
333
  chunk.disconnectFromGroups();
@@ -418,13 +394,13 @@ class ChunkGraph {
418
394
  const oldCgm = this._getChunkGraphModule(oldModule);
419
395
  const newCgm = this._getChunkGraphModule(newModule);
420
396
 
421
- for (const chunk of oldCgm.chunks) {
397
+ for (const chunk of oldCgm.chunkCombination._chunks) {
422
398
  const cgc = this._getChunkGraphChunk(chunk);
423
399
  cgc.modules.delete(oldModule);
424
400
  cgc.modules.add(newModule);
425
- newCgm.chunks.add(chunk);
401
+ newCgm.chunkCombination = newCgm.chunkCombination.with(chunk);
426
402
  }
427
- oldCgm.chunks.clear();
403
+ oldCgm.chunkCombination = ChunkCombination.empty;
428
404
 
429
405
  if (oldCgm.entryInChunks !== undefined) {
430
406
  if (newCgm.entryInChunks === undefined) {
@@ -511,13 +487,22 @@ class ChunkGraph {
511
487
  return cgm.entryInChunks !== undefined;
512
488
  }
513
489
 
490
+ /**
491
+ * @param {Module} module the module
492
+ * @returns {ChunkCombination} chunk combination (do not modify)
493
+ */
494
+ getModuleChunkCombination(module) {
495
+ const cgm = this._getChunkGraphModule(module);
496
+ return cgm.chunkCombination;
497
+ }
498
+
514
499
  /**
515
500
  * @param {Module} module the module
516
501
  * @returns {Iterable<Chunk>} iterable of chunks (do not modify)
517
502
  */
518
503
  getModuleChunksIterable(module) {
519
504
  const cgm = this._getChunkGraphModule(module);
520
- return cgm.chunks;
505
+ return cgm.chunkCombination._chunks;
521
506
  }
522
507
 
523
508
  /**
@@ -527,8 +512,9 @@ class ChunkGraph {
527
512
  */
528
513
  getOrderedModuleChunksIterable(module, sortFn) {
529
514
  const cgm = this._getChunkGraphModule(module);
530
- cgm.chunks.sortWith(sortFn);
531
- return cgm.chunks;
515
+ const chunks = cgm.chunkCombination._chunks;
516
+ chunks.sortWith(sortFn);
517
+ return chunks;
532
518
  }
533
519
 
534
520
  /**
@@ -537,7 +523,7 @@ class ChunkGraph {
537
523
  */
538
524
  getModuleChunks(module) {
539
525
  const cgm = this._getChunkGraphModule(module);
540
- return cgm.chunks.getFromCache(getArray);
526
+ return cgm.chunkCombination.getChunks();
541
527
  }
542
528
 
543
529
  /**
@@ -546,7 +532,7 @@ class ChunkGraph {
546
532
  */
547
533
  getNumberOfModuleChunks(module) {
548
534
  const cgm = this._getChunkGraphModule(module);
549
- return cgm.chunks.size;
535
+ return cgm.chunkCombination.size;
550
536
  }
551
537
 
552
538
  /**
@@ -555,7 +541,10 @@ class ChunkGraph {
555
541
  */
556
542
  getModuleRuntimes(module) {
557
543
  const cgm = this._getChunkGraphModule(module);
558
- return cgm.chunks.getFromUnorderedCache(getModuleRuntimes);
544
+ if (cgm.chunkCombination.size === 0) return EMPTY_RUNTIME_SPEC_SET;
545
+ return cgm.chunkCombination._chunks.getFromUnorderedCache(
546
+ getModuleRuntimes
547
+ );
559
548
  }
560
549
 
561
550
  /**
@@ -919,8 +908,7 @@ class ChunkGraph {
919
908
  // Merge runtime
920
909
  chunkA.runtime = mergeRuntime(chunkA.runtime, chunkB.runtime);
921
910
 
922
- // getChunkModules is used here to create a clone, because disconnectChunkAndModule modifies
923
- for (const module of this.getChunkModules(chunkB)) {
911
+ for (const module of this.getChunkModulesIterable(chunkB)) {
924
912
  this.disconnectChunkAndModule(chunkB, module);
925
913
  this.connectChunkAndModule(chunkA, module);
926
914
  }
@@ -1405,8 +1405,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1405
1405
  processModuleDependenciesNonRecursive(module) {
1406
1406
  const processDependenciesBlock = block => {
1407
1407
  if (block.dependencies) {
1408
+ let i = 0;
1408
1409
  for (const dep of block.dependencies) {
1409
- this.moduleGraph.setParents(dep, block, module);
1410
+ this.moduleGraph.setParents(dep, block, module, i++);
1410
1411
  }
1411
1412
  }
1412
1413
  if (block.blocks) {
@@ -1450,10 +1451,11 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1450
1451
 
1451
1452
  /**
1452
1453
  * @param {Dependency} dep dependency
1454
+ * @param {number} index index in block
1453
1455
  * @returns {void}
1454
1456
  */
1455
- const processDependency = dep => {
1456
- this.moduleGraph.setParents(dep, currentBlock, module);
1457
+ const processDependency = (dep, index) => {
1458
+ this.moduleGraph.setParents(dep, currentBlock, module, index);
1457
1459
  if (this._unsafeCache) {
1458
1460
  try {
1459
1461
  const cachedModule = unsafeCacheDependencies.get(dep);
@@ -1557,7 +1559,8 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1557
1559
  const block = queue.pop();
1558
1560
  if (block.dependencies) {
1559
1561
  currentBlock = block;
1560
- for (const dep of block.dependencies) processDependency(dep);
1562
+ let i = 0;
1563
+ for (const dep of block.dependencies) processDependency(dep, i++);
1561
1564
  }
1562
1565
  if (block.blocks) {
1563
1566
  for (const b of block.blocks) queue.push(b);
@@ -2334,7 +2337,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2334
2337
  );
2335
2338
  }
2336
2339
 
2337
- _updateAffectedModulesWithIds() {
2340
+ _computeAffectedModulesWithChunkGraph() {
2338
2341
  const { moduleMemCaches } = this;
2339
2342
  if (!moduleMemCaches) return;
2340
2343
  const moduleMemCaches2 = (this.moduleMemCaches2 = new Map());
@@ -2739,13 +2742,14 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2739
2742
  this.chunkGroups.push(entrypoint);
2740
2743
  connectChunkGroupAndChunk(entrypoint, chunk);
2741
2744
 
2745
+ const entryModules = new Set();
2742
2746
  for (const dep of [...this.globalEntry.dependencies, ...dependencies]) {
2743
2747
  entrypoint.addOrigin(null, { name }, /** @type {any} */ (dep).request);
2744
2748
 
2745
2749
  const module = this.moduleGraph.getModule(dep);
2746
2750
  if (module) {
2747
2751
  chunkGraph.connectChunkAndEntryModule(chunk, module, entrypoint);
2748
- this.assignDepth(module);
2752
+ entryModules.add(module);
2749
2753
  const modulesList = chunkGraphInit.get(entrypoint);
2750
2754
  if (modulesList === undefined) {
2751
2755
  chunkGraphInit.set(entrypoint, [module]);
@@ -2755,6 +2759,8 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2755
2759
  }
2756
2760
  }
2757
2761
 
2762
+ this.assignDepths(entryModules);
2763
+
2758
2764
  const mapAndSort = deps =>
2759
2765
  deps
2760
2766
  .map(dep => this.moduleGraph.getModule(dep))
@@ -2901,7 +2907,9 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
2901
2907
 
2902
2908
  this.assignRuntimeIds();
2903
2909
 
2904
- this._updateAffectedModulesWithIds();
2910
+ this.logger.time("compute affected modules with chunk graph");
2911
+ this._computeAffectedModulesWithChunkGraph();
2912
+ this.logger.timeEnd("compute affected modules with chunk graph");
2905
2913
 
2906
2914
  this.sortItemsWithChunkIds();
2907
2915
 
@@ -3522,6 +3530,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3522
3530
  }
3523
3531
 
3524
3532
  /**
3533
+ * @deprecated
3525
3534
  * @param {Module} module module to assign depth
3526
3535
  * @returns {void}
3527
3536
  */
@@ -3555,6 +3564,38 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3555
3564
  }
3556
3565
  }
3557
3566
 
3567
+ /**
3568
+ * @param {Set<Module>} modules module to assign depth
3569
+ * @returns {void}
3570
+ */
3571
+ assignDepths(modules) {
3572
+ const moduleGraph = this.moduleGraph;
3573
+
3574
+ /** @type {Set<Module | number>} */
3575
+ const queue = new Set(modules);
3576
+ queue.add(1);
3577
+ let depth = 0;
3578
+
3579
+ let i = 0;
3580
+ for (const module of queue) {
3581
+ i++;
3582
+ if (typeof module === "number") {
3583
+ depth = module;
3584
+ if (queue.size === i) return;
3585
+ queue.add(depth + 1);
3586
+ } else {
3587
+ moduleGraph.setDepth(module, depth);
3588
+ for (const { module: refModule } of moduleGraph.getOutgoingConnections(
3589
+ module
3590
+ )) {
3591
+ if (refModule) {
3592
+ queue.add(refModule);
3593
+ }
3594
+ }
3595
+ }
3596
+ }
3597
+ }
3598
+
3558
3599
  /**
3559
3600
  * @param {Dependency} dependency the dependency
3560
3601
  * @param {RuntimeSpec} runtime the runtime
@@ -3592,7 +3633,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3592
3633
  this.moduleGraph.removeConnection(dep);
3593
3634
 
3594
3635
  if (this.chunkGraph) {
3595
- for (const chunk of this.chunkGraph.getModuleChunks(
3636
+ for (const chunk of this.chunkGraph.getModuleChunksIterable(
3596
3637
  originalModule
3597
3638
  )) {
3598
3639
  this.patchChunksAfterReasonRemoval(originalModule, chunk);
@@ -22,6 +22,15 @@ class DependenciesBlock {
22
22
  this.dependencies = [];
23
23
  /** @type {AsyncDependenciesBlock[]} */
24
24
  this.blocks = [];
25
+ /** @type {DependenciesBlock} */
26
+ this.parent = undefined;
27
+ }
28
+
29
+ getRootBlock() {
30
+ /** @type {DependenciesBlock} */
31
+ let current = this;
32
+ while (current.parent) current = current.parent;
33
+ return current;
25
34
  }
26
35
 
27
36
  /**
package/lib/Dependency.js CHANGED
@@ -91,6 +91,8 @@ class Dependency {
91
91
  this._parentModule = undefined;
92
92
  /** @type {DependenciesBlock} */
93
93
  this._parentDependenciesBlock = undefined;
94
+ /** @type {number} */
95
+ this._parentDependenciesBlockIndex = -1;
94
96
  // TODO check if this can be moved into ModuleDependency
95
97
  /** @type {boolean} */
96
98
  this.weak = false;
package/lib/Module.js CHANGED
@@ -885,6 +885,10 @@ class Module extends DependenciesBlock {
885
885
  return true;
886
886
  }
887
887
 
888
+ hasChunkCondition() {
889
+ return this.chunkCondition !== Module.prototype.chunkCondition;
890
+ }
891
+
888
892
  /**
889
893
  * Assuming this module is in the cache. Update the (cached) module with
890
894
  * the fresh module from the factory. Usually updates internal references
@@ -123,14 +123,6 @@ class ModuleGraph {
123
123
  /** @type {WeakMap<any, Object>} */
124
124
  this._metaMap = new WeakMap();
125
125
 
126
- // Caching
127
- this._cacheModuleGraphModuleKey1 = undefined;
128
- this._cacheModuleGraphModuleValue1 = undefined;
129
- this._cacheModuleGraphModuleKey2 = undefined;
130
- this._cacheModuleGraphModuleValue2 = undefined;
131
- this._cacheModuleGraphDependencyKey = undefined;
132
- this._cacheModuleGraphDependencyValue = undefined;
133
-
134
126
  /** @type {WeakTupleMap<any[], any>} */
135
127
  this._cache = undefined;
136
128
 
@@ -143,19 +135,11 @@ class ModuleGraph {
143
135
  * @returns {ModuleGraphModule} the internal module
144
136
  */
145
137
  _getModuleGraphModule(module) {
146
- if (this._cacheModuleGraphModuleKey1 === module)
147
- return this._cacheModuleGraphModuleValue1;
148
- if (this._cacheModuleGraphModuleKey2 === module)
149
- return this._cacheModuleGraphModuleValue2;
150
138
  let mgm = this._moduleMap.get(module);
151
139
  if (mgm === undefined) {
152
140
  mgm = new ModuleGraphModule();
153
141
  this._moduleMap.set(module, mgm);
154
142
  }
155
- this._cacheModuleGraphModuleKey2 = this._cacheModuleGraphModuleKey1;
156
- this._cacheModuleGraphModuleValue2 = this._cacheModuleGraphModuleValue1;
157
- this._cacheModuleGraphModuleKey1 = module;
158
- this._cacheModuleGraphModuleValue1 = mgm;
159
143
  return mgm;
160
144
  }
161
145
 
@@ -163,9 +147,11 @@ class ModuleGraph {
163
147
  * @param {Dependency} dependency the dependency
164
148
  * @param {DependenciesBlock} block parent block
165
149
  * @param {Module} module parent module
150
+ * @param {number=} indexInBlock position in block
166
151
  * @returns {void}
167
152
  */
168
- setParents(dependency, block, module) {
153
+ setParents(dependency, block, module, indexInBlock = -1) {
154
+ dependency._parentDependenciesBlockIndex = indexInBlock;
169
155
  dependency._parentDependenciesBlock = block;
170
156
  dependency._parentModule = module;
171
157
  }
@@ -186,6 +172,14 @@ class ModuleGraph {
186
172
  return dependency._parentDependenciesBlock;
187
173
  }
188
174
 
175
+ /**
176
+ * @param {Dependency} dependency the dependency
177
+ * @returns {number} index
178
+ */
179
+ getParentBlockIndex(dependency) {
180
+ return dependency._parentDependenciesBlockIndex;
181
+ }
182
+
189
183
  /**
190
184
  * @param {Module} originModule the referencing module
191
185
  * @param {Dependency} dependency the referencing dependency