* @param {Dependency[]} dependencies all dependencies * @param {ChunkGraph} chunkGraph chunk graph * @returns {FakeMap | FakeMapType} fake map
(dependencies, chunkGraph)
| 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; |
no test coverage detected