* Generates code and runtime requirements for this module. * @param {CodeGenerationContext} context context for code generation * @returns {CodeGenerationResult} result
({ runtimeTemplate, moduleGraph, chunkGraph })
| 168 | * @returns {CodeGenerationResult} result |
| 169 | */ |
| 170 | codeGeneration({ runtimeTemplate, moduleGraph, chunkGraph }) { |
| 171 | const dep = /** @type {DelegatedSourceDependency} */ (this.dependencies[0]); |
| 172 | const sourceModule = moduleGraph.getModule(dep); |
| 173 | /** @type {string} */ |
| 174 | let str; |
| 175 | |
| 176 | if (!sourceModule) { |
| 177 | str = runtimeTemplate.throwMissingModuleErrorBlock({ |
| 178 | request: this.sourceRequest |
| 179 | }); |
| 180 | } else { |
| 181 | str = `module.exports = (${runtimeTemplate.moduleExports({ |
| 182 | module: sourceModule, |
| 183 | chunkGraph, |
| 184 | request: dep.request, |
| 185 | /** @type {RuntimeRequirements} */ |
| 186 | runtimeRequirements: new Set() |
| 187 | })})`; |
| 188 | |
| 189 | switch (this.delegationType) { |
| 190 | case "require": |
| 191 | str += `(${JSON.stringify(this.request)})`; |
| 192 | break; |
| 193 | case "object": |
| 194 | str += `[${JSON.stringify(this.request)}]`; |
| 195 | break; |
| 196 | } |
| 197 | |
| 198 | str += ";"; |
| 199 | } |
| 200 | |
| 201 | /** @type {Sources} */ |
| 202 | const sources = new Map(); |
| 203 | if (this.useSourceMap || this.useSimpleSourceMap) { |
| 204 | sources.set(JAVASCRIPT_TYPE, new OriginalSource(str, this.identifier())); |
| 205 | } else { |
| 206 | sources.set(JAVASCRIPT_TYPE, new RawSource(str)); |
| 207 | } |
| 208 | |
| 209 | return { |
| 210 | sources, |
| 211 | runtimeRequirements: RUNTIME_REQUIREMENTS |
| 212 | }; |
| 213 | } |
| 214 | |
| 215 | /** |
| 216 | * Returns the estimated size for the requested source type. |
nothing calls this directly
no test coverage detected