Use for-of loops instead of forEachModule

This commit is contained in:
Florent Cailhol 2018-01-04 12:48:09 +01:00
parent 9334fd8547
commit 9f9e730ff3
3 changed files with 9 additions and 9 deletions

View File

@ -16,11 +16,11 @@ class FlagInitialModulesAsUsedPlugin {
if(!chunk.isInitial()) {
return;
}
chunk.forEachModule((module) => {
for(const module of chunk.modulesIterable) {
module.used = true;
module.usedExports = true;
module.addReason(null, null, this.explanation);
});
}
});
});
});

View File

@ -115,11 +115,11 @@ module.exports = class HotModuleReplacementPlugin {
const currentChunk = compilation.chunks.find(chunk => chunk.id === chunkId);
if(currentChunk) {
const newModules = currentChunk.getModules().filter(module => module.hotUpdate);
const allModules = {};
currentChunk.forEachModule(module => {
allModules[module.id] = true;
});
const removedModules = records.chunkModuleIds[chunkId].filter(id => !allModules[id]);
const allModules = new Set();
for(const module of currentChunk.modulesIterable) {
allModules.add(module.id);
}
const removedModules = records.chunkModuleIds[chunkId].filter(id => !allModules.has(id));
if(newModules.length > 0 || removedModules.length > 0) {
const source = hotUpdateChunkTemplate.render(chunkId, newModules, removedModules, compilation.hash, compilation.moduleTemplates.javascript, compilation.dependencyTemplates);
const filename = compilation.getPath(hotUpdateChunkFilename, {

View File

@ -12,7 +12,7 @@ class EnsureChunkConditionsPlugin {
const handler = (chunks) => {
let changed = false;
chunks.forEach((chunk) => {
chunk.forEachModule((module) => {
for(const module of chunk.modulesIterable) {
if(!module.chunkCondition) return;
if(!module.chunkCondition(chunk)) {
let usedChunks = triesMap.get(module);
@ -30,7 +30,7 @@ class EnsureChunkConditionsPlugin {
chunk.removeModule(module);
changed = true;
}
});
}
});
if(changed) return true;
};