|
8 | 8 | const InitFragment = require("./InitFragment"); |
9 | 9 | const RuntimeGlobals = require("./RuntimeGlobals"); |
10 | 10 | const Template = require("./Template"); |
| 11 | +const { |
| 12 | + getOutgoingAsyncModules |
| 13 | +} = require("./async-modules/AsyncModuleHelpers"); |
11 | 14 | const { |
12 | 15 | getMakeDeferredNamespaceModeFromExportsType, |
13 | 16 | getOptimizedDeferredModule |
@@ -814,27 +817,12 @@ class RuntimeTemplate { |
814 | 817 | ]; |
815 | 818 | } |
816 | 819 |
|
817 | | - /** @type {Set<Module>} */ |
818 | | - const innerAsyncDependencies = new Set(); |
819 | 820 | defer = defer && (module.buildMeta ? !module.buildMeta.async : true); |
820 | 821 |
|
821 | | - if (this.compilation.options.experiments.deferImport && defer) { |
822 | | - const seen = new Set(); |
823 | | - (function gatherInnerAsyncDependencies(mod) { |
824 | | - if (!moduleGraph.isAsync(mod) || seen.has(mod)) return; |
825 | | - seen.add(mod); |
826 | | - if (mod.buildMeta && mod.buildMeta.async) { |
827 | | - innerAsyncDependencies.add(mod); |
828 | | - } else { |
829 | | - for (const dep of mod.dependencies) { |
830 | | - const module = moduleGraph.getModule(dep); |
831 | | - if (module) { |
832 | | - gatherInnerAsyncDependencies(module); |
833 | | - } |
834 | | - } |
835 | | - } |
836 | | - })(module); |
837 | | - } |
| 822 | + /** @type {Set<Module>} */ |
| 823 | + const outgoingAsyncModules = defer |
| 824 | + ? getOutgoingAsyncModules(moduleGraph, module) |
| 825 | + : new Set(); |
838 | 826 |
|
839 | 827 | if (chunkGraph.getModuleId(module) === null) { |
840 | 828 | if (weak) { |
@@ -877,13 +865,14 @@ class RuntimeTemplate { |
877 | 865 | this, |
878 | 866 | exportsType, |
879 | 867 | moduleId, |
880 | | - Array.from(innerAsyncDependencies, mod => chunkGraph.getModuleId(mod)) |
| 868 | + Array.from(outgoingAsyncModules, mod => chunkGraph.getModuleId(mod)) |
881 | 869 | )};\n`; |
882 | | - } else { |
883 | | - importContent = `/* harmony import */ ${optDeclaration}${importVar} = ${RuntimeGlobals.require}(${moduleId});\n`; |
| 870 | + |
| 871 | + return [importContent, ""]; |
884 | 872 | } |
| 873 | + importContent = `/* harmony import */ ${optDeclaration}${importVar} = ${RuntimeGlobals.require}(${moduleId});\n`; |
885 | 874 |
|
886 | | - if (exportsType === "dynamic" && !defer) { |
| 875 | + if (exportsType === "dynamic") { |
887 | 876 | runtimeRequirements.add(RuntimeGlobals.compatGetDefaultExport); |
888 | 877 | return [ |
889 | 878 | importContent, |
|
0 commit comments