MCPcopy
hub / github.com/webpack/webpack / getFakeMap

Method getFakeMap

lib/ContextModule.js:670–733  ·  view source on GitHub ↗

* @param {Dependency[]} dependencies all dependencies * @param {ChunkGraph} chunkGraph chunk graph * @returns {FakeMap | FakeMapType} fake map

(dependencies, chunkGraph)

Source from the content-addressed store, hash-verified

668 * @returns {FakeMap | FakeMapType} fake map
669 */
670 getFakeMap(dependencies, chunkGraph) {
671 if (!this.options.namespaceObject) {
672 return 9;
673 }
674 const moduleGraph = chunkGraph.moduleGraph;
675 // bitfield
676 let hasType = 0;
677 const comparator = compareModulesById(chunkGraph);
678 // if we filter first we get a new array
679 // therefore we don't need to create a clone of dependencies explicitly
680 // therefore the order of this is !important!
681 const sortedModules = dependencies
682 .map(
683 (dependency) =>
684 /** @type {Module} */ (moduleGraph.getModule(dependency))
685 )
686 .filter(Boolean)
687 .sort(comparator);
688 /** @type {FakeMap} */
689 const fakeMap = Object.create(null);
690 for (const module of sortedModules) {
691 const exportsType = module.getExportsType(
692 moduleGraph,
693 this.options.namespaceObject === "strict"
694 );
695 const id = /** @type {ModuleId} */ (chunkGraph.getModuleId(module));
696 switch (exportsType) {
697 case "namespace":
698 fakeMap[id] = 9;
699 hasType |= 1;
700 break;
701 case "dynamic":
702 fakeMap[id] = 7;
703 hasType |= 2;
704 break;
705 case "default-only":
706 fakeMap[id] = 1;
707 hasType |= 4;
708 break;
709 case "default-with-named":
710 fakeMap[id] = 3;
711 hasType |= 8;
712 break;
713 default:
714 throw new Error(`Unexpected exports type ${exportsType}`);
715 }
716 }
717 if (hasType === 1) {
718 return 9;
719 }
720 if (hasType === 2) {
721 return 7;
722 }
723 if (hasType === 4) {
724 return 1;
725 }
726 if (hasType === 8) {
727 return 3;

Callers 7

getSyncSourceMethod · 0.95
getWeakSyncSourceMethod · 0.95
getAsyncWeakSourceMethod · 0.95
getEagerSourceMethod · 0.95
getLazyOnceSourceMethod · 0.95
getLazySourceMethod · 0.95
codeGenerationMethod · 0.95

Calls 6

compareModulesByIdFunction · 0.85
sortMethod · 0.80
getModuleIdMethod · 0.80
getModuleMethod · 0.45
createMethod · 0.45
getExportsTypeMethod · 0.45

Tested by

no test coverage detected