| | |
| | | |
| | | /** @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 |
| | |
| | | } |
| | | |
| | | /** |
| | | * 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 |
| | |
| | | } |
| | | |
| | | /** |
| | | * 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) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * 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 |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns an arbitrary metadata entry recorded during code generation. |
| | | * @param {Module} module the module |
| | | * @param {RuntimeSpec} runtime runtime(s) |
| | | * @param {string} key data key |
| | |
| | | } |
| | | |
| | | /** |
| | | * 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 |
| | |
| | | } |
| | | |
| | | /** |
| | | * 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); |
| | | } |
| | | } |