| | |
| | | |
| | | const Dependency = require("../Dependency"); |
| | | const makeSerializable = require("../util/makeSerializable"); |
| | | const { ImportPhaseUtils } = require("./ImportPhase"); |
| | | const ModuleDependency = require("./ModuleDependency"); |
| | | |
| | | /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */ |
| | |
| | | |
| | | class ImportDependency extends ModuleDependency { |
| | | /** |
| | | * Creates an instance of ImportDependency. |
| | | * @param {string} request the request |
| | | * @param {Range} range expression range |
| | | * @param {RawReferencedExports | null} referencedExports list of referenced exports |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns an identifier to merge equal requests. |
| | | * @returns {string | null} an identifier to merge equal requests |
| | | */ |
| | | getResourceIdentifier() { |
| | | let str = super.getResourceIdentifier(); |
| | | // We specifically use this check to avoid writing the default (`evaluation` or `0`) value and save memory |
| | | if (this.phase) { |
| | | str += `|phase${ImportPhaseUtils.stringify(this.phase)}`; |
| | | } |
| | | if (this.attributes) { |
| | | str += `|importAttributes${JSON.stringify(this.attributes)}`; |
| | | str += `|attributes${JSON.stringify(this.attributes)}`; |
| | | } |
| | | return str; |
| | | } |
| | |
| | | */ |
| | | getReferencedExports(moduleGraph, runtime) { |
| | | if (!this.referencedExports) return Dependency.EXPORTS_OBJECT_REFERENCED; |
| | | /** @type {ReferencedExports} */ |
| | | const refs = []; |
| | | for (const referencedExport of this.referencedExports) { |
| | | if (referencedExport[0] === "default") { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Serializes this instance into the provided serializer context. |
| | | * @param {ObjectSerializerContext} context context |
| | | */ |
| | | serialize(context) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Restores this instance from the provided deserializer context. |
| | | * @param {ObjectDeserializerContext} context context |
| | | */ |
| | | deserialize(context) { |
| | |
| | | ModuleDependency.Template |
| | | ) { |
| | | /** |
| | | * Applies the plugin by registering its hooks on the compiler. |
| | | * @param {Dependency} dependency the dependency for which the template should be applied |
| | | * @param {ReplaceSource} source the current replace source which can be modified |
| | | * @param {DependencyTemplateContext} templateContext the context object |
| | |
| | | const block = /** @type {AsyncDependenciesBlock} */ ( |
| | | moduleGraph.getParentBlock(dep) |
| | | ); |
| | | const content = runtimeTemplate.moduleNamespacePromise({ |
| | | let content = runtimeTemplate.moduleNamespacePromise({ |
| | | chunkGraph, |
| | | block, |
| | | module: /** @type {Module} */ (moduleGraph.getModule(dep)), |
| | |
| | | runtimeRequirements |
| | | }); |
| | | |
| | | // For source phase imports, unwrap the default export |
| | | // import.source() should return the source directly, not a namespace |
| | | if (ImportPhaseUtils.isSource(dep.phase)) { |
| | | content = `${content}.then(${runtimeTemplate.returningFunction( |
| | | 'm["default"]', |
| | | "m" |
| | | )})`; |
| | | } |
| | | |
| | | source.replace(dep.range[0], dep.range[1] - 1, content); |
| | | } |
| | | }; |