MCPcopy
hub / github.com/webpack/webpack / sourceDependency

Method sourceDependency

lib/css/CssGenerator.js:201–248  ·  view source on GitHub ↗

* Processes the provided module. * @param {NormalModule} module the current module * @param {Dependency} dependency the dependency to generate * @param {InitFragment<GenerateContext>[]} initFragments mutable list of init fragments * @param {ReplaceSource} source the current replace source wh

(module, dependency, initFragments, source, generateContext)

Source from the content-addressed store, hash-verified

199 * @returns {void}
200 */
201 sourceDependency(module, dependency, initFragments, source, generateContext) {
202 const constructor =
203 /** @type {DependencyConstructor} */
204 (dependency.constructor);
205 const template = generateContext.dependencyTemplates.get(constructor);
206 if (!template) {
207 throw new Error(
208 `No template for dependency: ${dependency.constructor.name}`
209 );
210 }
211
212 /** @type {DependencyTemplateContext} */
213 /** @type {InitFragment<GenerateContext>[] | undefined} */
214 let chunkInitFragments;
215 /** @type {DependencyTemplateContext} */
216 const templateContext = {
217 runtimeTemplate: generateContext.runtimeTemplate,
218 dependencyTemplates: generateContext.dependencyTemplates,
219 moduleGraph: generateContext.moduleGraph,
220 chunkGraph: generateContext.chunkGraph,
221 module,
222 runtime: generateContext.runtime,
223 runtimeRequirements: generateContext.runtimeRequirements,
224 concatenationScope: generateContext.concatenationScope,
225 codeGenerationResults:
226 /** @type {CodeGenerationResults} */
227 (generateContext.codeGenerationResults),
228 initFragments,
229 cssData: generateContext.cssData,
230 type: generateContext.type,
231 get chunkInitFragments() {
232 if (!chunkInitFragments) {
233 const data =
234 /** @type {NonNullable<GenerateContext["getData"]>} */
235 (generateContext.getData)();
236 chunkInitFragments = data.get("chunkInitFragments");
237 if (!chunkInitFragments) {
238 chunkInitFragments = [];
239 data.set("chunkInitFragments", chunkInitFragments);
240 }
241 }
242
243 return chunkInitFragments;
244 }
245 };
246
247 template.apply(dependency, source, templateContext);
248 }
249
250 /**
251 * Processes the provided module.

Callers 1

sourceModuleMethod · 0.95

Calls 2

applyMethod · 0.65
getMethod · 0.45

Tested by

no test coverage detected