WXL
4 天以前 3bd962a6d7f61239c020e2dbbeb7341e5b842dd1
node_modules/webpack/lib/CodeGenerationResults.js
@@ -13,23 +13,33 @@
/** @typedef {import("webpack-sources").Source} Source */
/** @typedef {import("./Module")} Module */
/** @typedef {import("./Module").SourceType} SourceType */
/** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */
/** @typedef {import("./Module").CodeGenerationResultData} CodeGenerationResultData */
/** @typedef {import("./Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
/** @typedef {typeof import("./util/Hash")} Hash */
/** @typedef {import("./util/Hash").HashFunction} HashFunction */
/** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
/**
 * Stores code generation results keyed by module and runtime so later stages
 * can retrieve emitted sources, metadata, and derived hashes.
 */
class CodeGenerationResults {
   /**
    * @param {string | Hash} hashFunction the hash function to use
    * Initializes an empty result store and remembers which hash function should
    * be used when a result hash needs to be derived lazily.
    * @param {HashFunction} hashFunction the hash function to use
    */
   constructor(hashFunction = DEFAULTS.HASH_FUNCTION) {
      /** @type {Map<Module, RuntimeSpecMap<CodeGenerationResult>>} */
      this.map = new Map();
      /** @type {HashFunction} */
      this._hashFunction = hashFunction;
   }
   /**
    * Returns the code generation result for a module/runtime pair, rejecting
    * ambiguous lookups where no unique runtime-independent result exists.
    * @param {Module} module the module
    * @param {RuntimeSpec} runtime runtime(s)
    * @returns {CodeGenerationResult} the CodeGenerationResult
@@ -75,6 +85,8 @@
   }
   /**
    * Reports whether a module has a stored result for the requested runtime, or
    * a single unambiguous result when no runtime is specified.
    * @param {Module} module the module
    * @param {RuntimeSpec} runtime runtime(s)
    * @returns {boolean} true, when we have data for this
@@ -94,9 +106,11 @@
   }
   /**
    * Returns a generated source of the requested source type from a stored code
    * generation result.
    * @param {Module} module the module
    * @param {RuntimeSpec} runtime runtime(s)
    * @param {string} sourceType the source type
    * @param {SourceType} sourceType the source type
    * @returns {Source} a source
    */
   getSource(module, runtime, sourceType) {
@@ -106,6 +120,8 @@
   }
   /**
    * Returns the runtime requirements captured during code generation for the
    * requested module/runtime pair.
    * @param {Module} module the module
    * @param {RuntimeSpec} runtime runtime(s)
    * @returns {ReadOnlyRuntimeRequirements | null} runtime requirements
@@ -115,6 +131,7 @@
   }
   /**
    * Returns an arbitrary metadata entry recorded during code generation.
    * @param {Module} module the module
    * @param {RuntimeSpec} runtime runtime(s)
    * @param {string} key data key
@@ -126,6 +143,8 @@
   }
   /**
    * Returns a stable hash for the generated sources and runtime requirements,
    * computing and caching it on first access.
    * @param {Module} module the module
    * @param {RuntimeSpec} runtime runtime(s)
    * @returns {string} hash of the code generation
@@ -145,13 +164,21 @@
   }
   /**
    * Stores a code generation result for a module/runtime pair, creating the
    * per-module runtime map when needed.
    * @param {Module} module the module
    * @param {RuntimeSpec} runtime runtime(s)
    * @param {CodeGenerationResult} result result from module
    * @returns {void}
    */
   add(module, runtime, result) {
      const map = getOrInsert(this.map, module, () => new RuntimeSpecMap());
      const map = getOrInsert(
         this.map,
         module,
         () =>
            /** @type {RuntimeSpecMap<CodeGenerationResult>} */
            new RuntimeSpecMap()
      );
      map.set(runtime, result);
   }
}