MCPcopy
hub / github.com/webpack/webpack / updateParent

Method updateParent

lib/ModuleGraph.js:317–357  ·  lib/ModuleGraph.js::ModuleGraph.updateParent

* Updates parent using the provided dependency. * @param {Dependency} dependency the need update dependency * @param {ModuleGraphConnection=} connection the target connection * @param {Module=} parentModule the parent module * @returns {void}

(dependency, connection, parentModule)

Source from the content-addressed store, hash-verified

315 * @returns {void}
316 */
317 updateParent(dependency, connection, parentModule) {
318 if (this._dependencySourceOrderMap.has(dependency)) {
319 return;
320 }
321 if (!connection || !parentModule) {
322 return;
323 }
324 const originDependency = connection.dependency;
325
326 class="cm">// src/index.js
327 class="cm">// import { c } from class="st">"lib/c" -> c = 0
328 class="cm">// import { a, b } from class="st">"lib" -> a and b have the same source order -> a = b = 1
329 class="cm">// import { d } from class="st">"lib/d" -> d = 2
330 const currentSourceOrder =
331 /** @type {HarmonyImportSideEffectDependency | HarmonyImportSpecifierDependency} */
332 (dependency).sourceOrder;
333
334 class="cm">// lib/index.js (reexport)
335 class="cm">// import { a } from class="st">"lib/a" -> a = 0
336 class="cm">// import { b } from class="st">"lib/b" -> b = 1
337 const originSourceOrder =
338 /** @type {HarmonyImportSideEffectDependency | HarmonyImportSpecifierDependency} */
339 (originDependency).sourceOrder;
340 if (
341 typeof currentSourceOrder === class="st">"number" &&
342 typeof originSourceOrder === class="st">"number"
343 ) {
344 class="cm">// src/index.js
345 class="cm">// import { c } from class="st">"lib/c" -> c = 0
346 class="cm">// import { a } from class="st">"lib/a" -> a = 1.0 = 1(main) + 0.0(sub)
347 class="cm">// import { b } from class="st">"lib/b" -> b = 1.1 = 1(main) + 0.1(sub)
348 class="cm">// import { d } from class="st">"lib/d" -> d = 2
349 this._dependencySourceOrderMap.set(dependency, {
350 main: currentSourceOrder,
351 sub: originSourceOrder
352 });
353
354 class="cm">// Save for later batch sorting
355 this._modulesNeedingSort.add(parentModule);
356 }
357 }
358
359 /**
360 * Finish update parent.

Callers 1

Calls 3

hasMethod · 0.45
setMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected