MCPcopy
hub / github.com/webpack/webpack / toCacheVersion

Function toCacheVersion

lib/DefinePlugin.js:313–347  ·  lib/DefinePlugin.js::toCacheVersion
(code)

Source from the content-addressed store, hash-verified

311 * @returns {string | undefined} result
312 */
313const toCacheVersion = (code) => {
314 if (code === null) {
315 return class="st">"null";
316 }
317 if (code === undefined) {
318 return class="st">"undefined";
319 }
320 if (Object.is(code, -0)) {
321 return class="st">"-0";
322 }
323 if (code instanceof RuntimeValue) {
324 return code.getCacheVersion();
325 }
326 if (code instanceof RegExp && code.toString) {
327 return code.toString();
328 }
329 if (typeof code === class="st">"function" && code.toString) {
330 return `(${code.toString()})`;
331 }
332 if (typeof code === class="st">"object") {
333 const items = Object.keys(code).map((key) => ({
334 key,
335 value: toCacheVersion(
336 /** @type {Record<string, CodeValue>} */
337 (code)[key]
338 )
339 }));
340 if (items.some(({ value }) => value === undefined)) return;
341 return `{${items.map(({ key, value }) => `${key}: ${value}`).join(class="st">", ")}}`;
342 }
343 if (typeof code === class="st">"bigint") {
344 return `${code}n`;
345 }
346 return `${code}`;
347};
348
349const PLUGIN_NAME = class="st">"DefinePlugin";
350const VALUE_DEP_PREFIX = `webpack/${PLUGIN_NAME} `;

Callers 1

Calls 3

keysMethod · 0.65
getCacheVersionMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected