MCPcopy
hub / github.com/webpack/webpack / getExportsType

Method getExportsType

lib/Module.js:655–714  ·  view source on GitHub ↗

* Returns export type. * @param {ModuleGraph} moduleGraph the module graph * @param {boolean | undefined} strict the importing module is strict * @returns {ExportsType} export type * "namespace": Exports is already a namespace object. namespace = exports. * "dynamic": Check at runtime if _

(moduleGraph, strict)

Source from the content-addressed store, hash-verified

653 * "default-with-named": Provide a namespace object with named and default export. namespace = { ...exports, default: exports }
654 */
655 getExportsType(moduleGraph, strict) {
656 switch (this.buildMeta && this.buildMeta.exportsType) {
657 case "flagged":
658 return strict ? "default-with-named" : "namespace";
659 case "namespace":
660 return "namespace";
661 case "default":
662 switch (/** @type {BuildMeta} */ (this.buildMeta).defaultObject) {
663 case "redirect":
664 return "default-with-named";
665 case "redirect-warn":
666 return strict ? "default-only" : "default-with-named";
667 default:
668 return "default-only";
669 }
670 case "dynamic": {
671 if (strict) return "default-with-named";
672 // Try to figure out value of __esModule by following reexports
673 const handleDefault = () => {
674 switch (/** @type {BuildMeta} */ (this.buildMeta).defaultObject) {
675 case "redirect":
676 case "redirect-warn":
677 return "default-with-named";
678 default:
679 return "default-only";
680 }
681 };
682 const exportInfo = moduleGraph.getReadOnlyExportInfo(
683 this,
684 "__esModule"
685 );
686 if (exportInfo.provided === false) {
687 return handleDefault();
688 }
689 const target = exportInfo.getTarget(moduleGraph);
690 if (
691 !target ||
692 !target.export ||
693 target.export.length !== 1 ||
694 target.export[0] !== "__esModule"
695 ) {
696 return "dynamic";
697 }
698 switch (
699 target.module.buildMeta &&
700 target.module.buildMeta.exportsType
701 ) {
702 case "flagged":
703 case "namespace":
704 return "namespace";
705 case "default":
706 return handleDefault();
707 default:
708 return "dynamic";
709 }
710 }
711 default:
712 return strict ? "default-with-named" : "dynamic";

Callers 6

getFakeMapMethod · 0.45
moduleNamespaceMethod · 0.45
importStatementMethod · 0.45
exportFromImportMethod · 0.45
processConnectionMethod · 0.45

Calls 2

getTargetMethod · 0.80
getReadOnlyExportInfoMethod · 0.45

Tested by

no test coverage detected