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