Skip to content

Commit 822099d

Browse files
committed
WIP: move index and index2 calculation
1 parent 850e209 commit 822099d

File tree

1 file changed

+18
-65
lines changed

1 file changed

+18
-65
lines changed

lib/Compilation.js

Lines changed: 18 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,6 @@ class Compilation extends Tapable {
257257
this._modules = new Map();
258258
this.cache = null;
259259
this.records = null;
260-
this.nextFreeModuleIndex = undefined;
261-
this.nextFreeModuleIndex2 = undefined;
262260
this.additionalChunkAssets = [];
263261
this.assets = {};
264262
this.errors = [];
@@ -853,8 +851,6 @@ class Compilation extends Tapable {
853851
}
854852
this.hooks.afterOptimizeDependencies.call(this.modules);
855853

856-
this.nextFreeModuleIndex = 0;
857-
this.nextFreeModuleIndex2 = 0;
858854
for (const preparedEntrypoint of this._preparedEntrypoints) {
859855
const module = preparedEntrypoint.module;
860856
const name = preparedEntrypoint.name;
@@ -1067,67 +1063,7 @@ class Compilation extends Tapable {
10671063
}
10681064

10691065
assignIndex(module) {
1070-
const assignIndexToModule = module => {
1071-
// enter module
1072-
if (typeof module.index !== "number") {
1073-
module.index = this.nextFreeModuleIndex++;
1074-
1075-
// leave module
1076-
queue.push(() => (module.index2 = this.nextFreeModuleIndex2++));
1077-
1078-
// enter it as block
1079-
assignIndexToDependencyBlock(module);
1080-
}
1081-
};
1082-
1083-
const assignIndexToDependency = dependency => {
1084-
if (dependency.module) {
1085-
queue.push(() => assignIndexToModule(dependency.module));
1086-
}
1087-
};
1088-
1089-
const assignIndexToDependencyBlock = block => {
1090-
let allDependencies = [];
1091-
1092-
const iteratorDependency = d => allDependencies.push(d);
1093-
1094-
const iteratorBlock = b =>
1095-
queue.push(() => assignIndexToDependencyBlock(b));
1096-
1097-
if (block.variables) {
1098-
iterationBlockVariable(block.variables, iteratorDependency);
1099-
}
1100-
1101-
if (block.dependencies) {
1102-
iterationOfArrayCallback(block.dependencies, iteratorDependency);
1103-
}
1104-
if (block.blocks) {
1105-
const blocks = block.blocks;
1106-
let indexBlock = blocks.length;
1107-
while (indexBlock--) {
1108-
iteratorBlock(blocks[indexBlock]);
1109-
}
1110-
}
1111-
1112-
let indexAll = allDependencies.length;
1113-
while (indexAll--) {
1114-
iteratorAllDependencies(allDependencies[indexAll]);
1115-
}
1116-
};
1117-
1118-
const queue = [
1119-
() => {
1120-
assignIndexToModule(module);
1121-
}
1122-
];
1123-
1124-
const iteratorAllDependencies = d => {
1125-
queue.push(() => assignIndexToDependency(d));
1126-
};
1127-
1128-
while (queue.length) {
1129-
queue.pop()();
1130-
}
1066+
11311067
}
11321068

11331069
assignDepth(module) {
@@ -1263,12 +1199,21 @@ class Compilation extends Tapable {
12631199

12641200
// PART ONE
12651201

1202+
/** @type {Set<Module>} */
1203+
const alreadyEntered = new Set();
1204+
1205+
/** @type {Set<Module>} */
1206+
const alreadyLeaved = new Set();
1207+
12661208
/** @type {Map<ChunkGroup, { index: number, index2: number }>} */
12671209
const chunkGroupCounters = new Map();
12681210
for (const chunkGroup of inputChunkGroups) {
12691211
chunkGroupCounters.set(chunkGroup, { index: 0, index2: 0 });
12701212
}
12711213

1214+
let nextFreeModuleIndex = 0;
1215+
let nextFreeModuleIndex2 = 0;
1216+
12721217
const blockChunkGroups = new Map();
12731218

12741219
const ENTER = 0;
@@ -1380,6 +1325,10 @@ class Compilation extends Tapable {
13801325
);
13811326
}
13821327
}
1328+
1329+
if (module.index === undefined) {
1330+
module.index = nextFreeModuleIndex++;
1331+
}
13831332
}
13841333
// fallthrough
13851334
case ASYNC: {
@@ -1418,6 +1367,10 @@ class Compilation extends Tapable {
14181367
);
14191368
}
14201369
}
1370+
1371+
if (module.index2 === undefined) {
1372+
module.index2 = nextFreeModuleIndex2++;
1373+
}
14211374
break;
14221375
}
14231376
}

0 commit comments

Comments
 (0)