WXL
3 天以前 9bce51f651aad297ef9eb6df832bfdaf1de05d84
node_modules/webpack/lib/dependencies/ImportDependency.js
@@ -7,6 +7,7 @@
const Dependency = require("../Dependency");
const makeSerializable = require("../util/makeSerializable");
const { ImportPhaseUtils } = require("./ImportPhase");
const ModuleDependency = require("./ModuleDependency");
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
@@ -26,6 +27,7 @@
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
@@ -49,12 +51,17 @@
   }
   /**
    * 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;
   }
@@ -67,6 +74,7 @@
    */
   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") {
@@ -97,6 +105,7 @@
   }
   /**
    * Serializes this instance into the provided serializer context.
    * @param {ObjectSerializerContext} context context
    */
   serialize(context) {
@@ -108,6 +117,7 @@
   }
   /**
    * Restores this instance from the provided deserializer context.
    * @param {ObjectDeserializerContext} context context
    */
   deserialize(context) {
@@ -125,6 +135,7 @@
   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
@@ -139,7 +150,7 @@
      const block = /** @type {AsyncDependenciesBlock} */ (
         moduleGraph.getParentBlock(dep)
      );
      const content = runtimeTemplate.moduleNamespacePromise({
      let content = runtimeTemplate.moduleNamespacePromise({
         chunkGraph,
         block,
         module: /** @type {Module} */ (moduleGraph.getModule(dep)),
@@ -150,6 +161,15 @@
         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);
   }
};