MCPcopy
hub / github.com/webpack/webpack / moduleNamespace

Method moduleNamespace

lib/RuntimeTemplate.js:737–794  ·  view source on GitHub ↗

* Returns the expression. * @param {object} options options object * @param {Module} options.module the module * @param {ChunkGraph} options.chunkGraph the chunk graph * @param {string} options.request the request that should be printed as comment * @param {boolean=} options.strict if the

({
		module,
		chunkGraph,
		request,
		strict,
		weak,
		runtimeRequirements
	})

Source from the content-addressed store, hash-verified

735 * @returns {string} the expression
736 */
737 moduleNamespace({
738 module,
739 chunkGraph,
740 request,
741 strict,
742 weak,
743 runtimeRequirements
744 }) {
745 if (!module) {
746 return this.missingModule({
747 request
748 });
749 }
750 if (chunkGraph.getModuleId(module) === null) {
751 if (weak) {
752 // only weak referenced modules don't get an id
753 // we can always emit an error emitting code here
754 return this.weakError({
755 module,
756 chunkGraph,
757 request,
758 type: "expression"
759 });
760 }
761 throw new Error(
762 `RuntimeTemplate.moduleNamespace(): ${noModuleIdErrorMessage(
763 module,
764 chunkGraph
765 )}`
766 );
767 }
768 const moduleId = this.moduleId({
769 module,
770 chunkGraph,
771 request,
772 weak
773 });
774 const exportsType = module.getExportsType(chunkGraph.moduleGraph, strict);
775 switch (exportsType) {
776 case "namespace":
777 return this.moduleRaw({
778 module,
779 chunkGraph,
780 request,
781 weak,
782 runtimeRequirements
783 });
784 case "default-with-named":
785 runtimeRequirements.add(RuntimeGlobals.createFakeNamespaceObject);
786 return `${RuntimeGlobals.createFakeNamespaceObject}(${moduleId}, 3)`;
787 case "default-only":
788 runtimeRequirements.add(RuntimeGlobals.createFakeNamespaceObject);
789 return `${RuntimeGlobals.createFakeNamespaceObject}(${moduleId}, 1)`;
790 case "dynamic":
791 runtimeRequirements.add(RuntimeGlobals.createFakeNamespaceObject);
792 return `${RuntimeGlobals.createFakeNamespaceObject}(${moduleId}, 7)`;
793 }
794 }

Callers

nothing calls this directly

Calls 8

missingModuleMethod · 0.95
weakErrorMethod · 0.95
moduleIdMethod · 0.95
moduleRawMethod · 0.95
noModuleIdErrorMessageFunction · 0.85
getModuleIdMethod · 0.80
getExportsTypeMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected