fix combining dependencies in Compilation

remove extra layer, use concatenated key instead
This commit is contained in:
Ivan Kopeykin 2020-05-28 01:23:54 +03:00
parent 2365361679
commit 0dd9aaf25b
1 changed files with 16 additions and 21 deletions

View File

@ -208,6 +208,7 @@ const {
/** @template T @typedef {Pick<AsyncSeriesHook<T>, "tap" | "tapAsync" | "tapPromise" | "name"> & FakeHookMarker} FakeHook<T> */
const esmDependencyCategory = "esm";
// TODO webpack 6: remove
const deprecatedNormalModuleLoaderHook = util.deprecate(
compilation => {
@ -1128,21 +1129,22 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
let factoryCacheKey;
let factoryCacheValue;
let factoryCacheValue2;
let listCacheKey1;
let listCacheKey2;
let listCacheKey;
let listCacheValue;
const processDependency = dep => {
this.moduleGraph.setParents(dep, currentBlock, module);
const resourceIdent = dep.getResourceIdentifier();
const category = dep.category;
const resourceIdent =
dep.category === esmDependencyCategory
? dep.getResourceIdentifier()
: `${dep.category}${dep.getResourceIdentifier()}`;
if (resourceIdent) {
const constructor = dep.constructor;
let mapByIdent;
let innerMap;
let factory;
if (factoryCacheKey === constructor) {
mapByIdent = factoryCacheValue;
if (listCacheKey1 === resourceIdent && listCacheKey2 === category) {
innerMap = factoryCacheValue;
if (listCacheKey === resourceIdent) {
listCacheValue.push(dep);
return;
}
@ -1153,23 +1155,17 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
`No module factory available for dependency type: ${dep.constructor.name}`
);
}
mapByIdent = dependencies.get(factory);
if (mapByIdent === undefined) {
dependencies.set(factory, (mapByIdent = new Map()));
innerMap = dependencies.get(factory);
if (innerMap === undefined) {
dependencies.set(factory, (innerMap = new Map()));
}
factoryCacheKey = constructor;
factoryCacheValue = mapByIdent;
factoryCacheValue = innerMap;
factoryCacheValue2 = factory;
}
let mapByCategory = mapByIdent.get(resourceIdent);
if (mapByCategory === undefined) {
mapByIdent.set(resourceIdent, (mapByCategory = new Map()));
}
let list = mapByCategory.get(category);
let list = innerMap.get(resourceIdent);
if (list === undefined) {
mapByCategory.set(category, (list = []));
innerMap.set(resourceIdent, (list = []));
sortedDependencies.push({
factory: factoryCacheValue2,
dependencies: list,
@ -1177,8 +1173,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
});
}
list.push(dep);
listCacheKey1 = resourceIdent;
listCacheKey2 = category;
listCacheKey = resourceIdent;
listCacheValue = list;
}
};