| | |
| | | /** @typedef {import("./util/comparators").DependencySourceOrder} DependencySourceOrder */ |
| | | |
| | | /** |
| | | * Defines the optimization bailout function callback. |
| | | * @callback OptimizationBailoutFunction |
| | | * @param {RequestShortener} requestShortener |
| | | * @returns {string} |
| | | */ |
| | | |
| | | /** @type {Iterable<ModuleGraphConnection>} */ |
| | | const EMPTY_SET = new Set(); |
| | | |
| | | /** |
| | | * Gets connections by key. |
| | | * @template {Module | null | undefined} T |
| | | * @param {SortableSet<ModuleGraphConnection>} set input |
| | | * @param {(connection: ModuleGraphConnection) => T} getKey function to extract key from connection |
| | | * @returns {ReadonlyMap<T, ReadonlyArray<ModuleGraphConnection>>} mapped by key |
| | | */ |
| | | const getConnectionsByKey = (set, getKey) => { |
| | | /** @type {Map<T, ModuleGraphConnection[]>} */ |
| | | const map = new Map(); |
| | | /** @type {T | 0} */ |
| | | let lastKey = 0; |
| | |
| | | }; |
| | | |
| | | /** |
| | | * Gets connections by origin module. |
| | | * @param {SortableSet<ModuleGraphConnection>} set input |
| | | * @returns {ReadonlyMap<Module | undefined | null, ReadonlyArray<ModuleGraphConnection>>} mapped by origin module |
| | | */ |
| | |
| | | getConnectionsByKey(set, (connection) => connection.originModule); |
| | | |
| | | /** |
| | | * Gets connections by module. |
| | | * @param {SortableSet<ModuleGraphConnection>} set input |
| | | * @returns {ReadonlyMap<Module | undefined, ReadonlyArray<ModuleGraphConnection>>} mapped by module |
| | | */ |
| | |
| | | /** @typedef {import("./dependencies/HarmonyExportImportedSpecifierDependency").idsSymbol} HarmonyExportImportedSpecifierDependencyIDsSymbol */ |
| | | |
| | | /** |
| | | * Defines the known meta type used by this module. |
| | | * @typedef {object} KnownMeta |
| | | * @property {Map<Module, string>=} importVarMap |
| | | * @property {Map<Module, string>=} deferredImportVarMap |
| | |
| | | * @private |
| | | */ |
| | | this._dependencySourceOrderMap = new WeakMap(); |
| | | |
| | | /** |
| | | * @type {Set<Module>} |
| | | * @private |
| | | */ |
| | | this._modulesNeedingSort = new Set(); |
| | | } |
| | | |
| | | /** |
| | | * Get module graph module. |
| | | * @param {Module} module the module |
| | | * @returns {ModuleGraphModule} the internal module |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Updates parents using the provided dependency. |
| | | * @param {Dependency} dependency the dependency |
| | | * @param {DependenciesBlock} block parent block |
| | | * @param {Module} module parent module |
| | |
| | | } |
| | | |
| | | /** |
| | | * Sets parent dependencies block index. |
| | | * @param {Dependency} dependency the dependency |
| | | * @param {number} index the index |
| | | * @returns {void} |
| | |
| | | } |
| | | |
| | | /** |
| | | * Gets parent module. |
| | | * @param {Dependency} dependency the dependency |
| | | * @returns {Module | undefined} parent module |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns parent block. |
| | | * @param {Dependency} dependency the dependency |
| | | * @returns {DependenciesBlock | undefined} parent block |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Gets parent block index. |
| | | * @param {Dependency} dependency the dependency |
| | | * @returns {number} index |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Sets resolved module. |
| | | * @param {Module | null} originModule the referencing module |
| | | * @param {Dependency} dependency the referencing dependency |
| | | * @param {Module} module the referenced module |
| | |
| | | } |
| | | |
| | | /** |
| | | * Updates module using the provided dependency. |
| | | * @param {Dependency} dependency the referencing dependency |
| | | * @param {Module} module the referenced module |
| | | * @returns {void} |
| | |
| | | } |
| | | |
| | | /** |
| | | * 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 |
| | |
| | | // import { a, b } from "lib" -> a and b have the same source order -> a = b = 1 |
| | | // import { d } from "lib/d" -> d = 2 |
| | | const currentSourceOrder = |
| | | /** @type { HarmonyImportSideEffectDependency | HarmonyImportSpecifierDependency} */ ( |
| | | dependency |
| | | ).sourceOrder; |
| | | /** @type {HarmonyImportSideEffectDependency | HarmonyImportSpecifierDependency} */ |
| | | (dependency).sourceOrder; |
| | | |
| | | // lib/index.js (reexport) |
| | | // import { a } from "lib/a" -> a = 0 |
| | | // import { b } from "lib/b" -> b = 1 |
| | | const originSourceOrder = |
| | | /** @type { HarmonyImportSideEffectDependency | HarmonyImportSpecifierDependency} */ ( |
| | | originDependency |
| | | ).sourceOrder; |
| | | /** @type {HarmonyImportSideEffectDependency | HarmonyImportSpecifierDependency} */ |
| | | (originDependency).sourceOrder; |
| | | if ( |
| | | typeof currentSourceOrder === "number" && |
| | | typeof originSourceOrder === "number" |
| | |
| | | sub: originSourceOrder |
| | | }); |
| | | |
| | | // If dependencies like HarmonyImportSideEffectDependency and HarmonyImportSpecifierDependency have a SourceOrder, |
| | | // we sort based on it; otherwise, we preserve the original order. |
| | | sortWithSourceOrder( |
| | | parentModule.dependencies, |
| | | this._dependencySourceOrderMap |
| | | ); |
| | | |
| | | for (const [index, dep] of parentModule.dependencies.entries()) { |
| | | this.setParentDependenciesBlockIndex(dep, index); |
| | | } |
| | | // Save for later batch sorting |
| | | this._modulesNeedingSort.add(parentModule); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Finish update parent. |
| | | * @returns {void} |
| | | */ |
| | | finishUpdateParent() { |
| | | if (this._modulesNeedingSort.size === 0) { |
| | | return; |
| | | } |
| | | for (const mod of this._modulesNeedingSort) { |
| | | // If dependencies like HarmonyImportSideEffectDependency and HarmonyImportSpecifierDependency have a SourceOrder, |
| | | // we sort based on it; otherwise, we preserve the original order. |
| | | sortWithSourceOrder( |
| | | mod.dependencies, |
| | | this._dependencySourceOrderMap, |
| | | (dep, index) => this.setParentDependenciesBlockIndex(dep, index) |
| | | ); |
| | | } |
| | | this._modulesNeedingSort.clear(); |
| | | } |
| | | |
| | | /** |
| | | * Removes connection. |
| | | * @param {Dependency} dependency the referencing dependency |
| | | * @returns {void} |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Adds the provided dependency to the module graph. |
| | | * @param {Dependency} dependency the referencing dependency |
| | | * @param {string} explanation an explanation |
| | | * @returns {void} |
| | |
| | | } |
| | | |
| | | /** |
| | | * Clones module attributes. |
| | | * @param {Module} sourceModule the source module |
| | | * @param {Module} targetModule the target module |
| | | * @returns {void} |
| | |
| | | } |
| | | |
| | | /** |
| | | * Removes module attributes. |
| | | * @param {Module} module the module |
| | | * @returns {void} |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Removes all module attributes. |
| | | * @returns {void} |
| | | */ |
| | | removeAllModuleAttributes() { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Move module connections. |
| | | * @param {Module} oldModule the old referencing module |
| | | * @param {Module} newModule the new referencing module |
| | | * @param {FilterConnection} filterConnection filter predicate for replacement |
| | |
| | | } |
| | | |
| | | /** |
| | | * Copies outgoing module connections. |
| | | * @param {Module} oldModule the old referencing module |
| | | * @param {Module} newModule the new referencing module |
| | | * @param {FilterConnection} filterConnection filter predicate for replacement |
| | |
| | | } |
| | | |
| | | /** |
| | | * Adds the provided module to the module graph. |
| | | * @param {Module} module the referenced module |
| | | * @param {string} explanation an explanation why it's referenced |
| | | * @returns {void} |
| | |
| | | } |
| | | |
| | | /** |
| | | * Gets resolved module. |
| | | * @param {Dependency} dependency the dependency to look for a referenced module |
| | | * @returns {Module | null} the referenced module |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns the connection. |
| | | * @param {Dependency} dependency the dependency to look for a referenced module |
| | | * @returns {ModuleGraphConnection | undefined} the connection |
| | | */ |
| | |
| | | mgm._unassignedConnections && |
| | | mgm._unassignedConnections.length !== 0 |
| | | ) { |
| | | /** @type {undefined | ModuleGraphConnection} */ |
| | | let foundConnection; |
| | | for (const connection of mgm._unassignedConnections) { |
| | | this._dependencyMap.set( |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns the referenced module. |
| | | * @param {Dependency} dependency the dependency to look for a referenced module |
| | | * @returns {Module | null} the referenced module |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns the referencing module. |
| | | * @param {Dependency} dependency the dependency to look for a referencing module |
| | | * @returns {Module | null} the referencing module |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Gets resolved origin. |
| | | * @param {Dependency} dependency the dependency to look for a referencing module |
| | | * @returns {Module | null} the original referencing module |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Gets incoming connections. |
| | | * @param {Module} module the module |
| | | * @returns {Iterable<ModuleGraphConnection>} reasons why a module is included |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Gets outgoing connections. |
| | | * @param {Module} module the module |
| | | * @returns {Iterable<ModuleGraphConnection>} list of outgoing connections |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Gets incoming connections by origin module. |
| | | * @param {Module} module the module |
| | | * @returns {ReadonlyMap<Module | undefined | null, ReadonlyArray<ModuleGraphConnection>>} reasons why a module is included, in a map by source module |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Gets outgoing connections by module. |
| | | * @param {Module} module the module |
| | | * @returns {ReadonlyMap<Module | undefined, ReadonlyArray<ModuleGraphConnection>> | undefined} connections to modules, in a map by module |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns the module profile. |
| | | * @param {Module} module the module |
| | | * @returns {ModuleProfile | undefined} the module profile |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Updates profile using the provided module. |
| | | * @param {Module} module the module |
| | | * @param {ModuleProfile | undefined} profile the module profile |
| | | * @returns {void} |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns the issuer module. |
| | | * @param {Module} module the module |
| | | * @returns {Issuer} the issuer module |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Updates issuer using the provided module. |
| | | * @param {Module} module the module |
| | | * @param {Module | null} issuer the issuer module |
| | | * @returns {void} |
| | |
| | | } |
| | | |
| | | /** |
| | | * Sets issuer if unset. |
| | | * @param {Module} module the module |
| | | * @param {Module | null} issuer the issuer module |
| | | * @returns {void} |
| | |
| | | } |
| | | |
| | | /** |
| | | * Gets optimization bailout. |
| | | * @param {Module} module the module |
| | | * @returns {OptimizationBailouts} optimization bailouts |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Gets provided exports. |
| | | * @param {Module} module the module |
| | | * @returns {null | true | ExportInfoName[]} the provided exports |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Checks whether this module graph is export provided. |
| | | * @param {Module} module the module |
| | | * @param {ExportInfoName | ExportInfoName[]} exportName a name of an export |
| | | * @returns {boolean | null} true, if the export is provided by the module. |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns info about the exports. |
| | | * @param {Module} module the module |
| | | * @returns {ExportsInfo} info about the exports |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns info about the export. |
| | | * @param {Module} module the module |
| | | * @param {string} exportName the export |
| | | * @returns {ExportInfo} info about the export |
| | |
| | | } |
| | | |
| | | /** |
| | | * Gets read only export info. |
| | | * @param {Module} module the module |
| | | * @param {string} exportName the export |
| | | * @returns {ExportInfo} info about the export (do not modify) |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns the used exports. |
| | | * @param {Module} module the module |
| | | * @param {RuntimeSpec} runtime the runtime |
| | | * @returns {false | true | SortableSet<string> | null} the used exports |
| | |
| | | } |
| | | |
| | | /** |
| | | * Gets pre order index. |
| | | * @param {Module} module the module |
| | | * @returns {number | null} the index of the module |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Gets post order index. |
| | | * @param {Module} module the module |
| | | * @returns {number | null} the index of the module |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Sets pre order index. |
| | | * @param {Module} module the module |
| | | * @param {number} index the index of the module |
| | | * @returns {void} |
| | |
| | | } |
| | | |
| | | /** |
| | | * Sets pre order index if unset. |
| | | * @param {Module} module the module |
| | | * @param {number} index the index of the module |
| | | * @returns {boolean} true, if the index was set |
| | |
| | | } |
| | | |
| | | /** |
| | | * Sets post order index. |
| | | * @param {Module} module the module |
| | | * @param {number} index the index of the module |
| | | * @returns {void} |
| | |
| | | } |
| | | |
| | | /** |
| | | * Sets post order index if unset. |
| | | * @param {Module} module the module |
| | | * @param {number} index the index of the module |
| | | * @returns {boolean} true, if the index was set |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns the depth of the module. |
| | | * @param {Module} module the module |
| | | * @returns {number | null} the depth of the module |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Updates depth using the provided module. |
| | | * @param {Module} module the module |
| | | * @param {number} depth the depth of the module |
| | | * @returns {void} |
| | |
| | | } |
| | | |
| | | /** |
| | | * Sets depth if lower. |
| | | * @param {Module} module the module |
| | | * @param {number} depth the depth of the module |
| | | * @returns {boolean} true, if the depth was set |
| | |
| | | } |
| | | |
| | | /** |
| | | * Checks whether this module graph is async. |
| | | * @param {Module} module the module |
| | | * @returns {boolean} true, if the module is async |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Checks whether this module graph is deferred. |
| | | * @param {Module} module the module |
| | | * @returns {boolean} true, if the module is used as a deferred module at least once |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Updates async using the provided module. |
| | | * @param {Module} module the module |
| | | * @returns {void} |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns metadata. |
| | | * @param {MetaKey} thing any thing |
| | | * @returns {Meta} metadata |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Gets meta if existing. |
| | | * @param {MetaKey} thing any thing |
| | | * @returns {Meta | undefined} metadata |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Processes the provided cache stage. |
| | | * @param {string=} cacheStage a persistent stage name for caching |
| | | */ |
| | | freeze(cacheStage) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns computed value or cached. |
| | | * @template {EXPECTED_ANY[]} T |
| | | * @template R |
| | | * @param {(moduleGraph: ModuleGraph, ...args: T) => R} fn computer |
| | |
| | | } |
| | | |
| | | /** |
| | | * Sets module mem caches. |
| | | * @param {ModuleMemCaches} moduleMemCaches mem caches for modules for better caching |
| | | */ |
| | | setModuleMemCaches(moduleMemCaches) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Dependency cache provide. |
| | | * @template {Dependency} D |
| | | * @template {EXPECTED_ANY[]} ARGS |
| | | * @template R |
| | |
| | | |
| | | // TODO remove in webpack 6 |
| | | /** |
| | | * Gets module graph for module. |
| | | * @deprecated |
| | | * @param {Module} module the module |
| | | * @param {string} deprecateMessage message for the deprecation message |
| | | * @param {string} deprecationCode code for the deprecation |
| | |
| | | if (fn) return fn(module); |
| | | const newFn = util.deprecate( |
| | | /** |
| | | * Handles the callback logic for this hook. |
| | | * @param {Module} module the module |
| | | * @returns {ModuleGraph} the module graph |
| | | */ |
| | |
| | | |
| | | // TODO remove in webpack 6 |
| | | /** |
| | | * Sets module graph for module. |
| | | * @deprecated |
| | | * @param {Module} module the module |
| | | * @param {ModuleGraph} moduleGraph the module graph |
| | | * @returns {void} |
| | |
| | | |
| | | // TODO remove in webpack 6 |
| | | /** |
| | | * Clear module graph for module. |
| | | * @deprecated |
| | | * @param {Module} module the module |
| | | * @returns {void} |
| | | */ |