webpack 5.99.9 → 5.100.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (308) hide show
  1. package/bin/webpack.js +8 -2
  2. package/hot/log.js +15 -15
  3. package/hot/poll.js +1 -0
  4. package/lib/APIPlugin.js +3 -3
  5. package/lib/AbstractMethodError.js +1 -0
  6. package/lib/AutomaticPrefetchPlugin.js +1 -0
  7. package/lib/BannerPlugin.js +1 -1
  8. package/lib/CaseSensitiveModulesWarning.js +4 -4
  9. package/lib/Chunk.js +6 -6
  10. package/lib/ChunkGraph.js +37 -31
  11. package/lib/ChunkGroup.js +4 -4
  12. package/lib/ChunkTemplate.js +1 -1
  13. package/lib/CleanPlugin.js +94 -17
  14. package/lib/CodeGenerationResults.js +1 -1
  15. package/lib/CompatibilityPlugin.js +5 -2
  16. package/lib/Compilation.js +67 -45
  17. package/lib/Compiler.js +46 -16
  18. package/lib/ConcatenationScope.js +15 -6
  19. package/lib/ConstPlugin.js +5 -3
  20. package/lib/ContextModule.js +16 -12
  21. package/lib/ContextModuleFactory.js +4 -3
  22. package/lib/ContextReplacementPlugin.js +4 -2
  23. package/lib/CssModule.js +2 -2
  24. package/lib/DefinePlugin.js +111 -3
  25. package/lib/DelegatedModuleFactoryPlugin.js +18 -18
  26. package/lib/Dependency.js +11 -4
  27. package/lib/DependencyTemplate.js +1 -0
  28. package/lib/DllEntryPlugin.js +3 -1
  29. package/lib/DllPlugin.js +4 -3
  30. package/lib/DllReferencePlugin.js +2 -2
  31. package/lib/DynamicEntryPlugin.js +1 -1
  32. package/lib/EntryOptionPlugin.js +5 -0
  33. package/lib/ErrorHelpers.js +4 -4
  34. package/lib/EvalDevToolModulePlugin.js +3 -3
  35. package/lib/EvalSourceMapDevToolPlugin.js +7 -7
  36. package/lib/ExportsInfo.js +48 -39
  37. package/lib/ExternalModule.js +15 -11
  38. package/lib/ExternalModuleFactoryPlugin.js +5 -2
  39. package/lib/FileSystemInfo.js +51 -36
  40. package/lib/FlagDependencyExportsPlugin.js +14 -7
  41. package/lib/FlagDependencyUsagePlugin.js +1 -1
  42. package/lib/Generator.js +14 -1
  43. package/lib/HookWebpackError.js +1 -0
  44. package/lib/HotModuleReplacementPlugin.js +77 -50
  45. package/lib/IgnorePlugin.js +5 -2
  46. package/lib/InvalidDependenciesModuleWarning.js +1 -1
  47. package/lib/JavascriptMetaInfoPlugin.js +0 -1
  48. package/lib/LibManifestPlugin.js +4 -2
  49. package/lib/LoaderOptionsPlugin.js +6 -4
  50. package/lib/MainTemplate.js +2 -2
  51. package/lib/Module.js +21 -6
  52. package/lib/ModuleFactory.js +1 -0
  53. package/lib/ModuleGraph.js +24 -2
  54. package/lib/ModuleGraphConnection.js +5 -5
  55. package/lib/ModuleInfoHeaderPlugin.js +2 -1
  56. package/lib/ModuleParseError.js +1 -0
  57. package/lib/ModuleSourceTypesConstants.js +12 -12
  58. package/lib/ModuleTemplate.js +1 -1
  59. package/lib/ModuleTypeConstants.js +21 -21
  60. package/lib/MultiCompiler.js +6 -6
  61. package/lib/NormalModule.js +31 -44
  62. package/lib/NormalModuleFactory.js +34 -20
  63. package/lib/NormalModuleReplacementPlugin.js +1 -1
  64. package/lib/NullFactory.js +1 -0
  65. package/lib/OptimizationStages.js +1 -1
  66. package/lib/Parser.js +1 -0
  67. package/lib/ProgressPlugin.js +12 -5
  68. package/lib/ProvidePlugin.js +5 -1
  69. package/lib/RawModule.js +14 -0
  70. package/lib/RecordIdsPlugin.js +3 -3
  71. package/lib/RuntimeGlobals.js +175 -155
  72. package/lib/RuntimeModule.js +1 -0
  73. package/lib/RuntimePlugin.js +33 -7
  74. package/lib/RuntimeTemplate.js +111 -11
  75. package/lib/SourceMapDevToolModuleOptionsPlugin.js +15 -25
  76. package/lib/SourceMapDevToolPlugin.js +19 -17
  77. package/lib/Template.js +2 -2
  78. package/lib/TemplatedPathPlugin.js +1 -1
  79. package/lib/WarnDeprecatedOptionPlugin.js +7 -8
  80. package/lib/WatchIgnorePlugin.js +4 -3
  81. package/lib/WebpackIsIncludedPlugin.js +2 -1
  82. package/lib/WebpackOptionsApply.js +115 -27
  83. package/lib/asset/AssetGenerator.js +15 -11
  84. package/lib/asset/AssetModulesPlugin.js +19 -17
  85. package/lib/asset/AssetSourceGenerator.js +4 -4
  86. package/lib/asset/RawDataUrlModule.js +4 -2
  87. package/lib/async-modules/AwaitDependenciesInitFragment.js +1 -1
  88. package/lib/buildChunkGraph.js +6 -3
  89. package/lib/cache/AddBuildDependenciesPlugin.js +5 -6
  90. package/lib/cache/IdleFileCachePlugin.js +7 -4
  91. package/lib/cache/MemoryCachePlugin.js +1 -0
  92. package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
  93. package/lib/cache/PackFileCacheStrategy.js +26 -20
  94. package/lib/cache/ResolverCachePlugin.js +16 -8
  95. package/lib/cli.js +15 -10
  96. package/lib/config/browserslistTargetHandler.js +3 -3
  97. package/lib/config/defaults.js +25 -17
  98. package/lib/config/normalization.js +2 -1
  99. package/lib/config/target.js +6 -5
  100. package/lib/container/ContainerPlugin.js +1 -1
  101. package/lib/container/ContainerReferencePlugin.js +1 -1
  102. package/lib/container/FallbackModule.js +2 -1
  103. package/lib/container/HoistContainerReferencesPlugin.js +1 -1
  104. package/lib/container/ModuleFederationPlugin.js +2 -2
  105. package/lib/container/RemoteModule.js +1 -1
  106. package/lib/css/CssGenerator.js +9 -6
  107. package/lib/css/CssModulesPlugin.js +44 -31
  108. package/lib/css/CssParser.js +6 -4
  109. package/lib/css/walkCssTokens.js +33 -37
  110. package/lib/debug/ProfilingPlugin.js +6 -6
  111. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +8 -8
  112. package/lib/dependencies/AMDPlugin.js +12 -8
  113. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +28 -26
  114. package/lib/dependencies/CachedConstDependency.js +1 -5
  115. package/lib/dependencies/CommonJsExportRequireDependency.js +6 -4
  116. package/lib/dependencies/CommonJsExportsParserPlugin.js +22 -25
  117. package/lib/dependencies/CommonJsFullRequireDependency.js +1 -9
  118. package/lib/dependencies/CommonJsImportsParserPlugin.js +100 -114
  119. package/lib/dependencies/CommonJsPlugin.js +15 -16
  120. package/lib/dependencies/ContextDependencyHelpers.js +2 -1
  121. package/lib/dependencies/ContextDependencyTemplateAsId.js +1 -0
  122. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +1 -0
  123. package/lib/dependencies/CssIcssExportDependency.js +1 -1
  124. package/lib/dependencies/CssLocalIdentifierDependency.js +2 -2
  125. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +2 -1
  126. package/lib/dependencies/DynamicExports.js +9 -9
  127. package/lib/dependencies/ExportsInfoDependency.js +1 -1
  128. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +122 -101
  129. package/lib/dependencies/HarmonyExportExpressionDependency.js +1 -1
  130. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +95 -19
  131. package/lib/dependencies/HarmonyExportInitFragment.js +1 -1
  132. package/lib/dependencies/HarmonyImportDependency.js +11 -5
  133. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +238 -162
  134. package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -1
  135. package/lib/dependencies/HarmonyImportSpecifierDependency.js +20 -9
  136. package/lib/dependencies/HarmonyModulesPlugin.js +23 -12
  137. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -0
  138. package/lib/dependencies/ImportMetaContextPlugin.js +2 -1
  139. package/lib/dependencies/ImportMetaPlugin.js +2 -2
  140. package/lib/dependencies/ImportParserPlugin.js +40 -9
  141. package/lib/dependencies/ImportPlugin.js +3 -1
  142. package/lib/dependencies/LoaderPlugin.js +1 -0
  143. package/lib/dependencies/ModuleDependency.js +3 -1
  144. package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +1 -0
  145. package/lib/dependencies/RequireContextPlugin.js +3 -1
  146. package/lib/dependencies/RequireEnsurePlugin.js +6 -6
  147. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +33 -34
  148. package/lib/dependencies/RequireIncludePlugin.js +1 -0
  149. package/lib/dependencies/RuntimeRequirementsDependency.js +1 -1
  150. package/lib/dependencies/SystemPlugin.js +1 -1
  151. package/lib/dependencies/URLContextDependency.js +65 -0
  152. package/lib/dependencies/URLPlugin.js +17 -157
  153. package/lib/dependencies/WorkerPlugin.js +23 -10
  154. package/lib/dependencies/processExportInfo.js +2 -1
  155. package/lib/esm/ModuleChunkFormatPlugin.js +269 -185
  156. package/lib/esm/ModuleChunkLoadingPlugin.js +39 -1
  157. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +70 -3
  158. package/lib/hmr/HotModuleReplacement.runtime.js +0 -1
  159. package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
  160. package/lib/hmr/JavascriptHotModuleReplacementHelper.js +37 -0
  161. package/lib/hmr/LazyCompilationPlugin.js +4 -2
  162. package/lib/hmr/lazyCompilationBackend.js +4 -2
  163. package/lib/ids/ChunkModuleIdRangePlugin.js +6 -3
  164. package/lib/ids/DeterministicChunkIdsPlugin.js +30 -35
  165. package/lib/ids/DeterministicModuleIdsPlugin.js +4 -3
  166. package/lib/ids/HashedModuleIdsPlugin.js +5 -4
  167. package/lib/ids/IdHelpers.js +21 -17
  168. package/lib/ids/NamedChunkIdsPlugin.js +5 -5
  169. package/lib/ids/NamedModuleIdsPlugin.js +4 -4
  170. package/lib/ids/NaturalChunkIdsPlugin.js +2 -1
  171. package/lib/ids/NaturalModuleIdsPlugin.js +1 -1
  172. package/lib/ids/OccurrenceChunkIdsPlugin.js +3 -2
  173. package/lib/ids/OccurrenceModuleIdsPlugin.js +1 -1
  174. package/lib/ids/SyncModuleIdsPlugin.js +1 -1
  175. package/lib/index.js +13 -3
  176. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +113 -119
  177. package/lib/javascript/BasicEvaluatedExpression.js +2 -1
  178. package/lib/javascript/ChunkHelpers.js +1 -0
  179. package/lib/javascript/CommonJsChunkFormatPlugin.js +121 -136
  180. package/lib/javascript/EnableChunkLoadingPlugin.js +6 -3
  181. package/lib/javascript/JavascriptGenerator.js +14 -2
  182. package/lib/javascript/JavascriptModulesPlugin.js +68 -27
  183. package/lib/javascript/JavascriptParser.js +117 -76
  184. package/lib/javascript/JavascriptParserHelpers.js +41 -41
  185. package/lib/javascript/StartupHelpers.js +17 -17
  186. package/lib/json/JsonGenerator.js +4 -2
  187. package/lib/json/JsonModulesPlugin.js +2 -2
  188. package/lib/json/JsonParser.js +1 -1
  189. package/lib/library/AbstractLibraryPlugin.js +6 -2
  190. package/lib/library/AssignLibraryPlugin.js +21 -6
  191. package/lib/library/EnableLibraryPlugin.js +23 -3
  192. package/lib/library/UmdLibraryPlugin.js +15 -6
  193. package/lib/logging/createConsoleLogger.js +3 -3
  194. package/lib/logging/runtime.js +9 -9
  195. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +4 -22
  196. package/lib/node/RequireChunkLoadingRuntimeModule.js +4 -22
  197. package/lib/node/nodeConsole.js +4 -2
  198. package/lib/optimize/AggressiveMergingPlugin.js +45 -46
  199. package/lib/optimize/AggressiveSplittingPlugin.js +13 -12
  200. package/lib/optimize/ConcatenatedModule.js +227 -57
  201. package/lib/optimize/EnsureChunkConditionsPlugin.js +58 -58
  202. package/lib/optimize/FlagIncludedChunksPlugin.js +3 -1
  203. package/lib/optimize/InnerGraph.js +115 -112
  204. package/lib/optimize/InnerGraphPlugin.js +2 -2
  205. package/lib/optimize/LimitChunkCountPlugin.js +4 -2
  206. package/lib/optimize/MangleExportsPlugin.js +4 -3
  207. package/lib/optimize/MergeDuplicateChunksPlugin.js +80 -81
  208. package/lib/optimize/MinChunkSizePlugin.js +6 -3
  209. package/lib/optimize/ModuleConcatenationPlugin.js +31 -22
  210. package/lib/optimize/RealContentHashPlugin.js +26 -20
  211. package/lib/optimize/RemoveEmptyChunksPlugin.js +2 -1
  212. package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
  213. package/lib/optimize/SideEffectsFlagPlugin.js +3 -2
  214. package/lib/optimize/SplitChunksPlugin.js +16 -13
  215. package/lib/rules/BasicEffectRulePlugin.js +4 -2
  216. package/lib/rules/BasicMatcherRulePlugin.js +3 -1
  217. package/lib/rules/ObjectMatcherRulePlugin.js +3 -1
  218. package/lib/rules/RuleSetCompiler.js +19 -5
  219. package/lib/rules/UseEffectRulePlugin.js +17 -9
  220. package/lib/runtime/AsyncModuleRuntimeModule.js +64 -9
  221. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +1 -1
  222. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +214 -0
  223. package/lib/runtime/RuntimeIdRuntimeModule.js +2 -1
  224. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +8 -7
  225. package/lib/schemes/FileUriPlugin.js +1 -1
  226. package/lib/schemes/HttpUriPlugin.js +27 -19
  227. package/lib/schemes/VirtualUrlPlugin.js +222 -0
  228. package/lib/serialization/AggregateErrorSerializer.js +1 -1
  229. package/lib/serialization/BinaryMiddleware.js +5 -4
  230. package/lib/serialization/FileMiddleware.js +7 -4
  231. package/lib/serialization/ObjectMiddleware.js +14 -8
  232. package/lib/serialization/Serializer.js +5 -3
  233. package/lib/serialization/SerializerMiddleware.js +2 -0
  234. package/lib/sharing/ConsumeSharedModule.js +1 -1
  235. package/lib/sharing/ConsumeSharedPlugin.js +3 -3
  236. package/lib/sharing/ConsumeSharedRuntimeModule.js +2 -2
  237. package/lib/sharing/ProvideSharedModule.js +1 -1
  238. package/lib/sharing/ProvideSharedPlugin.js +3 -2
  239. package/lib/sharing/SharePlugin.js +2 -1
  240. package/lib/sharing/ShareRuntimeModule.js +3 -5
  241. package/lib/sharing/utils.js +34 -34
  242. package/lib/stats/DefaultStatsFactoryPlugin.js +49 -46
  243. package/lib/stats/DefaultStatsPresetPlugin.js +13 -13
  244. package/lib/stats/DefaultStatsPrinterPlugin.js +15 -9
  245. package/lib/stats/StatsFactory.js +6 -3
  246. package/lib/stats/StatsPrinter.js +6 -7
  247. package/lib/url/URLParserPlugin.js +266 -0
  248. package/lib/util/ArrayQueue.js +1 -1
  249. package/lib/util/AsyncQueue.js +1 -1
  250. package/lib/util/Hash.js +2 -0
  251. package/lib/util/IterableHelpers.js +1 -1
  252. package/lib/util/LazyBucketSortedSet.js +2 -1
  253. package/lib/util/LazySet.js +11 -6
  254. package/lib/util/ParallelismFactorCalculator.js +1 -1
  255. package/lib/util/SetHelpers.js +3 -3
  256. package/lib/util/SortableSet.js +2 -2
  257. package/lib/util/StackedCacheMap.js +3 -1
  258. package/lib/util/StackedMap.js +2 -2
  259. package/lib/util/StringXor.js +1 -0
  260. package/lib/util/TupleSet.js +1 -0
  261. package/lib/util/URLAbsoluteSpecifier.js +1 -1
  262. package/lib/util/cleverMerge.js +95 -58
  263. package/lib/util/comparators.js +154 -127
  264. package/lib/util/compileBooleanMatcher.js +8 -3
  265. package/lib/util/concatenate.js +8 -7
  266. package/lib/util/conventions.js +72 -73
  267. package/lib/util/create-schema-validation.js +2 -1
  268. package/lib/util/createHash.js +10 -4
  269. package/lib/util/deprecation.js +69 -66
  270. package/lib/util/deterministicGrouping.js +4 -2
  271. package/lib/util/extractUrlAndGlobal.js +1 -1
  272. package/lib/util/findGraphRoots.js +2 -2
  273. package/lib/util/fs.js +30 -23
  274. package/lib/util/hash/md4.js +2 -2
  275. package/lib/util/hash/wasm-hash.js +4 -2
  276. package/lib/util/identifier.js +13 -12
  277. package/lib/util/internalSerializables.js +2 -0
  278. package/lib/util/magicComment.js +5 -5
  279. package/lib/util/processAsyncTree.js +1 -1
  280. package/lib/util/propertyAccess.js +1 -1
  281. package/lib/util/propertyName.js +1 -1
  282. package/lib/util/registerExternalSerializer.js +1 -2
  283. package/lib/util/removeBOM.js +1 -1
  284. package/lib/util/runtime.js +29 -21
  285. package/lib/util/semver.js +1 -1
  286. package/lib/util/serialization.js +3 -0
  287. package/lib/util/source.js +3 -2
  288. package/lib/validateSchema.js +1 -0
  289. package/lib/wasm/EnableWasmLoadingPlugin.js +6 -3
  290. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -1
  291. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +46 -49
  292. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +2 -2
  293. package/lib/wasm-sync/WebAssemblyGenerator.js +2 -3
  294. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +3 -2
  295. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +3 -0
  296. package/lib/wasm-sync/WebAssemblyUtils.js +1 -1
  297. package/lib/web/JsonpChunkLoadingRuntimeModule.js +4 -22
  298. package/lib/webpack.js +4 -5
  299. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +1 -0
  300. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +6 -24
  301. package/lib/webworker/WebWorkerTemplatePlugin.js +1 -0
  302. package/package.json +119 -113
  303. package/schemas/WebpackOptions.check.js +1 -1
  304. package/schemas/WebpackOptions.json +17 -0
  305. package/schemas/plugins/schemes/VirtualUrlPlugin.check.d.ts +7 -0
  306. package/schemas/plugins/schemes/VirtualUrlPlugin.check.js +6 -0
  307. package/schemas/plugins/schemes/VirtualUrlPlugin.json +77 -0
  308. package/types.d.ts +1243 -409
@@ -5,17 +5,17 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const util = require("util");
8
9
  const asyncLib = require("neo-async");
9
10
  const {
11
+ AsyncParallelHook,
12
+ AsyncSeriesBailHook,
13
+ AsyncSeriesHook,
10
14
  HookMap,
11
- SyncHook,
12
15
  SyncBailHook,
13
- SyncWaterfallHook,
14
- AsyncSeriesHook,
15
- AsyncSeriesBailHook,
16
- AsyncParallelHook
16
+ SyncHook,
17
+ SyncWaterfallHook
17
18
  } = require("tapable");
18
- const util = require("util");
19
19
  const { CachedSource } = require("webpack-sources");
20
20
  const { MultiItemCache } = require("./CacheFacade");
21
21
  const Chunk = require("./Chunk");
@@ -56,7 +56,7 @@ const Stats = require("./Stats");
56
56
  const WebpackError = require("./WebpackError");
57
57
  const buildChunkGraph = require("./buildChunkGraph");
58
58
  const BuildCycleError = require("./errors/BuildCycleError");
59
- const { Logger, LogType } = require("./logging/Logger");
59
+ const { LogType, Logger } = require("./logging/Logger");
60
60
  const StatsFactory = require("./stats/StatsFactory");
61
61
  const StatsPrinter = require("./stats/StatsPrinter");
62
62
  const { equals: arrayEquals } = require("./util/ArrayHelpers");
@@ -66,18 +66,18 @@ const { getOrInsert } = require("./util/MapHelpers");
66
66
  const WeakTupleMap = require("./util/WeakTupleMap");
67
67
  const { cachedCleverMerge } = require("./util/cleverMerge");
68
68
  const {
69
+ compareIds,
69
70
  compareLocations,
70
- concatComparators,
71
+ compareModulesByIdentifier,
71
72
  compareSelect,
72
- compareIds,
73
73
  compareStringsNumeric,
74
- compareModulesByIdentifier
74
+ concatComparators
75
75
  } = require("./util/comparators");
76
76
  const createHash = require("./util/createHash");
77
77
  const {
78
78
  arrayToSetDeprecation,
79
- soonFrozenObjectDeprecation,
80
- createFakeHook
79
+ createFakeHook,
80
+ soonFrozenObjectDeprecation
81
81
  } = require("./util/deprecation");
82
82
  const processAsyncTree = require("./util/processAsyncTree");
83
83
  const { getRuntimeKey } = require("./util/runtime");
@@ -102,6 +102,7 @@ const { isSourceEqual } = require("./util/source");
102
102
  /** @typedef {import("./Compiler").MemCache} MemCache */
103
103
  /** @typedef {import("./Compiler").WeakReferences} WeakReferences */
104
104
  /** @typedef {import("./Compiler").ModuleMemCachesItem} ModuleMemCachesItem */
105
+ /** @typedef {import("./Compiler").Records} Records */
105
106
  /** @typedef {import("./DependenciesBlock")} DependenciesBlock */
106
107
  /** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
107
108
  /** @typedef {import("./Dependency").ReferencedExport} ReferencedExport */
@@ -391,8 +392,6 @@ const { isSourceEqual } = require("./util/source");
391
392
 
392
393
  /** @typedef {Set<Module>} NotCodeGeneratedModules */
393
394
 
394
- /** @typedef {Record<string, TODO>} Records */
395
-
396
395
  /** @type {AssetInfo} */
397
396
  const EMPTY_ASSET_INFO = Object.freeze({});
398
397
 
@@ -531,8 +530,9 @@ class Compilation {
531
530
  if (
532
531
  /** @type {ProcessedAssets} */
533
532
  (processedAssets).has(this.assets)
534
- )
533
+ ) {
535
534
  additionalAssetsFn(assets);
535
+ }
536
536
  });
537
537
  }
538
538
  return {
@@ -549,8 +549,9 @@ class Compilation {
549
549
  } catch (err) {
550
550
  return callback(/** @type {Error} */ (err));
551
551
  }
552
- if (processedAssets !== undefined)
552
+ if (processedAssets !== undefined) {
553
553
  processedAssets.add(this.assets);
554
+ }
554
555
  const newAssets = popNewAssets(assets);
555
556
  if (newAssets !== undefined) {
556
557
  this.hooks.processAdditionalAssets.callAsync(
@@ -570,8 +571,9 @@ class Compilation {
570
571
  if (
571
572
  /** @type {ProcessedAssets} */
572
573
  (processedAssets).has(this.assets)
573
- )
574
+ ) {
574
575
  return additionalAssetsFn(assets, callback);
576
+ }
575
577
  callback();
576
578
  }
577
579
  );
@@ -592,8 +594,9 @@ class Compilation {
592
594
  */
593
595
  err => {
594
596
  if (err) return callback(err);
595
- if (processedAssets !== undefined)
597
+ if (processedAssets !== undefined) {
596
598
  processedAssets.add(this.assets);
599
+ }
597
600
  const newAssets = popNewAssets(assets);
598
601
  if (newAssets !== undefined) {
599
602
  this.hooks.processAdditionalAssets.callAsync(
@@ -613,8 +616,9 @@ class Compilation {
613
616
  if (
614
617
  /** @type {ProcessedAssets} */
615
618
  (processedAssets).has(this.assets)
616
- )
619
+ ) {
617
620
  return additionalAssetsFn(assets);
621
+ }
618
622
  return Promise.resolve();
619
623
  });
620
624
  }
@@ -628,8 +632,9 @@ class Compilation {
628
632
  const p = fn(assets);
629
633
  if (!p || !p.then) return p;
630
634
  return p.then(() => {
631
- if (processedAssets !== undefined)
635
+ if (processedAssets !== undefined) {
632
636
  processedAssets.add(this.assets);
637
+ }
633
638
  const newAssets = popNewAssets(assets);
634
639
  if (newAssets !== undefined) {
635
640
  return this.hooks.processAdditionalAssets.promise(
@@ -678,7 +683,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
678
683
  {
679
684
  name,
680
685
  /** @type {AsyncSeriesHook<T>["intercept"]} */
681
- intercept(interceptor) {
686
+ intercept(_interceptor) {
682
687
  throw new Error(errorMessage("it's using 'intercept'"));
683
688
  },
684
689
  /** @type {AsyncSeriesHook<T>["tap"]} */
@@ -1232,7 +1237,6 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1232
1237
  // properties in the prototype chain
1233
1238
  /** @type {Partial<NormalizedStatsOptions>} */
1234
1239
  const options = {};
1235
- // eslint-disable-next-line guard-for-in
1236
1240
  for (const key in optionsOrPreset) {
1237
1241
  options[key] = optionsOrPreset[/** @type {keyof StatsOptions} */ (key)];
1238
1242
  }
@@ -1445,8 +1449,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1445
1449
  }
1446
1450
  this._modules.set(identifier, module);
1447
1451
  this.modules.add(module);
1448
- if (this._backCompat)
1452
+ if (this._backCompat) {
1449
1453
  ModuleGraph.setModuleGraphForModule(module, this.moduleGraph);
1454
+ }
1450
1455
  if (currentProfile !== undefined) {
1451
1456
  currentProfile.markIntegrationEnd();
1452
1457
  }
@@ -1739,8 +1744,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1739
1744
  inProgressTransitive = -1;
1740
1745
  onTransitiveTasksFinished(err);
1741
1746
  }
1742
- if (--inProgressTransitive === 0)
1747
+ if (--inProgressTransitive === 0) {
1743
1748
  return onTransitiveTasksFinished();
1749
+ }
1744
1750
  }
1745
1751
  );
1746
1752
  if (--inProgressSorting === 0) onDependenciesSorted();
@@ -1891,8 +1897,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1891
1897
 
1892
1898
  this._modules.set(module.identifier(), module);
1893
1899
  this.modules.add(module);
1894
- if (this._backCompat)
1900
+ if (this._backCompat) {
1895
1901
  ModuleGraph.setModuleGraphForModule(module, this.moduleGraph);
1902
+ }
1896
1903
 
1897
1904
  this._handleModuleBuildAndDependencies(
1898
1905
  originModule,
@@ -2442,8 +2449,8 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2442
2449
  */
2443
2450
  _rebuildModule(module, callback) {
2444
2451
  this.hooks.rebuildModule.call(module);
2445
- const oldDependencies = module.dependencies.slice();
2446
- const oldBlocks = module.blocks.slice();
2452
+ const oldDependencies = [...module.dependencies];
2453
+ const oldBlocks = [...module.blocks];
2447
2454
  module.invalidateBuild();
2448
2455
  this.buildQueue.invalidate(module);
2449
2456
  this.buildModule(module, err => {
@@ -2693,7 +2700,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2693
2700
  }
2694
2701
  if (module.blocks.length > 0) {
2695
2702
  blocks = [];
2696
- const queue = Array.from(module.blocks);
2703
+ const queue = [...module.blocks];
2697
2704
  for (const block of queue) {
2698
2705
  const chunkGroup = chunkGraph.getBlockChunkGroup(block);
2699
2706
  if (chunkGroup) {
@@ -2725,7 +2732,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2725
2732
  }
2726
2733
  }
2727
2734
  if (blocks !== undefined) {
2728
- const queue = Array.from(module.blocks);
2735
+ const queue = [...module.blocks];
2729
2736
  let i = 0;
2730
2737
  for (const block of queue) {
2731
2738
  const chunkGroup = chunkGraph.getBlockChunkGroup(block);
@@ -2783,7 +2790,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2783
2790
  this.factorizeQueue.clear();
2784
2791
  if (this.profile) {
2785
2792
  this.logger.time("finish module profiles");
2793
+
2786
2794
  const ParallelismFactorCalculator = require("./util/ParallelismFactorCalculator");
2795
+
2787
2796
  const p = new ParallelismFactorCalculator();
2788
2797
  const moduleGraph = this.moduleGraph;
2789
2798
  /** @type {Map<Module, ModuleProfile>} */
@@ -3456,8 +3465,9 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3456
3465
  }
3457
3466
  }
3458
3467
 
3459
- if (this.reportDependencyErrorsAndWarnings(module, block.blocks))
3468
+ if (this.reportDependencyErrorsAndWarnings(module, block.blocks)) {
3460
3469
  hasProblems = true;
3470
+ }
3461
3471
  }
3462
3472
  return hasProblems;
3463
3473
  }
@@ -3842,8 +3852,9 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3842
3852
  */
3843
3853
  addRuntimeModule(chunk, module, chunkGraph = this.chunkGraph) {
3844
3854
  // Deprecated ModuleGraph association
3845
- if (this._backCompat)
3855
+ if (this._backCompat) {
3846
3856
  ModuleGraph.setModuleGraphForModule(module, this.moduleGraph);
3857
+ }
3847
3858
 
3848
3859
  // add it to the list
3849
3860
  this.modules.add(module);
@@ -3915,7 +3926,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3915
3926
  }
3916
3927
  }
3917
3928
  const chunkGroup = new ChunkGroup(groupOptions);
3918
- if (module)
3929
+ if (module) {
3919
3930
  chunkGroup.addOrigin(
3920
3931
  module,
3921
3932
  /** @type {DependencyLocation} */
@@ -3923,6 +3934,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3923
3934
  /** @type {string} */
3924
3935
  (request)
3925
3936
  );
3937
+ }
3926
3938
  const chunk = this.addChunk(name);
3927
3939
 
3928
3940
  connectChunkGroupAndChunk(chunkGroup, chunk);
@@ -3992,8 +4004,9 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3992
4004
  }
3993
4005
  const chunk = new Chunk(name, this._backCompat);
3994
4006
  this.chunks.add(chunk);
3995
- if (this._backCompat)
4007
+ if (this._backCompat) {
3996
4008
  ChunkGraph.setChunkGraphForChunk(chunk, this.chunkGraph);
4009
+ }
3997
4010
  if (name) {
3998
4011
  this.namedChunks.set(name, chunk);
3999
4012
  }
@@ -4089,7 +4102,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4089
4102
 
4090
4103
  /**
4091
4104
  * @param {Module} module module relationship for removal
4092
- * @param {DependenciesBlockLike} block //TODO: good description
4105
+ * @param {DependenciesBlockLike} block dependencies block
4093
4106
  * @returns {void}
4094
4107
  */
4095
4108
  removeReasonsOfDependencyBlock(module, block) {
@@ -4367,16 +4380,21 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4367
4380
  /** @type {Chunk[]} */
4368
4381
  const unorderedRuntimeChunks = [];
4369
4382
  /** @type {Chunk[]} */
4370
- const otherChunks = [];
4383
+ const initialChunks = [];
4384
+ /** @type {Chunk[]} */
4385
+ const asyncChunks = [];
4371
4386
  for (const c of this.chunks) {
4372
4387
  if (c.hasRuntime()) {
4373
4388
  unorderedRuntimeChunks.push(c);
4389
+ } else if (c.canBeInitial()) {
4390
+ initialChunks.push(c);
4374
4391
  } else {
4375
- otherChunks.push(c);
4392
+ asyncChunks.push(c);
4376
4393
  }
4377
4394
  }
4378
4395
  unorderedRuntimeChunks.sort(byId);
4379
- otherChunks.sort(byId);
4396
+ initialChunks.sort(byId);
4397
+ asyncChunks.sort(byId);
4380
4398
 
4381
4399
  /** @typedef {{ chunk: Chunk, referencedBy: RuntimeChunkInfo[], remaining: number }} RuntimeChunkInfo */
4382
4400
  /** @type {Map<Chunk, RuntimeChunkInfo>} */
@@ -4391,7 +4409,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4391
4409
  let remaining = 0;
4392
4410
  for (const info of runtimeChunksMap.values()) {
4393
4411
  for (const other of new Set(
4394
- Array.from(info.chunk.getAllReferencedAsyncEntrypoints()).map(
4412
+ [...info.chunk.getAllReferencedAsyncEntrypoints()].map(
4395
4413
  e => e.chunks[e.chunks.length - 1]
4396
4414
  )
4397
4415
  )) {
@@ -4542,8 +4560,9 @@ This prevents using hashes of each other and should be avoided.`);
4542
4560
  }
4543
4561
  this.logger.timeAggregate("hashing: hash chunks");
4544
4562
  };
4545
- for (const chunk of otherChunks) processChunk(chunk);
4563
+ for (const chunk of asyncChunks) processChunk(chunk);
4546
4564
  for (const chunk of runtimeChunks) processChunk(chunk);
4565
+ for (const chunk of initialChunks) processChunk(chunk);
4547
4566
  if (errors.length > 0) {
4548
4567
  errors.sort(compareSelect(err => err.module, compareModulesByIdentifier));
4549
4568
  for (const error of errors) {
@@ -4767,7 +4786,9 @@ This prevents using hashes of each other and should be avoided.`);
4767
4786
  newEntry = entry.map(x => (x === file ? newFile : x));
4768
4787
  } else if (entry === file) {
4769
4788
  newEntry = newFile;
4770
- } else continue;
4789
+ } else {
4790
+ continue;
4791
+ }
4771
4792
  this.assetsInfo.set(name, {
4772
4793
  ...info,
4773
4794
  related: {
@@ -5258,7 +5279,7 @@ This prevents using hashes of each other and should be avoided.`);
5258
5279
  runtimeTemplate,
5259
5280
  errors,
5260
5281
  codeGenerationResults,
5261
- (err, codeGenerated) => {
5282
+ (err, _codeGenerated) => {
5262
5283
  callback(err);
5263
5284
  }
5264
5285
  );
@@ -5495,6 +5516,7 @@ This prevents using hashes of each other and should be avoided.`);
5495
5516
  (moduleArgumentsMap.get(runtimeModule))
5496
5517
  );
5497
5518
  }
5519
+
5498
5520
  exports = __webpack_require__(module.identifier());
5499
5521
  } catch (execErr) {
5500
5522
  const { message, stack, module } =
@@ -5594,7 +5616,7 @@ Compilation.prototype.factorizeModule = /**
5594
5616
  (options: FactorizeModuleOptions & { factoryResult?: false }, callback: ModuleCallback): void;
5595
5617
  (options: FactorizeModuleOptions & { factoryResult: true }, callback: ModuleFactoryResultCallback): void;
5596
5618
  }} */ (
5597
- function (options, callback) {
5619
+ function factorizeModule(options, callback) {
5598
5620
  this.factorizeQueue.add(options, /** @type {TODO} */ (callback));
5599
5621
  }
5600
5622
  );
@@ -5624,7 +5646,7 @@ Object.defineProperty(compilationPrototype, "cache", {
5624
5646
  * @this {Compilation} the compilation
5625
5647
  * @returns {Cache} the cache
5626
5648
  */
5627
- function () {
5649
+ function cache() {
5628
5650
  return this.compiler.cache;
5629
5651
  },
5630
5652
  "Compilation.cache was removed in favor of Compilation.getCache()",
@@ -5632,9 +5654,9 @@ Object.defineProperty(compilationPrototype, "cache", {
5632
5654
  ),
5633
5655
  set: util.deprecate(
5634
5656
  /**
5635
- * @param {EXPECTED_ANY} v value
5657
+ * @param {EXPECTED_ANY} _v value
5636
5658
  */
5637
- v => {},
5659
+ _v => {},
5638
5660
  "Compilation.cache was removed in favor of Compilation.getCache()",
5639
5661
  "DEP_WEBPACK_COMPILATION_CACHE"
5640
5662
  )
package/lib/Compiler.js CHANGED
@@ -8,13 +8,12 @@
8
8
  const parseJson = require("json-parse-even-better-errors");
9
9
  const asyncLib = require("neo-async");
10
10
  const {
11
- SyncHook,
12
- SyncBailHook,
13
11
  AsyncParallelHook,
14
- AsyncSeriesHook
12
+ AsyncSeriesHook,
13
+ SyncBailHook,
14
+ SyncHook
15
15
  } = require("tapable");
16
16
  const { SizeOnlySource } = require("webpack-sources");
17
- const webpack = require(".");
18
17
  const Cache = require("./Cache");
19
18
  const CacheFacade = require("./CacheFacade");
20
19
  const ChunkGraph = require("./ChunkGraph");
@@ -29,9 +28,10 @@ const Stats = require("./Stats");
29
28
  const Watching = require("./Watching");
30
29
  const WebpackError = require("./WebpackError");
31
30
  const { Logger } = require("./logging/Logger");
32
- const { join, dirname, mkdirp } = require("./util/fs");
31
+ const { dirname, join, mkdirp } = require("./util/fs");
33
32
  const { makePathsRelative } = require("./util/identifier");
34
33
  const { isSourceEqual } = require("./util/source");
34
+ const webpack = require(".");
35
35
 
36
36
  /** @typedef {import("webpack-sources").Source} Source */
37
37
  /** @typedef {import("../declarations/WebpackOptions").EntryNormalized} Entry */
@@ -42,10 +42,19 @@ const { isSourceEqual } = require("./util/source");
42
42
  /** @typedef {import("./Chunk")} Chunk */
43
43
  /** @typedef {import("./ChunkGraph").ModuleId} ModuleId */
44
44
  /** @typedef {import("./Dependency")} Dependency */
45
+ /** @typedef {import("./HotModuleReplacementPlugin").ChunkHashes} ChunkHashes */
46
+ /** @typedef {import("./HotModuleReplacementPlugin").ChunkModuleHashes} ChunkModuleHashes */
47
+ /** @typedef {import("./HotModuleReplacementPlugin").ChunkModuleIds} ChunkModuleIds */
48
+ /** @typedef {import("./HotModuleReplacementPlugin").ChunkRuntime} ChunkRuntime */
49
+ /** @typedef {import("./HotModuleReplacementPlugin").FullHashChunkModuleHashes} FullHashChunkModuleHashes */
50
+ /** @typedef {import("./HotModuleReplacementPlugin").HotIndex} HotIndex */
45
51
  /** @typedef {import("./Module")} Module */
46
52
  /** @typedef {import("./Module").BuildInfo} BuildInfo */
53
+ /** @typedef {import("./RecordIdsPlugin").RecordsChunks} RecordsChunks */
54
+ /** @typedef {import("./RecordIdsPlugin").RecordsModules} RecordsModules */
47
55
  /** @typedef {import("./config/target").PlatformTargetProperties} PlatformTargetProperties */
48
56
  /** @typedef {import("./logging/createConsoleLogger").LoggingFunction} LoggingFunction */
57
+ /** @typedef {import("./optimize/AggressiveSplittingPlugin").SplitData} SplitData */
49
58
  /** @typedef {import("./util/fs").IStats} IStats */
50
59
  /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
51
60
  /** @typedef {import("./util/fs").IntermediateFileSystem} IntermediateFileSystem */
@@ -80,6 +89,22 @@ const { isSourceEqual } = require("./util/source");
80
89
  * @param {Compilation=} compilation
81
90
  */
82
91
 
92
+ /**
93
+ * @typedef {object} KnownRecords
94
+ * @property {SplitData[]=} aggressiveSplits
95
+ * @property {RecordsChunks=} chunks
96
+ * @property {RecordsModules=} modules
97
+ * @property {string=} hash
98
+ * @property {HotIndex=} hotIndex
99
+ * @property {FullHashChunkModuleHashes=} fullHashChunkModuleHashes
100
+ * @property {ChunkModuleHashes=} chunkModuleHashes
101
+ * @property {ChunkHashes=} chunkHashes
102
+ * @property {ChunkRuntime=} chunkRuntime
103
+ * @property {ChunkModuleIds=} chunkModuleIds
104
+ */
105
+
106
+ /** @typedef {KnownRecords & Record<string, KnownRecords[]> & Record<string, EXPECTED_ANY>} Records */
107
+
83
108
  /**
84
109
  * @typedef {object} AssetEmittedInfo
85
110
  * @property {Buffer} content
@@ -238,11 +263,11 @@ class Compiler {
238
263
  /** @type {WatchFileSystem | null} */
239
264
  this.watchFileSystem = null;
240
265
 
241
- /** @type {string|null} */
266
+ /** @type {string | null} */
242
267
  this.recordsInputPath = null;
243
- /** @type {string|null} */
268
+ /** @type {string | null} */
244
269
  this.recordsOutputPath = null;
245
- /** @type {Record<string, TODO>} */
270
+ /** @type {Records} */
246
271
  this.records = {};
247
272
  /** @type {Set<string | RegExp>} */
248
273
  this.managedPaths = new Set();
@@ -1075,8 +1100,10 @@ ${other}`);
1075
1100
  };
1076
1101
 
1077
1102
  const recordsOutputPathDirectory = dirname(
1078
- /** @type {OutputFileSystem} */ (this.outputFileSystem),
1079
- /** @type {string} */ (this.recordsOutputPath)
1103
+ /** @type {OutputFileSystem} */
1104
+ (this.outputFileSystem),
1105
+ /** @type {string} */
1106
+ (this.recordsOutputPath)
1080
1107
  );
1081
1108
  if (!recordsOutputPathDirectory) {
1082
1109
  return writeFile();
@@ -1140,7 +1167,7 @@ ${other}`);
1140
1167
 
1141
1168
  try {
1142
1169
  this.records = parseJson(
1143
- /** @type {Buffer} */ (content).toString("utf-8")
1170
+ /** @type {Buffer} */ (content).toString("utf8")
1144
1171
  );
1145
1172
  } catch (parseErr) {
1146
1173
  return callback(
@@ -1201,7 +1228,9 @@ ${other}`);
1201
1228
  this.records[relativeCompilerName] = [];
1202
1229
  }
1203
1230
  if (this.records[relativeCompilerName][compilerIndex]) {
1204
- childCompiler.records = this.records[relativeCompilerName][compilerIndex];
1231
+ childCompiler.records =
1232
+ /** @type {Records} */
1233
+ (this.records[relativeCompilerName][compilerIndex]);
1205
1234
  } else {
1206
1235
  this.records[relativeCompilerName].push((childCompiler.records = {}));
1207
1236
  }
@@ -1231,11 +1260,12 @@ ${other}`);
1231
1260
  childCompiler.hooks[
1232
1261
  /** @type {keyof Compiler["hooks"]} */
1233
1262
  (name)
1234
- ].taps =
1235
- this.hooks[
1263
+ ].taps = [
1264
+ ...this.hooks[
1236
1265
  /** @type {keyof Compiler["hooks"]} */
1237
1266
  (name)
1238
- ].taps.slice();
1267
+ ].taps
1268
+ ];
1239
1269
  }
1240
1270
  }
1241
1271
 
@@ -1361,7 +1391,7 @@ ${other}`);
1361
1391
  close(callback) {
1362
1392
  if (this.watching) {
1363
1393
  // When there is still an active watching, close this first
1364
- this.watching.close(err => {
1394
+ this.watching.close(_err => {
1365
1395
  this.close(callback);
1366
1396
  });
1367
1397
  return;
@@ -15,13 +15,14 @@ const {
15
15
  /** @typedef {import("./optimize/ConcatenatedModule").ModuleInfo} ModuleInfo */
16
16
 
17
17
  const MODULE_REFERENCE_REGEXP =
18
- /^__WEBPACK_MODULE_REFERENCE__(\d+)_([\da-f]+|ns)(_call)?(_directImport)?(?:_asiSafe(\d))?__$/;
18
+ /^__WEBPACK_MODULE_REFERENCE__(\d+)_([\da-f]+|ns)(_call)?(_directImport)?(_deferredImport)?(?:_asiSafe(\d))?__$/;
19
19
 
20
20
  /**
21
21
  * @typedef {object} ModuleReferenceOptions
22
22
  * @property {string[]} ids the properties/exports of the module
23
23
  * @property {boolean} call true, when this referenced export is called
24
24
  * @property {boolean} directImport true, when this referenced export is directly imported (not via property access)
25
+ * @property {boolean} deferredImport true, when this referenced export is deferred
25
26
  * @property {boolean | undefined} asiSafe if the position is ASI safe or unknown
26
27
  */
27
28
 
@@ -90,21 +91,28 @@ class ConcatenationScope {
90
91
  */
91
92
  createModuleReference(
92
93
  module,
93
- { ids = undefined, call = false, directImport = false, asiSafe = false }
94
+ {
95
+ ids = undefined,
96
+ call = false,
97
+ directImport = false,
98
+ deferredImport = false,
99
+ asiSafe = false
100
+ }
94
101
  ) {
95
102
  const info = /** @type {ModuleInfo} */ (this._modulesMap.get(module));
96
103
  const callFlag = call ? "_call" : "";
97
104
  const directImportFlag = directImport ? "_directImport" : "";
105
+ const deferredImportFlag = deferredImport ? "_deferredImport" : "";
98
106
  const asiSafeFlag = asiSafe
99
107
  ? "_asiSafe1"
100
108
  : asiSafe === false
101
109
  ? "_asiSafe0"
102
110
  : "";
103
111
  const exportData = ids
104
- ? Buffer.from(JSON.stringify(ids), "utf-8").toString("hex")
112
+ ? Buffer.from(JSON.stringify(ids), "utf8").toString("hex")
105
113
  : "ns";
106
114
  // a "._" is appended to allow "delete ...", which would cause a SyntaxError in strict mode
107
- return `__WEBPACK_MODULE_REFERENCE__${info.index}_${exportData}${callFlag}${directImportFlag}${asiSafeFlag}__._`;
115
+ return `__WEBPACK_MODULE_REFERENCE__${info.index}_${exportData}${callFlag}${directImportFlag}${deferredImportFlag}${asiSafeFlag}__._`;
108
116
  }
109
117
 
110
118
  /**
@@ -123,15 +131,16 @@ class ConcatenationScope {
123
131
  const match = MODULE_REFERENCE_REGEXP.exec(name);
124
132
  if (!match) return null;
125
133
  const index = Number(match[1]);
126
- const asiSafe = match[5];
134
+ const asiSafe = match[6];
127
135
  return {
128
136
  index,
129
137
  ids:
130
138
  match[2] === "ns"
131
139
  ? []
132
- : JSON.parse(Buffer.from(match[2], "hex").toString("utf-8")),
140
+ : JSON.parse(Buffer.from(match[2], "hex").toString("utf8")),
133
141
  call: Boolean(match[3]),
134
142
  directImport: Boolean(match[4]),
143
+ deferredImport: Boolean(match[5]),
135
144
  asiSafe: asiSafe ? asiSafe === "1" : undefined
136
145
  };
137
146
  }
@@ -68,6 +68,7 @@ const collectDeclaration = (declarations, pattern) => {
68
68
  * @returns {Array<string>} hoisted declarations
69
69
  */
70
70
  const getHoistedDeclarations = (branch, includeFunctionDeclarations) => {
71
+ /** @type {Set<string>} */
71
72
  const declarations = new Set();
72
73
  /** @type {Array<Statement | null | undefined>} */
73
74
  const stack = [branch];
@@ -129,7 +130,7 @@ const getHoistedDeclarations = (branch, includeFunctionDeclarations) => {
129
130
  break;
130
131
  }
131
132
  }
132
- return Array.from(declarations);
133
+ return [...declarations];
133
134
  };
134
135
 
135
136
  const PLUGIN_NAME = "ConstPlugin";
@@ -159,7 +160,7 @@ class ConstPlugin {
159
160
  * @param {JavascriptParser} parser the parser
160
161
  */
161
162
  const handler = parser => {
162
- parser.hooks.terminate.tap(PLUGIN_NAME, statement => true);
163
+ parser.hooks.terminate.tap(PLUGIN_NAME, _statement => true);
163
164
  parser.hooks.statementIf.tap(PLUGIN_NAME, statement => {
164
165
  if (parser.scope.isAsmJs) return;
165
166
  const param = parser.evaluateExpression(statement.test);
@@ -189,8 +190,9 @@ class ConstPlugin {
189
190
  parser.scope.isAsmJs ||
190
191
  // Check top level scope here again
191
192
  parser.scope.topLevelScope === true
192
- )
193
+ ) {
193
194
  return;
195
+ }
194
196
  this.eliminateUnusedStatement(parser, statement);
195
197
  return true;
196
198
  });
@@ -16,15 +16,15 @@ const Template = require("./Template");
16
16
  const WebpackError = require("./WebpackError");
17
17
  const {
18
18
  compareLocations,
19
- concatComparators,
19
+ compareModulesById,
20
20
  compareSelect,
21
- keepOriginalOrder,
22
- compareModulesById
21
+ concatComparators,
22
+ keepOriginalOrder
23
23
  } = require("./util/comparators");
24
24
  const {
25
25
  contextify,
26
- parseResource,
27
- makePathsRelative
26
+ makePathsRelative,
27
+ parseResource
28
28
  } = require("./util/identifier");
29
29
  const makeSerializable = require("./util/makeSerializable");
30
30
 
@@ -412,8 +412,9 @@ class ContextModule extends Module {
412
412
  const buildInfo = /** @type {BuildInfo} */ (this.buildInfo);
413
413
 
414
414
  // always build when we have no snapshot and context
415
- if (!buildInfo.snapshot)
415
+ if (!buildInfo.snapshot) {
416
416
  return callback(null, Boolean(this.context || this.options.resource));
417
+ }
417
418
 
418
419
  fileSystemInfo.checkSnapshotValid(buildInfo.snapshot, (err, valid) => {
419
420
  callback(err, !valid);
@@ -996,10 +997,11 @@ module.exports = webpackAsyncContext;`;
996
997
  if (hasFakeMap) {
997
998
  arrayStart.push(fakeMap[moduleId]);
998
999
  }
999
- map[item.userRequest] = arrayStart.concat(
1000
- /** @type {Chunk[]} */
1000
+ map[item.userRequest] = [
1001
+ ...arrayStart,
1002
+ .../** @type {Chunk[]} */
1001
1003
  (item.chunks).map(chunk => /** @type {ChunkId} */ (chunk.id))
1002
- );
1004
+ ];
1003
1005
  }
1004
1006
  }
1005
1007
 
@@ -1186,11 +1188,13 @@ module.exports = webpackEmptyAsyncContext;`;
1186
1188
  const set = new Set();
1187
1189
  const allDeps =
1188
1190
  this.dependencies.length > 0
1189
- ? /** @type {ContextElementDependency[]} */ (this.dependencies).slice()
1191
+ ? /** @type {ContextElementDependency[]} */ [...this.dependencies]
1190
1192
  : [];
1191
- for (const block of this.blocks)
1192
- for (const dep of block.dependencies)
1193
+ for (const block of this.blocks) {
1194
+ for (const dep of block.dependencies) {
1193
1195
  allDeps.push(/** @type {ContextElementDependency} */ (dep));
1196
+ }
1197
+ }
1194
1198
  set.add(RuntimeGlobals.module);
1195
1199
  set.add(RuntimeGlobals.hasOwnProperty);
1196
1200
  if (allDeps.length > 0) {