webpack 5.107.1 → 5.108.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.
Files changed (360) hide show
  1. package/hot/dev-server.js +2 -0
  2. package/lib/APIPlugin.js +8 -4
  3. package/lib/CacheFacade.js +7 -0
  4. package/lib/Chunk.js +4 -0
  5. package/lib/ChunkGraph.js +30 -9
  6. package/lib/CircularModulesPlugin.js +190 -0
  7. package/lib/CleanPlugin.js +2 -1
  8. package/lib/Compilation.js +396 -65
  9. package/lib/Compiler.js +52 -14
  10. package/lib/ConcatenationScope.js +10 -3
  11. package/lib/ContextExclusionPlugin.js +1 -0
  12. package/lib/ContextModule.js +92 -47
  13. package/lib/ContextModuleFactory.js +45 -38
  14. package/lib/ContextReplacementPlugin.js +4 -0
  15. package/lib/DefinePlugin.js +89 -15
  16. package/lib/Dependency.js +111 -7
  17. package/lib/EntryOptionPlugin.js +39 -2
  18. package/lib/EntryPlugin.js +2 -0
  19. package/lib/ExportsInfo.js +314 -73
  20. package/lib/ExternalModule.js +82 -34
  21. package/lib/ExternalModuleFactoryPlugin.js +1 -0
  22. package/lib/ExternalsPlugin.js +1 -0
  23. package/lib/FileSystemInfo.js +173 -23
  24. package/lib/FlagAllModulesAsUsedPlugin.js +1 -5
  25. package/lib/FlagDependencyExportsPlugin.js +23 -0
  26. package/lib/FlagDependencyUsagePlugin.js +87 -5
  27. package/lib/FlagEntryExportAsUsedPlugin.js +2 -0
  28. package/lib/Generator.js +8 -0
  29. package/lib/HotModuleReplacementPlugin.js +65 -28
  30. package/lib/IgnorePlugin.js +1 -0
  31. package/lib/InitFragment.js +5 -0
  32. package/lib/JavascriptMetaInfoPlugin.js +7 -5
  33. package/lib/LazyBarrel.js +361 -0
  34. package/lib/LoaderTargetPlugin.js +1 -0
  35. package/lib/Module.js +21 -42
  36. package/lib/ModuleGraph.js +3 -2
  37. package/lib/ModuleProfile.js +27 -1
  38. package/lib/ModuleTemplate.js +2 -0
  39. package/lib/MultiCompiler.js +16 -0
  40. package/lib/MultiStats.js +1 -0
  41. package/lib/MultiWatching.js +2 -0
  42. package/lib/NodeStuffPlugin.js +22 -17
  43. package/lib/NormalModule.js +557 -77
  44. package/lib/NormalModuleReplacementPlugin.js +2 -0
  45. package/lib/PrefetchPlugin.js +2 -0
  46. package/lib/ProgressPlugin.js +9 -1
  47. package/lib/ProvidePlugin.js +1 -0
  48. package/lib/RawModule.js +20 -16
  49. package/lib/RecordIdsPlugin.js +1 -0
  50. package/lib/RuntimeGlobals.js +5 -0
  51. package/lib/RuntimePlugin.js +58 -26
  52. package/lib/RuntimeTemplate.js +278 -21
  53. package/lib/SelfModuleFactory.js +1 -0
  54. package/lib/SourceMapDevToolPlugin.js +105 -30
  55. package/lib/Stats.js +1 -0
  56. package/lib/Template.js +8 -2
  57. package/lib/TemplatedPathPlugin.js +473 -131
  58. package/lib/WarnCaseSensitiveModulesPlugin.js +1 -0
  59. package/lib/WarnDeprecatedOptionPlugin.js +4 -0
  60. package/lib/WarnNoModeSetPlugin.js +1 -0
  61. package/lib/WatchIgnorePlugin.js +1 -0
  62. package/lib/Watching.js +9 -0
  63. package/lib/WebpackOptionsApply.js +50 -5
  64. package/lib/asset/AssetBytesGenerator.js +11 -3
  65. package/lib/asset/AssetGenerator.js +47 -22
  66. package/lib/asset/AssetModule.js +47 -0
  67. package/lib/asset/AssetModulesPlugin.js +14 -14
  68. package/lib/asset/AssetParser.js +2 -2
  69. package/lib/asset/AssetSourceGenerator.js +8 -0
  70. package/lib/asset/RawDataUrlModule.js +12 -13
  71. package/lib/buildChunkGraph.js +88 -9
  72. package/lib/bun/BunTargetPlugin.js +48 -0
  73. package/lib/cache/AddBuildDependenciesPlugin.js +1 -0
  74. package/lib/cache/AddManagedPathsPlugin.js +3 -0
  75. package/lib/cache/IdleFileCachePlugin.js +4 -0
  76. package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
  77. package/lib/cache/PackFileCacheStrategy.js +1 -0
  78. package/lib/cache/ResolverCachePlugin.js +2 -0
  79. package/lib/cache/getLazyHashedEtag.js +9 -2
  80. package/lib/cache/mergeEtags.js +2 -0
  81. package/lib/cli.js +109 -19
  82. package/lib/config/browserslistTargetHandler.js +99 -0
  83. package/lib/config/defaults.js +147 -7
  84. package/lib/config/defineConfig.js +31 -0
  85. package/lib/config/normalization.js +5 -0
  86. package/lib/config/target.js +181 -2
  87. package/lib/container/ContainerEntryModule.js +15 -14
  88. package/lib/container/ContainerExposedDependency.js +2 -2
  89. package/lib/container/ContainerReferencePlugin.js +1 -1
  90. package/lib/container/FallbackDependency.js +5 -7
  91. package/lib/container/FallbackModule.js +10 -9
  92. package/lib/container/RemoteModule.js +20 -10
  93. package/lib/container/RemoteRuntimeModule.js +14 -12
  94. package/lib/css/CssGenerator.js +353 -327
  95. package/lib/css/CssInjectStyleRuntimeModule.js +36 -8
  96. package/lib/css/CssLoadingRuntimeModule.js +118 -47
  97. package/lib/css/CssModule.js +52 -23
  98. package/lib/css/CssModulesPlugin.js +107 -124
  99. package/lib/css/CssParser.js +2759 -2205
  100. package/lib/css/syntax.js +2859 -0
  101. package/lib/debug/ProfilingPlugin.js +2 -0
  102. package/lib/deno/DenoTargetPlugin.js +47 -0
  103. package/lib/dependencies/AMDDefineDependency.js +22 -17
  104. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +1 -0
  105. package/lib/dependencies/AMDRequireArrayDependency.js +7 -11
  106. package/lib/dependencies/AMDRequireContextDependency.js +7 -11
  107. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +1 -0
  108. package/lib/dependencies/AMDRequireDependency.js +24 -20
  109. package/lib/dependencies/CachedConstDependency.js +3 -0
  110. package/lib/dependencies/CommonJsDependencyHelpers.js +1 -0
  111. package/lib/dependencies/CommonJsExportRequireDependency.js +79 -31
  112. package/lib/dependencies/CommonJsExportsDependency.js +21 -16
  113. package/lib/dependencies/CommonJsExportsParserPlugin.js +230 -7
  114. package/lib/dependencies/CommonJsFullRequireDependency.js +27 -19
  115. package/lib/dependencies/CommonJsImportsParserPlugin.js +51 -16
  116. package/lib/dependencies/CommonJsPlugin.js +1 -1
  117. package/lib/dependencies/CommonJsRequireContextDependency.js +10 -13
  118. package/lib/dependencies/CommonJsRequireDependency.js +42 -11
  119. package/lib/dependencies/CommonJsSelfReferenceDependency.js +22 -14
  120. package/lib/dependencies/ConstDependency.js +16 -11
  121. package/lib/dependencies/ContextDependency.js +4 -0
  122. package/lib/dependencies/ContextDependencyTemplateAsId.js +1 -1
  123. package/lib/dependencies/ContextElementDependency.js +23 -14
  124. package/lib/dependencies/CreateRequireParserPlugin.js +1 -0
  125. package/lib/dependencies/CreateScriptUrlDependency.js +5 -7
  126. package/lib/dependencies/CriticalDependencyWarning.js +1 -0
  127. package/lib/dependencies/CssIcssExportDependency.js +512 -574
  128. package/lib/dependencies/CssIcssImportDependency.js +9 -9
  129. package/lib/dependencies/CssIcssSymbolDependency.js +22 -15
  130. package/lib/dependencies/CssImportDependency.js +25 -1
  131. package/lib/dependencies/CssUrlDependency.js +23 -14
  132. package/lib/dependencies/DllEntryDependency.js +9 -13
  133. package/lib/dependencies/ExportBindingInitFragment.js +164 -0
  134. package/lib/dependencies/ExportsInfoDependency.js +12 -12
  135. package/lib/dependencies/ExternalModuleDependency.js +8 -5
  136. package/lib/dependencies/ExternalModuleInitFragment.js +7 -5
  137. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +13 -10
  138. package/lib/dependencies/HarmonyAcceptDependency.js +11 -11
  139. package/lib/dependencies/HarmonyAcceptImportDependency.js +1 -0
  140. package/lib/dependencies/HarmonyDetectionParserPlugin.js +47 -22
  141. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +28 -2
  142. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +46 -22
  143. package/lib/dependencies/HarmonyExportExpressionDependency.js +107 -30
  144. package/lib/dependencies/HarmonyExportHeaderDependency.js +7 -9
  145. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +109 -31
  146. package/lib/dependencies/HarmonyExportInitFragment.js +22 -20
  147. package/lib/dependencies/HarmonyExportSpecifierDependency.js +83 -18
  148. package/lib/dependencies/HarmonyExports.js +4 -1
  149. package/lib/dependencies/HarmonyImportDependency.js +24 -0
  150. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +110 -74
  151. package/lib/dependencies/HarmonyImportGuard.js +254 -0
  152. package/lib/dependencies/HarmonyImportSideEffectDependency.js +18 -1
  153. package/lib/dependencies/HarmonyImportSpecifierDependency.js +118 -14
  154. package/lib/dependencies/HarmonyLinkingError.js +1 -0
  155. package/lib/dependencies/HarmonyModulesPlugin.js +1 -0
  156. package/lib/dependencies/{HtmlScriptSrcDependency.js → HtmlEntryDependency.js} +267 -154
  157. package/lib/dependencies/HtmlInlineHtmlDependency.js +107 -0
  158. package/lib/dependencies/HtmlInlineScriptDependency.js +20 -27
  159. package/lib/dependencies/HtmlInlineStyleDependency.js +62 -11
  160. package/lib/dependencies/HtmlSourceDependency.js +18 -0
  161. package/lib/dependencies/ImportContextDependency.js +5 -9
  162. package/lib/dependencies/ImportDependency.js +44 -2
  163. package/lib/dependencies/ImportMetaHotAcceptDependency.js +1 -0
  164. package/lib/dependencies/ImportMetaHotDeclineDependency.js +1 -0
  165. package/lib/dependencies/ImportMetaPlugin.js +74 -30
  166. package/lib/dependencies/ImportParserPlugin.js +19 -0
  167. package/lib/dependencies/ImportWeakDependency.js +1 -0
  168. package/lib/dependencies/JsonExportsDependency.js +9 -9
  169. package/lib/dependencies/LoaderImportDependency.js +1 -0
  170. package/lib/dependencies/LocalModule.js +11 -12
  171. package/lib/dependencies/LocalModuleDependency.js +11 -13
  172. package/lib/dependencies/ModuleDecoratorDependency.js +9 -9
  173. package/lib/dependencies/ModuleDependency.js +7 -0
  174. package/lib/dependencies/ModuleHotAcceptDependency.js +1 -0
  175. package/lib/dependencies/ModuleHotDeclineDependency.js +1 -0
  176. package/lib/dependencies/ModuleInitFragmentDependency.js +15 -11
  177. package/lib/dependencies/ProvidedDependency.js +31 -27
  178. package/lib/dependencies/PureExpressionDependency.js +7 -9
  179. package/lib/dependencies/RequireEnsureDependency.js +12 -13
  180. package/lib/dependencies/RequireHeaderDependency.js +3 -4
  181. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +3 -0
  182. package/lib/dependencies/RequireResolveContextDependency.js +7 -11
  183. package/lib/dependencies/RequireResolveDependency.js +1 -0
  184. package/lib/dependencies/RequireResolveHeaderDependency.js +3 -5
  185. package/lib/dependencies/RuntimeRequirementsDependency.js +6 -7
  186. package/lib/dependencies/StaticExportsDependency.js +10 -10
  187. package/lib/dependencies/SystemPlugin.js +2 -0
  188. package/lib/dependencies/URLContextDependency.js +5 -7
  189. package/lib/dependencies/URLDependency.js +14 -16
  190. package/lib/dependencies/UnsupportedDependency.js +8 -13
  191. package/lib/dependencies/WebAssemblyExportImportedDependency.js +11 -16
  192. package/lib/dependencies/WebAssemblyImportDependency.js +14 -16
  193. package/lib/dependencies/WebpackIsIncludedDependency.js +1 -0
  194. package/lib/dependencies/WorkerDependency.js +19 -8
  195. package/lib/dependencies/WorkerPlugin.js +40 -10
  196. package/lib/dependencies/processExportInfo.js +13 -11
  197. package/lib/dll/DelegatedModule.js +29 -15
  198. package/lib/dll/DelegatedModuleFactoryPlugin.js +1 -0
  199. package/lib/dll/DelegatedPlugin.js +1 -0
  200. package/lib/dll/DllEntryPlugin.js +3 -0
  201. package/lib/dll/DllModule.js +3 -2
  202. package/lib/dll/DllPlugin.js +16 -0
  203. package/lib/dll/DllReferencePlugin.js +3 -0
  204. package/lib/dll/LibManifestPlugin.js +1 -0
  205. package/lib/electron/ElectronTargetPlugin.js +22 -4
  206. package/lib/errors/ConcurrentCompilationError.js +1 -0
  207. package/lib/errors/HookWebpackError.js +11 -13
  208. package/lib/errors/IgnoreErrorModuleFactory.js +1 -0
  209. package/lib/errors/InvalidDependenciesModuleWarning.js +2 -0
  210. package/lib/errors/JSONParseError.js +9 -8
  211. package/lib/errors/ModuleBuildError.js +16 -13
  212. package/lib/errors/ModuleDependencyError.js +8 -1
  213. package/lib/errors/ModuleDependencyWarning.js +8 -1
  214. package/lib/errors/ModuleError.js +5 -11
  215. package/lib/errors/ModuleHashingError.js +4 -0
  216. package/lib/errors/ModuleNotFoundError.js +3 -0
  217. package/lib/errors/ModuleParseError.js +5 -11
  218. package/lib/errors/ModuleRestoreError.js +2 -0
  219. package/lib/errors/ModuleStoreError.js +3 -0
  220. package/lib/errors/ModuleWarning.js +7 -11
  221. package/lib/errors/NodeStuffInWebError.js +1 -0
  222. package/lib/errors/NonErrorEmittedError.js +2 -0
  223. package/lib/errors/UnhandledSchemeError.js +1 -0
  224. package/lib/esm/ModuleChunkLoadingPlugin.js +0 -1
  225. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +28 -23
  226. package/lib/hmr/HotModuleReplacement.runtime.js +175 -30
  227. package/lib/hmr/HotModuleReplacementRuntimeModule.js +7 -0
  228. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +173 -26
  229. package/lib/hmr/LazyCompilationPlugin.js +134 -6
  230. package/lib/html/HtmlGenerator.js +292 -50
  231. package/lib/html/HtmlModule.js +40 -0
  232. package/lib/html/HtmlModulesPlugin.js +287 -60
  233. package/lib/html/HtmlParser.js +1108 -1099
  234. package/lib/html/{walkHtmlTokens.js → syntax.js} +4701 -212
  235. package/lib/ids/IdHelpers.js +4 -2
  236. package/lib/index.js +19 -0
  237. package/lib/javascript/BasicEvaluatedExpression.js +1 -0
  238. package/lib/javascript/EnableChunkLoadingPlugin.js +1 -0
  239. package/lib/javascript/JavascriptGenerator.js +6 -2
  240. package/lib/javascript/JavascriptModule.js +54 -0
  241. package/lib/javascript/JavascriptModulesPlugin.js +257 -102
  242. package/lib/javascript/JavascriptParser.js +286 -159
  243. package/lib/json/JsonModule.js +40 -0
  244. package/lib/json/JsonModulesPlugin.js +7 -0
  245. package/lib/json/JsonParser.js +4 -2
  246. package/lib/library/AssignLibraryPlugin.js +5 -3
  247. package/lib/library/ExportPropertyLibraryPlugin.js +1 -0
  248. package/lib/library/FalseIIFEUmdWarning.js +1 -0
  249. package/lib/library/ModuleLibraryPlugin.js +54 -29
  250. package/lib/library/SystemLibraryPlugin.js +3 -3
  251. package/lib/node/NodeTargetPlugin.js +1 -0
  252. package/lib/node/NodeWatchFileSystem.js +38 -22
  253. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +10 -9
  254. package/lib/node/RequireChunkLoadingRuntimeModule.js +18 -16
  255. package/lib/optimize/ConcatenatedModule.js +397 -78
  256. package/lib/optimize/ConstExportsPlugin.js +211 -0
  257. package/lib/optimize/InlineExports.js +178 -0
  258. package/lib/optimize/InnerGraph.js +372 -275
  259. package/lib/optimize/InnerGraphPlugin.js +196 -99
  260. package/lib/optimize/ModuleConcatenationPlugin.js +56 -25
  261. package/lib/optimize/RealContentHashPlugin.js +14 -1
  262. package/lib/optimize/SideEffectsFlagPlugin.js +234 -64
  263. package/lib/runtime/AsyncModuleRuntimeModule.js +32 -30
  264. package/lib/runtime/AutoPublicPathRuntimeModule.js +11 -5
  265. package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +1 -1
  266. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +6 -4
  267. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +33 -4
  268. package/lib/runtime/GetChunkFilenameRuntimeModule.js +82 -3
  269. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -1
  270. package/lib/runtime/HasOwnPropertyRuntimeModule.js +1 -1
  271. package/lib/runtime/LoadScriptRuntimeModule.js +18 -13
  272. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +39 -26
  273. package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +1 -1
  274. package/lib/runtime/OnChunksLoadedRuntimeModule.js +4 -4
  275. package/lib/runtime/RelativeUrlRuntimeModule.js +3 -2
  276. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -1
  277. package/lib/runtime/StartupEntrypointRuntimeModule.js +4 -3
  278. package/lib/runtime/WorkerRuntimeModule.js +33 -0
  279. package/lib/schemes/HttpUriPlugin.js +3 -2
  280. package/lib/serialization/AggregateErrorSerializer.js +7 -6
  281. package/lib/serialization/ArraySerializer.js +4 -8
  282. package/lib/serialization/BinaryMiddleware.js +538 -468
  283. package/lib/serialization/DateObjectSerializer.js +2 -2
  284. package/lib/serialization/ErrorObjectSerializer.js +7 -6
  285. package/lib/serialization/MapObjectSerializer.js +5 -9
  286. package/lib/serialization/NullPrototypeObjectSerializer.js +7 -9
  287. package/lib/serialization/ObjectMiddleware.js +50 -13
  288. package/lib/serialization/PlainObjectSerializer.js +9 -8
  289. package/lib/serialization/RegExpObjectSerializer.js +2 -2
  290. package/lib/serialization/Serializer.js +1 -0
  291. package/lib/serialization/SetObjectSerializer.js +4 -8
  292. package/lib/sharing/ConsumeSharedModule.js +6 -7
  293. package/lib/sharing/ConsumeSharedPlugin.js +1 -0
  294. package/lib/sharing/ConsumeSharedRuntimeModule.js +46 -41
  295. package/lib/sharing/ProvideSharedDependency.js +30 -15
  296. package/lib/sharing/ProvideSharedModule.js +30 -11
  297. package/lib/sharing/ProvideSharedPlugin.js +4 -2
  298. package/lib/sharing/SharePlugin.js +3 -0
  299. package/lib/sharing/ShareRuntimeModule.js +18 -16
  300. package/lib/sharing/resolveMatchedConfigs.js +2 -1
  301. package/lib/sharing/utils.js +1 -1
  302. package/lib/stats/DefaultStatsFactoryPlugin.js +4 -6
  303. package/lib/stats/DefaultStatsPrinterPlugin.js +14 -14
  304. package/lib/stats/StatsFactory.js +11 -9
  305. package/lib/stats/StatsPrinter.js +9 -2
  306. package/lib/url/URLParserPlugin.js +5 -2
  307. package/lib/util/AsyncQueue.js +10 -0
  308. package/lib/util/LazyBucketSortedSet.js +5 -0
  309. package/lib/util/LazySet.js +6 -4
  310. package/lib/util/LocConverter.js +11 -1
  311. package/lib/util/Semaphore.js +1 -0
  312. package/lib/util/SourceProcessor.js +106 -0
  313. package/lib/util/TupleSet.js +1 -0
  314. package/lib/util/WeakTupleMap.js +27 -1
  315. package/lib/util/chainedImports.js +3 -3
  316. package/lib/util/comparators.js +2 -2
  317. package/lib/util/concatenate.js +31 -7
  318. package/lib/util/createHash.js +0 -1
  319. package/lib/util/deterministicGrouping.js +19 -12
  320. package/lib/util/extractSourceMap.js +1 -1
  321. package/lib/util/findGraphRoots.js +2 -0
  322. package/lib/util/fs.js +16 -6
  323. package/lib/util/hash/DebugHash.js +1 -0
  324. package/lib/util/hash/hash-digest.js +24 -15
  325. package/lib/util/identifier.js +7 -0
  326. package/lib/util/internalSerializables.js +11 -2
  327. package/lib/util/magicComment.js +42 -0
  328. package/lib/util/makeSerializable.js +1 -0
  329. package/lib/util/nonNumericOnlyHash.js +30 -1
  330. package/lib/util/property.js +7 -1
  331. package/lib/util/publicPathPlaceholder.js +64 -0
  332. package/lib/util/registerExternalSerializer.js +4 -4
  333. package/lib/wasm-async/AsyncWasmModule.js +77 -0
  334. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +1 -1
  335. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +1 -96
  336. package/lib/wasm-async/AsyncWebAssemblyParser.js +1 -1
  337. package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +1 -1
  338. package/lib/wasm-sync/SyncWasmModule.js +39 -0
  339. package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +1 -0
  340. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +6 -3
  341. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +2 -1
  342. package/lib/wasm-sync/WebAssemblyGenerator.js +1 -0
  343. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +2 -0
  344. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +10 -0
  345. package/lib/wasm-sync/WebAssemblyParser.js +7 -3
  346. package/lib/web/JsonpChunkLoadingRuntimeModule.js +45 -39
  347. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +11 -10
  348. package/package.json +36 -28
  349. package/schemas/WebpackOptions.check.js +1 -1
  350. package/schemas/WebpackOptions.json +212 -3
  351. package/schemas/plugins/HtmlGeneratorOptions.check.js +1 -1
  352. package/schemas/plugins/HtmlParserOptions.check.d.ts +7 -0
  353. package/schemas/plugins/HtmlParserOptions.check.js +6 -0
  354. package/schemas/plugins/HtmlParserOptions.json +3 -0
  355. package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +1 -1
  356. package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
  357. package/schemas/plugins/css/CssParserOptions.check.js +1 -1
  358. package/types.d.ts +1592 -314
  359. package/lib/css/walkCssTokens.js +0 -2020
  360. package/lib/util/AppendOnlyStackedSet.js +0 -93
@@ -29,24 +29,26 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
29
29
  const { runtimeTemplate } = compilation;
30
30
  const fn = RuntimeGlobals.asyncModule;
31
31
  const defer = this._deferInterop;
32
+ const cst = runtimeTemplate.renderConst();
33
+ const lt = runtimeTemplate.renderLet();
32
34
  return Template.asString([
33
- 'var hasSymbol = typeof Symbol === "function";',
34
- 'var webpackQueues = hasSymbol ? Symbol("webpack queues") : "__webpack_queues__";',
35
- `var webpackExports = ${
35
+ `${cst} hasSymbol = typeof Symbol === "function";`,
36
+ `${cst} webpackQueues = hasSymbol ? Symbol("webpack queues") : "__webpack_queues__";`,
37
+ `${cst} webpackExports = ${
36
38
  defer ? `${RuntimeGlobals.asyncModuleExportSymbol}= ` : ""
37
39
  }hasSymbol ? Symbol("webpack exports") : "${RuntimeGlobals.exports}";`,
38
- 'var webpackError = hasSymbol ? Symbol("webpack error") : "__webpack_error__";',
40
+ `${cst} webpackError = hasSymbol ? Symbol("webpack error") : "__webpack_error__";`,
39
41
  defer
40
42
  ? Template.asString([
41
- `var webpackDone = ${RuntimeGlobals.asyncModuleDoneSymbol} = hasSymbol ? Symbol("webpack done") : "__webpack_done__";`,
42
- `var webpackDefer = ${RuntimeGlobals.deferredModuleAsyncTransitiveDependenciesSymbol} = hasSymbol ? Symbol("webpack defer") : "__webpack_defer__";`,
43
+ `${cst} webpackDone = ${RuntimeGlobals.asyncModuleDoneSymbol} = hasSymbol ? Symbol("webpack done") : "__webpack_done__";`,
44
+ `${cst} webpackDefer = ${RuntimeGlobals.deferredModuleAsyncTransitiveDependenciesSymbol} = hasSymbol ? Symbol("webpack defer") : "__webpack_defer__";`,
43
45
  `${RuntimeGlobals.deferredModuleAsyncTransitiveDependencies} = ${runtimeTemplate.basicFunction(
44
46
  "asyncDeps",
45
47
  [
46
48
  Template.indent([
47
- "var hasUnresolvedAsyncSubgraph = asyncDeps.some((id) => {",
49
+ `${cst} hasUnresolvedAsyncSubgraph = asyncDeps.some((id) => {`,
48
50
  Template.indent([
49
- "var cache = __webpack_module_cache__[id];",
51
+ `${cst} cache = __webpack_module_cache__[id];`,
50
52
  "return !cache || cache[webpackDone] === false;"
51
53
  ]),
52
54
  "});",
@@ -60,8 +62,8 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
60
62
  )}`
61
63
  ])
62
64
  : "",
63
- `var resolveQueue = ${runtimeTemplate.basicFunction("queue", [
64
- "if(queue && queue.d < 1) {",
65
+ `${cst} resolveQueue = ${runtimeTemplate.basicFunction("queue", [
66
+ `if(${runtimeTemplate.optionalChaining("queue", "d < 1")}) {`,
65
67
  Template.indent([
66
68
  "queue.d = 1;",
67
69
  `queue.forEach(${runtimeTemplate.expressionFunction(
@@ -75,7 +77,7 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
75
77
  ]),
76
78
  "}"
77
79
  ])}`,
78
- `var wrapDeps = ${runtimeTemplate.returningFunction(
80
+ `${cst} wrapDeps = ${runtimeTemplate.returningFunction(
79
81
  `deps.map(${runtimeTemplate.basicFunction("dep", [
80
82
  'if(dep !== null && typeof dep === "object") {',
81
83
  Template.indent([
@@ -83,10 +85,10 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
83
85
  ? Template.asString([
84
86
  "if(!dep[webpackQueues] && dep[webpackDefer]) {",
85
87
  Template.indent([
86
- `var asyncDeps = ${RuntimeGlobals.deferredModuleAsyncTransitiveDependencies}(dep[webpackDefer]);`,
88
+ `${cst} asyncDeps = ${RuntimeGlobals.deferredModuleAsyncTransitiveDependencies}(dep[webpackDefer]);`,
87
89
  "if (asyncDeps) {",
88
90
  Template.indent([
89
- "var d = dep;",
91
+ `${cst} d = dep;`,
90
92
  "dep = {",
91
93
  Template.indent([
92
94
  "then(onFulfilled, onRejected) {",
@@ -107,7 +109,7 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
107
109
  "if(dep[webpackQueues]) return dep;",
108
110
  "if(dep.then) {",
109
111
  Template.indent([
110
- "var queue = [];",
112
+ `${cst} queue = [];`,
111
113
  "queue.d = 0;",
112
114
  `dep.then(${runtimeTemplate.basicFunction("r", [
113
115
  "obj[webpackExports] = r;",
@@ -116,7 +118,7 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
116
118
  "obj[webpackError] = e;",
117
119
  "resolveQueue(queue);"
118
120
  ])});`,
119
- "var obj = {};",
121
+ `${cst} obj = {};`,
120
122
  defer ? "obj[webpackDefer] = false;" : "",
121
123
  `obj[webpackQueues] = ${runtimeTemplate.expressionFunction(
122
124
  "fn(queue)",
@@ -127,7 +129,7 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
127
129
  "}"
128
130
  ]),
129
131
  "}",
130
- "var ret = {};",
132
+ `${cst} ret = {};`,
131
133
  `ret[webpackQueues] = ${runtimeTemplate.emptyFunction()};`,
132
134
  "ret[webpackExports] = dep;",
133
135
  "return ret;"
@@ -135,14 +137,14 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
135
137
  "deps"
136
138
  )};`,
137
139
  `${fn} = ${runtimeTemplate.basicFunction("module, body, hasAwait", [
138
- "var queue;",
140
+ `${lt} queue;`,
139
141
  "hasAwait && ((queue = []).d = -1);",
140
- "var depQueues = new Set();",
141
- "var exports = module.exports;",
142
- "var currentDeps;",
143
- "var outerResolve;",
144
- "var reject;",
145
- `var promise = new Promise(${runtimeTemplate.basicFunction(
142
+ `${cst} depQueues = new Set();`,
143
+ `${cst} exports = module.exports;`,
144
+ `${lt} currentDeps;`,
145
+ `${lt} outerResolve;`,
146
+ `${lt} reject;`,
147
+ `${cst} promise = new Promise(${runtimeTemplate.basicFunction(
146
148
  "resolve, rej",
147
149
  ["reject = rej;", "outerResolve = resolve;"]
148
150
  )});`,
@@ -152,17 +154,17 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
152
154
  "fn"
153
155
  )};`,
154
156
  "module.exports = promise;",
155
- `var handle = ${runtimeTemplate.basicFunction("deps", [
157
+ `${cst} handle = ${runtimeTemplate.basicFunction("deps", [
156
158
  "currentDeps = wrapDeps(deps);",
157
- "var fn;",
158
- `var getResult = ${runtimeTemplate.returningFunction(
159
+ `${lt} fn;`,
160
+ `${cst} getResult = ${runtimeTemplate.returningFunction(
159
161
  `currentDeps.map(${runtimeTemplate.basicFunction("d", [
160
162
  defer ? "if(d[webpackDefer]) return d;" : "",
161
163
  "if(d[webpackError]) throw d[webpackError];",
162
164
  "return d[webpackExports];"
163
165
  ])})`
164
166
  )}`,
165
- `var promise = new Promise(${runtimeTemplate.basicFunction(
167
+ `${cst} promise = new Promise(${runtimeTemplate.basicFunction(
166
168
  "resolve",
167
169
  [
168
170
  `fn = ${runtimeTemplate.expressionFunction(
@@ -170,7 +172,7 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
170
172
  ""
171
173
  )};`,
172
174
  "fn.r = 0;",
173
- `var fnQueue = ${runtimeTemplate.expressionFunction(
175
+ `${cst} fnQueue = ${runtimeTemplate.expressionFunction(
174
176
  "q !== queue && !depQueues.has(q) && (depQueues.add(q), q && !q.d && (fn.r++, q.push(fn)))",
175
177
  "q"
176
178
  )};`,
@@ -184,14 +186,14 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
184
186
  )});`,
185
187
  "return fn.r ? promise : getResult();"
186
188
  ])}`,
187
- `var done = ${runtimeTemplate.expressionFunction(
189
+ `${cst} done = ${runtimeTemplate.expressionFunction(
188
190
  `(err ? reject(promise[webpackError] = err) : outerResolve(exports)), resolveQueue(queue)${
189
191
  defer ? ", promise[webpackDone] = true" : ""
190
192
  }`,
191
193
  "err"
192
194
  )}`,
193
195
  "body(handle, done);",
194
- "queue && queue.d < 0 && (queue.d = 0);"
196
+ `${runtimeTemplate.optionalChaining("queue", "d < 0")} && (queue.d = 0);`
195
197
  ])};`
196
198
  ]);
197
199
  }
@@ -47,26 +47,32 @@ class AutoPublicPathRuntimeModule extends RuntimeModule {
47
47
  ? "globalThis"
48
48
  : RuntimeGlobals.global;
49
49
 
50
+ const runtimeTemplate = compilation.runtimeTemplate;
51
+ const cst = runtimeTemplate.renderConst();
52
+ const lt = runtimeTemplate.renderLet();
50
53
  return Template.asString([
51
- "var scriptUrl;",
54
+ `${lt} scriptUrl;`,
52
55
  scriptType === "module"
53
56
  ? `if (typeof ${importMetaName}.url === "string") scriptUrl = ${importMetaName}.url`
54
57
  : Template.asString([
55
58
  `if (${global}.importScripts) scriptUrl = ${global}.location + "";`,
56
- `var document = ${global}.document;`,
59
+ `${cst} document = ${global}.document;`,
57
60
  "if (!scriptUrl && document) {",
58
61
  Template.indent([
59
62
  // Technically we could use `document.currentScript instanceof window.HTMLScriptElement`,
60
63
  // but an attacker could try to inject `<script>HTMLScriptElement = HTMLImageElement</script>`
61
64
  // and use `<img name="currentScript" src="https://attacker.controlled.server/"></img>`
62
- "if (document.currentScript && document.currentScript.tagName.toUpperCase() === 'SCRIPT')",
65
+ `if (${runtimeTemplate.optionalChaining(
66
+ "document.currentScript",
67
+ "tagName.toUpperCase() === 'SCRIPT'"
68
+ )})`,
63
69
  Template.indent("scriptUrl = document.currentScript.src;"),
64
70
  "if (!scriptUrl) {",
65
71
  Template.indent([
66
- 'var scripts = document.getElementsByTagName("script");',
72
+ `${cst} scripts = document.getElementsByTagName("script");`,
67
73
  "if(scripts.length) {",
68
74
  Template.indent([
69
- "var i = scripts.length - 1;",
75
+ `${lt} i = scripts.length - 1;`,
70
76
  "while (i > -1 && (!scriptUrl || !/^http(s?):/.test(scriptUrl))) scriptUrl = scripts[i--].src;"
71
77
  ]),
72
78
  "}"
@@ -26,7 +26,7 @@ class CompatGetDefaultExportRuntimeModule extends HelperRuntimeModule {
26
26
  return Template.asString([
27
27
  "// getDefaultExport function for compatibility with non-harmony modules",
28
28
  `${fn} = ${runtimeTemplate.basicFunction("module", [
29
- "var getter = module && module.__esModule ?",
29
+ `${runtimeTemplate.renderConst()} getter = module && module.__esModule ?`,
30
30
  Template.indent([
31
31
  `${runtimeTemplate.returningFunction("module['default']")} :`,
32
32
  `${runtimeTemplate.returningFunction("module")};`
@@ -23,12 +23,14 @@ class CreateFakeNamespaceObjectRuntimeModule extends HelperRuntimeModule {
23
23
  const compilation = /** @type {Compilation} */ (this.compilation);
24
24
  const { runtimeTemplate } = compilation;
25
25
  const fn = RuntimeGlobals.createFakeNamespaceObject;
26
+ const cst = runtimeTemplate.renderConst();
27
+ const lt = runtimeTemplate.renderLet();
26
28
  return Template.asString([
27
- `var getProto = Object.getPrototypeOf ? ${runtimeTemplate.returningFunction(
29
+ `${cst} getProto = Object.getPrototypeOf ? ${runtimeTemplate.returningFunction(
28
30
  "Object.getPrototypeOf(obj)",
29
31
  "obj"
30
32
  )} : ${runtimeTemplate.returningFunction("obj.__proto__", "obj")};`,
31
- "var leafPrototypes;",
33
+ `${lt} leafPrototypes;`,
32
34
  "// create a fake namespace object",
33
35
  "// mode & 1: value is a module id, require it",
34
36
  "// mode & 2: merge all properties of value into the ns",
@@ -46,9 +48,9 @@ class CreateFakeNamespaceObjectRuntimeModule extends HelperRuntimeModule {
46
48
  "if((mode & 16) && typeof value.then === 'function') return value;"
47
49
  ]),
48
50
  "}",
49
- "var ns = Object.create(null);",
51
+ `${cst} ns = Object.create(null);`,
50
52
  `${RuntimeGlobals.makeNamespaceObject}(ns);`,
51
- "var def = {};",
53
+ `${cst} def = {};`,
52
54
  "leafPrototypes = leafPrototypes || [null, getProto({}), getProto([]), getProto(getProto)];",
53
55
  "for(var current = mode & 2 && value; (typeof current == 'object' || typeof current == 'function') && !~leafPrototypes.indexOf(current); current = getProto(current)) {",
54
56
  Template.indent([
@@ -24,13 +24,42 @@ class DefinePropertyGettersRuntimeModule extends HelperRuntimeModule {
24
24
  const { runtimeTemplate } = compilation;
25
25
  const fn = RuntimeGlobals.definePropertyGetters;
26
26
  return Template.asString([
27
- "// define getter functions for harmony exports",
27
+ "// define getter/value functions for harmony exports",
28
28
  `${fn} = ${runtimeTemplate.basicFunction("exports, definition", [
29
- "for(var key in definition) {",
29
+ "if(Array.isArray(definition)) {",
30
30
  Template.indent([
31
- `if(${RuntimeGlobals.hasOwnProperty}(definition, key) && !${RuntimeGlobals.hasOwnProperty}(exports, key)) {`,
31
+ "var i = 0;",
32
+ "while(i < definition.length) {",
32
33
  Template.indent([
33
- "Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });"
34
+ "var key = definition[i++];",
35
+ "var binding = definition[i++];",
36
+ `if(!${RuntimeGlobals.hasOwnProperty}(exports, key)) {`,
37
+ Template.indent([
38
+ "if(binding === 0) {",
39
+ Template.indent([
40
+ "Object.defineProperty(exports, key, { enumerable: true, value: definition[i++] });"
41
+ ]),
42
+ "} else {",
43
+ Template.indent([
44
+ "Object.defineProperty(exports, key, { enumerable: true, get: binding });"
45
+ ]),
46
+ "}"
47
+ ]),
48
+ "} else if(binding === 0) { i++; }"
49
+ ]),
50
+ "}"
51
+ ]),
52
+ // TODO webpack 6: remove object format support. Internal code (e.g. ConcatenatedModule)
53
+ // and third-party libraries may still call __webpack_require__.d() with an object.
54
+ "} else {",
55
+ Template.indent([
56
+ "for(var key in definition) {",
57
+ Template.indent([
58
+ `if(${RuntimeGlobals.hasOwnProperty}(definition, key) && !${RuntimeGlobals.hasOwnProperty}(exports, key)) {`,
59
+ Template.indent([
60
+ "Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });"
61
+ ]),
62
+ "}"
34
63
  ]),
35
64
  "}"
36
65
  ]),
@@ -7,6 +7,7 @@
7
7
  const RuntimeGlobals = require("../RuntimeGlobals");
8
8
  const RuntimeModule = require("../RuntimeModule");
9
9
  const Template = require("../Template");
10
+ const { reEncodeDigest } = require("../TemplatedPathPlugin");
10
11
  const { first } = require("../util/SetHelpers");
11
12
 
12
13
  /** @typedef {import("../Chunk")} Chunk */
@@ -14,6 +15,7 @@ const { first } = require("../util/SetHelpers");
14
15
  /** @typedef {import("../ChunkGraph")} ChunkGraph */
15
16
  /** @typedef {import("../Compilation")} Compilation */
16
17
  /** @typedef {import("../Compilation").HashWithLengthFunction} HashWithLengthFunction */
18
+ /** @typedef {import("../Compilation").HashWithDigestFunction} HashWithDigestFunction */
17
19
  /** @typedef {import("../Chunk").ChunkFilenameTemplate} ChunkFilenameTemplate */
18
20
 
19
21
  class GetChunkFilenameRuntimeModule extends RuntimeModule {
@@ -23,8 +25,16 @@ class GetChunkFilenameRuntimeModule extends RuntimeModule {
23
25
  * @param {string} global function name to be assigned
24
26
  * @param {(chunk: Chunk) => ChunkFilenameTemplate | false} getFilenameForChunk functor to get the filename or function
25
27
  * @param {boolean} allChunks when false, only async chunks are included
28
+ * @param {boolean=} usesFullHashDigest the filename uses `[fullhash:<digest>]`/`[hash:<digest>]`, so the re-encoded full hash must be inlined (post-hash) instead of read from the runtime `getFullHash()` expression
26
29
  */
27
- constructor(contentType, name, global, getFilenameForChunk, allChunks) {
30
+ constructor(
31
+ contentType,
32
+ name,
33
+ global,
34
+ getFilenameForChunk,
35
+ allChunks,
36
+ usesFullHashDigest
37
+ ) {
28
38
  super(`get ${name} chunk filename`);
29
39
  /** @type {string} */
30
40
  this.contentType = contentType;
@@ -34,8 +44,16 @@ class GetChunkFilenameRuntimeModule extends RuntimeModule {
34
44
  this.getFilenameForChunk = getFilenameForChunk;
35
45
  /** @type {boolean} */
36
46
  this.allChunks = allChunks;
37
- /** @type {boolean} */
38
- this.dependentHash = true;
47
+ // An inline digest on `[fullhash]` needs the final hash inlined, so this
48
+ // module must re-render after hashing (`fullHash`); otherwise it only needs
49
+ // the referenced chunk hashes, available before the full hash (`dependentHash`).
50
+ if (usesFullHashDigest) {
51
+ /** @type {boolean} */
52
+ this.fullHash = true;
53
+ } else {
54
+ /** @type {boolean} */
55
+ this.dependentHash = true;
56
+ }
39
57
  }
40
58
 
41
59
  /**
@@ -48,6 +66,37 @@ class GetChunkFilenameRuntimeModule extends RuntimeModule {
48
66
  const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
49
67
  const chunk = /** @type {Chunk} */ (this.chunk);
50
68
  const { runtimeTemplate } = compilation;
69
+ // Digest the stored hashes are encoded in, for re-encoding `[<hash>:<digest>]`.
70
+ const sourceDigest = compilation.outputOptions.hashDigest;
71
+
72
+ /**
73
+ * Re-encodes a full hash digest into the requested digest, optionally truncated.
74
+ * @param {string} value full hash digest
75
+ * @param {string} digest requested digest
76
+ * @param {number=} length requested length
77
+ * @returns {string} re-encoded hash
78
+ */
79
+ const reEncode = (value, digest, length) => {
80
+ const hash = reEncodeDigest(
81
+ value,
82
+ /** @type {string} */ (sourceDigest),
83
+ digest
84
+ );
85
+ return length ? hash.slice(0, length) : hash;
86
+ };
87
+
88
+ // `[fullhash:<digest>]`/`[hash:<digest>]` would resolve to a runtime
89
+ // `getFullHash()` expression that can't be re-encoded; instead this module is
90
+ // flagged `fullHash` and re-rendered after hashing, so we inline the
91
+ // re-encoded full hash here — byte-identical to the statically emitted file.
92
+ /** @type {HashWithDigestFunction} */
93
+ const fullHashWithDigest = (digest, length) => {
94
+ const fullHash = compilation.fullHash;
95
+ // Pre-hash pass (hash not computed yet): a placeholder, replaced on the
96
+ // post-hash re-render. Matches `GetFullHashRuntimeModule`'s `|| "XXXX"`.
97
+ if (!fullHash) return length ? "x".repeat(length) : "x";
98
+ return reEncode(fullHash, digest, length);
99
+ };
51
100
 
52
101
  /** @type {Map<ChunkFilenameTemplate, Set<Chunk>>} */
53
102
  const chunkFilenames = new Map();
@@ -162,12 +211,17 @@ class GetChunkFilenameRuntimeModule extends RuntimeModule {
162
211
  hash: `" + ${RuntimeGlobals.getFullHash}() + "`,
163
212
  hashWithLength: (length) =>
164
213
  `" + ${RuntimeGlobals.getFullHash}().slice(0, ${length}) + "`,
214
+ hashWithDigest: fullHashWithDigest,
165
215
  chunk: {
166
216
  id: unquotedStringify(/** @type {ChunkId} */ (c.id)),
167
217
  hash: unquotedStringify(/** @type {string} */ (c.renderedHash)),
168
218
  hashWithLength: unquotedStringifyWithLength(
169
219
  /** @type {string} */ (c.renderedHash)
170
220
  ),
221
+ hashWithDigest: (digest, length) =>
222
+ unquotedStringify(
223
+ reEncode(/** @type {string} */ (c.hash), digest, length)
224
+ ),
171
225
  name: unquotedStringify(c.name || /** @type {ChunkId} */ (c.id)),
172
226
  contentHash: {
173
227
  [contentType]: unquotedStringify(c.contentHash[contentType])
@@ -176,6 +230,16 @@ class GetChunkFilenameRuntimeModule extends RuntimeModule {
176
230
  [contentType]: unquotedStringifyWithLength(
177
231
  c.contentHash[contentType]
178
232
  )
233
+ },
234
+ contentHashWithDigest: {
235
+ [contentType]: (digest, length) =>
236
+ unquotedStringify(
237
+ reEncode(
238
+ c.contentHashFull[contentType] || c.contentHash[contentType],
239
+ digest,
240
+ length
241
+ )
242
+ )
179
243
  }
180
244
  },
181
245
  contentHashType: contentType
@@ -248,18 +312,33 @@ class GetChunkFilenameRuntimeModule extends RuntimeModule {
248
312
  hash: `" + ${RuntimeGlobals.getFullHash}() + "`,
249
313
  hashWithLength: (length) =>
250
314
  `" + ${RuntimeGlobals.getFullHash}().slice(0, ${length}) + "`,
315
+ hashWithDigest: fullHashWithDigest,
251
316
  chunk: {
252
317
  id: '" + chunkId + "',
253
318
  hash: mapExpr((c) => /** @type {string} */ (c.renderedHash)),
254
319
  hashWithLength: mapExprWithLength(
255
320
  (c) => /** @type {string} */ (c.renderedHash)
256
321
  ),
322
+ hashWithDigest: (digest, length) =>
323
+ mapExpr((c) =>
324
+ reEncode(/** @type {string} */ (c.hash), digest, length)
325
+ ),
257
326
  name: mapExpr((c) => c.name || /** @type {ChunkId} */ (c.id)),
258
327
  contentHash: {
259
328
  [contentType]: mapExpr((c) => c.contentHash[contentType])
260
329
  },
261
330
  contentHashWithLength: {
262
331
  [contentType]: mapExprWithLength((c) => c.contentHash[contentType])
332
+ },
333
+ contentHashWithDigest: {
334
+ [contentType]: (digest, length) =>
335
+ mapExpr((c) =>
336
+ reEncode(
337
+ c.contentHashFull[contentType] || c.contentHash[contentType],
338
+ digest,
339
+ length
340
+ )
341
+ )
263
342
  }
264
343
  },
265
344
  contentHashType: contentType
@@ -35,7 +35,7 @@ class GetTrustedTypesPolicyRuntimeModule extends HelperRuntimeModule {
35
35
  : false;
36
36
 
37
37
  return Template.asString([
38
- "var policy;",
38
+ `${runtimeTemplate.renderLet()} policy;`,
39
39
  `${fn} = ${runtimeTemplate.basicFunction("", [
40
40
  "// Create Trusted Type policy if Trusted Types are available and the policy doesn't exist yet.",
41
41
  "if (policy === undefined) {",
@@ -26,7 +26,7 @@ class HasOwnPropertyRuntimeModule extends RuntimeModule {
26
26
 
27
27
  return Template.asString([
28
28
  `${RuntimeGlobals.hasOwnProperty} = ${runtimeTemplate.returningFunction(
29
- "Object.prototype.hasOwnProperty.call(obj, prop)",
29
+ runtimeTemplate.objectHasOwn("obj", "prop"),
30
30
  "obj, prop"
31
31
  )}`
32
32
  ]);
@@ -111,10 +111,12 @@ class LoadScriptRuntimeModule extends HelperRuntimeModule {
111
111
  : ""
112
112
  ]);
113
113
 
114
+ const cst = runtimeTemplate.renderConst();
115
+ const lt = runtimeTemplate.renderLet();
114
116
  return Template.asString([
115
- "var inProgress = {};",
117
+ `${cst} inProgress = {};`,
116
118
  uniqueName
117
- ? `var dataWebpackPrefix = ${JSON.stringify(`${uniqueName}:`)};`
119
+ ? `${cst} dataWebpackPrefix = ${JSON.stringify(`${uniqueName}:`)};`
118
120
  : "// data-webpack is not used as build has no uniqueName",
119
121
  "// loadScript function to load a script via script tag",
120
122
  `${fn} = ${runtimeTemplate.basicFunction(
@@ -123,13 +125,13 @@ class LoadScriptRuntimeModule extends HelperRuntimeModule {
123
125
  }`,
124
126
  [
125
127
  "if(inProgress[url]) { inProgress[url].push(done); return; }",
126
- "var script, needAttach;",
128
+ `${lt} script, needAttach;`,
127
129
  "if(key !== undefined) {",
128
130
  Template.indent([
129
- 'var scripts = document.getElementsByTagName("script");',
131
+ `${cst} scripts = document.getElementsByTagName("script");`,
130
132
  "for(var i = 0; i < scripts.length; i++) {",
131
133
  Template.indent([
132
- "var s = scripts[i];",
134
+ `${cst} s = scripts[i];`,
133
135
  `if(s.getAttribute("src") == url${
134
136
  uniqueName
135
137
  ? ' || s.getAttribute("data-webpack") == dataWebpackPrefix + key'
@@ -146,23 +148,26 @@ class LoadScriptRuntimeModule extends HelperRuntimeModule {
146
148
  ]),
147
149
  "}",
148
150
  "inProgress[url] = [done];",
149
- `var onScriptComplete = ${runtimeTemplate.basicFunction(
151
+ `${cst} onScriptComplete = ${runtimeTemplate.basicFunction(
150
152
  "prev, event",
151
153
  Template.asString([
152
154
  "// avoid mem leaks in IE.",
153
155
  "script.onerror = script.onload = null;",
154
156
  "clearTimeout(timeout);",
155
- "var doneFns = inProgress[url];",
157
+ `${cst} doneFns = inProgress[url];`,
156
158
  "delete inProgress[url];",
157
- "script.parentNode && script.parentNode.removeChild(script);",
158
- `doneFns && doneFns.forEach(${runtimeTemplate.returningFunction(
159
- "fn(event)",
160
- "fn"
161
- )});`,
159
+ `${runtimeTemplate.optionalChaining(
160
+ "script.parentNode",
161
+ "removeChild(script)"
162
+ )};`,
163
+ `${runtimeTemplate.optionalChaining(
164
+ "doneFns",
165
+ `forEach(${runtimeTemplate.returningFunction("fn(event)", "fn")})`
166
+ )};`,
162
167
  "if(prev) return prev(event);"
163
168
  ])
164
169
  )}`,
165
- `var timeout = setTimeout(onScriptComplete.bind(null, undefined, { type: 'timeout', target: script }), ${loadTimeout});`,
170
+ `${cst} timeout = setTimeout(onScriptComplete.bind(null, undefined, { type: 'timeout', target: script }), ${loadTimeout});`,
166
171
  "script.onerror = onScriptComplete.bind(null, script.onerror);",
167
172
  "script.onload = onScriptComplete.bind(null, script.onload);",
168
173
  "needAttach && document.head.appendChild(script);"