MCPcopy
hub / github.com/webpack/webpack / codeGeneration

Method codeGeneration

lib/sharing/ProvideSharedModule.js:147–178  ·  view source on GitHub ↗

* Generates code and runtime requirements for this module. * @param {CodeGenerationContext} context context for code generation * @returns {CodeGenerationResult} result

({ runtimeTemplate, chunkGraph })

Source from the content-addressed store, hash-verified

145 * @returns {CodeGenerationResult} result
146 */
147 codeGeneration({ runtimeTemplate, chunkGraph }) {
148 const runtimeRequirements = new Set([RuntimeGlobals.initializeSharing]);
149 const code = `register(${JSON.stringify(this._name)}, ${JSON.stringify(
150 this._version || "0"
151 )}, ${
152 this._eager
153 ? runtimeTemplate.syncModuleFactory({
154 dependency: this.dependencies[0],
155 chunkGraph,
156 request: this._request,
157 runtimeRequirements
158 })
159 : runtimeTemplate.asyncModuleFactory({
160 block: this.blocks[0],
161 chunkGraph,
162 request: this._request,
163 runtimeRequirements
164 })
165 }${this._eager ? ", 1" : ""});`;
166 /** @type {Sources} */
167 const sources = new Map();
168 /** @type {CodeGenerationResultData} */
169 const data = new Map();
170 data.set("share-init", [
171 {
172 shareScope: this._shareScope,
173 initStage: 10,
174 init: code
175 }
176 ]);
177 return { sources, data, runtimeRequirements };
178 }
179
180 /**
181 * Serializes this instance into the provided serializer context.

Callers

nothing calls this directly

Calls 3

syncModuleFactoryMethod · 0.80
asyncModuleFactoryMethod · 0.80
setMethod · 0.45

Tested by

no test coverage detected