webpack 5.99.9 → 5.100.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (308) hide show
  1. package/bin/webpack.js +8 -2
  2. package/hot/log.js +15 -15
  3. package/hot/poll.js +1 -0
  4. package/lib/APIPlugin.js +3 -3
  5. package/lib/AbstractMethodError.js +1 -0
  6. package/lib/AutomaticPrefetchPlugin.js +1 -0
  7. package/lib/BannerPlugin.js +1 -1
  8. package/lib/CaseSensitiveModulesWarning.js +4 -4
  9. package/lib/Chunk.js +6 -6
  10. package/lib/ChunkGraph.js +37 -31
  11. package/lib/ChunkGroup.js +4 -4
  12. package/lib/ChunkTemplate.js +1 -1
  13. package/lib/CleanPlugin.js +94 -17
  14. package/lib/CodeGenerationResults.js +1 -1
  15. package/lib/CompatibilityPlugin.js +5 -2
  16. package/lib/Compilation.js +67 -45
  17. package/lib/Compiler.js +46 -16
  18. package/lib/ConcatenationScope.js +15 -6
  19. package/lib/ConstPlugin.js +5 -3
  20. package/lib/ContextModule.js +16 -12
  21. package/lib/ContextModuleFactory.js +4 -3
  22. package/lib/ContextReplacementPlugin.js +4 -2
  23. package/lib/CssModule.js +2 -2
  24. package/lib/DefinePlugin.js +111 -3
  25. package/lib/DelegatedModuleFactoryPlugin.js +18 -18
  26. package/lib/Dependency.js +11 -4
  27. package/lib/DependencyTemplate.js +1 -0
  28. package/lib/DllEntryPlugin.js +3 -1
  29. package/lib/DllPlugin.js +4 -3
  30. package/lib/DllReferencePlugin.js +2 -2
  31. package/lib/DynamicEntryPlugin.js +1 -1
  32. package/lib/EntryOptionPlugin.js +5 -0
  33. package/lib/ErrorHelpers.js +4 -4
  34. package/lib/EvalDevToolModulePlugin.js +3 -3
  35. package/lib/EvalSourceMapDevToolPlugin.js +7 -7
  36. package/lib/ExportsInfo.js +48 -39
  37. package/lib/ExternalModule.js +15 -11
  38. package/lib/ExternalModuleFactoryPlugin.js +5 -2
  39. package/lib/FileSystemInfo.js +51 -36
  40. package/lib/FlagDependencyExportsPlugin.js +14 -7
  41. package/lib/FlagDependencyUsagePlugin.js +1 -1
  42. package/lib/Generator.js +14 -1
  43. package/lib/HookWebpackError.js +1 -0
  44. package/lib/HotModuleReplacementPlugin.js +77 -50
  45. package/lib/IgnorePlugin.js +5 -2
  46. package/lib/InvalidDependenciesModuleWarning.js +1 -1
  47. package/lib/JavascriptMetaInfoPlugin.js +0 -1
  48. package/lib/LibManifestPlugin.js +4 -2
  49. package/lib/LoaderOptionsPlugin.js +6 -4
  50. package/lib/MainTemplate.js +2 -2
  51. package/lib/Module.js +21 -6
  52. package/lib/ModuleFactory.js +1 -0
  53. package/lib/ModuleGraph.js +24 -2
  54. package/lib/ModuleGraphConnection.js +5 -5
  55. package/lib/ModuleInfoHeaderPlugin.js +2 -1
  56. package/lib/ModuleParseError.js +1 -0
  57. package/lib/ModuleSourceTypesConstants.js +12 -12
  58. package/lib/ModuleTemplate.js +1 -1
  59. package/lib/ModuleTypeConstants.js +21 -21
  60. package/lib/MultiCompiler.js +6 -6
  61. package/lib/NormalModule.js +31 -44
  62. package/lib/NormalModuleFactory.js +34 -20
  63. package/lib/NormalModuleReplacementPlugin.js +1 -1
  64. package/lib/NullFactory.js +1 -0
  65. package/lib/OptimizationStages.js +1 -1
  66. package/lib/Parser.js +1 -0
  67. package/lib/ProgressPlugin.js +12 -5
  68. package/lib/ProvidePlugin.js +5 -1
  69. package/lib/RawModule.js +14 -0
  70. package/lib/RecordIdsPlugin.js +3 -3
  71. package/lib/RuntimeGlobals.js +175 -155
  72. package/lib/RuntimeModule.js +1 -0
  73. package/lib/RuntimePlugin.js +33 -7
  74. package/lib/RuntimeTemplate.js +111 -11
  75. package/lib/SourceMapDevToolModuleOptionsPlugin.js +15 -25
  76. package/lib/SourceMapDevToolPlugin.js +19 -17
  77. package/lib/Template.js +2 -2
  78. package/lib/TemplatedPathPlugin.js +1 -1
  79. package/lib/WarnDeprecatedOptionPlugin.js +7 -8
  80. package/lib/WatchIgnorePlugin.js +4 -3
  81. package/lib/WebpackIsIncludedPlugin.js +2 -1
  82. package/lib/WebpackOptionsApply.js +115 -27
  83. package/lib/asset/AssetGenerator.js +15 -11
  84. package/lib/asset/AssetModulesPlugin.js +19 -17
  85. package/lib/asset/AssetSourceGenerator.js +4 -4
  86. package/lib/asset/RawDataUrlModule.js +4 -2
  87. package/lib/async-modules/AwaitDependenciesInitFragment.js +1 -1
  88. package/lib/buildChunkGraph.js +6 -3
  89. package/lib/cache/AddBuildDependenciesPlugin.js +5 -6
  90. package/lib/cache/IdleFileCachePlugin.js +7 -4
  91. package/lib/cache/MemoryCachePlugin.js +1 -0
  92. package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
  93. package/lib/cache/PackFileCacheStrategy.js +26 -20
  94. package/lib/cache/ResolverCachePlugin.js +16 -8
  95. package/lib/cli.js +15 -10
  96. package/lib/config/browserslistTargetHandler.js +3 -3
  97. package/lib/config/defaults.js +25 -17
  98. package/lib/config/normalization.js +2 -1
  99. package/lib/config/target.js +6 -5
  100. package/lib/container/ContainerPlugin.js +1 -1
  101. package/lib/container/ContainerReferencePlugin.js +1 -1
  102. package/lib/container/FallbackModule.js +2 -1
  103. package/lib/container/HoistContainerReferencesPlugin.js +1 -1
  104. package/lib/container/ModuleFederationPlugin.js +2 -2
  105. package/lib/container/RemoteModule.js +1 -1
  106. package/lib/css/CssGenerator.js +9 -6
  107. package/lib/css/CssModulesPlugin.js +44 -31
  108. package/lib/css/CssParser.js +6 -4
  109. package/lib/css/walkCssTokens.js +33 -37
  110. package/lib/debug/ProfilingPlugin.js +6 -6
  111. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +8 -8
  112. package/lib/dependencies/AMDPlugin.js +12 -8
  113. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +28 -26
  114. package/lib/dependencies/CachedConstDependency.js +1 -5
  115. package/lib/dependencies/CommonJsExportRequireDependency.js +6 -4
  116. package/lib/dependencies/CommonJsExportsParserPlugin.js +22 -25
  117. package/lib/dependencies/CommonJsFullRequireDependency.js +1 -9
  118. package/lib/dependencies/CommonJsImportsParserPlugin.js +100 -114
  119. package/lib/dependencies/CommonJsPlugin.js +15 -16
  120. package/lib/dependencies/ContextDependencyHelpers.js +2 -1
  121. package/lib/dependencies/ContextDependencyTemplateAsId.js +1 -0
  122. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +1 -0
  123. package/lib/dependencies/CssIcssExportDependency.js +1 -1
  124. package/lib/dependencies/CssLocalIdentifierDependency.js +2 -2
  125. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +2 -1
  126. package/lib/dependencies/DynamicExports.js +9 -9
  127. package/lib/dependencies/ExportsInfoDependency.js +1 -1
  128. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +122 -101
  129. package/lib/dependencies/HarmonyExportExpressionDependency.js +1 -1
  130. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +95 -19
  131. package/lib/dependencies/HarmonyExportInitFragment.js +1 -1
  132. package/lib/dependencies/HarmonyImportDependency.js +11 -5
  133. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +238 -162
  134. package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -1
  135. package/lib/dependencies/HarmonyImportSpecifierDependency.js +20 -9
  136. package/lib/dependencies/HarmonyModulesPlugin.js +23 -12
  137. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -0
  138. package/lib/dependencies/ImportMetaContextPlugin.js +2 -1
  139. package/lib/dependencies/ImportMetaPlugin.js +2 -2
  140. package/lib/dependencies/ImportParserPlugin.js +40 -9
  141. package/lib/dependencies/ImportPlugin.js +3 -1
  142. package/lib/dependencies/LoaderPlugin.js +1 -0
  143. package/lib/dependencies/ModuleDependency.js +3 -1
  144. package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +1 -0
  145. package/lib/dependencies/RequireContextPlugin.js +3 -1
  146. package/lib/dependencies/RequireEnsurePlugin.js +6 -6
  147. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +33 -34
  148. package/lib/dependencies/RequireIncludePlugin.js +1 -0
  149. package/lib/dependencies/RuntimeRequirementsDependency.js +1 -1
  150. package/lib/dependencies/SystemPlugin.js +1 -1
  151. package/lib/dependencies/URLContextDependency.js +65 -0
  152. package/lib/dependencies/URLPlugin.js +17 -157
  153. package/lib/dependencies/WorkerPlugin.js +23 -10
  154. package/lib/dependencies/processExportInfo.js +2 -1
  155. package/lib/esm/ModuleChunkFormatPlugin.js +269 -185
  156. package/lib/esm/ModuleChunkLoadingPlugin.js +39 -1
  157. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +70 -3
  158. package/lib/hmr/HotModuleReplacement.runtime.js +0 -1
  159. package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
  160. package/lib/hmr/JavascriptHotModuleReplacementHelper.js +37 -0
  161. package/lib/hmr/LazyCompilationPlugin.js +4 -2
  162. package/lib/hmr/lazyCompilationBackend.js +4 -2
  163. package/lib/ids/ChunkModuleIdRangePlugin.js +6 -3
  164. package/lib/ids/DeterministicChunkIdsPlugin.js +30 -35
  165. package/lib/ids/DeterministicModuleIdsPlugin.js +4 -3
  166. package/lib/ids/HashedModuleIdsPlugin.js +5 -4
  167. package/lib/ids/IdHelpers.js +21 -17
  168. package/lib/ids/NamedChunkIdsPlugin.js +5 -5
  169. package/lib/ids/NamedModuleIdsPlugin.js +4 -4
  170. package/lib/ids/NaturalChunkIdsPlugin.js +2 -1
  171. package/lib/ids/NaturalModuleIdsPlugin.js +1 -1
  172. package/lib/ids/OccurrenceChunkIdsPlugin.js +3 -2
  173. package/lib/ids/OccurrenceModuleIdsPlugin.js +1 -1
  174. package/lib/ids/SyncModuleIdsPlugin.js +1 -1
  175. package/lib/index.js +13 -3
  176. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +113 -119
  177. package/lib/javascript/BasicEvaluatedExpression.js +2 -1
  178. package/lib/javascript/ChunkHelpers.js +1 -0
  179. package/lib/javascript/CommonJsChunkFormatPlugin.js +121 -136
  180. package/lib/javascript/EnableChunkLoadingPlugin.js +6 -3
  181. package/lib/javascript/JavascriptGenerator.js +14 -2
  182. package/lib/javascript/JavascriptModulesPlugin.js +68 -27
  183. package/lib/javascript/JavascriptParser.js +117 -76
  184. package/lib/javascript/JavascriptParserHelpers.js +41 -41
  185. package/lib/javascript/StartupHelpers.js +17 -17
  186. package/lib/json/JsonGenerator.js +4 -2
  187. package/lib/json/JsonModulesPlugin.js +2 -2
  188. package/lib/json/JsonParser.js +1 -1
  189. package/lib/library/AbstractLibraryPlugin.js +6 -2
  190. package/lib/library/AssignLibraryPlugin.js +21 -6
  191. package/lib/library/EnableLibraryPlugin.js +23 -3
  192. package/lib/library/UmdLibraryPlugin.js +15 -6
  193. package/lib/logging/createConsoleLogger.js +3 -3
  194. package/lib/logging/runtime.js +9 -9
  195. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +4 -22
  196. package/lib/node/RequireChunkLoadingRuntimeModule.js +4 -22
  197. package/lib/node/nodeConsole.js +4 -2
  198. package/lib/optimize/AggressiveMergingPlugin.js +45 -46
  199. package/lib/optimize/AggressiveSplittingPlugin.js +13 -12
  200. package/lib/optimize/ConcatenatedModule.js +227 -57
  201. package/lib/optimize/EnsureChunkConditionsPlugin.js +58 -58
  202. package/lib/optimize/FlagIncludedChunksPlugin.js +3 -1
  203. package/lib/optimize/InnerGraph.js +115 -112
  204. package/lib/optimize/InnerGraphPlugin.js +2 -2
  205. package/lib/optimize/LimitChunkCountPlugin.js +4 -2
  206. package/lib/optimize/MangleExportsPlugin.js +4 -3
  207. package/lib/optimize/MergeDuplicateChunksPlugin.js +80 -81
  208. package/lib/optimize/MinChunkSizePlugin.js +6 -3
  209. package/lib/optimize/ModuleConcatenationPlugin.js +31 -22
  210. package/lib/optimize/RealContentHashPlugin.js +26 -20
  211. package/lib/optimize/RemoveEmptyChunksPlugin.js +2 -1
  212. package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
  213. package/lib/optimize/SideEffectsFlagPlugin.js +3 -2
  214. package/lib/optimize/SplitChunksPlugin.js +16 -13
  215. package/lib/rules/BasicEffectRulePlugin.js +4 -2
  216. package/lib/rules/BasicMatcherRulePlugin.js +3 -1
  217. package/lib/rules/ObjectMatcherRulePlugin.js +3 -1
  218. package/lib/rules/RuleSetCompiler.js +19 -5
  219. package/lib/rules/UseEffectRulePlugin.js +17 -9
  220. package/lib/runtime/AsyncModuleRuntimeModule.js +64 -9
  221. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +1 -1
  222. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +214 -0
  223. package/lib/runtime/RuntimeIdRuntimeModule.js +2 -1
  224. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +8 -7
  225. package/lib/schemes/FileUriPlugin.js +1 -1
  226. package/lib/schemes/HttpUriPlugin.js +27 -19
  227. package/lib/schemes/VirtualUrlPlugin.js +222 -0
  228. package/lib/serialization/AggregateErrorSerializer.js +1 -1
  229. package/lib/serialization/BinaryMiddleware.js +5 -4
  230. package/lib/serialization/FileMiddleware.js +7 -4
  231. package/lib/serialization/ObjectMiddleware.js +14 -8
  232. package/lib/serialization/Serializer.js +5 -3
  233. package/lib/serialization/SerializerMiddleware.js +2 -0
  234. package/lib/sharing/ConsumeSharedModule.js +1 -1
  235. package/lib/sharing/ConsumeSharedPlugin.js +3 -3
  236. package/lib/sharing/ConsumeSharedRuntimeModule.js +2 -2
  237. package/lib/sharing/ProvideSharedModule.js +1 -1
  238. package/lib/sharing/ProvideSharedPlugin.js +3 -2
  239. package/lib/sharing/SharePlugin.js +2 -1
  240. package/lib/sharing/ShareRuntimeModule.js +3 -5
  241. package/lib/sharing/utils.js +34 -34
  242. package/lib/stats/DefaultStatsFactoryPlugin.js +49 -46
  243. package/lib/stats/DefaultStatsPresetPlugin.js +13 -13
  244. package/lib/stats/DefaultStatsPrinterPlugin.js +15 -9
  245. package/lib/stats/StatsFactory.js +6 -3
  246. package/lib/stats/StatsPrinter.js +6 -7
  247. package/lib/url/URLParserPlugin.js +266 -0
  248. package/lib/util/ArrayQueue.js +1 -1
  249. package/lib/util/AsyncQueue.js +1 -1
  250. package/lib/util/Hash.js +2 -0
  251. package/lib/util/IterableHelpers.js +1 -1
  252. package/lib/util/LazyBucketSortedSet.js +2 -1
  253. package/lib/util/LazySet.js +11 -6
  254. package/lib/util/ParallelismFactorCalculator.js +1 -1
  255. package/lib/util/SetHelpers.js +3 -3
  256. package/lib/util/SortableSet.js +2 -2
  257. package/lib/util/StackedCacheMap.js +3 -1
  258. package/lib/util/StackedMap.js +2 -2
  259. package/lib/util/StringXor.js +1 -0
  260. package/lib/util/TupleSet.js +1 -0
  261. package/lib/util/URLAbsoluteSpecifier.js +1 -1
  262. package/lib/util/cleverMerge.js +95 -58
  263. package/lib/util/comparators.js +154 -127
  264. package/lib/util/compileBooleanMatcher.js +8 -3
  265. package/lib/util/concatenate.js +8 -7
  266. package/lib/util/conventions.js +72 -73
  267. package/lib/util/create-schema-validation.js +2 -1
  268. package/lib/util/createHash.js +10 -4
  269. package/lib/util/deprecation.js +69 -66
  270. package/lib/util/deterministicGrouping.js +4 -2
  271. package/lib/util/extractUrlAndGlobal.js +1 -1
  272. package/lib/util/findGraphRoots.js +2 -2
  273. package/lib/util/fs.js +30 -23
  274. package/lib/util/hash/md4.js +2 -2
  275. package/lib/util/hash/wasm-hash.js +4 -2
  276. package/lib/util/identifier.js +13 -12
  277. package/lib/util/internalSerializables.js +2 -0
  278. package/lib/util/magicComment.js +5 -5
  279. package/lib/util/processAsyncTree.js +1 -1
  280. package/lib/util/propertyAccess.js +1 -1
  281. package/lib/util/propertyName.js +1 -1
  282. package/lib/util/registerExternalSerializer.js +1 -2
  283. package/lib/util/removeBOM.js +1 -1
  284. package/lib/util/runtime.js +29 -21
  285. package/lib/util/semver.js +1 -1
  286. package/lib/util/serialization.js +3 -0
  287. package/lib/util/source.js +3 -2
  288. package/lib/validateSchema.js +1 -0
  289. package/lib/wasm/EnableWasmLoadingPlugin.js +6 -3
  290. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -1
  291. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +46 -49
  292. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +2 -2
  293. package/lib/wasm-sync/WebAssemblyGenerator.js +2 -3
  294. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +3 -2
  295. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +3 -0
  296. package/lib/wasm-sync/WebAssemblyUtils.js +1 -1
  297. package/lib/web/JsonpChunkLoadingRuntimeModule.js +4 -22
  298. package/lib/webpack.js +4 -5
  299. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +1 -0
  300. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +6 -24
  301. package/lib/webworker/WebWorkerTemplatePlugin.js +1 -0
  302. package/package.json +119 -113
  303. package/schemas/WebpackOptions.check.js +1 -1
  304. package/schemas/WebpackOptions.json +17 -0
  305. package/schemas/plugins/schemes/VirtualUrlPlugin.check.d.ts +7 -0
  306. package/schemas/plugins/schemes/VirtualUrlPlugin.check.js +6 -0
  307. package/schemas/plugins/schemes/VirtualUrlPlugin.json +77 -0
  308. package/types.d.ts +1243 -409
@@ -5,6 +5,7 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const WebpackError = require("../WebpackError");
8
9
  const { getImportAttributes } = require("../javascript/JavascriptParser");
9
10
  const InnerGraph = require("../optimize/InnerGraph");
10
11
  const ConstDependency = require("./ConstDependency");
@@ -14,6 +15,7 @@ const HarmonyExportImportedSpecifierDependency = require("./HarmonyExportImporte
14
15
  const HarmonyExportSpecifierDependency = require("./HarmonyExportSpecifierDependency");
15
16
  const { ExportPresenceModes } = require("./HarmonyImportDependency");
16
17
  const {
18
+ getImportMode,
17
19
  harmonySpecifierTag
18
20
  } = require("./HarmonyImportDependencyParserPlugin");
19
21
  const HarmonyImportSideEffectDependency = require("./HarmonyImportSideEffectDependency");
@@ -26,11 +28,14 @@ const HarmonyImportSideEffectDependency = require("./HarmonyImportSideEffectDepe
26
28
 
27
29
  const { HarmonyStarExportsList } = HarmonyExportImportedSpecifierDependency;
28
30
 
31
+ const PLUGIN_NAME = "HarmonyExportDependencyParserPlugin";
32
+
29
33
  module.exports = class HarmonyExportDependencyParserPlugin {
30
34
  /**
31
35
  * @param {import("../../declarations/WebpackOptions").JavascriptParserOptions} options options
36
+ * @param {boolean=} deferImport defer import enabled
32
37
  */
33
- constructor(options) {
38
+ constructor(options, deferImport) {
34
39
  this.exportPresenceMode =
35
40
  options.reexportExportsPresence !== undefined
36
41
  ? ExportPresenceModes.fromUserOption(options.reexportExportsPresence)
@@ -39,6 +44,7 @@ module.exports = class HarmonyExportDependencyParserPlugin {
39
44
  : options.strictExportPresence
40
45
  ? ExportPresenceModes.ERROR
41
46
  : ExportPresenceModes.AUTO;
47
+ this.deferImport = deferImport;
42
48
  }
43
49
 
44
50
  /**
@@ -47,107 +53,111 @@ module.exports = class HarmonyExportDependencyParserPlugin {
47
53
  */
48
54
  apply(parser) {
49
55
  const { exportPresenceMode } = this;
50
- parser.hooks.export.tap(
51
- "HarmonyExportDependencyParserPlugin",
52
- statement => {
53
- const dep = new HarmonyExportHeaderDependency(
54
- /** @type {Range | false} */ (
55
- statement.declaration && statement.declaration.range
56
- ),
57
- /** @type {Range} */ (statement.range)
58
- );
59
- dep.loc = Object.create(
60
- /** @type {DependencyLocation} */ (statement.loc)
56
+ parser.hooks.export.tap(PLUGIN_NAME, statement => {
57
+ const dep = new HarmonyExportHeaderDependency(
58
+ /** @type {Range | false} */ (
59
+ statement.declaration && statement.declaration.range
60
+ ),
61
+ /** @type {Range} */ (statement.range)
62
+ );
63
+ dep.loc = Object.create(
64
+ /** @type {DependencyLocation} */ (statement.loc)
65
+ );
66
+ dep.loc.index = -1;
67
+ parser.state.module.addPresentationalDependency(dep);
68
+ return true;
69
+ });
70
+ parser.hooks.exportImport.tap(PLUGIN_NAME, (statement, source) => {
71
+ parser.state.lastHarmonyImportOrder =
72
+ (parser.state.lastHarmonyImportOrder || 0) + 1;
73
+ const clearDep = new ConstDependency(
74
+ "",
75
+ /** @type {Range} */ (statement.range)
76
+ );
77
+ clearDep.loc = /** @type {DependencyLocation} */ (statement.loc);
78
+ clearDep.loc.index = -1;
79
+ parser.state.module.addPresentationalDependency(clearDep);
80
+ const { defer } = getImportMode(
81
+ parser,
82
+ statement,
83
+ this.deferImport,
84
+ true
85
+ );
86
+ if (defer) {
87
+ const error = new WebpackError(
88
+ "Deferred re-export (`export defer * as namespace from '...'`) is not a part of the Import Defer proposal.\nUse the following code instead:\n import defer * as namespace from '...';\n export { namespace };"
61
89
  );
62
- dep.loc.index = -1;
63
- parser.state.module.addPresentationalDependency(dep);
64
- return true;
65
- }
66
- );
67
- parser.hooks.exportImport.tap(
68
- "HarmonyExportDependencyParserPlugin",
69
- (statement, source) => {
70
- parser.state.lastHarmonyImportOrder =
71
- (parser.state.lastHarmonyImportOrder || 0) + 1;
72
- const clearDep = new ConstDependency(
73
- "",
74
- /** @type {Range} */ (statement.range)
75
- );
76
- clearDep.loc = /** @type {DependencyLocation} */ (statement.loc);
77
- clearDep.loc.index = -1;
78
- parser.state.module.addPresentationalDependency(clearDep);
79
- const sideEffectDep = new HarmonyImportSideEffectDependency(
80
- /** @type {string} */ (source),
81
- parser.state.lastHarmonyImportOrder,
82
- getImportAttributes(statement)
83
- );
84
- sideEffectDep.loc = Object.create(
85
- /** @type {DependencyLocation} */ (statement.loc)
86
- );
87
- sideEffectDep.loc.index = -1;
88
- parser.state.current.addDependency(sideEffectDep);
89
- return true;
90
+ error.loc = statement.loc || undefined;
91
+ parser.state.current.addError(error);
90
92
  }
91
- );
92
- parser.hooks.exportExpression.tap(
93
- "HarmonyExportDependencyParserPlugin",
94
- (statement, node) => {
95
- const isFunctionDeclaration = node.type === "FunctionDeclaration";
96
- const exprRange = /** @type {Range} */ (node.range);
97
- const statementRange = /** @type {Range} */ (statement.range);
98
- const comments = parser.getComments([statementRange[0], exprRange[0]]);
99
- const dep = new HarmonyExportExpressionDependency(
100
- exprRange,
101
- statementRange,
102
- comments
103
- .map(c => {
104
- switch (c.type) {
105
- case "Block":
106
- return `/*${c.value}*/`;
107
- case "Line":
108
- return `//${c.value}\n`;
93
+ const sideEffectDep = new HarmonyImportSideEffectDependency(
94
+ /** @type {string} */ (source),
95
+ parser.state.lastHarmonyImportOrder,
96
+ getImportAttributes(statement),
97
+ defer
98
+ );
99
+ sideEffectDep.loc = Object.create(
100
+ /** @type {DependencyLocation} */ (statement.loc)
101
+ );
102
+ sideEffectDep.loc.index = -1;
103
+ parser.state.current.addDependency(sideEffectDep);
104
+ return true;
105
+ });
106
+ parser.hooks.exportExpression.tap(PLUGIN_NAME, (statement, node) => {
107
+ const isFunctionDeclaration = node.type === "FunctionDeclaration";
108
+ const exprRange = /** @type {Range} */ (node.range);
109
+ const statementRange = /** @type {Range} */ (statement.range);
110
+ const comments = parser.getComments([statementRange[0], exprRange[0]]);
111
+ const dep = new HarmonyExportExpressionDependency(
112
+ exprRange,
113
+ statementRange,
114
+ comments
115
+ .map(c => {
116
+ switch (c.type) {
117
+ case "Block":
118
+ return `/*${c.value}*/`;
119
+ case "Line":
120
+ return `//${c.value}\n`;
121
+ }
122
+ return "";
123
+ })
124
+ .join(""),
125
+ node.type.endsWith("Declaration") &&
126
+ /** @type {FunctionDeclaration | ClassDeclaration} */ (node).id
127
+ ? /** @type {FunctionDeclaration | ClassDeclaration} */
128
+ (node).id.name
129
+ : isFunctionDeclaration
130
+ ? {
131
+ range: [
132
+ exprRange[0],
133
+ node.params.length > 0
134
+ ? /** @type {Range} */ (node.params[0].range)[0]
135
+ : /** @type {Range} */ (node.body.range)[0]
136
+ ],
137
+ prefix: `${node.async ? "async " : ""}function${
138
+ node.generator ? "*" : ""
139
+ } `,
140
+ suffix: `(${node.params.length > 0 ? "" : ") "}`
109
141
  }
110
- return "";
111
- })
112
- .join(""),
113
- node.type.endsWith("Declaration") &&
142
+ : undefined
143
+ );
144
+ dep.loc = Object.create(
145
+ /** @type {DependencyLocation} */ (statement.loc)
146
+ );
147
+ dep.loc.index = -1;
148
+ parser.state.current.addDependency(dep);
149
+ InnerGraph.addVariableUsage(
150
+ parser,
151
+ node.type.endsWith("Declaration") &&
114
152
  /** @type {FunctionDeclaration | ClassDeclaration} */ (node).id
115
- ? /** @type {FunctionDeclaration | ClassDeclaration} */
116
- (node).id.name
117
- : isFunctionDeclaration
118
- ? {
119
- range: [
120
- exprRange[0],
121
- node.params.length > 0
122
- ? /** @type {Range} */ (node.params[0].range)[0]
123
- : /** @type {Range} */ (node.body.range)[0]
124
- ],
125
- prefix: `${node.async ? "async " : ""}function${
126
- node.generator ? "*" : ""
127
- } `,
128
- suffix: `(${node.params.length > 0 ? "" : ") "}`
129
- }
130
- : undefined
131
- );
132
- dep.loc = Object.create(
133
- /** @type {DependencyLocation} */ (statement.loc)
134
- );
135
- dep.loc.index = -1;
136
- parser.state.current.addDependency(dep);
137
- InnerGraph.addVariableUsage(
138
- parser,
139
- node.type.endsWith("Declaration") &&
140
- /** @type {FunctionDeclaration | ClassDeclaration} */ (node).id
141
- ? /** @type {FunctionDeclaration | ClassDeclaration} */ (node).id
142
- .name
143
- : "*default*",
144
- "default"
145
- );
146
- return true;
147
- }
148
- );
153
+ ? /** @type {FunctionDeclaration | ClassDeclaration} */ (node).id.name
154
+ : "*default*",
155
+ "default"
156
+ );
157
+ return true;
158
+ });
149
159
  parser.hooks.exportSpecifier.tap(
150
- "HarmonyExportDependencyParserPlugin",
160
+ PLUGIN_NAME,
151
161
  (statement, id, name, idx) => {
152
162
  const settings = parser.getTagData(id, harmonySpecifierTag);
153
163
  const harmonyNamedExports = (parser.state.harmonyNamedExports =
@@ -164,7 +174,8 @@ module.exports = class HarmonyExportDependencyParserPlugin {
164
174
  null,
165
175
  exportPresenceMode,
166
176
  null,
167
- settings.attributes
177
+ settings.attributes,
178
+ settings.defer
168
179
  )
169
180
  : new HarmonyExportSpecifierDependency(id, name);
170
181
  dep.loc = Object.create(
@@ -183,10 +194,11 @@ module.exports = class HarmonyExportDependencyParserPlugin {
183
194
  }
184
195
  );
185
196
  parser.hooks.exportImportSpecifier.tap(
186
- "HarmonyExportDependencyParserPlugin",
197
+ PLUGIN_NAME,
187
198
  (statement, source, id, name, idx) => {
188
199
  const harmonyNamedExports = (parser.state.harmonyNamedExports =
189
200
  parser.state.harmonyNamedExports || new Set());
201
+ /** @type {InstanceType<HarmonyStarExportsList> | null} */
190
202
  let harmonyStarExports = null;
191
203
  if (name) {
192
204
  harmonyNamedExports.add(name);
@@ -195,16 +207,25 @@ module.exports = class HarmonyExportDependencyParserPlugin {
195
207
  parser.state.harmonyStarExports || new HarmonyStarExportsList();
196
208
  }
197
209
  const attributes = getImportAttributes(statement);
210
+ const { defer } = getImportMode(
211
+ parser,
212
+ statement,
213
+ this.deferImport,
214
+ false
215
+ );
198
216
  const dep = new HarmonyExportImportedSpecifierDependency(
199
- /** @type {string} */ (source),
217
+ /** @type {string} */
218
+ (source),
200
219
  parser.state.lastHarmonyImportOrder,
201
220
  id ? [id] : [],
202
221
  name,
203
222
  harmonyNamedExports,
223
+ // eslint-disable-next-line unicorn/prefer-spread
204
224
  harmonyStarExports && harmonyStarExports.slice(),
205
225
  exportPresenceMode,
206
226
  harmonyStarExports,
207
- attributes
227
+ attributes,
228
+ defer
208
229
  );
209
230
  if (harmonyStarExports) {
210
231
  harmonyStarExports.push(dep);
@@ -27,7 +27,7 @@ class HarmonyExportExpressionDependency extends NullDependency {
27
27
  * @param {Range} range range
28
28
  * @param {Range} rangeStatement range statement
29
29
  * @param {string} prefix prefix
30
- * @param {string | { range: Range, prefix: string, suffix: string }=} declarationId declaration id
30
+ * @param {string | { id?: string | undefined, range: Range, prefix: string, suffix: string }=} declarationId declaration id
31
31
  */
32
32
  constructor(range, rangeStatement, prefix, declarationId) {
33
33
  super();
@@ -12,15 +12,18 @@ const HarmonyLinkingError = require("../HarmonyLinkingError");
12
12
  const InitFragment = require("../InitFragment");
13
13
  const RuntimeGlobals = require("../RuntimeGlobals");
14
14
  const Template = require("../Template");
15
+ const {
16
+ getMakeDeferredNamespaceModeFromExportsType
17
+ } = require("../runtime/MakeDeferredNamespaceObjectRuntime");
15
18
  const { countIterable } = require("../util/IterableHelpers");
16
- const { first, combine } = require("../util/SetHelpers");
19
+ const { combine, first } = require("../util/SetHelpers");
17
20
  const makeSerializable = require("../util/makeSerializable");
18
21
  const propertyAccess = require("../util/propertyAccess");
19
22
  const { propertyName } = require("../util/propertyName");
20
23
  const {
24
+ filterRuntime,
21
25
  getRuntimeKey,
22
- keyToRuntime,
23
- filterRuntime
26
+ keyToRuntime
24
27
  } = require("../util/runtime");
25
28
  const HarmonyExportInitFragment = require("./HarmonyExportInitFragment");
26
29
  const HarmonyImportDependency = require("./HarmonyImportDependency");
@@ -121,7 +124,7 @@ class ExportMode {
121
124
 
122
125
  /**
123
126
  * @param {ModuleGraph} moduleGraph module graph
124
- * @param {HarmonyExportImportedSpecifierDependency[]} dependencies dependencies
127
+ * @param {ReadonlyArray<HarmonyExportImportedSpecifierDependency>} dependencies dependencies
125
128
  * @param {TODO=} additionalDependency additional dependency
126
129
  * @returns {{ names: Names, dependencyIndices: DependencyIndices }} result
127
130
  */
@@ -130,12 +133,13 @@ const determineExportAssignments = (
130
133
  dependencies,
131
134
  additionalDependency
132
135
  ) => {
136
+ /** @type {Set<string>} */
133
137
  const names = new Set();
134
138
  /** @type {number[]} */
135
139
  const dependencyIndices = [];
136
140
 
137
141
  if (additionalDependency) {
138
- dependencies = dependencies.concat(additionalDependency);
142
+ dependencies = [...dependencies, additionalDependency];
139
143
  }
140
144
 
141
145
  for (const dep of dependencies) {
@@ -158,7 +162,7 @@ const determineExportAssignments = (
158
162
  }
159
163
  dependencyIndices.push(names.size);
160
164
 
161
- return { names: Array.from(names), dependencyIndices };
165
+ return { names: [...names], dependencyIndices };
162
166
  };
163
167
 
164
168
  /**
@@ -166,7 +170,7 @@ const determineExportAssignments = (
166
170
  * @param {Names} options.names names
167
171
  * @param {DependencyIndices} options.dependencyIndices dependency indices
168
172
  * @param {string} name name
169
- * @param {Iterable<HarmonyExportImportedSpecifierDependency>} dependencies dependencies
173
+ * @param {ReadonlyArray<HarmonyExportImportedSpecifierDependency>} dependencies dependencies
170
174
  * @returns {HarmonyExportImportedSpecifierDependency | undefined} found dependency or nothing
171
175
  */
172
176
  const findDependencyForName = (
@@ -302,7 +306,6 @@ const getMode = (moduleGraph, dep, runtimeKey) => {
302
306
  }
303
307
 
304
308
  // Star reexporting
305
-
306
309
  const { ignoredExports, exports, checked, hidden } = dep.getStarReexports(
307
310
  moduleGraph,
308
311
  runtime,
@@ -371,10 +374,11 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
371
374
  * @param {Ids} ids the requested export name of the imported module
372
375
  * @param {string | null} name the export name of for this module
373
376
  * @param {Set<string>} activeExports other named exports in the module
374
- * @param {ReadonlyArray<HarmonyExportImportedSpecifierDependency> | Iterable<HarmonyExportImportedSpecifierDependency> | null} otherStarExports other star exports in the module before this import
377
+ * @param {ReadonlyArray<HarmonyExportImportedSpecifierDependency> | null} otherStarExports other star exports in the module before this import
375
378
  * @param {ExportPresenceMode} exportPresenceMode mode of checking export names
376
379
  * @param {HarmonyStarExportsList | null} allStarExports all star exports in the module
377
380
  * @param {ImportAttributes=} attributes import attributes
381
+ * @param {boolean=} deferEvaluation defer evaluation
378
382
  */
379
383
  constructor(
380
384
  request,
@@ -385,7 +389,8 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
385
389
  otherStarExports,
386
390
  exportPresenceMode,
387
391
  allStarExports,
388
- attributes
392
+ attributes,
393
+ deferEvaluation
389
394
  ) {
390
395
  super(request, sourceOrder, attributes);
391
396
 
@@ -395,6 +400,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
395
400
  this.otherStarExports = otherStarExports;
396
401
  this.exportPresenceMode = exportPresenceMode;
397
402
  this.allStarExports = allStarExports;
403
+ this.defer = deferEvaluation;
398
404
  }
399
405
 
400
406
  /**
@@ -578,8 +584,9 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
578
584
  return Dependency.EXPORTS_OBJECT_REFERENCED;
579
585
 
580
586
  case "reexport-named-default": {
581
- if (!mode.partialNamespaceExportInfo)
587
+ if (!mode.partialNamespaceExportInfo) {
582
588
  return Dependency.EXPORTS_OBJECT_REFERENCED;
589
+ }
583
590
  /** @type {ReferencedExports} */
584
591
  const referencedExports = [];
585
592
  processExportInfo(
@@ -593,8 +600,9 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
593
600
 
594
601
  case "reexport-namespace-object":
595
602
  case "reexport-fake-namespace-object": {
596
- if (!mode.partialNamespaceExportInfo)
603
+ if (!mode.partialNamespaceExportInfo) {
597
604
  return Dependency.EXPORTS_OBJECT_REFERENCED;
605
+ }
598
606
  /** @type {ReferencedExports} */
599
607
  const referencedExports = [];
600
608
  processExportInfo(
@@ -658,7 +666,8 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
658
666
 
659
667
  const { names, dependencyIndices } = moduleGraph.cached(
660
668
  determineExportAssignments,
661
- this.otherStarExports,
669
+ /** @type {HarmonyExportImportedSpecifierDependency[]} */
670
+ (this.otherStarExports),
662
671
  this
663
672
  );
664
673
 
@@ -811,8 +820,9 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
811
820
  * @returns {ExportPresenceMode} effective mode
812
821
  */
813
822
  _getEffectiveExportPresenceLevel(moduleGraph) {
814
- if (this.exportPresenceMode !== ExportPresenceModes.AUTO)
823
+ if (this.exportPresenceMode !== ExportPresenceModes.AUTO) {
815
824
  return this.exportPresenceMode;
825
+ }
816
826
  const module = /** @type {Module} */ (moduleGraph.getParentModule(this));
817
827
  return /** @type {BuildMeta} */ (module.buildMeta).strictHarmonyModule
818
828
  ? ExportPresenceModes.ERROR
@@ -884,7 +894,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
884
894
  this.allStarExports
885
895
  ? this.allStarExports.dependencies
886
896
  : [
887
- .../** @type {Iterable<HarmonyExportImportedSpecifierDependency>} */
897
+ .../** @type {ReadonlyArray<HarmonyExportImportedSpecifierDependency>} */
888
898
  (this.otherStarExports),
889
899
  this
890
900
  ]
@@ -1011,6 +1021,7 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
1011
1021
  mode,
1012
1022
  templateContext.module,
1013
1023
  moduleGraph,
1024
+ templateContext.chunkGraph,
1014
1025
  runtime,
1015
1026
  templateContext.runtimeTemplate,
1016
1027
  templateContext.runtimeRequirements
@@ -1024,6 +1035,7 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
1024
1035
  * @param {ExportMode} mode the export mode
1025
1036
  * @param {Module} module the current module
1026
1037
  * @param {ModuleGraph} moduleGraph the module graph
1038
+ * @param {ChunkGraph} chunkGraph the chunk graph
1027
1039
  * @param {RuntimeSpec} runtime the runtime
1028
1040
  * @param {RuntimeTemplate} runtimeTemplate the runtime template
1029
1041
  * @param {RuntimeRequirements} runtimeRequirements runtime requirements
@@ -1035,6 +1047,7 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
1035
1047
  mode,
1036
1048
  module,
1037
1049
  moduleGraph,
1050
+ chunkGraph,
1038
1051
  runtime,
1039
1052
  runtimeTemplate,
1040
1053
  runtimeRequirements
@@ -1042,6 +1055,29 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
1042
1055
  const importedModule = /** @type {Module} */ (moduleGraph.getModule(dep));
1043
1056
  const importVar = dep.getImportVar(moduleGraph);
1044
1057
 
1058
+ if (
1059
+ (mode.type === "reexport-namespace-object" ||
1060
+ mode.type === "reexport-fake-namespace-object") &&
1061
+ dep.defer &&
1062
+ !moduleGraph.isAsync(importedModule)
1063
+ ) {
1064
+ initFragments.push(
1065
+ ...this.getReexportDeferredNamespaceObjectFragments(
1066
+ importedModule,
1067
+ chunkGraph,
1068
+ moduleGraph
1069
+ .getExportsInfo(module)
1070
+ .getUsedName(mode.name ? mode.name : [], runtime),
1071
+ importVar,
1072
+ importedModule.getExportsType(
1073
+ moduleGraph,
1074
+ module.buildMeta && module.buildMeta.strictHarmonyModule
1075
+ ),
1076
+ runtimeRequirements
1077
+ )
1078
+ );
1079
+ return;
1080
+ }
1045
1081
  switch (mode.type) {
1046
1082
  case "missing":
1047
1083
  case "empty-star":
@@ -1210,9 +1246,9 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
1210
1246
  // Filter out exports which are defined by other exports
1211
1247
  // and filter out default export because it cannot be reexported with *
1212
1248
  if (ignored.size > 1) {
1213
- content += `if(${JSON.stringify(
1214
- Array.from(ignored)
1215
- )}.indexOf(__WEBPACK_IMPORT_KEY__) < 0) `;
1249
+ content += `if(${JSON.stringify([
1250
+ ...ignored
1251
+ ])}.indexOf(__WEBPACK_IMPORT_KEY__) < 0) `;
1216
1252
  } else if (ignored.size === 1) {
1217
1253
  content += `if(__WEBPACK_IMPORT_KEY__ !== ${JSON.stringify(
1218
1254
  first(ignored)
@@ -1311,6 +1347,46 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
1311
1347
  ];
1312
1348
  }
1313
1349
 
1350
+ /**
1351
+ * @param {Module} module module
1352
+ * @param {ChunkGraph} chunkGraph chunkGraph
1353
+ * @param {string | false | string[]} key key
1354
+ * @param {string} name name
1355
+ * @param {import("../Module").ExportsType} exportsType exportsType
1356
+ * @param {Set<string>} runtimeRequirements runtimeRequirements
1357
+ * @returns {InitFragment<GenerateContext>[]} fragments
1358
+ */
1359
+ getReexportDeferredNamespaceObjectFragments(
1360
+ module,
1361
+ chunkGraph,
1362
+ key,
1363
+ name,
1364
+ exportsType,
1365
+ runtimeRequirements
1366
+ ) {
1367
+ runtimeRequirements.add(RuntimeGlobals.exports);
1368
+ runtimeRequirements.add(RuntimeGlobals.definePropertyGetters);
1369
+ runtimeRequirements.add(RuntimeGlobals.makeDeferredNamespaceObject);
1370
+
1371
+ const map = new Map();
1372
+ const moduleId = JSON.stringify(chunkGraph.getModuleId(module));
1373
+ const mode = getMakeDeferredNamespaceModeFromExportsType(exportsType);
1374
+ map.set(
1375
+ key,
1376
+ `/* reexport deferred namespace object */ ${name}_deferred_namespace_cache || (${name}_deferred_namespace_cache = ${RuntimeGlobals.makeDeferredNamespaceObject}(${moduleId}, ${mode}))`
1377
+ );
1378
+
1379
+ return [
1380
+ new InitFragment(
1381
+ `var ${name}_deferred_namespace_cache;\n`,
1382
+ InitFragment.STAGE_CONSTANTS,
1383
+ -1,
1384
+ `${name}_deferred_namespace_cache`
1385
+ ),
1386
+ new HarmonyExportInitFragment(module.exportsArgument, map)
1387
+ ];
1388
+ }
1389
+
1314
1390
  /**
1315
1391
  * @param {Module} module module
1316
1392
  * @param {string} key key
@@ -1383,7 +1459,7 @@ class HarmonyStarExportsList {
1383
1459
  }
1384
1460
 
1385
1461
  slice() {
1386
- return this.dependencies.slice();
1462
+ return [...this.dependencies];
1387
1463
  }
1388
1464
 
1389
1465
  /**
@@ -154,7 +154,7 @@ class HarmonyExportInitFragment extends InitFragment {
154
154
  ? `/* unused harmony export ${first(this.unusedExports)} */\n`
155
155
  : "";
156
156
  const definitions = [];
157
- const orderedExportMap = Array.from(this.exportMap).sort(([a], [b]) =>
157
+ const orderedExportMap = [...this.exportMap].sort(([a], [b]) =>
158
158
  a < b ? -1 : 1
159
159
  );
160
160
  for (const [key, value] of orderedExportMap) {
@@ -92,15 +92,19 @@ class HarmonyImportDependency extends ModuleDependency {
92
92
  getImportVar(moduleGraph) {
93
93
  const module = /** @type {Module} */ (moduleGraph.getParentModule(this));
94
94
  const meta = moduleGraph.getMeta(module);
95
- let importVarMap = meta.importVarMap;
96
- if (!importVarMap) meta.importVarMap = importVarMap = new Map();
95
+ const defer = this.defer;
96
+
97
+ const metaKey = defer ? "deferredImportVarMap" : "importVarMap";
98
+ let importVarMap = meta[metaKey];
99
+ if (!importVarMap) meta[metaKey] = importVarMap = new Map();
100
+
97
101
  let importVar = importVarMap.get(
98
102
  /** @type {Module} */ (moduleGraph.getModule(this))
99
103
  );
100
104
  if (importVar) return importVar;
101
105
  importVar = `${Template.toIdentifier(
102
106
  `${this.userRequest}`
103
- )}__WEBPACK_IMPORTED_MODULE_${importVarMap.size}__`;
107
+ )}__WEBPACK_${this.defer ? "DEFERRED_" : ""}IMPORTED_MODULE_${importVarMap.size}__`;
104
108
  importVarMap.set(
105
109
  /** @type {Module} */ (moduleGraph.getModule(this)),
106
110
  importVar
@@ -120,11 +124,13 @@ class HarmonyImportDependency extends ModuleDependency {
120
124
  return runtimeTemplate.importStatement({
121
125
  update,
122
126
  module: /** @type {Module} */ (moduleGraph.getModule(this)),
127
+ moduleGraph,
123
128
  chunkGraph,
124
129
  importVar: this.getImportVar(moduleGraph),
125
130
  request: this.request,
126
131
  originModule: module,
127
- runtimeRequirements
132
+ runtimeRequirements,
133
+ defer: this.defer
128
134
  });
129
135
  }
130
136
 
@@ -299,7 +305,7 @@ HarmonyImportDependency.Template = class HarmonyImportDependencyTemplate extends
299
305
  const moduleKey = referencedModule
300
306
  ? referencedModule.identifier()
301
307
  : dep.request;
302
- const key = `harmony import ${moduleKey}`;
308
+ const key = `${dep.defer ? "deferred " : ""}harmony import ${moduleKey}`;
303
309
 
304
310
  const runtimeCondition = dep.weak
305
311
  ? false