MCPcopy
hub / github.com/webpack/webpack / classify

Method classify

lib/LazyBarrel.js:218–300  ·  view source on GitHub ↗

* Classifies the re-export dependencies of a side-effect-free module (lazy barrel) * into deferrable groups and marks the deferred ones. * @param {Module} module the module whose dependencies are processed * @returns {boolean} true, when some dependencies were deferred

(module)

Source from the content-addressed store, hash-verified

216 * @returns {boolean} true, when some dependencies were deferred
217 */
218 classify(module) {
219 const modules = this._modules;
220 const factoryMeta = module.factoryMeta;
221 if (factoryMeta === undefined || !factoryMeta.sideEffectFree) {
222 return false;
223 }
224 const dependencies = module.dependencies;
225 const dependencyFactories = this._compilation.dependencyFactories;
226 /** @type {LazyBarrelInfo | undefined} */
227 let info;
228 let hasFallback = false;
229 for (const dep of dependencies) {
230 // TODO remove in webpack 6
231 // It may be missing on custom dependency types not extending the base Dependency
232 if (!("getLazyUntil" in dep)) continue;
233
234 const until = dep.getLazyUntil();
235 // null (eager) and LAZY_UNTIL_LOCAL (terminal) defer nothing; terminals are
236 // only consulted alongside a star re-export, so they are recorded below
237 if (until === null || until === Dependency.LAZY_UNTIL_LOCAL) continue;
238 // deferrable: setLazy is needed to toggle its deferred state
239 if (!("setLazy" in dep)) continue;
240 const resourceIdent = dep.getResourceIdentifier();
241 if (resourceIdent === null) continue;
242 const factory = dependencyFactories.get(
243 /** @type {DependencyConstructor} */ (dep.constructor)
244 );
245 if (factory === undefined) continue;
246 const category = dep.category;
247 // Match the request grouping key of `processDependencyForResolving`
248 const requestKey =
249 category === esmDependencyCategory
250 ? resourceIdent
251 : `${category}${resourceIdent}`;
252 if (info === undefined) info = new LazyBarrelInfo();
253 if (dep.isLazy()) {
254 info.addLazy(requestKey, dep, factory, dep.getContext());
255 }
256 if (until === Dependency.LAZY_UNTIL_ID) {
257 info.addForwardId(
258 /** @type {string} */ (dep.getLazyName()),
259 requestKey
260 );
261 } else if (until === Dependency.LAZY_UNTIL_FALLBACK) {
262 info.addFallback(requestKey);
263 hasFallback = true;
264 }
265 }
266 const state = modules.get(module);
267 // info is only created once a deferrable target exists, so it is never empty here
268 if (info === undefined) {
269 if (state !== undefined) modules.delete(module);
270 return false;
271 }
272 // terminals only matter together with a star re-export (to avoid building it
273 // for a locally-provided name); skip the extra pass otherwise
274 if (hasFallback) {
275 for (const dep of dependencies) {

Callers 1

Calls 14

addLazyMethod · 0.80
addForwardIdMethod · 0.80
addFallbackMethod · 0.80
addTerminalMethod · 0.80
getLazyUntilMethod · 0.45
getResourceIdentifierMethod · 0.45
getMethod · 0.45
isLazyMethod · 0.45
getContextMethod · 0.45
getLazyNameMethod · 0.45
deleteMethod · 0.45
requestMethod · 0.45

Tested by

no test coverage detected