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

Method updateParent

lib/ModuleGraph.js:317–357  ·  view source on GitHub ↗

* 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 // src/index.js
327 // import { c } from "lib/c" -> c = 0
328 // import { a, b } from "lib" -> a and b have the same source order -> a = b = 1
329 // import { d } from "lib/d" -> d = 2
330 const currentSourceOrder =
331 /** @type {HarmonyImportSideEffectDependency | HarmonyImportSpecifierDependency} */
332 (dependency).sourceOrder;
333
334 // lib/index.js (reexport)
335 // import { a } from "lib/a" -> a = 0
336 // import { b } from "lib/b" -> b = 1
337 const originSourceOrder =
338 /** @type {HarmonyImportSideEffectDependency | HarmonyImportSpecifierDependency} */
339 (originDependency).sourceOrder;
340 if (
341 typeof currentSourceOrder === "number" &&
342 typeof originSourceOrder === "number"
343 ) {
344 // src/index.js
345 // import { c } from "lib/c" -> c = 0
346 // import { a } from "lib/a" -> a = 1.0 = 1(main) + 0.0(sub)
347 // import { b } from "lib/b" -> b = 1.1 = 1(main) + 0.1(sub)
348 // import { d } from "lib/d" -> d = 2
349 this._dependencySourceOrderMap.set(dependency, {
350 main: currentSourceOrder,
351 sub: originSourceOrder
352 });
353
354 // 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