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

Method sourceDependency

lib/javascript/JavascriptGenerator.js:123–183  ·  view source on GitHub ↗

* Processes the provided module. * @param {Module} 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 which ca

(module, dependency, initFragments, source, generateContext)

Source from the content-addressed store, hash-verified

121 * @returns {void}
122 */
123 sourceDependency(module, dependency, initFragments, source, generateContext) {
124 const constructor =
125 /** @type {DependencyConstructor} */
126 (dependency.constructor);
127 const template = generateContext.dependencyTemplates.get(constructor);
128 if (!template) {
129 throw new Error(
130 `No template for dependency: ${dependency.constructor.name}`
131 );
132 }
133
134 /** @type {InitFragment<GenerateContext>[] | undefined} */
135 let chunkInitFragments;
136
137 /** @type {DependencyTemplateContext} */
138 const templateContext = {
139 runtimeTemplate: generateContext.runtimeTemplate,
140 dependencyTemplates: generateContext.dependencyTemplates,
141 moduleGraph: generateContext.moduleGraph,
142 chunkGraph: generateContext.chunkGraph,
143 module,
144 runtime: generateContext.runtime,
145 runtimeRequirements: generateContext.runtimeRequirements,
146 concatenationScope: generateContext.concatenationScope,
147 codeGenerationResults:
148 /** @type {NonNullable<GenerateContext["codeGenerationResults"]>} */
149 (generateContext.codeGenerationResults),
150 initFragments,
151 get chunkInitFragments() {
152 if (!chunkInitFragments) {
153 const data =
154 /** @type {NonNullable<GenerateContext["getData"]>} */
155 (generateContext.getData)();
156 chunkInitFragments = data.get("chunkInitFragments");
157 if (!chunkInitFragments) {
158 chunkInitFragments = [];
159 data.set("chunkInitFragments", chunkInitFragments);
160 }
161 }
162
163 return chunkInitFragments;
164 }
165 };
166
167 template.apply(dependency, source, templateContext);
168
169 // TODO remove in webpack 6
170 if ("getInitFragments" in template) {
171 const fragments = deprecatedGetInitFragments(
172 template,
173 dependency,
174 templateContext
175 );
176
177 if (fragments) {
178 for (const fragment of fragments) {
179 initFragments.push(fragment);
180 }

Callers 2

sourceBlockMethod · 0.95
sourceModuleMethod · 0.95

Calls 3

applyMethod · 0.65
getMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected