MCPcopy
hub / github.com/webpack/webpack / runtimeConditionExpression

Method runtimeConditionExpression

lib/RuntimeTemplate.js:1004–1031  ·  view source on GitHub ↗

* Runtime condition expression. * @param {object} options options object * @param {ChunkGraph} options.chunkGraph the chunk graph * @param {RuntimeSpec=} options.runtime runtime for which this code will be generated * @param {RuntimeSpec | boolean=} options.runtimeCondition only execute the

({
		chunkGraph,
		runtimeCondition,
		runtime,
		runtimeRequirements
	})

Source from the content-addressed store, hash-verified

1002 * @returns {string} expression
1003 */
1004 runtimeConditionExpression({
1005 chunkGraph,
1006 runtimeCondition,
1007 runtime,
1008 runtimeRequirements
1009 }) {
1010 if (runtimeCondition === undefined) return "true";
1011 if (typeof runtimeCondition === "boolean") return `${runtimeCondition}`;
1012 /** @type {Set<string>} */
1013 const positiveRuntimeIds = new Set();
1014 forEachRuntime(runtimeCondition, (runtime) =>
1015 positiveRuntimeIds.add(
1016 `${chunkGraph.getRuntimeId(/** @type {string} */ (runtime))}`
1017 )
1018 );
1019 /** @type {Set<string>} */
1020 const negativeRuntimeIds = new Set();
1021 forEachRuntime(subtractRuntime(runtime, runtimeCondition), (runtime) =>
1022 negativeRuntimeIds.add(
1023 `${chunkGraph.getRuntimeId(/** @type {string} */ (runtime))}`
1024 )
1025 );
1026 runtimeRequirements.add(RuntimeGlobals.runtimeId);
1027 return compileBooleanMatcher.fromLists(
1028 [...positiveRuntimeIds],
1029 [...negativeRuntimeIds]
1030 )(RuntimeGlobals.runtimeId);
1031 }
1032
1033 /**
1034 * Returns the import statement and the compat statement.

Callers 5

getContentMethod · 0.80
getEndContentMethod · 0.80
codeGenerationMethod · 0.80
applyMethod · 0.80
applyMethod · 0.80

Calls 4

forEachRuntimeFunction · 0.85
subtractRuntimeFunction · 0.85
getRuntimeIdMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected