MCPcopy
hub / github.com/webpack/webpack / get

Method get

lib/CodeGenerationResults.js:47–85  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

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(", ")}).
66Caller 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

Callers 6

getSourceMethod · 0.95
getDataMethod · 0.95
getHashMethod · 0.95
executeModuleMethod · 0.95
hasMethod · 0.45

Calls 6

runtimeToStringFunction · 0.85
firstFunction · 0.85
keysMethod · 0.65
identifierMethod · 0.45
valuesMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected