webpack 5.98.0 → 5.99.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 (251) hide show
  1. package/README.md +7 -3
  2. package/lib/AsyncDependenciesBlock.js +3 -1
  3. package/lib/BannerPlugin.js +1 -1
  4. package/lib/Cache.js +9 -7
  5. package/lib/CacheFacade.js +5 -5
  6. package/lib/Chunk.js +2 -2
  7. package/lib/ChunkGraph.js +21 -16
  8. package/lib/ChunkTemplate.js +6 -6
  9. package/lib/CleanPlugin.js +10 -10
  10. package/lib/CodeGenerationResults.js +4 -3
  11. package/lib/CompatibilityPlugin.js +4 -1
  12. package/lib/Compilation.js +326 -152
  13. package/lib/Compiler.js +13 -18
  14. package/lib/ConditionalInitFragment.js +1 -1
  15. package/lib/ConstPlugin.js +5 -3
  16. package/lib/ContextModule.js +4 -2
  17. package/lib/ContextModuleFactory.js +3 -3
  18. package/lib/ContextReplacementPlugin.js +43 -16
  19. package/lib/DefinePlugin.js +25 -24
  20. package/lib/DelegatedModule.js +4 -2
  21. package/lib/DelegatedModuleFactoryPlugin.js +2 -1
  22. package/lib/Dependency.js +19 -13
  23. package/lib/DependencyTemplates.js +4 -3
  24. package/lib/DllModule.js +4 -2
  25. package/lib/DllModuleFactory.js +2 -2
  26. package/lib/DllReferencePlugin.js +2 -1
  27. package/lib/DynamicEntryPlugin.js +1 -1
  28. package/lib/EnvironmentPlugin.js +4 -2
  29. package/lib/ExportsInfo.js +72 -40
  30. package/lib/ExternalModule.js +14 -5
  31. package/lib/ExternalModuleFactoryPlugin.js +24 -12
  32. package/lib/FileSystemInfo.js +129 -94
  33. package/lib/FlagDependencyExportsPlugin.js +6 -4
  34. package/lib/FlagDependencyUsagePlugin.js +1 -1
  35. package/lib/Generator.js +29 -1
  36. package/lib/HookWebpackError.js +2 -2
  37. package/lib/HotModuleReplacementPlugin.js +3 -9
  38. package/lib/IgnoreErrorModuleFactory.js +2 -2
  39. package/lib/IgnorePlugin.js +0 -5
  40. package/lib/InitFragment.js +1 -1
  41. package/lib/LoaderOptionsPlugin.js +8 -5
  42. package/lib/MainTemplate.js +7 -7
  43. package/lib/Module.js +40 -17
  44. package/lib/ModuleBuildError.js +3 -1
  45. package/lib/ModuleDependencyError.js +4 -3
  46. package/lib/ModuleDependencyWarning.js +4 -3
  47. package/lib/ModuleFactory.js +9 -3
  48. package/lib/ModuleFilenameHelpers.js +13 -13
  49. package/lib/ModuleGraph.js +20 -14
  50. package/lib/ModuleGraphConnection.js +7 -13
  51. package/lib/ModuleNotFoundError.js +1 -1
  52. package/lib/ModuleParseError.js +2 -1
  53. package/lib/ModuleSourceTypesConstants.js +11 -0
  54. package/lib/ModuleTemplate.js +5 -5
  55. package/lib/ModuleTypeConstants.js +15 -0
  56. package/lib/MultiCompiler.js +4 -4
  57. package/lib/MultiStats.js +1 -1
  58. package/lib/NormalModule.js +101 -54
  59. package/lib/NormalModuleFactory.js +38 -33
  60. package/lib/NormalModuleReplacementPlugin.js +3 -2
  61. package/lib/NullFactory.js +2 -2
  62. package/lib/Parser.js +4 -3
  63. package/lib/ProgressPlugin.js +1 -2
  64. package/lib/RawModule.js +4 -2
  65. package/lib/RecordIdsPlugin.js +6 -2
  66. package/lib/RequestShortener.js +3 -1
  67. package/lib/ResolverFactory.js +12 -9
  68. package/lib/RuntimeModule.js +4 -2
  69. package/lib/RuntimeTemplate.js +2 -1
  70. package/lib/SelfModuleFactory.js +2 -2
  71. package/lib/SourceMapDevToolPlugin.js +0 -8
  72. package/lib/Template.js +6 -5
  73. package/lib/TemplatedPathPlugin.js +15 -12
  74. package/lib/WebpackOptionsApply.js +1 -1
  75. package/lib/asset/AssetGenerator.js +237 -170
  76. package/lib/asset/AssetModulesPlugin.js +50 -8
  77. package/lib/asset/AssetSourceGenerator.js +18 -0
  78. package/lib/asset/RawDataUrlModule.js +4 -2
  79. package/lib/buildChunkGraph.js +14 -4
  80. package/lib/cache/MemoryWithGcCachePlugin.js +6 -2
  81. package/lib/cache/PackFileCacheStrategy.js +137 -121
  82. package/lib/cache/ResolverCachePlugin.js +15 -7
  83. package/lib/cache/getLazyHashedEtag.js +4 -3
  84. package/lib/cli.js +23 -15
  85. package/lib/config/defaults.js +93 -26
  86. package/lib/config/normalization.js +14 -13
  87. package/lib/config/target.js +8 -8
  88. package/lib/container/ContainerEntryModule.js +4 -2
  89. package/lib/container/ContainerEntryModuleFactory.js +2 -2
  90. package/lib/container/FallbackModule.js +4 -2
  91. package/lib/container/FallbackModuleFactory.js +2 -2
  92. package/lib/container/RemoteModule.js +4 -2
  93. package/lib/container/options.js +5 -5
  94. package/lib/css/CssGenerator.js +71 -9
  95. package/lib/css/CssModulesPlugin.js +30 -5
  96. package/lib/css/CssParser.js +37 -17
  97. package/lib/css/walkCssTokens.js +17 -17
  98. package/lib/debug/ProfilingPlugin.js +98 -38
  99. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +10 -4
  100. package/lib/dependencies/AMDPlugin.js +5 -2
  101. package/lib/dependencies/AMDRequireArrayDependency.js +4 -3
  102. package/lib/dependencies/AMDRequireContextDependency.js +2 -1
  103. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +15 -7
  104. package/lib/dependencies/AMDRuntimeModules.js +3 -1
  105. package/lib/dependencies/CommonJsExportRequireDependency.js +4 -5
  106. package/lib/dependencies/CommonJsExportsParserPlugin.js +3 -3
  107. package/lib/dependencies/CommonJsImportsParserPlugin.js +8 -7
  108. package/lib/dependencies/CommonJsRequireContextDependency.js +2 -1
  109. package/lib/dependencies/ContextDependencyHelpers.js +13 -6
  110. package/lib/dependencies/CssIcssExportDependency.js +15 -12
  111. package/lib/dependencies/CssIcssImportDependency.js +4 -1
  112. package/lib/dependencies/CssLocalIdentifierDependency.js +17 -14
  113. package/lib/dependencies/ExportsInfoDependency.js +6 -1
  114. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +5 -5
  115. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +22 -15
  116. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +23 -8
  117. package/lib/dependencies/HarmonyExportSpecifierDependency.js +2 -2
  118. package/lib/dependencies/HarmonyImportDependency.js +8 -6
  119. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +19 -14
  120. package/lib/dependencies/HarmonyImportSpecifierDependency.js +5 -5
  121. package/lib/dependencies/ImportContextDependency.js +2 -1
  122. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +8 -4
  123. package/lib/dependencies/JsonExportsDependency.js +24 -8
  124. package/lib/dependencies/LoaderPlugin.js +4 -14
  125. package/lib/dependencies/RequireContextDependency.js +2 -1
  126. package/lib/dependencies/RequireContextDependencyParserPlugin.js +6 -3
  127. package/lib/dependencies/RequireEnsureDependenciesBlock.js +3 -2
  128. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +11 -5
  129. package/lib/dependencies/RequireResolveContextDependency.js +1 -1
  130. package/lib/dependencies/WebAssemblyExportImportedDependency.js +1 -1
  131. package/lib/dependencies/WorkerDependency.js +6 -3
  132. package/lib/dependencies/WorkerPlugin.js +100 -41
  133. package/lib/esm/ModuleChunkFormatPlugin.js +5 -0
  134. package/lib/hmr/HotModuleReplacement.runtime.js +1 -0
  135. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +1 -0
  136. package/lib/hmr/LazyCompilationPlugin.js +32 -24
  137. package/lib/hmr/lazyCompilationBackend.js +1 -1
  138. package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
  139. package/lib/ids/HashedModuleIdsPlugin.js +2 -1
  140. package/lib/ids/IdHelpers.js +15 -14
  141. package/lib/ids/SyncModuleIdsPlugin.js +9 -5
  142. package/lib/index.js +5 -5
  143. package/lib/javascript/BasicEvaluatedExpression.js +6 -6
  144. package/lib/javascript/JavascriptGenerator.js +11 -1
  145. package/lib/javascript/JavascriptModulesPlugin.js +51 -31
  146. package/lib/javascript/JavascriptParser.js +272 -188
  147. package/lib/javascript/JavascriptParserHelpers.js +10 -9
  148. package/lib/javascript/StartupHelpers.js +4 -1
  149. package/lib/json/JsonData.js +4 -4
  150. package/lib/json/JsonGenerator.js +54 -22
  151. package/lib/json/JsonModulesPlugin.js +16 -2
  152. package/lib/json/JsonParser.js +8 -4
  153. package/lib/library/AbstractLibraryPlugin.js +7 -3
  154. package/lib/library/AssignLibraryPlugin.js +29 -1
  155. package/lib/library/EnableLibraryPlugin.js +7 -10
  156. package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
  157. package/lib/library/ModuleLibraryPlugin.js +121 -15
  158. package/lib/logging/Logger.js +2 -2
  159. package/lib/logging/createConsoleLogger.js +4 -4
  160. package/lib/node/NodeEnvironmentPlugin.js +6 -2
  161. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +1 -2
  162. package/lib/node/ReadFileCompileWasmPlugin.js +1 -2
  163. package/lib/node/nodeConsole.js +3 -1
  164. package/lib/optimize/AggressiveSplittingPlugin.js +1 -1
  165. package/lib/optimize/ConcatenatedModule.js +19 -12
  166. package/lib/optimize/InnerGraph.js +3 -2
  167. package/lib/optimize/InnerGraphPlugin.js +13 -7
  168. package/lib/optimize/LimitChunkCountPlugin.js +20 -0
  169. package/lib/optimize/ModuleConcatenationPlugin.js +10 -7
  170. package/lib/optimize/RealContentHashPlugin.js +8 -4
  171. package/lib/optimize/SideEffectsFlagPlugin.js +4 -2
  172. package/lib/optimize/SplitChunksPlugin.js +87 -65
  173. package/lib/rules/BasicEffectRulePlugin.js +9 -1
  174. package/lib/rules/BasicMatcherRulePlugin.js +15 -4
  175. package/lib/rules/ObjectMatcherRulePlugin.js +12 -3
  176. package/lib/rules/RuleSetCompiler.js +25 -14
  177. package/lib/rules/UseEffectRulePlugin.js +47 -17
  178. package/lib/runtime/GetChunkFilenameRuntimeModule.js +6 -6
  179. package/lib/schemes/HttpUriPlugin.js +38 -17
  180. package/lib/serialization/BinaryMiddleware.js +52 -19
  181. package/lib/serialization/FileMiddleware.js +78 -48
  182. package/lib/serialization/ObjectMiddleware.js +78 -29
  183. package/lib/serialization/PlainObjectSerializer.js +1 -1
  184. package/lib/serialization/Serializer.js +15 -10
  185. package/lib/serialization/SerializerMiddleware.js +80 -41
  186. package/lib/serialization/SingleItemMiddleware.js +10 -7
  187. package/lib/serialization/types.js +1 -1
  188. package/lib/sharing/ConsumeSharedModule.js +4 -2
  189. package/lib/sharing/ProvideSharedModule.js +4 -2
  190. package/lib/sharing/ProvideSharedModuleFactory.js +5 -3
  191. package/lib/sharing/utils.js +2 -2
  192. package/lib/stats/DefaultStatsFactoryPlugin.js +80 -78
  193. package/lib/stats/DefaultStatsPresetPlugin.js +43 -23
  194. package/lib/stats/DefaultStatsPrinterPlugin.js +85 -43
  195. package/lib/stats/StatsFactory.js +11 -11
  196. package/lib/stats/StatsPrinter.js +7 -7
  197. package/lib/util/ArrayHelpers.js +2 -4
  198. package/lib/util/ArrayQueue.js +1 -1
  199. package/lib/util/AsyncQueue.js +4 -4
  200. package/lib/util/IterableHelpers.js +1 -1
  201. package/lib/util/LazyBucketSortedSet.js +41 -23
  202. package/lib/util/LazySet.js +3 -2
  203. package/lib/util/MapHelpers.js +1 -1
  204. package/lib/util/ParallelismFactorCalculator.js +1 -1
  205. package/lib/util/Semaphore.js +3 -3
  206. package/lib/util/SetHelpers.js +1 -1
  207. package/lib/util/SortableSet.js +9 -7
  208. package/lib/util/TupleQueue.js +9 -8
  209. package/lib/util/TupleSet.js +2 -2
  210. package/lib/util/WeakTupleMap.js +12 -11
  211. package/lib/util/binarySearchBounds.js +2 -1
  212. package/lib/util/cleverMerge.js +84 -54
  213. package/lib/util/comparators.js +22 -21
  214. package/lib/util/compileBooleanMatcher.js +3 -3
  215. package/lib/util/concatenate.js +6 -4
  216. package/lib/util/create-schema-validation.js +4 -4
  217. package/lib/util/createHash.js +2 -2
  218. package/lib/util/deprecation.js +35 -33
  219. package/lib/util/deterministicGrouping.js +6 -6
  220. package/lib/util/findGraphRoots.js +1 -1
  221. package/lib/util/fs.js +39 -39
  222. package/lib/util/hash/wasm-hash.js +2 -2
  223. package/lib/util/identifier.js +15 -18
  224. package/lib/util/makeSerializable.js +1 -1
  225. package/lib/util/memoize.js +4 -1
  226. package/lib/util/objectToMap.js +3 -2
  227. package/lib/util/processAsyncTree.js +2 -2
  228. package/lib/util/propertyName.js +0 -1
  229. package/lib/util/registerExternalSerializer.js +15 -18
  230. package/lib/util/removeBOM.js +25 -0
  231. package/lib/util/runtime.js +34 -27
  232. package/lib/util/serialization.js +5 -16
  233. package/lib/util/smartGrouping.js +3 -3
  234. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +3 -3
  235. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +11 -0
  236. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +10 -0
  237. package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +4 -0
  238. package/lib/wasm-sync/WebAssemblyGenerator.js +28 -12
  239. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +10 -0
  240. package/lib/wasm-sync/WebAssemblyParser.js +9 -4
  241. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -0
  242. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +30 -25
  243. package/package.json +19 -17
  244. package/schemas/WebpackOptions.check.js +1 -1
  245. package/schemas/WebpackOptions.json +48 -13
  246. package/schemas/plugins/JsonModulesPluginGenerator.check.d.ts +7 -0
  247. package/schemas/plugins/JsonModulesPluginGenerator.check.js +6 -0
  248. package/schemas/plugins/JsonModulesPluginGenerator.json +11 -0
  249. package/schemas/plugins/SourceMapDevToolPlugin.json +2 -2
  250. package/types.d.ts +918 -615
  251. package/lib/library/ModernModuleLibraryPlugin.js +0 -144
@@ -5,9 +5,9 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- /** @type {WeakMap<object, WeakMap<object, object>>} */
8
+ /** @type {WeakMap<EXPECTED_OBJECT, WeakMap<EXPECTED_OBJECT, EXPECTED_OBJECT>>} */
9
9
  const mergeCache = new WeakMap();
10
- /** @type {WeakMap<object, Map<string, Map<string|number|boolean, object>>>} */
10
+ /** @type {WeakMap<EXPECTED_OBJECT, Map<string, Map<string | number | boolean, EXPECTED_OBJECT>>>} */
11
11
  const setPropertyCache = new WeakMap();
12
12
  const DELETE = Symbol("DELETE");
13
13
  const DYNAMIC_INFO = Symbol("cleverMerge dynamic info");
@@ -44,14 +44,14 @@ const cachedCleverMerge = (first, second) => {
44
44
  if (prevMerge !== undefined) return prevMerge;
45
45
  const newMerge = _cleverMerge(first, second, true);
46
46
  innerCache.set(second, newMerge);
47
- return /** @type {T & O} */ (newMerge);
47
+ return newMerge;
48
48
  };
49
49
 
50
50
  /**
51
51
  * @template T
52
52
  * @param {Partial<T>} obj object
53
53
  * @param {string} property property
54
- * @param {string|number|boolean} value assignment value
54
+ * @param {string | number | boolean} value assignment value
55
55
  * @returns {T} new object
56
56
  */
57
57
  const cachedSetProperty = (obj, property, value) => {
@@ -82,38 +82,45 @@ const cachedSetProperty = (obj, property, value) => {
82
82
  return /** @type {T} */ (result);
83
83
  };
84
84
 
85
- /** @typedef {Map<string, any>} ByValues */
85
+ /**
86
+ * @template V
87
+ * @typedef {Map<string, V | undefined>} ByValues
88
+ */
86
89
 
87
90
  /**
88
91
  * @typedef {object} ObjectParsedPropertyEntry
89
92
  * @property {any | undefined} base base value
90
93
  * @property {string | undefined} byProperty the name of the selector property
91
- * @property {ByValues} byValues value depending on selector property, merged with base
94
+ * @property {ByValues<any>} byValues value depending on selector property, merged with base
92
95
  */
93
96
 
97
+ /** @typedef {(function(...EXPECTED_ANY): object) & { [DYNAMIC_INFO]: [DynamicFunction, object] }} DynamicFunction */
98
+
94
99
  /**
95
100
  * @typedef {object} ParsedObject
96
101
  * @property {Map<string, ObjectParsedPropertyEntry>} static static properties (key is property name)
97
- * @property {{ byProperty: string, fn: Function } | undefined} dynamic dynamic part
102
+ * @property {{ byProperty: string, fn: DynamicFunction } | undefined} dynamic dynamic part
98
103
  */
99
104
 
100
- /** @type {WeakMap<object, ParsedObject>} */
105
+ /** @type {WeakMap<EXPECTED_OBJECT, ParsedObject>} */
101
106
  const parseCache = new WeakMap();
102
107
 
103
108
  /**
104
- * @param {object} obj the object
109
+ * @template {object} T
110
+ * @param {T} obj the object
105
111
  * @returns {ParsedObject} parsed object
106
112
  */
107
113
  const cachedParseObject = obj => {
108
- const entry = parseCache.get(obj);
114
+ const entry = parseCache.get(/** @type {EXPECTED_OBJECT} */ (obj));
109
115
  if (entry !== undefined) return entry;
110
116
  const result = parseObject(obj);
111
- parseCache.set(obj, result);
117
+ parseCache.set(/** @type {EXPECTED_OBJECT} */ (obj), result);
112
118
  return result;
113
119
  };
114
120
 
115
121
  /**
116
122
  * @template {object} T
123
+ * @template V
117
124
  * @param {T} obj the object
118
125
  * @returns {ParsedObject} parsed object
119
126
  */
@@ -138,7 +145,7 @@ const parseObject = obj => {
138
145
  for (const key of Object.keys(obj)) {
139
146
  if (key.startsWith("by")) {
140
147
  const byProperty = /** @type {keyof T} */ (key);
141
- const byObj = /** @type {object} */ (obj[byProperty]);
148
+ const byObj = /** @type {TODO} */ (obj[byProperty]);
142
149
  if (typeof byObj === "object") {
143
150
  for (const byValue of Object.keys(byObj)) {
144
151
  const obj = byObj[/** @type {keyof (keyof T)} */ (byValue)];
@@ -152,7 +159,7 @@ const parseObject = obj => {
152
159
  `${/** @type {string} */ (byProperty)} and ${entry.byProperty} for a single property is not supported`
153
160
  );
154
161
  }
155
- /** @type {ByValues} */
162
+ /** @type {ByValues<V>} */
156
163
  (entry.byValues).set(
157
164
  byValue,
158
165
  obj[/** @type {keyof (keyof T)} */ (key)]
@@ -160,9 +167,12 @@ const parseObject = obj => {
160
167
  if (byValue === "default") {
161
168
  for (const otherByValue of Object.keys(byObj)) {
162
169
  if (
163
- !(/** @type {ByValues} */ (entry.byValues).has(otherByValue))
170
+ !(
171
+ /** @type {ByValues<V>} */
172
+ (entry.byValues).has(otherByValue)
173
+ )
164
174
  )
165
- /** @type {ByValues} */
175
+ /** @type {ByValues<V>} */
166
176
  (entry.byValues).set(otherByValue, undefined);
167
177
  }
168
178
  }
@@ -197,7 +207,7 @@ const parseObject = obj => {
197
207
  /**
198
208
  * @template {object} T
199
209
  * @param {Map<string, ObjectParsedPropertyEntry>} info static properties (key is property name)
200
- * @param {{ byProperty: string, fn: Function } | undefined} dynamicInfo dynamic part
210
+ * @param {{ byProperty: string, fn: (...args: EXPECTED_ANY[]) => T } | undefined} dynamicInfo dynamic part
201
211
  * @returns {T} the object
202
212
  */
203
213
  const serializeObject = (info, dynamicInfo) => {
@@ -205,7 +215,9 @@ const serializeObject = (info, dynamicInfo) => {
205
215
  // Setup byProperty structure
206
216
  for (const entry of info.values()) {
207
217
  if (entry.byProperty !== undefined) {
208
- const byObj = (obj[entry.byProperty] = obj[entry.byProperty] || {});
218
+ const byProperty = /** @type {keyof T} */ (entry.byProperty);
219
+ const byObj = (obj[byProperty] =
220
+ obj[byProperty] || /** @type {TODO} */ ({}));
209
221
  for (const byValue of entry.byValues.keys()) {
210
222
  byObj[byValue] = byObj[byValue] || {};
211
223
  }
@@ -217,7 +229,9 @@ const serializeObject = (info, dynamicInfo) => {
217
229
  }
218
230
  // Fill byProperty structure
219
231
  if (entry.byProperty !== undefined) {
220
- const byObj = (obj[entry.byProperty] = obj[entry.byProperty] || {});
232
+ const byProperty = /** @type {keyof T} */ (entry.byProperty);
233
+ const byObj = (obj[byProperty] =
234
+ obj[byProperty] || /** @type {TODO} */ ({}));
221
235
  for (const byValue of Object.keys(byObj)) {
222
236
  const value = getFromByValues(entry.byValues, byValue);
223
237
  if (value !== undefined) byObj[byValue][key] = value;
@@ -225,7 +239,8 @@ const serializeObject = (info, dynamicInfo) => {
225
239
  }
226
240
  }
227
241
  if (dynamicInfo !== undefined) {
228
- obj[dynamicInfo.byProperty] = dynamicInfo.fn;
242
+ /** @type {TODO} */
243
+ (obj)[dynamicInfo.byProperty] = dynamicInfo.fn;
229
244
  }
230
245
  return obj;
231
246
  };
@@ -237,7 +252,8 @@ const VALUE_TYPE_OBJECT = 3;
237
252
  const VALUE_TYPE_DELETE = 4;
238
253
 
239
254
  /**
240
- * @param {any} value a single value
255
+ * @template T
256
+ * @param {T} value a single value
241
257
  * @returns {VALUE_TYPE_UNDEFINED | VALUE_TYPE_ATOM | VALUE_TYPE_ARRAY_EXTEND | VALUE_TYPE_OBJECT | VALUE_TYPE_DELETE} value type
242
258
  */
243
259
  const getValueType = value => {
@@ -278,11 +294,13 @@ const cleverMerge = (first, second) => {
278
294
  };
279
295
 
280
296
  /**
297
+ * @template {object} T
298
+ * @template {object} O
281
299
  * Merges two objects. Objects are deeply clever merged.
282
- * @param {object} first first object
283
- * @param {object} second second object
300
+ * @param {T} first first
301
+ * @param {O} second second
284
302
  * @param {boolean} internalCaching should parsing of objects and nested merges be cached
285
- * @returns {object} merged object of first and second object
303
+ * @returns {T & O} merged object of first and second object
286
304
  */
287
305
  const _cleverMerge = (first, second, internalCaching = false) => {
288
306
  const firstObject = internalCaching
@@ -295,11 +313,16 @@ const _cleverMerge = (first, second, internalCaching = false) => {
295
313
  let { byProperty, fn } = firstDynamicInfo;
296
314
  const fnInfo = fn[DYNAMIC_INFO];
297
315
  if (fnInfo) {
298
- second = internalCaching
299
- ? cachedCleverMerge(fnInfo[1], second)
300
- : cleverMerge(fnInfo[1], second);
316
+ second =
317
+ /** @type {TODO} */
318
+ (
319
+ internalCaching
320
+ ? cachedCleverMerge(fnInfo[1], second)
321
+ : cleverMerge(fnInfo[1], second)
322
+ );
301
323
  fn = fnInfo[0];
302
324
  }
325
+ /** @type {DynamicFunction} */
303
326
  const newFn = (...args) => {
304
327
  const fnResult = fn(...args);
305
328
  return internalCaching
@@ -307,7 +330,9 @@ const _cleverMerge = (first, second, internalCaching = false) => {
307
330
  : cleverMerge(fnResult, second);
308
331
  };
309
332
  newFn[DYNAMIC_INFO] = [fn, second];
310
- return serializeObject(firstObject.static, { byProperty, fn: newFn });
333
+ return /** @type {T & O} */ (
334
+ serializeObject(firstObject.static, { byProperty, fn: newFn })
335
+ );
311
336
  }
312
337
 
313
338
  // If the first part is static only, we merge the static parts and keep the dynamic part of the second argument
@@ -330,7 +355,7 @@ const _cleverMerge = (first, second, internalCaching = false) => {
330
355
  resultInfo.set(key, secondEntry);
331
356
  }
332
357
  }
333
- return serializeObject(resultInfo, secondDynamicInfo);
358
+ return /** @type {T & O} */ (serializeObject(resultInfo, secondDynamicInfo));
334
359
  };
335
360
 
336
361
  /**
@@ -446,9 +471,10 @@ const mergeEntries = (firstEntry, secondEntry, internalCaching) => {
446
471
  };
447
472
 
448
473
  /**
449
- * @param {Map<string, any>} byValues all values
474
+ * @template V
475
+ * @param {ByValues<V>} byValues all values
450
476
  * @param {string} key value of the selector
451
- * @returns {any | undefined} value
477
+ * @returns {V | undefined} value
452
478
  */
453
479
  const getFromByValues = (byValues, key) => {
454
480
  if (key !== "default" && byValues.has(key)) {
@@ -458,10 +484,12 @@ const getFromByValues = (byValues, key) => {
458
484
  };
459
485
 
460
486
  /**
461
- * @param {any} a value
462
- * @param {any} b value
487
+ * @template A
488
+ * @template B
489
+ * @param {A | A[]} a value
490
+ * @param {B | B[]} b value
463
491
  * @param {boolean} internalCaching should parsing of objects and nested merges be cached
464
- * @returns {any} value
492
+ * @returns {A & B | (A | B)[] | A | A[] | B | B[]} value
465
493
  */
466
494
  const mergeSingleValue = (a, b, internalCaching) => {
467
495
  const bType = getValueType(b);
@@ -490,12 +518,13 @@ const mergeSingleValue = (a, b, internalCaching) => {
490
518
  case VALUE_TYPE_UNDEFINED:
491
519
  return b;
492
520
  case VALUE_TYPE_DELETE:
493
- return /** @type {any[]} */ (b).filter(item => item !== "...");
521
+ return /** @type {B[]} */ (b).filter(item => item !== "...");
494
522
  case VALUE_TYPE_ARRAY_EXTEND: {
523
+ /** @type {(A | B)[]} */
495
524
  const newArray = [];
496
- for (const item of b) {
525
+ for (const item of /** @type {B[]} */ (b)) {
497
526
  if (item === "...") {
498
- for (const item of a) {
527
+ for (const item of /** @type {A[]} */ (a)) {
499
528
  newArray.push(item);
500
529
  }
501
530
  } else {
@@ -505,8 +534,8 @@ const mergeSingleValue = (a, b, internalCaching) => {
505
534
  return newArray;
506
535
  }
507
536
  case VALUE_TYPE_OBJECT:
508
- return /** @type {any[]} */ (b).map(item =>
509
- item === "..." ? a : item
537
+ return /** @type {(A | B)[]} */ (b).map(item =>
538
+ item === "..." ? /** @type {A} */ (a) : item
510
539
  );
511
540
  default:
512
541
  throw new Error("Not implemented");
@@ -524,14 +553,12 @@ const mergeSingleValue = (a, b, internalCaching) => {
524
553
  */
525
554
  const removeOperations = (obj, keysToKeepOriginalValue = []) => {
526
555
  const newObj = /** @type {T} */ ({});
527
- for (const key of Object.keys(obj)) {
528
- const value = obj[/** @type {keyof T} */ (key)];
556
+ for (const _key of Object.keys(obj)) {
557
+ const key = /** @type {keyof T} */ (_key);
558
+ const value = obj[key];
529
559
  const type = getValueType(value);
530
- if (
531
- type === VALUE_TYPE_OBJECT &&
532
- keysToKeepOriginalValue.includes(/** @type {keyof T} */ (key))
533
- ) {
534
- newObj[/** @type {keyof T} */ (key)] = value;
560
+ if (type === VALUE_TYPE_OBJECT && keysToKeepOriginalValue.includes(key)) {
561
+ newObj[key] = value;
535
562
  continue;
536
563
  }
537
564
  switch (type) {
@@ -539,25 +566,26 @@ const removeOperations = (obj, keysToKeepOriginalValue = []) => {
539
566
  case VALUE_TYPE_DELETE:
540
567
  break;
541
568
  case VALUE_TYPE_OBJECT:
542
- newObj[/** @type {keyof T} */ (key)] =
569
+ newObj[key] =
543
570
  /** @type {T[keyof T]} */
544
571
  (
545
572
  removeOperations(
546
- /** @type {TODO} */ (value),
573
+ /** @type {T} */
574
+ (value),
547
575
  keysToKeepOriginalValue
548
576
  )
549
577
  );
550
578
  break;
551
579
  case VALUE_TYPE_ARRAY_EXTEND:
552
- newObj[/** @type {keyof T} */ (key)] =
580
+ newObj[key] =
553
581
  /** @type {T[keyof T]} */
554
582
  (
555
- /** @type {any[]} */
583
+ /** @type {EXPECTED_ANY[]} */
556
584
  (value).filter(i => i !== "...")
557
585
  );
558
586
  break;
559
587
  default:
560
- newObj[/** @type {keyof T} */ (key)] = value;
588
+ newObj[key] = value;
561
589
  break;
562
590
  }
563
591
  }
@@ -566,10 +594,11 @@ const removeOperations = (obj, keysToKeepOriginalValue = []) => {
566
594
 
567
595
  /**
568
596
  * @template T
569
- * @template {string} P
597
+ * @template {keyof T} P
598
+ * @template V
570
599
  * @param {T} obj the object
571
600
  * @param {P} byProperty the by description
572
- * @param {...any} values values
601
+ * @param {...V} values values
573
602
  * @returns {Omit<T, P>} object with merged byProperty
574
603
  */
575
604
  const resolveByProperty = (obj, byProperty, ...values) => {
@@ -579,10 +608,10 @@ const resolveByProperty = (obj, byProperty, ...values) => {
579
608
  const { [byProperty]: _byValue, ..._remaining } = obj;
580
609
  const remaining = /** @type {T} */ (_remaining);
581
610
  const byValue =
582
- /** @type {Record<string, T> | function(...any[]): T} */
611
+ /** @type {Record<string, T> | ((...args: V[]) => T)} */
583
612
  (_byValue);
584
613
  if (typeof byValue === "object") {
585
- const key = values[0];
614
+ const key = /** @type {string} */ (values[0]);
586
615
  if (key in byValue) {
587
616
  return cachedCleverMerge(remaining, byValue[key]);
588
617
  } else if ("default" in byValue) {
@@ -597,6 +626,7 @@ const resolveByProperty = (obj, byProperty, ...values) => {
597
626
  resolveByProperty(result, byProperty, ...values)
598
627
  );
599
628
  }
629
+ return obj;
600
630
  };
601
631
 
602
632
  module.exports.cachedSetProperty = cachedSetProperty;
@@ -18,29 +18,30 @@ const { compareRuntime } = require("./runtime");
18
18
 
19
19
  /**
20
20
  * @template T
21
- * @typedef {function(T, T): -1|0|1} Comparator
21
+ * @typedef {(a: T, b: T) => -1 | 0 | 1} Comparator
22
22
  */
23
23
  /**
24
- * @template TArg
24
+ * @template {object} TArg
25
25
  * @template T
26
- * @typedef {function(TArg, T, T): -1|0|1} RawParameterizedComparator
26
+ * @typedef {(tArg: TArg, a: T, b: T) => -1 | 0 | 1} RawParameterizedComparator
27
27
  */
28
28
  /**
29
- * @template TArg
29
+ * @template {object} TArg
30
30
  * @template T
31
- * @typedef {function(TArg): Comparator<T>} ParameterizedComparator
31
+ * @typedef {(tArg: TArg) => Comparator<T>} ParameterizedComparator
32
32
  */
33
33
 
34
34
  /**
35
- * @template T
36
- * @param {RawParameterizedComparator<any, T>} fn comparator with argument
37
- * @returns {ParameterizedComparator<any, T>} comparator
35
+ * @template {object} TArg
36
+ * @template {object} T
37
+ * @param {RawParameterizedComparator<TArg, T>} fn comparator with argument
38
+ * @returns {ParameterizedComparator<TArg, T>} comparator
38
39
  */
39
40
  const createCachedParameterizedComparator = fn => {
40
- /** @type {WeakMap<object, Comparator<T>>} */
41
+ /** @type {WeakMap<EXPECTED_OBJECT, Comparator<T>>} */
41
42
  const map = new WeakMap();
42
43
  return arg => {
43
- const cachedResult = map.get(arg);
44
+ const cachedResult = map.get(/** @type {EXPECTED_OBJECT} */ (arg));
44
45
  if (cachedResult !== undefined) return cachedResult;
45
46
  /**
46
47
  * @param {T} a first item
@@ -48,7 +49,7 @@ const createCachedParameterizedComparator = fn => {
48
49
  * @returns {-1|0|1} compare result
49
50
  */
50
51
  const result = fn.bind(null, arg);
51
- map.set(arg, result);
52
+ map.set(/** @type {EXPECTED_OBJECT} */ (arg), result);
52
53
  return result;
53
54
  };
54
55
  };
@@ -233,7 +234,7 @@ module.exports.compareModulesByIdOrIdentifier =
233
234
  * @param {ChunkGraph} chunkGraph the chunk graph
234
235
  * @param {Chunk} a chunk
235
236
  * @param {Chunk} b chunk
236
- * @returns {-1|0|1} compare result
237
+ * @returns {-1 | 0 | 1} compare result
237
238
  */
238
239
  const compareChunks = (chunkGraph, a, b) => chunkGraph.compareChunks(a, b);
239
240
  /** @type {ParameterizedComparator<ChunkGraph, Chunk>} */
@@ -241,9 +242,9 @@ module.exports.compareChunks =
241
242
  createCachedParameterizedComparator(compareChunks);
242
243
 
243
244
  /**
244
- * @param {string|number} a first id
245
- * @param {string|number} b second id
246
- * @returns {-1|0|1} compare result
245
+ * @param {string | number} a first id
246
+ * @param {string | number} b second id
247
+ * @returns {-1 | 0 | 1} compare result
247
248
  */
248
249
  const compareIds = (a, b) => {
249
250
  if (typeof a !== typeof b) {
@@ -272,22 +273,22 @@ module.exports.compareStrings = compareStrings;
272
273
  /**
273
274
  * @param {ChunkGroup} a first chunk group
274
275
  * @param {ChunkGroup} b second chunk group
275
- * @returns {-1|0|1} compare result
276
+ * @returns {-1 | 0 | 1} compare result
276
277
  */
277
278
  const compareChunkGroupsByIndex = (a, b) =>
278
279
  /** @type {number} */ (a.index) < /** @type {number} */ (b.index) ? -1 : 1;
279
280
  module.exports.compareChunkGroupsByIndex = compareChunkGroupsByIndex;
280
281
 
281
282
  /**
282
- * @template K1 {Object}
283
- * @template K2
283
+ * @template {EXPECTED_OBJECT} K1
284
+ * @template {EXPECTED_OBJECT} K2
284
285
  * @template T
285
286
  */
286
287
  class TwoKeyWeakMap {
287
288
  constructor() {
288
289
  /**
289
290
  * @private
290
- * @type {WeakMap<any, WeakMap<any, T | undefined>>}
291
+ * @type {WeakMap<K1, WeakMap<K2, T | undefined>>}
291
292
  */
292
293
  this._map = new WeakMap();
293
294
  }
@@ -321,7 +322,7 @@ class TwoKeyWeakMap {
321
322
  }
322
323
  }
323
324
 
324
- /** @type {TwoKeyWeakMap<Comparator<any>, Comparator<any>, Comparator<any>>}} */
325
+ /** @type {TwoKeyWeakMap<Comparator<EXPECTED_ANY>, Comparator<EXPECTED_ANY>, Comparator<EXPECTED_ANY>>}} */
325
326
  const concatComparatorsCache = new TwoKeyWeakMap();
326
327
 
327
328
  /**
@@ -397,7 +398,7 @@ const compareSelect = (getter, comparator) => {
397
398
  };
398
399
  module.exports.compareSelect = compareSelect;
399
400
 
400
- /** @type {WeakMap<Comparator<any>, Comparator<Iterable<any>>>} */
401
+ /** @type {WeakMap<Comparator<EXPECTED_ANY>, Comparator<Iterable<EXPECTED_ANY>>>} */
401
402
  const compareIteratorsCache = new WeakMap();
402
403
 
403
404
  /**
@@ -23,8 +23,8 @@ const toSimpleString = str => {
23
23
  };
24
24
 
25
25
  /**
26
- * @param {Record<string|number, boolean>} map value map
27
- * @returns {boolean|(function(string): string)} true/false, when unconditionally true/false, or a template function to determine the value at runtime
26
+ * @param {Record<string | number, boolean>} map value map
27
+ * @returns {boolean | ((value: string) => string)} true/false, when unconditionally true/false, or a template function to determine the value at runtime
28
28
  */
29
29
  const compileBooleanMatcher = map => {
30
30
  const positiveItems = Object.keys(map).filter(i => map[i]);
@@ -37,7 +37,7 @@ const compileBooleanMatcher = map => {
37
37
  /**
38
38
  * @param {string[]} positiveItems positive items
39
39
  * @param {string[]} negativeItems negative items
40
- * @returns {function(string): string} a template function to determine the value at runtime
40
+ * @returns {(value: string) => string} a template function to determine the value at runtime
41
41
  */
42
42
  const compileBooleanMatcherFromLists = (positiveItems, negativeItems) => {
43
43
  if (positiveItems.length === 0) return () => "false";
@@ -139,11 +139,13 @@ function findNewName(oldName, usedNamed1, usedNamed2, extraInfo) {
139
139
  return nameWithNumber;
140
140
  }
141
141
 
142
+ /** @typedef {Set<Scope>} ScopeSet */
143
+
142
144
  /**
143
145
  * @param {Scope | null} s scope
144
146
  * @param {UsedNames} nameSet name set
145
- * @param {TODO} scopeSet1 scope set 1
146
- * @param {TODO} scopeSet2 scope set 2
147
+ * @param {ScopeSet} scopeSet1 scope set 1
148
+ * @param {ScopeSet} scopeSet2 scope set 2
147
149
  */
148
150
  const addScopeSymbols = (s, nameSet, scopeSet1, scopeSet2) => {
149
151
  let scope = s;
@@ -197,10 +199,10 @@ const RESERVED_NAMES = new Set(
197
199
  );
198
200
 
199
201
  /**
200
- * @param {Map<string, { usedNames: UsedNames, alreadyCheckedScopes: Set<TODO> }>} usedNamesInScopeInfo used names in scope info
202
+ * @param {Map<string, { usedNames: UsedNames, alreadyCheckedScopes: ScopeSet }>} usedNamesInScopeInfo used names in scope info
201
203
  * @param {string} module module identifier
202
204
  * @param {string} id export id
203
- * @returns {{ usedNames: UsedNames, alreadyCheckedScopes: Set<TODO> }} info
205
+ * @returns {{ usedNames: UsedNames, alreadyCheckedScopes: ScopeSet }} info
204
206
  */
205
207
  const getUsedNamesInScopeInfo = (usedNamesInScopeInfo, module, id) => {
206
208
  const key = `${module}-${id}`;
@@ -14,18 +14,18 @@ const getValidate = memoize(() => require("schema-utils").validate);
14
14
 
15
15
  /**
16
16
  * @template {object | object[]} T
17
- * @param {(function(T): boolean) | undefined} check check
17
+ * @param {((value: T) => boolean) | undefined} check check
18
18
  * @param {() => JsonObject} getSchema get schema fn
19
19
  * @param {ValidationErrorConfiguration} options options
20
- * @returns {function(T=): void} validate
20
+ * @returns {(value?: T) => void} validate
21
21
  */
22
22
  const createSchemaValidation = (check, getSchema, options) => {
23
23
  getSchema = memoize(getSchema);
24
24
  return value => {
25
- if (check && !check(/** @type {T} */ (value))) {
25
+ if (check && value && !check(value)) {
26
26
  getValidate()(
27
27
  getSchema(),
28
- /** @type {object | object[]} */
28
+ /** @type {EXPECTED_OBJECT | EXPECTED_OBJECT[]} */
29
29
  (value),
30
30
  options
31
31
  );
@@ -14,12 +14,12 @@ const BULK_SIZE = 2000;
14
14
  /** @type {{[key: string]: Map<string, string>}} */
15
15
  const digestCaches = {};
16
16
 
17
- /** @typedef {function(): Hash} HashFactory */
17
+ /** @typedef {() => Hash} HashFactory */
18
18
 
19
19
  class BulkUpdateDecorator extends Hash {
20
20
  /**
21
21
  * @param {Hash | HashFactory} hashOrFactory function to create a hash
22
- * @param {string=} hashKey key for caching
22
+ * @param {string} [hashKey] key for caching
23
23
  */
24
24
  constructor(hashOrFactory, hashKey) {
25
25
  super();