MCPcopy
hub / github.com/webpack/webpack / setCachedModuleConstant

Method setCachedModuleConstant

lib/NodeStuffPlugin.js:167–217  ·  view source on GitHub ↗
(
					parser,
					expressionName,
					fn,
					property,
					warning
				)

Source from the content-addressed store, hash-verified

165 * @returns {void}
166 */
167 const setCachedModuleConstant = (
168 parser,
169 expressionName,
170 fn,
171 property,
172 warning
173 ) => {
174 parser.hooks.expression
175 .for(expressionName)
176 .tap(PLUGIN_NAME, (expr) => {
177 const dep = new CachedConstDependency(
178 JSON.stringify(fn(parser.state.module)),
179 /** @type {Range} */
180 (expr.range),
181 `__webpack_${property}__`
182 );
183 dep.loc = /** @type {DependencyLocation} */ (expr.loc);
184 parser.state.module.addPresentationalDependency(dep);
185
186 if (warning) {
187 parser.state.module.addWarning(
188 new NodeStuffInWebError(dep.loc, expressionName, warning)
189 );
190 }
191
192 return true;
193 });
194
195 if (
196 expressionName === IMPORT_META_FILENAME ||
197 expressionName === IMPORT_META_DIRNAME
198 ) {
199 hooks.propertyInDestructuring.tap(PLUGIN_NAME, (usingProperty) => {
200 if (property === usingProperty.id) {
201 if (warning) {
202 parser.state.module.addWarning(
203 new NodeStuffInWebError(
204 usingProperty.loc,
205 expressionName,
206 warning
207 )
208 );
209 }
210
211 return `${property}: ${JSON.stringify(
212 fn(parser.state.module)
213 )},`;
214 }
215 });
216 }
217 };
218
219 /**
220 * Updates constant using the provided parser.

Callers

nothing calls this directly

Calls 4

tapMethod · 0.80
fnFunction · 0.50
addWarningMethod · 0.45

Tested by

no test coverage detected