MCPcopy
hub / github.com/webpack/webpack / generateModuleRemapping

Function generateModuleRemapping

lib/ExternalModule.js:522–555  ·  view source on GitHub ↗
(
	input,
	exportsInfo,
	runtime,
	runtimeTemplate
)

Source from the content-addressed store, hash-verified

520 * @returns {string | undefined} the module remapping
521 */
522const generateModuleRemapping = (
523 input,
524 exportsInfo,
525 runtime,
526 runtimeTemplate
527) => {
528 if (exportsInfo.otherExportsInfo.getUsed(runtime) === UsageState.Unused) {
529 /** @type {string[]} */
530 const properties = [];
531 for (const exportInfo of exportsInfo.orderedExports) {
532 const used = exportInfo.getUsedName(exportInfo.name, runtime);
533 if (!used) continue;
534 const nestedInfo = exportInfo.getNestedExportsInfo();
535 if (nestedInfo) {
536 const nestedExpr = generateModuleRemapping(
537 `${input}${propertyAccess([exportInfo.name])}`,
538 nestedInfo
539 );
540 if (nestedExpr) {
541 properties.push(`[${JSON.stringify(used)}]: y(${nestedExpr})`);
542 continue;
543 }
544 }
545 properties.push(
546 `[${JSON.stringify(used)}]: ${
547 /** @type {RuntimeTemplate} */ (runtimeTemplate).returningFunction(
548 `${input}${propertyAccess([exportInfo.name])}`
549 )
550 }`
551 );
552 }
553 return `x({ ${properties.join(", ")} })`;
554 }
555};
556
557/**
558 * Gets source for module external.

Callers 1

Calls 6

propertyAccessFunction · 0.85
returningFunctionMethod · 0.80
getUsedMethod · 0.45
getUsedNameMethod · 0.45
getNestedExportsInfoMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected