* 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
(module, runtime)
| 45 | * @returns {CodeGenerationResult} the CodeGenerationResult |
| 46 | */ |
| 47 | get(module, runtime) { |
| 48 | const entry = this.map.get(module); |
| 49 | if (entry === undefined) { |
| 50 | throw new Error( |
| 51 | `No code generation entry for ${module.identifier()} (existing entries: ${Array.from( |
| 52 | this.map.keys(), |
| 53 | (m) => m.identifier() |
| 54 | ).join(", ")})` |
| 55 | ); |
| 56 | } |
| 57 | if (runtime === undefined) { |
| 58 | if (entry.size > 1) { |
| 59 | const results = new Set(entry.values()); |
| 60 | if (results.size !== 1) { |
| 61 | throw new Error( |
| 62 | `No unique code generation entry for unspecified runtime for ${module.identifier()} (existing runtimes: ${Array.from( |
| 63 | entry.keys(), |
| 64 | (r) => runtimeToString(r) |
| 65 | ).join(", ")}). |
| 66 | Caller might not support runtime-dependent code generation (opt-out via optimization.usedExports: "global").` |
| 67 | ); |
| 68 | } |
| 69 | return /** @type {CodeGenerationResult} */ (first(results)); |
| 70 | } |
| 71 | return /** @type {CodeGenerationResult} */ (entry.values().next().value); |
| 72 | } |
| 73 | const result = entry.get(runtime); |
| 74 | if (result === undefined) { |
| 75 | throw new Error( |
| 76 | `No code generation entry for runtime ${runtimeToString( |
| 77 | runtime |
| 78 | )} for ${module.identifier()} (existing runtimes: ${Array.from( |
| 79 | entry.keys(), |
| 80 | (r) => runtimeToString(r) |
| 81 | ).join(", ")})` |
| 82 | ); |
| 83 | } |
| 84 | return result; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Reports whether a module has a stored result for the requested runtime, or |
no test coverage detected