webpack 5.76.1 → 5.88.0

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.

Potentially problematic release.


This version of webpack might be problematic. Click here for more details.

Files changed (436) hide show
  1. package/README.md +10 -4
  2. package/bin/webpack.js +26 -2
  3. package/hot/dev-server.js +2 -1
  4. package/hot/lazy-compilation-node.js +10 -0
  5. package/hot/lazy-compilation-web.js +9 -0
  6. package/hot/log-apply-result.js +5 -0
  7. package/hot/log.js +22 -0
  8. package/hot/only-dev-server.js +2 -1
  9. package/hot/poll.js +3 -0
  10. package/hot/signal.js +4 -0
  11. package/lib/APIPlugin.js +174 -116
  12. package/lib/AsyncDependenciesBlock.js +13 -5
  13. package/lib/AutomaticPrefetchPlugin.js +1 -0
  14. package/lib/BannerPlugin.js +4 -0
  15. package/lib/CacheFacade.js +4 -0
  16. package/lib/CaseSensitiveModulesWarning.js +3 -1
  17. package/lib/Chunk.js +36 -18
  18. package/lib/ChunkGraph.js +4 -4
  19. package/lib/ChunkGroup.js +25 -10
  20. package/lib/CleanPlugin.js +30 -7
  21. package/lib/CodeGenerationResults.js +2 -2
  22. package/lib/CompatibilityPlugin.js +85 -46
  23. package/lib/Compilation.js +17 -8
  24. package/lib/Compiler.js +12 -8
  25. package/lib/ConcatenationScope.js +2 -2
  26. package/lib/ConditionalInitFragment.js +11 -1
  27. package/lib/ConstPlugin.js +79 -44
  28. package/lib/ContextModule.js +20 -6
  29. package/lib/ContextModuleFactory.js +2 -1
  30. package/lib/ContextReplacementPlugin.js +13 -0
  31. package/lib/CssModule.js +169 -0
  32. package/lib/DefinePlugin.js +152 -86
  33. package/lib/DelegatedModule.js +22 -4
  34. package/lib/DelegatedModuleFactoryPlugin.js +6 -0
  35. package/lib/DependenciesBlock.js +17 -1
  36. package/lib/Dependency.js +19 -5
  37. package/lib/DllEntryPlugin.js +16 -1
  38. package/lib/DllModule.js +17 -2
  39. package/lib/DllModuleFactory.js +1 -1
  40. package/lib/DllReferencePlugin.js +13 -1
  41. package/lib/Entrypoint.js +1 -1
  42. package/lib/ErrorHelpers.js +62 -22
  43. package/lib/EvalSourceMapDevToolPlugin.js +9 -2
  44. package/lib/ExportsInfo.js +20 -3
  45. package/lib/ExportsInfoApiPlugin.js +30 -14
  46. package/lib/ExternalModule.js +30 -9
  47. package/lib/FileSystemInfo.js +9 -1
  48. package/lib/FlagAllModulesAsUsedPlugin.js +27 -27
  49. package/lib/FlagDependencyExportsPlugin.js +336 -348
  50. package/lib/FlagDependencyUsagePlugin.js +9 -9
  51. package/lib/FlagEntryExportAsUsedPlugin.js +26 -23
  52. package/lib/HookWebpackError.js +1 -1
  53. package/lib/HotModuleReplacementPlugin.js +60 -46
  54. package/lib/IgnoreErrorModuleFactory.js +1 -1
  55. package/lib/InitFragment.js +28 -5
  56. package/lib/JavascriptMetaInfoPlugin.js +27 -15
  57. package/lib/LibManifestPlugin.js +22 -5
  58. package/lib/LoaderOptionsPlugin.js +12 -2
  59. package/lib/MainTemplate.js +2 -2
  60. package/lib/Module.js +44 -12
  61. package/lib/ModuleBuildError.js +9 -0
  62. package/lib/ModuleDependencyError.js +4 -2
  63. package/lib/ModuleDependencyWarning.js +4 -2
  64. package/lib/ModuleError.js +9 -0
  65. package/lib/ModuleFactory.js +1 -1
  66. package/lib/ModuleFilenameHelpers.js +114 -4
  67. package/lib/ModuleGraph.js +33 -23
  68. package/lib/ModuleGraphConnection.js +19 -6
  69. package/lib/ModuleInfoHeaderPlugin.js +9 -2
  70. package/lib/ModuleNotFoundError.js +5 -2
  71. package/lib/ModuleParseError.js +9 -0
  72. package/lib/ModuleProfile.js +1 -0
  73. package/lib/ModuleRestoreError.js +2 -0
  74. package/lib/ModuleStoreError.js +2 -1
  75. package/lib/ModuleTypeConstants.js +169 -0
  76. package/lib/ModuleWarning.js +9 -0
  77. package/lib/MultiWatching.js +4 -0
  78. package/lib/NodeStuffPlugin.js +65 -35
  79. package/lib/NormalModule.js +12 -2
  80. package/lib/NormalModuleFactory.js +56 -8
  81. package/lib/NormalModuleReplacementPlugin.js +5 -3
  82. package/lib/NullFactory.js +1 -1
  83. package/lib/PrefetchPlugin.js +4 -0
  84. package/lib/ProgressPlugin.js +71 -15
  85. package/lib/ProvidePlugin.js +30 -14
  86. package/lib/RawModule.js +13 -2
  87. package/lib/RecordIdsPlugin.js +4 -4
  88. package/lib/RequireJsStuffPlugin.js +22 -15
  89. package/lib/RuntimeGlobals.js +5 -0
  90. package/lib/RuntimeModule.js +12 -11
  91. package/lib/RuntimePlugin.js +10 -3
  92. package/lib/RuntimeTemplate.js +29 -11
  93. package/lib/SelfModuleFactory.js +12 -0
  94. package/lib/SourceMapDevToolModuleOptionsPlugin.js +4 -0
  95. package/lib/SourceMapDevToolPlugin.js +47 -11
  96. package/lib/Template.js +5 -3
  97. package/lib/UseStrictPlugin.js +29 -11
  98. package/lib/WarnCaseSensitiveModulesPlugin.js +12 -0
  99. package/lib/WarnDeprecatedOptionPlugin.js +7 -0
  100. package/lib/WatchIgnorePlugin.js +4 -0
  101. package/lib/WebpackError.js +14 -5
  102. package/lib/WebpackIsIncludedPlugin.js +22 -13
  103. package/lib/WebpackOptionsApply.js +41 -44
  104. package/lib/WebpackOptionsDefaulter.js +10 -3
  105. package/lib/asset/AssetGenerator.js +24 -9
  106. package/lib/asset/AssetModulesPlugin.js +28 -12
  107. package/lib/asset/AssetParser.js +15 -7
  108. package/lib/asset/AssetSourceParser.js +8 -3
  109. package/lib/asset/RawDataUrlModule.js +15 -4
  110. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -0
  111. package/lib/async-modules/InferAsyncModulesPlugin.js +1 -1
  112. package/lib/cache/IdleFileCachePlugin.js +2 -1
  113. package/lib/cache/MemoryWithGcCachePlugin.js +2 -0
  114. package/lib/cache/PackFileCacheStrategy.js +42 -15
  115. package/lib/cache/ResolverCachePlugin.js +3 -0
  116. package/lib/config/browserslistTargetHandler.js +10 -10
  117. package/lib/config/defaults.js +306 -105
  118. package/lib/config/normalization.js +110 -71
  119. package/lib/config/target.js +37 -10
  120. package/lib/container/ContainerEntryModule.js +11 -1
  121. package/lib/container/ContainerEntryModuleFactory.js +1 -1
  122. package/lib/container/ContainerExposedDependency.js +9 -0
  123. package/lib/container/ContainerPlugin.js +3 -1
  124. package/lib/container/FallbackDependency.js +13 -0
  125. package/lib/container/FallbackItemDependency.js +3 -0
  126. package/lib/container/FallbackModule.js +12 -2
  127. package/lib/container/FallbackModuleFactory.js +1 -1
  128. package/lib/container/RemoteModule.js +11 -1
  129. package/lib/container/RemoteRuntimeModule.js +3 -2
  130. package/lib/container/RemoteToExternalDependency.js +3 -0
  131. package/lib/css/CssExportsGenerator.js +9 -0
  132. package/lib/css/CssGenerator.js +5 -1
  133. package/lib/css/CssLoadingRuntimeModule.js +53 -22
  134. package/lib/css/CssModulesPlugin.js +253 -74
  135. package/lib/css/CssParser.js +697 -282
  136. package/lib/css/walkCssTokens.js +269 -138
  137. package/lib/debug/ProfilingPlugin.js +33 -12
  138. package/lib/dependencies/AMDDefineDependency.js +54 -10
  139. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +13 -2
  140. package/lib/dependencies/AMDPlugin.js +33 -20
  141. package/lib/dependencies/AMDRequireArrayDependency.js +13 -0
  142. package/lib/dependencies/AMDRequireContextDependency.js +15 -0
  143. package/lib/dependencies/AMDRequireDependenciesBlock.js +6 -0
  144. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +8 -2
  145. package/lib/dependencies/AMDRequireDependency.js +16 -1
  146. package/lib/dependencies/AMDRequireItemDependency.js +6 -0
  147. package/lib/dependencies/AMDRuntimeModules.js +2 -2
  148. package/lib/dependencies/CachedConstDependency.js +14 -0
  149. package/lib/dependencies/CommonJsDependencyHelpers.js +9 -0
  150. package/lib/dependencies/CommonJsExportRequireDependency.js +19 -0
  151. package/lib/dependencies/CommonJsExportsDependency.js +16 -0
  152. package/lib/dependencies/CommonJsExportsParserPlugin.js +77 -5
  153. package/lib/dependencies/CommonJsFullRequireDependency.js +10 -1
  154. package/lib/dependencies/CommonJsImportsParserPlugin.js +174 -63
  155. package/lib/dependencies/CommonJsPlugin.js +51 -26
  156. package/lib/dependencies/CommonJsRequireContextDependency.js +17 -0
  157. package/lib/dependencies/CommonJsRequireDependency.js +7 -0
  158. package/lib/dependencies/CommonJsSelfReferenceDependency.js +16 -0
  159. package/lib/dependencies/ConstDependency.js +11 -2
  160. package/lib/dependencies/ContextDependency.js +15 -2
  161. package/lib/dependencies/ContextDependencyHelpers.js +3 -3
  162. package/lib/dependencies/ContextElementDependency.js +8 -0
  163. package/lib/dependencies/CreateScriptUrlDependency.js +10 -1
  164. package/lib/dependencies/CriticalDependencyWarning.js +3 -0
  165. package/lib/dependencies/CssExportDependency.js +8 -0
  166. package/lib/dependencies/CssImportDependency.js +55 -3
  167. package/lib/dependencies/CssLocalIdentifierDependency.js +15 -1
  168. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +10 -1
  169. package/lib/dependencies/CssUrlDependency.js +46 -16
  170. package/lib/dependencies/DelegatedSourceDependency.js +3 -0
  171. package/lib/dependencies/DllEntryDependency.js +14 -0
  172. package/lib/dependencies/DynamicExports.js +10 -6
  173. package/lib/dependencies/ExportsInfoDependency.js +25 -4
  174. package/lib/dependencies/HarmonyAcceptDependency.js +10 -1
  175. package/lib/dependencies/HarmonyAcceptImportDependency.js +3 -0
  176. package/lib/dependencies/HarmonyCompatibilityDependency.js +2 -1
  177. package/lib/dependencies/HarmonyDetectionParserPlugin.js +22 -2
  178. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +32 -6
  179. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +5 -0
  180. package/lib/dependencies/HarmonyExportExpressionDependency.js +20 -3
  181. package/lib/dependencies/HarmonyExportHeaderDependency.js +13 -0
  182. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +22 -6
  183. package/lib/dependencies/HarmonyExportInitFragment.js +2 -1
  184. package/lib/dependencies/HarmonyExportSpecifierDependency.js +12 -0
  185. package/lib/dependencies/HarmonyExports.js +11 -5
  186. package/lib/dependencies/HarmonyImportDependency.js +10 -1
  187. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +53 -22
  188. package/lib/dependencies/HarmonyImportSideEffectDependency.js +7 -2
  189. package/lib/dependencies/HarmonyImportSpecifierDependency.js +139 -16
  190. package/lib/dependencies/HarmonyModulesPlugin.js +23 -5
  191. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -3
  192. package/lib/dependencies/ImportContextDependency.js +15 -0
  193. package/lib/dependencies/ImportDependency.js +15 -4
  194. package/lib/dependencies/ImportEagerDependency.js +7 -4
  195. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +51 -13
  196. package/lib/dependencies/ImportMetaContextPlugin.js +18 -5
  197. package/lib/dependencies/ImportMetaHotAcceptDependency.js +6 -0
  198. package/lib/dependencies/ImportMetaHotDeclineDependency.js +6 -0
  199. package/lib/dependencies/ImportMetaPlugin.js +103 -51
  200. package/lib/dependencies/ImportParserPlugin.js +83 -25
  201. package/lib/dependencies/ImportPlugin.js +21 -7
  202. package/lib/dependencies/ImportWeakDependency.js +7 -4
  203. package/lib/dependencies/JsonExportsDependency.js +9 -1
  204. package/lib/dependencies/LocalModule.js +16 -0
  205. package/lib/dependencies/LocalModuleDependency.js +15 -0
  206. package/lib/dependencies/LocalModulesHelpers.js +18 -0
  207. package/lib/dependencies/ModuleDecoratorDependency.js +8 -0
  208. package/lib/dependencies/ModuleDependency.js +9 -1
  209. package/lib/dependencies/ModuleDependencyTemplateAsId.js +2 -1
  210. package/lib/dependencies/ModuleHotAcceptDependency.js +6 -0
  211. package/lib/dependencies/ModuleHotDeclineDependency.js +6 -0
  212. package/lib/dependencies/PrefetchDependency.js +3 -0
  213. package/lib/dependencies/ProvidedDependency.js +14 -2
  214. package/lib/dependencies/PureExpressionDependency.js +10 -1
  215. package/lib/dependencies/RequireContextDependency.js +6 -0
  216. package/lib/dependencies/RequireContextDependencyParserPlugin.js +13 -5
  217. package/lib/dependencies/RequireContextPlugin.js +19 -6
  218. package/lib/dependencies/RequireEnsureDependenciesBlock.js +7 -0
  219. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +6 -1
  220. package/lib/dependencies/RequireEnsureDependency.js +16 -2
  221. package/lib/dependencies/RequireEnsureItemDependency.js +3 -0
  222. package/lib/dependencies/RequireEnsurePlugin.js +27 -7
  223. package/lib/dependencies/RequireHeaderDependency.js +14 -1
  224. package/lib/dependencies/RequireIncludeDependency.js +5 -0
  225. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +29 -5
  226. package/lib/dependencies/RequireIncludePlugin.js +25 -5
  227. package/lib/dependencies/RequireResolveContextDependency.js +17 -0
  228. package/lib/dependencies/RequireResolveDependency.js +6 -0
  229. package/lib/dependencies/RequireResolveHeaderDependency.js +18 -0
  230. package/lib/dependencies/RuntimeRequirementsDependency.js +8 -0
  231. package/lib/dependencies/StaticExportsDependency.js +8 -0
  232. package/lib/dependencies/SystemPlugin.js +48 -21
  233. package/lib/dependencies/SystemRuntimeModule.js +1 -1
  234. package/lib/dependencies/URLDependency.js +13 -4
  235. package/lib/dependencies/URLPlugin.js +31 -18
  236. package/lib/dependencies/UnsupportedDependency.js +13 -0
  237. package/lib/dependencies/WebAssemblyExportImportedDependency.js +14 -0
  238. package/lib/dependencies/WebAssemblyImportDependency.js +9 -1
  239. package/lib/dependencies/WebpackIsIncludedDependency.js +5 -0
  240. package/lib/dependencies/WorkerDependency.js +47 -3
  241. package/lib/dependencies/WorkerPlugin.js +105 -32
  242. package/lib/dependencies/getFunctionExpression.js +7 -0
  243. package/lib/esm/ExportWebpackRequireRuntimeModule.js +3 -2
  244. package/lib/esm/ModuleChunkFormatPlugin.js +21 -8
  245. package/lib/esm/ModuleChunkLoadingPlugin.js +9 -0
  246. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +19 -12
  247. package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
  248. package/lib/hmr/LazyCompilationPlugin.js +14 -5
  249. package/lib/ids/ChunkModuleIdRangePlugin.js +11 -0
  250. package/lib/ids/DeterministicChunkIdsPlugin.js +11 -2
  251. package/lib/ids/DeterministicModuleIdsPlugin.js +11 -7
  252. package/lib/ids/HashedModuleIdsPlugin.js +9 -2
  253. package/lib/ids/IdHelpers.js +6 -0
  254. package/lib/ids/NamedChunkIdsPlugin.js +13 -1
  255. package/lib/ids/NamedModuleIdsPlugin.js +14 -3
  256. package/lib/ids/OccurrenceChunkIdsPlugin.js +6 -2
  257. package/lib/ids/OccurrenceModuleIdsPlugin.js +1 -1
  258. package/lib/ids/SyncModuleIdsPlugin.js +3 -2
  259. package/lib/index.js +8 -0
  260. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +3 -3
  261. package/lib/javascript/BasicEvaluatedExpression.js +137 -11
  262. package/lib/javascript/ChunkHelpers.js +2 -2
  263. package/lib/javascript/CommonJsChunkFormatPlugin.js +7 -3
  264. package/lib/javascript/EnableChunkLoadingPlugin.js +4 -0
  265. package/lib/javascript/JavascriptModulesPlugin.js +194 -194
  266. package/lib/javascript/JavascriptParser.js +941 -256
  267. package/lib/javascript/JavascriptParserHelpers.js +37 -15
  268. package/lib/javascript/StartupHelpers.js +2 -2
  269. package/lib/json/JsonData.js +26 -1
  270. package/lib/json/JsonGenerator.js +21 -7
  271. package/lib/json/JsonModulesPlugin.js +14 -5
  272. package/lib/json/JsonParser.js +27 -13
  273. package/lib/library/AbstractLibraryPlugin.js +4 -0
  274. package/lib/library/AmdLibraryPlugin.js +22 -6
  275. package/lib/library/AssignLibraryPlugin.js +6 -4
  276. package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
  277. package/lib/library/ModuleLibraryPlugin.js +8 -4
  278. package/lib/library/SystemLibraryPlugin.js +1 -0
  279. package/lib/library/UmdLibraryPlugin.js +4 -0
  280. package/lib/logging/runtime.js +1 -1
  281. package/lib/logging/truncateArgs.js +4 -0
  282. package/lib/node/CommonJsChunkLoadingPlugin.js +17 -2
  283. package/lib/node/NodeTargetPlugin.js +3 -0
  284. package/lib/node/NodeTemplatePlugin.js +10 -2
  285. package/lib/node/NodeWatchFileSystem.js +1 -1
  286. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +18 -9
  287. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +12 -2
  288. package/lib/node/ReadFileCompileWasmPlugin.js +21 -3
  289. package/lib/node/RequireChunkLoadingRuntimeModule.js +15 -8
  290. package/lib/node/nodeConsole.js +2 -4
  291. package/lib/optimize/AggressiveMergingPlugin.js +8 -0
  292. package/lib/optimize/AggressiveSplittingPlugin.js +9 -2
  293. package/lib/optimize/ConcatenatedModule.js +8 -6
  294. package/lib/optimize/EnsureChunkConditionsPlugin.js +3 -0
  295. package/lib/optimize/FlagIncludedChunksPlugin.js +11 -5
  296. package/lib/optimize/InnerGraph.js +5 -5
  297. package/lib/optimize/InnerGraphPlugin.js +57 -48
  298. package/lib/optimize/LimitChunkCountPlugin.js +29 -4
  299. package/lib/optimize/MangleExportsPlugin.js +1 -1
  300. package/lib/optimize/MinMaxSizeWarning.js +5 -0
  301. package/lib/optimize/ModuleConcatenationPlugin.js +59 -2
  302. package/lib/optimize/RealContentHashPlugin.js +86 -30
  303. package/lib/optimize/RemoveParentModulesPlugin.js +6 -0
  304. package/lib/optimize/RuntimeChunkPlugin.js +9 -1
  305. package/lib/optimize/SideEffectsFlagPlugin.js +53 -44
  306. package/lib/optimize/SplitChunksPlugin.js +71 -31
  307. package/lib/performance/SizeLimitsPlugin.js +7 -4
  308. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +4 -2
  309. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +3 -1
  310. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +6 -3
  311. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +4 -2
  312. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +4 -2
  313. package/lib/rules/BasicEffectRulePlugin.js +4 -0
  314. package/lib/rules/BasicMatcherRulePlugin.js +5 -0
  315. package/lib/rules/RuleSetCompiler.js +3 -3
  316. package/lib/rules/UseEffectRulePlugin.js +6 -4
  317. package/lib/runtime/AsyncModuleRuntimeModule.js +9 -6
  318. package/lib/runtime/AutoPublicPathRuntimeModule.js +16 -5
  319. package/lib/runtime/BaseUriRuntimeModule.js +8 -4
  320. package/lib/runtime/ChunkNameRuntimeModule.js +1 -1
  321. package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +5 -2
  322. package/lib/runtime/CompatRuntimeModule.js +7 -2
  323. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +5 -2
  324. package/lib/runtime/CreateScriptRuntimeModule.js +4 -2
  325. package/lib/runtime/CreateScriptUrlRuntimeModule.js +4 -2
  326. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +5 -2
  327. package/lib/runtime/EnsureChunkRuntimeModule.js +18 -4
  328. package/lib/runtime/GetChunkFilenameRuntimeModule.js +45 -26
  329. package/lib/runtime/GetFullHashRuntimeModule.js +4 -3
  330. package/lib/runtime/GetMainFilenameRuntimeModule.js +5 -2
  331. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +27 -6
  332. package/lib/runtime/GlobalRuntimeModule.js +1 -1
  333. package/lib/runtime/HasOwnPropertyRuntimeModule.js +5 -2
  334. package/lib/runtime/LoadScriptRuntimeModule.js +65 -50
  335. package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +5 -2
  336. package/lib/runtime/NonceRuntimeModule.js +1 -1
  337. package/lib/runtime/OnChunksLoadedRuntimeModule.js +4 -2
  338. package/lib/runtime/PublicPathRuntimeModule.js +9 -2
  339. package/lib/runtime/RelativeUrlRuntimeModule.js +5 -2
  340. package/lib/runtime/RuntimeIdRuntimeModule.js +6 -2
  341. package/lib/runtime/StartupChunkDependenciesPlugin.js +15 -0
  342. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +13 -4
  343. package/lib/runtime/StartupEntrypointRuntimeModule.js +11 -7
  344. package/lib/runtime/SystemContextRuntimeModule.js +1 -1
  345. package/lib/schemes/DataUriPlugin.js +16 -3
  346. package/lib/schemes/HttpUriPlugin.js +38 -0
  347. package/lib/serialization/ArraySerializer.js +22 -6
  348. package/lib/serialization/BinaryMiddleware.js +164 -1
  349. package/lib/serialization/DateObjectSerializer.js +15 -4
  350. package/lib/serialization/ErrorObjectSerializer.js +23 -8
  351. package/lib/serialization/FileMiddleware.js +17 -0
  352. package/lib/serialization/MapObjectSerializer.js +24 -8
  353. package/lib/serialization/NullPrototypeObjectSerializer.js +25 -8
  354. package/lib/serialization/ObjectMiddleware.js +33 -2
  355. package/lib/serialization/PlainObjectSerializer.js +23 -12
  356. package/lib/serialization/RegExpObjectSerializer.js +16 -5
  357. package/lib/serialization/SetObjectSerializer.js +21 -6
  358. package/lib/serialization/types.js +1 -1
  359. package/lib/sharing/ConsumeSharedFallbackDependency.js +3 -0
  360. package/lib/sharing/ConsumeSharedModule.js +13 -2
  361. package/lib/sharing/ConsumeSharedPlugin.js +4 -0
  362. package/lib/sharing/ConsumeSharedRuntimeModule.js +22 -7
  363. package/lib/sharing/ProvideSharedDependency.js +17 -0
  364. package/lib/sharing/ProvideSharedModule.js +11 -1
  365. package/lib/sharing/ProvideSharedModuleFactory.js +1 -1
  366. package/lib/sharing/ProvideSharedPlugin.js +22 -21
  367. package/lib/sharing/ShareRuntimeModule.js +19 -9
  368. package/lib/sharing/resolveMatchedConfigs.js +1 -1
  369. package/lib/sharing/utils.js +320 -7
  370. package/lib/stats/DefaultStatsFactoryPlugin.js +105 -29
  371. package/lib/stats/DefaultStatsPresetPlugin.js +9 -0
  372. package/lib/stats/DefaultStatsPrinterPlugin.js +43 -0
  373. package/lib/util/AsyncQueue.js +4 -2
  374. package/lib/util/LazySet.js +10 -2
  375. package/lib/util/MapHelpers.js +19 -5
  376. package/lib/util/ParallelismFactorCalculator.js +10 -0
  377. package/lib/util/Semaphore.js +1 -1
  378. package/lib/util/StackedCacheMap.js +6 -0
  379. package/lib/util/StringXor.js +51 -0
  380. package/lib/util/binarySearchBounds.js +49 -0
  381. package/lib/util/compileBooleanMatcher.js +31 -0
  382. package/lib/util/createHash.js +35 -13
  383. package/lib/util/deprecation.js +18 -3
  384. package/lib/util/deterministicGrouping.js +50 -11
  385. package/lib/util/findGraphRoots.js +4 -2
  386. package/lib/util/hash/md4.js +2 -2
  387. package/lib/util/hash/xxhash64.js +1 -1
  388. package/lib/util/identifier.js +4 -0
  389. package/lib/util/internalSerializables.js +1 -0
  390. package/lib/util/makeSerializable.js +7 -0
  391. package/lib/util/memoize.js +3 -3
  392. package/lib/util/numberHash.js +75 -21
  393. package/lib/util/processAsyncTree.js +7 -1
  394. package/lib/util/propertyAccess.js +9 -54
  395. package/lib/util/propertyName.js +79 -0
  396. package/lib/util/registerExternalSerializer.js +1 -1
  397. package/lib/util/runtime.js +14 -1
  398. package/lib/util/semver.js +1 -1
  399. package/lib/util/serialization.js +10 -0
  400. package/lib/util/smartGrouping.js +1 -1
  401. package/lib/validateSchema.js +6 -2
  402. package/lib/wasm/EnableWasmLoadingPlugin.js +4 -0
  403. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +15 -2
  404. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +9 -1
  405. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +14 -3
  406. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +28 -8
  407. package/lib/wasm-async/AsyncWebAssemblyParser.js +11 -4
  408. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +39 -8
  409. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +17 -6
  410. package/lib/wasm-sync/WebAssemblyGenerator.js +19 -5
  411. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +1 -1
  412. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +53 -43
  413. package/lib/wasm-sync/WebAssemblyParser.js +15 -4
  414. package/lib/wasm-sync/WebAssemblyUtils.js +1 -1
  415. package/lib/web/FetchCompileAsyncWasmPlugin.js +11 -1
  416. package/lib/web/FetchCompileWasmPlugin.js +59 -42
  417. package/lib/web/JsonpChunkLoadingPlugin.js +9 -0
  418. package/lib/web/JsonpChunkLoadingRuntimeModule.js +26 -9
  419. package/lib/webpack.js +12 -3
  420. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +9 -0
  421. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +20 -17
  422. package/module.d.ts +55 -37
  423. package/package.json +59 -56
  424. package/schemas/WebpackOptions.check.js +1 -1
  425. package/schemas/WebpackOptions.json +132 -5
  426. package/schemas/plugins/ProgressPlugin.check.js +1 -1
  427. package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
  428. package/schemas/plugins/SourceMapDevToolPlugin.json +4 -0
  429. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  430. package/schemas/plugins/container/ContainerPlugin.json +8 -0
  431. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  432. package/schemas/plugins/container/ModuleFederationPlugin.json +8 -0
  433. package/schemas/plugins/css/CssGeneratorOptions.json +1 -1
  434. package/schemas/plugins/css/CssParserOptions.json +1 -1
  435. package/schemas/plugins/sharing/SharePlugin.check.js +1 -1
  436. package/types.d.ts +1608 -667
@@ -19,10 +19,16 @@ const HarmonyImportDependency = require("./HarmonyImportDependency");
19
19
  /** @typedef {import("../Dependency").ReferencedExport} ReferencedExport */
20
20
  /** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
21
21
  /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
22
+ /** @typedef {import("../Module")} Module */
23
+ /** @typedef {import("../Module").BuildMeta} BuildMeta */
22
24
  /** @typedef {import("../ModuleGraph")} ModuleGraph */
23
25
  /** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
24
26
  /** @typedef {import("../ModuleGraphConnection").ConnectionState} ConnectionState */
25
27
  /** @typedef {import("../WebpackError")} WebpackError */
28
+ /** @typedef {import("../javascript/JavascriptParser").Assertions} Assertions */
29
+ /** @typedef {import("../javascript/JavascriptParser").Range} Range */
30
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
31
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
26
32
  /** @typedef {import("../util/Hash")} Hash */
27
33
  /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
28
34
 
@@ -31,6 +37,16 @@ const idsSymbol = Symbol("HarmonyImportSpecifierDependency.ids");
31
37
  const { ExportPresenceModes } = HarmonyImportDependency;
32
38
 
33
39
  class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
40
+ /**
41
+ * @param {TODO} request request
42
+ * @param {number} sourceOrder source order
43
+ * @param {string[]} ids ids
44
+ * @param {string} name name
45
+ * @param {Range} range range
46
+ * @param {TODO} exportPresenceMode export presence mode
47
+ * @param {Assertions=} assertions assertions
48
+ * @param {Range[]=} idRanges ranges for members of ids; the two arrays are right-aligned
49
+ */
34
50
  constructor(
35
51
  request,
36
52
  sourceOrder,
@@ -38,20 +54,25 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
38
54
  name,
39
55
  range,
40
56
  exportPresenceMode,
41
- assertions
57
+ assertions,
58
+ idRanges // TODO webpack 6 make this non-optional. It must always be set to properly trim ids.
42
59
  ) {
43
60
  super(request, sourceOrder, assertions);
44
61
  this.ids = ids;
45
62
  this.name = name;
46
63
  this.range = range;
64
+ this.idRanges = idRanges;
47
65
  this.exportPresenceMode = exportPresenceMode;
66
+ /** @type {boolean | undefined} */
48
67
  this.namespaceObjectAsContext = false;
49
68
  this.call = undefined;
50
69
  this.directImport = undefined;
51
70
  this.shorthand = undefined;
52
71
  this.asiSafe = undefined;
53
- /** @type {Set<string> | boolean} */
72
+ /** @type {Set<string> | boolean | undefined} */
54
73
  this.usedByExports = undefined;
74
+ /** @type {Set<string> | undefined} */
75
+ this.referencedPropertiesInDestructuring = undefined;
55
76
  }
56
77
 
57
78
  // TODO webpack 6 remove
@@ -121,20 +142,24 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
121
142
  */
122
143
  getReferencedExports(moduleGraph, runtime) {
123
144
  let ids = this.getIds(moduleGraph);
124
- if (ids.length === 0) return Dependency.EXPORTS_OBJECT_REFERENCED;
145
+ if (ids.length === 0) return this._getReferencedExportsInDestructuring();
125
146
  let namespaceObjectAsContext = this.namespaceObjectAsContext;
126
147
  if (ids[0] === "default") {
127
148
  const selfModule = moduleGraph.getParentModule(this);
128
- const importedModule = moduleGraph.getModule(this);
149
+ const importedModule =
150
+ /** @type {Module} */
151
+ (moduleGraph.getModule(this));
129
152
  switch (
130
153
  importedModule.getExportsType(
131
154
  moduleGraph,
132
- selfModule.buildMeta.strictHarmonyModule
155
+ /** @type {BuildMeta} */
156
+ (selfModule.buildMeta).strictHarmonyModule
133
157
  )
134
158
  ) {
135
159
  case "default-only":
136
160
  case "default-with-named":
137
- if (ids.length === 1) return Dependency.EXPORTS_OBJECT_REFERENCED;
161
+ if (ids.length === 1)
162
+ return this._getReferencedExportsInDestructuring();
138
163
  ids = ids.slice(1);
139
164
  namespaceObjectAsContext = true;
140
165
  break;
@@ -152,7 +177,27 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
152
177
  ids = ids.slice(0, -1);
153
178
  }
154
179
 
155
- return [ids];
180
+ return this._getReferencedExportsInDestructuring(ids);
181
+ }
182
+
183
+ /**
184
+ * @param {string[]=} ids ids
185
+ * @returns {(string[] | ReferencedExport)[]} referenced exports
186
+ */
187
+ _getReferencedExportsInDestructuring(ids) {
188
+ if (this.referencedPropertiesInDestructuring) {
189
+ /** @type {ReferencedExport[]} */
190
+ const refs = [];
191
+ for (const key of this.referencedPropertiesInDestructuring) {
192
+ refs.push({
193
+ name: ids ? ids.concat([key]) : [key],
194
+ canMangle: false
195
+ });
196
+ }
197
+ return refs;
198
+ } else {
199
+ return ids ? [ids] : Dependency.EXPORTS_OBJECT_REFERENCED;
200
+ }
156
201
  }
157
202
 
158
203
  /**
@@ -162,7 +207,10 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
162
207
  _getEffectiveExportPresenceLevel(moduleGraph) {
163
208
  if (this.exportPresenceMode !== ExportPresenceModes.AUTO)
164
209
  return this.exportPresenceMode;
165
- return moduleGraph.getParentModule(this).buildMeta.strictHarmonyModule
210
+ const buildMeta = /** @type {BuildMeta} */ (
211
+ moduleGraph.getParentModule(this).buildMeta
212
+ );
213
+ return buildMeta.strictHarmonyModule
166
214
  ? ExportPresenceModes.ERROR
167
215
  : ExportPresenceModes.WARN;
168
216
  }
@@ -170,7 +218,7 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
170
218
  /**
171
219
  * Returns warnings
172
220
  * @param {ModuleGraph} moduleGraph module graph
173
- * @returns {WebpackError[]} warnings
221
+ * @returns {WebpackError[] | null | undefined} warnings
174
222
  */
175
223
  getWarnings(moduleGraph) {
176
224
  const exportsPresence = this._getEffectiveExportPresenceLevel(moduleGraph);
@@ -183,7 +231,7 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
183
231
  /**
184
232
  * Returns errors
185
233
  * @param {ModuleGraph} moduleGraph module graph
186
- * @returns {WebpackError[]} errors
234
+ * @returns {WebpackError[] | null | undefined} errors
187
235
  */
188
236
  getErrors(moduleGraph) {
189
237
  const exportsPresence = this._getEffectiveExportPresenceLevel(moduleGraph);
@@ -214,11 +262,15 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
214
262
  return 0;
215
263
  }
216
264
 
265
+ /**
266
+ * @param {ObjectSerializerContext} context context
267
+ */
217
268
  serialize(context) {
218
269
  const { write } = context;
219
270
  write(this.ids);
220
271
  write(this.name);
221
272
  write(this.range);
273
+ write(this.idRanges);
222
274
  write(this.exportPresenceMode);
223
275
  write(this.namespaceObjectAsContext);
224
276
  write(this.call);
@@ -226,14 +278,19 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
226
278
  write(this.shorthand);
227
279
  write(this.asiSafe);
228
280
  write(this.usedByExports);
281
+ write(this.referencedPropertiesInDestructuring);
229
282
  super.serialize(context);
230
283
  }
231
284
 
285
+ /**
286
+ * @param {ObjectDeserializerContext} context context
287
+ */
232
288
  deserialize(context) {
233
289
  const { read } = context;
234
290
  this.ids = read();
235
291
  this.name = read();
236
292
  this.range = read();
293
+ this.idRanges = read();
237
294
  this.exportPresenceMode = read();
238
295
  this.namespaceObjectAsContext = read();
239
296
  this.call = read();
@@ -241,6 +298,7 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
241
298
  this.shorthand = read();
242
299
  this.asiSafe = read();
243
300
  this.usedByExports = read();
301
+ this.referencedPropertiesInDestructuring = read();
244
302
  super.deserialize(context);
245
303
  }
246
304
  }
@@ -266,14 +324,79 @@ HarmonyImportSpecifierDependency.Template = class HarmonyImportSpecifierDependen
266
324
  // Skip rendering depending when dependency is conditional
267
325
  if (connection && !connection.isTargetActive(runtime)) return;
268
326
 
269
- const ids = dep.getIds(moduleGraph);
270
- const exportExpr = this._getCodeForIds(dep, source, templateContext, ids);
271
- const range = dep.range;
327
+ const ids = dep.getIds(moduleGraph); // determine minimal set of IDs.
328
+ let trimmedIds = this._trimIdsToThoseImported(ids, moduleGraph, dep);
329
+
330
+ let [rangeStart, rangeEnd] = dep.range;
331
+ if (trimmedIds.length !== ids.length) {
332
+ // The array returned from dep.idRanges is right-aligned with the array returned from dep.getIds.
333
+ // Meaning, the two arrays may not always have the same number of elements, but the last element of
334
+ // dep.idRanges corresponds to [the expression fragment to the left of] the last element of dep.getIds.
335
+ // Use this to find the correct replacement range based on the number of ids that were trimmed.
336
+ const idx =
337
+ dep.idRanges === undefined
338
+ ? -1 /* trigger failure case below */
339
+ : dep.idRanges.length + (trimmedIds.length - ids.length);
340
+ if (idx < 0 || idx >= dep.idRanges.length) {
341
+ // cspell:ignore minifiers
342
+ // Should not happen but we can't throw an error here because of backward compatibility with
343
+ // external plugins in wp5. Instead, we just disable trimming for now. This may break some minifiers.
344
+ trimmedIds = ids;
345
+ // TODO webpack 6 remove the "trimmedIds = ids" above and uncomment the following line instead.
346
+ // throw new Error("Missing range starts data for id replacement trimming.");
347
+ } else {
348
+ [rangeStart, rangeEnd] = dep.idRanges[idx];
349
+ }
350
+ }
351
+
352
+ const exportExpr = this._getCodeForIds(
353
+ dep,
354
+ source,
355
+ templateContext,
356
+ trimmedIds
357
+ );
272
358
  if (dep.shorthand) {
273
- source.insert(range[1], `: ${exportExpr}`);
359
+ source.insert(rangeEnd, `: ${exportExpr}`);
274
360
  } else {
275
- source.replace(range[0], range[1] - 1, exportExpr);
361
+ source.replace(rangeStart, rangeEnd - 1, exportExpr);
362
+ }
363
+ }
364
+
365
+ /**
366
+ * @summary Determine which IDs in the id chain are actually referring to namespaces or imports,
367
+ * and which are deeper member accessors on the imported object. Only the former should be re-rendered.
368
+ * @param {string[]} ids ids
369
+ * @param {ModuleGraph} moduleGraph moduleGraph
370
+ * @param {HarmonyImportSpecifierDependency} dependency dependency
371
+ * @returns {string[]} generated code
372
+ */
373
+ _trimIdsToThoseImported(ids, moduleGraph, dependency) {
374
+ /** @type {string[]} */
375
+ let trimmedIds = [];
376
+ const exportsInfo = moduleGraph.getExportsInfo(
377
+ /** @type {Module} */ (moduleGraph.getModule(dependency))
378
+ );
379
+ let currentExportsInfo = /** @type {ExportsInfo=} */ exportsInfo;
380
+ for (let i = 0; i < ids.length; i++) {
381
+ if (i === 0 && ids[i] === "default") {
382
+ continue; // ExportInfo for the next level under default is still at the root ExportsInfo, so don't advance currentExportsInfo
383
+ }
384
+ const exportInfo = currentExportsInfo.getExportInfo(ids[i]);
385
+ if (exportInfo.provided === false) {
386
+ // json imports have nested ExportInfo for elements that things that are not actually exported, so check .provided
387
+ trimmedIds = ids.slice(0, i);
388
+ break;
389
+ }
390
+ const nestedInfo = exportInfo.getNestedExportsInfo();
391
+ if (!nestedInfo) {
392
+ // once all nested exports are traversed, the next item is the actual import so stop there
393
+ trimmedIds = ids.slice(0, i + 1);
394
+ break;
395
+ }
396
+ currentExportsInfo = nestedInfo;
276
397
  }
398
+ // Never trim to nothing. This can happen for invalid imports (e.g. import { notThere } from "./module", or import { anything } from "./missingModule")
399
+ return trimmedIds.length ? trimmedIds : ids;
277
400
  }
278
401
 
279
402
  /**
@@ -324,7 +447,7 @@ HarmonyImportSpecifierDependency.Template = class HarmonyImportSpecifierDependen
324
447
 
325
448
  exportExpr = runtimeTemplate.exportFromImport({
326
449
  moduleGraph,
327
- module: moduleGraph.getModule(dep),
450
+ module: /** @type {Module} */ (moduleGraph.getModule(dep)),
328
451
  request: dep.request,
329
452
  exportName: ids,
330
453
  originModule: module,
@@ -16,14 +16,27 @@ const HarmonyExportSpecifierDependency = require("./HarmonyExportSpecifierDepend
16
16
  const HarmonyImportSideEffectDependency = require("./HarmonyImportSideEffectDependency");
17
17
  const HarmonyImportSpecifierDependency = require("./HarmonyImportSpecifierDependency");
18
18
 
19
+ const {
20
+ JAVASCRIPT_MODULE_TYPE_AUTO,
21
+ JAVASCRIPT_MODULE_TYPE_ESM
22
+ } = require("../ModuleTypeConstants");
19
23
  const HarmonyDetectionParserPlugin = require("./HarmonyDetectionParserPlugin");
20
24
  const HarmonyExportDependencyParserPlugin = require("./HarmonyExportDependencyParserPlugin");
21
25
  const HarmonyImportDependencyParserPlugin = require("./HarmonyImportDependencyParserPlugin");
22
26
  const HarmonyTopLevelThisParserPlugin = require("./HarmonyTopLevelThisParserPlugin");
23
27
 
28
+ /** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
24
29
  /** @typedef {import("../Compiler")} Compiler */
30
+ /** @typedef {import("../javascript/JavascriptParser")} Parser */
31
+
32
+ const PLUGIN_NAME = "HarmonyModulesPlugin";
33
+
34
+ /** @typedef {{ topLevelAwait?: boolean }} HarmonyModulesPluginOptions */
25
35
 
26
36
  class HarmonyModulesPlugin {
37
+ /**
38
+ * @param {HarmonyModulesPluginOptions} options options
39
+ */
27
40
  constructor(options) {
28
41
  this.options = options;
29
42
  }
@@ -35,7 +48,7 @@ class HarmonyModulesPlugin {
35
48
  */
36
49
  apply(compiler) {
37
50
  compiler.hooks.compilation.tap(
38
- "HarmonyModulesPlugin",
51
+ PLUGIN_NAME,
39
52
  (compilation, { normalModuleFactory }) => {
40
53
  compilation.dependencyTemplates.set(
41
54
  HarmonyCompatibilityDependency,
@@ -107,6 +120,11 @@ class HarmonyModulesPlugin {
107
120
  new HarmonyAcceptImportDependency.Template()
108
121
  );
109
122
 
123
+ /**
124
+ * @param {Parser} parser parser parser
125
+ * @param {JavascriptParserOptions} parserOptions parserOptions
126
+ * @returns {void}
127
+ */
110
128
  const handler = (parser, parserOptions) => {
111
129
  // TODO webpack 6: rename harmony to esm or module
112
130
  if (parserOptions.harmony !== undefined && !parserOptions.harmony)
@@ -119,11 +137,11 @@ class HarmonyModulesPlugin {
119
137
  };
120
138
 
121
139
  normalModuleFactory.hooks.parser
122
- .for("javascript/auto")
123
- .tap("HarmonyModulesPlugin", handler);
140
+ .for(JAVASCRIPT_MODULE_TYPE_AUTO)
141
+ .tap(PLUGIN_NAME, handler);
124
142
  normalModuleFactory.hooks.parser
125
- .for("javascript/esm")
126
- .tap("HarmonyModulesPlugin", handler);
143
+ .for(JAVASCRIPT_MODULE_TYPE_ESM)
144
+ .tap(PLUGIN_NAME, handler);
127
145
  }
128
146
  );
129
147
  }
@@ -8,17 +8,29 @@
8
8
  const ConstDependency = require("./ConstDependency");
9
9
  const HarmonyExports = require("./HarmonyExports");
10
10
 
11
+ /** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
12
+ /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
13
+ /** @typedef {import("../javascript/JavascriptParser").Range} Range */
14
+
11
15
  class HarmonyTopLevelThisParserPlugin {
16
+ /**
17
+ * @param {JavascriptParser} parser the parser
18
+ * @returns {void}
19
+ */
12
20
  apply(parser) {
13
21
  parser.hooks.expression
14
22
  .for("this")
15
23
  .tap("HarmonyTopLevelThisParserPlugin", node => {
16
24
  if (!parser.scope.topLevelScope) return;
17
25
  if (HarmonyExports.isEnabled(parser.state)) {
18
- const dep = new ConstDependency("undefined", node.range, null);
19
- dep.loc = node.loc;
26
+ const dep = new ConstDependency(
27
+ "undefined",
28
+ /** @type {Range} */ (node.range),
29
+ null
30
+ );
31
+ dep.loc = /** @type {DependencyLocation} */ (node.loc);
20
32
  parser.state.module.addPresentationalDependency(dep);
21
- return this;
33
+ return true;
22
34
  }
23
35
  });
24
36
  }
@@ -9,7 +9,16 @@ const makeSerializable = require("../util/makeSerializable");
9
9
  const ContextDependency = require("./ContextDependency");
10
10
  const ContextDependencyTemplateAsRequireCall = require("./ContextDependencyTemplateAsRequireCall");
11
11
 
12
+ /** @typedef {import("../javascript/JavascriptParser").Range} Range */
13
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
14
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
15
+
12
16
  class ImportContextDependency extends ContextDependency {
17
+ /**
18
+ * @param {TODO} options options
19
+ * @param {Range} range range
20
+ * @param {Range} valueRange value range
21
+ */
13
22
  constructor(options, range, valueRange) {
14
23
  super(options);
15
24
 
@@ -25,6 +34,9 @@ class ImportContextDependency extends ContextDependency {
25
34
  return "esm";
26
35
  }
27
36
 
37
+ /**
38
+ * @param {ObjectSerializerContext} context context
39
+ */
28
40
  serialize(context) {
29
41
  const { write } = context;
30
42
 
@@ -33,6 +45,9 @@ class ImportContextDependency extends ContextDependency {
33
45
  super.serialize(context);
34
46
  }
35
47
 
48
+ /**
49
+ * @param {ObjectDeserializerContext} context context
50
+ */
36
51
  deserialize(context) {
37
52
  const { read } = context;
38
53
 
@@ -13,14 +13,19 @@ const ModuleDependency = require("./ModuleDependency");
13
13
  /** @typedef {import("../AsyncDependenciesBlock")} AsyncDependenciesBlock */
14
14
  /** @typedef {import("../Dependency").ReferencedExport} ReferencedExport */
15
15
  /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
16
+ /** @typedef {import("../Module")} Module */
17
+ /** @typedef {import("../Module").BuildMeta} BuildMeta */
16
18
  /** @typedef {import("../ModuleGraph")} ModuleGraph */
19
+ /** @typedef {import("../javascript/JavascriptParser").Range} Range */
20
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
21
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
17
22
  /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
18
23
 
19
24
  class ImportDependency extends ModuleDependency {
20
25
  /**
21
26
  * @param {string} request the request
22
- * @param {[number, number]} range expression range
23
- * @param {string[][]=} referencedExports list of referenced exports
27
+ * @param {Range} range expression range
28
+ * @param {(string[][] | null)=} referencedExports list of referenced exports
24
29
  */
25
30
  constructor(request, range, referencedExports) {
26
31
  super(request);
@@ -51,12 +56,18 @@ class ImportDependency extends ModuleDependency {
51
56
  : Dependency.EXPORTS_OBJECT_REFERENCED;
52
57
  }
53
58
 
59
+ /**
60
+ * @param {ObjectSerializerContext} context context
61
+ */
54
62
  serialize(context) {
55
63
  context.write(this.range);
56
64
  context.write(this.referencedExports);
57
65
  super.serialize(context);
58
66
  }
59
67
 
68
+ /**
69
+ * @param {ObjectDeserializerContext} context context
70
+ */
60
71
  deserialize(context) {
61
72
  this.range = context.read();
62
73
  this.referencedExports = context.read();
@@ -87,9 +98,9 @@ ImportDependency.Template = class ImportDependencyTemplate extends (
87
98
  const content = runtimeTemplate.moduleNamespacePromise({
88
99
  chunkGraph,
89
100
  block: block,
90
- module: moduleGraph.getModule(dep),
101
+ module: /** @type {Module} */ (moduleGraph.getModule(dep)),
91
102
  request: dep.request,
92
- strict: module.buildMeta.strictHarmonyModule,
103
+ strict: /** @type {BuildMeta} */ (module.buildMeta).strictHarmonyModule,
93
104
  message: "import()",
94
105
  runtimeRequirements
95
106
  });
@@ -12,13 +12,16 @@ const ImportDependency = require("./ImportDependency");
12
12
  /** @typedef {import("../Dependency")} Dependency */
13
13
  /** @typedef {import("../Dependency").ReferencedExport} ReferencedExport */
14
14
  /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
15
+ /** @typedef {import("../Module")} Module */
16
+ /** @typedef {import("../Module").BuildMeta} BuildMeta */
15
17
  /** @typedef {import("../ModuleGraph")} ModuleGraph */
18
+ /** @typedef {import("../javascript/JavascriptParser").Range} Range */
16
19
 
17
20
  class ImportEagerDependency extends ImportDependency {
18
21
  /**
19
22
  * @param {string} request the request
20
- * @param {[number, number]} range expression range
21
- * @param {string[][]=} referencedExports list of referenced exports
23
+ * @param {Range} range expression range
24
+ * @param {(string[][] | null)=} referencedExports list of referenced exports
22
25
  */
23
26
  constructor(request, range, referencedExports) {
24
27
  super(request, range, referencedExports);
@@ -55,9 +58,9 @@ ImportEagerDependency.Template = class ImportEagerDependencyTemplate extends (
55
58
  const dep = /** @type {ImportEagerDependency} */ (dependency);
56
59
  const content = runtimeTemplate.moduleNamespacePromise({
57
60
  chunkGraph,
58
- module: moduleGraph.getModule(dep),
61
+ module: /** @type {Module} */ (moduleGraph.getModule(dep)),
59
62
  request: dep.request,
60
- strict: module.buildMeta.strictHarmonyModule,
63
+ strict: /** @type {BuildMeta} */ (module.buildMeta).strictHarmonyModule,
61
64
  message: "import() eager",
62
65
  runtimeRequirements
63
66
  });
@@ -11,13 +11,20 @@ const {
11
11
  } = require("../javascript/JavascriptParserHelpers");
12
12
  const ImportMetaContextDependency = require("./ImportMetaContextDependency");
13
13
 
14
- /** @typedef {import("estree").Expression} ExpressionNode */
15
- /** @typedef {import("estree").ObjectExpression} ObjectExpressionNode */
14
+ /** @typedef {import("estree").Expression} Expression */
15
+ /** @typedef {import("estree").ObjectExpression} ObjectExpression */
16
+ /** @typedef {import("estree").Property} Property */
17
+ /** @typedef {import("estree").SourceLocation} SourceLocation */
16
18
  /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
17
19
  /** @typedef {import("../ContextModule").ContextModuleOptions} ContextModuleOptions */
18
20
  /** @typedef {import("../ChunkGroup").RawChunkGroupOptions} RawChunkGroupOptions */
19
21
  /** @typedef {Pick<ContextModuleOptions, 'mode'|'recursive'|'regExp'|'include'|'exclude'|'chunkName'>&{groupOptions: RawChunkGroupOptions, exports?: ContextModuleOptions["referencedExports"]}} ImportMetaContextOptions */
20
22
 
23
+ /**
24
+ * @param {TODO} prop property
25
+ * @param {string} expect except message
26
+ * @returns {WebpackError} error
27
+ */
21
28
  function createPropertyParseError(prop, expect) {
22
29
  return createError(
23
30
  `Parsing import.meta.webpackContext options failed. Unknown value for property ${JSON.stringify(
@@ -27,6 +34,11 @@ function createPropertyParseError(prop, expect) {
27
34
  );
28
35
  }
29
36
 
37
+ /**
38
+ * @param {string} msg message
39
+ * @param {SourceLocation} loc location
40
+ * @returns {WebpackError} error
41
+ */
30
42
  function createError(msg, loc) {
31
43
  const error = new WebpackError(msg);
32
44
  error.name = "ImportMetaContextError";
@@ -35,6 +47,10 @@ function createError(msg, loc) {
35
47
  }
36
48
 
37
49
  module.exports = class ImportMetaContextDependencyParserPlugin {
50
+ /**
51
+ * @param {JavascriptParser} parser the parser
52
+ * @returns {void}
53
+ */
38
54
  apply(parser) {
39
55
  parser.hooks.evaluateIdentifier
40
56
  .for("import.meta.webpackContext")
@@ -52,7 +68,9 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
52
68
  if (expr.arguments.length < 1 || expr.arguments.length > 2) return;
53
69
  const [directoryNode, optionsNode] = expr.arguments;
54
70
  if (optionsNode && optionsNode.type !== "ObjectExpression") return;
55
- const requestExpr = parser.evaluateExpression(directoryNode);
71
+ const requestExpr = parser.evaluateExpression(
72
+ /** @type {Expression} */ (directoryNode)
73
+ );
56
74
  if (!requestExpr.isString()) return;
57
75
  const request = requestExpr.string;
58
76
  const errors = [];
@@ -71,7 +89,8 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
71
89
  /** @type {ContextModuleOptions["referencedExports"]} */
72
90
  let exports;
73
91
  if (optionsNode) {
74
- for (const prop of optionsNode.properties) {
92
+ for (const prop of /** @type {ObjectExpression} */ (optionsNode)
93
+ .properties) {
75
94
  if (prop.type !== "Property" || prop.key.type !== "Identifier") {
76
95
  errors.push(
77
96
  createError(
@@ -84,7 +103,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
84
103
  switch (prop.key.name) {
85
104
  case "regExp": {
86
105
  const regExpExpr = parser.evaluateExpression(
87
- /** @type {ExpressionNode} */ (prop.value)
106
+ /** @type {Expression} */ (prop.value)
88
107
  );
89
108
  if (!regExpExpr.isRegExp()) {
90
109
  errors.push(createPropertyParseError(prop, "RegExp"));
@@ -95,7 +114,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
95
114
  }
96
115
  case "include": {
97
116
  const regExpExpr = parser.evaluateExpression(
98
- /** @type {ExpressionNode} */ (prop.value)
117
+ /** @type {Expression} */ (prop.value)
99
118
  );
100
119
  if (!regExpExpr.isRegExp()) {
101
120
  errors.push(createPropertyParseError(prop, "RegExp"));
@@ -106,7 +125,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
106
125
  }
107
126
  case "exclude": {
108
127
  const regExpExpr = parser.evaluateExpression(
109
- /** @type {ExpressionNode} */ (prop.value)
128
+ /** @type {Expression} */ (prop.value)
110
129
  );
111
130
  if (!regExpExpr.isRegExp()) {
112
131
  errors.push(createPropertyParseError(prop, "RegExp"));
@@ -117,7 +136,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
117
136
  }
118
137
  case "mode": {
119
138
  const modeExpr = parser.evaluateExpression(
120
- /** @type {ExpressionNode} */ (prop.value)
139
+ /** @type {Expression} */ (prop.value)
121
140
  );
122
141
  if (!modeExpr.isString()) {
123
142
  errors.push(createPropertyParseError(prop, "string"));
@@ -130,7 +149,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
130
149
  }
131
150
  case "chunkName": {
132
151
  const expr = parser.evaluateExpression(
133
- /** @type {ExpressionNode} */ (prop.value)
152
+ /** @type {Expression} */ (prop.value)
134
153
  );
135
154
  if (!expr.isString()) {
136
155
  errors.push(createPropertyParseError(prop, "string"));
@@ -141,7 +160,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
141
160
  }
142
161
  case "exports": {
143
162
  const expr = parser.evaluateExpression(
144
- /** @type {ExpressionNode} */ (prop.value)
163
+ /** @type {Expression} */ (prop.value)
145
164
  );
146
165
  if (expr.isString()) {
147
166
  exports = [[expr.string]];
@@ -176,7 +195,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
176
195
  }
177
196
  case "prefetch": {
178
197
  const expr = parser.evaluateExpression(
179
- /** @type {ExpressionNode} */ (prop.value)
198
+ /** @type {Expression} */ (prop.value)
180
199
  );
181
200
  if (expr.isBoolean()) {
182
201
  groupOptions.prefetchOrder = 0;
@@ -189,7 +208,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
189
208
  }
190
209
  case "preload": {
191
210
  const expr = parser.evaluateExpression(
192
- /** @type {ExpressionNode} */ (prop.value)
211
+ /** @type {Expression} */ (prop.value)
193
212
  );
194
213
  if (expr.isBoolean()) {
195
214
  groupOptions.preloadOrder = 0;
@@ -200,9 +219,28 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
200
219
  }
201
220
  break;
202
221
  }
222
+ case "fetchPriority": {
223
+ const expr = parser.evaluateExpression(
224
+ /** @type {Expression} */ (prop.value)
225
+ );
226
+ if (
227
+ expr.isString() &&
228
+ ["high", "low", "auto"].includes(expr.string)
229
+ ) {
230
+ groupOptions.fetchPriority =
231
+ /** @type {RawChunkGroupOptions["fetchPriority"]} */ (
232
+ expr.string
233
+ );
234
+ } else {
235
+ errors.push(
236
+ createPropertyParseError(prop, '"high"|"low"|"auto"')
237
+ );
238
+ }
239
+ break;
240
+ }
203
241
  case "recursive": {
204
242
  const recursiveExpr = parser.evaluateExpression(
205
- /** @type {ExpressionNode} */ (prop.value)
243
+ /** @type {Expression} */ (prop.value)
206
244
  );
207
245
  if (!recursiveExpr.isBoolean()) {
208
246
  errors.push(createPropertyParseError(prop, "boolean"));