MCPcopy
hub / github.com/webpack/webpack / processDependencyForResolving

Method processDependencyForResolving

lib/Compilation.js:2027–2118  ·  view source on GitHub ↗
(dep)

Source from the content-addressed store, hash-verified

2025 * @returns {void}
2026 */
2027 const processDependencyForResolving = (dep) => {
2028 const resourceIdent = dep.getResourceIdentifier();
2029 if (resourceIdent !== undefined && resourceIdent !== null) {
2030 const category = dep.category;
2031 const constructor =
2032 /** @type {DependencyConstructor} */
2033 (dep.constructor);
2034 if (factoryCacheKey === constructor) {
2035 // Fast path 1: same constructor as prev item
2036 if (listCacheKey1 === category && listCacheKey2 === resourceIdent) {
2037 // Super fast path 1: also same resource
2038 listCacheValue.push(dep);
2039 return;
2040 }
2041 } else {
2042 const factory = this.dependencyFactories.get(constructor);
2043 if (factory === undefined) {
2044 throw new Error(
2045 `No module factory available for dependency type: ${constructor.name}`
2046 );
2047 }
2048 if (factoryCacheKey2 === factory) {
2049 // Fast path 2: same factory as prev item
2050 factoryCacheKey = constructor;
2051 if (listCacheKey1 === category && listCacheKey2 === resourceIdent) {
2052 // Super fast path 2: also same resource
2053 listCacheValue.push(dep);
2054 return;
2055 }
2056 } else {
2057 // Slow path
2058 if (factoryCacheKey2 !== undefined) {
2059 // Archive last cache entry
2060 if (dependencies === undefined) dependencies = new Map();
2061 dependencies.set(
2062 factoryCacheKey2,
2063 /** @type {FactoryCacheValue} */ (factoryCacheValue)
2064 );
2065 factoryCacheValue = dependencies.get(factory);
2066 if (factoryCacheValue === undefined) {
2067 factoryCacheValue = new Map();
2068 }
2069 } else {
2070 factoryCacheValue = new Map();
2071 }
2072 factoryCacheKey = constructor;
2073 factoryCacheKey2 = factory;
2074 }
2075 }
2076 // Here webpack is using heuristic that assumes
2077 // mostly esm dependencies would be used
2078 // so we don't allocate extra string for them
2079 const cacheKey =
2080 category === esmDependencyCategory
2081 ? resourceIdent
2082 : `${category}${resourceIdent}`;
2083 let list = /** @type {FactoryCacheValue} */ (factoryCacheValue).get(
2084 cacheKey

Callers

nothing calls this directly

Calls 5

getResourceIdentifierMethod · 0.45
pushMethod · 0.45
getMethod · 0.45
setMethod · 0.45
getContextMethod · 0.45

Tested by

no test coverage detected