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
@@ -16,6 +16,8 @@ const HarmonyExportImportedSpecifierDependency = require("../dependencies/Harmon
16
16
  const HarmonyImportSpecifierDependency = require("../dependencies/HarmonyImportSpecifierDependency");
17
17
  const formatLocation = require("../formatLocation");
18
18
 
19
+ /** @typedef {import("estree").MaybeNamedClassDeclaration} MaybeNamedClassDeclaration */
20
+ /** @typedef {import("estree").MaybeNamedFunctionDeclaration} MaybeNamedFunctionDeclaration */
19
21
  /** @typedef {import("estree").ModuleDeclaration} ModuleDeclaration */
20
22
  /** @typedef {import("estree").Statement} Statement */
21
23
  /** @typedef {import("../Compiler")} Compiler */
@@ -43,7 +45,7 @@ const formatLocation = require("../formatLocation");
43
45
 
44
46
  /** @typedef {Map<string, RegExp>} CacheItem */
45
47
 
46
- /** @type {WeakMap<any, CacheItem>} */
48
+ /** @type {WeakMap<Compiler, CacheItem>} */
47
49
  const globToRegexpCache = new WeakMap();
48
50
 
49
51
  /**
@@ -128,7 +130,7 @@ class SideEffectsFlagPlugin {
128
130
  * @returns {void}
129
131
  */
130
132
  const parserHandler = parser => {
131
- /** @type {undefined | Statement | ModuleDeclaration} */
133
+ /** @type {undefined | Statement | ModuleDeclaration | MaybeNamedFunctionDeclaration | MaybeNamedClassDeclaration} */
132
134
  let sideEffectsStatement;
133
135
  parser.hooks.program.tap(PLUGIN_NAME, () => {
134
136
  sideEffectsStatement = undefined;
@@ -32,6 +32,7 @@ const MinMaxSizeWarning = require("./MinMaxSizeWarning");
32
32
  /** @typedef {import("../Module")} Module */
33
33
  /** @typedef {import("../ModuleGraph")} ModuleGraph */
34
34
  /** @typedef {import("../TemplatedPathPlugin").TemplatePath} TemplatePath */
35
+ /** @typedef {import("../util/createHash").Algorithm} Algorithm */
35
36
  /** @typedef {import("../util/deterministicGrouping").GroupedItems<Module>} DeterministicGroupingGroupedItemsForModule */
36
37
  /** @typedef {import("../util/deterministicGrouping").Options<Module>} DeterministicGroupingOptionsForModule */
37
38
 
@@ -52,7 +53,7 @@ const MinMaxSizeWarning = require("./MinMaxSizeWarning");
52
53
 
53
54
  /**
54
55
  * @typedef {object} CacheGroupSource
55
- * @property {string=} key
56
+ * @property {string} key
56
57
  * @property {number=} priority
57
58
  * @property {GetName=} getName
58
59
  * @property {ChunkFilterFunction=} chunksFilter
@@ -76,20 +77,20 @@ const MinMaxSizeWarning = require("./MinMaxSizeWarning");
76
77
  /**
77
78
  * @typedef {object} CacheGroup
78
79
  * @property {string} key
79
- * @property {number=} priority
80
+ * @property {number} priority
80
81
  * @property {GetName=} getName
81
- * @property {ChunkFilterFunction=} chunksFilter
82
+ * @property {ChunkFilterFunction} chunksFilter
82
83
  * @property {SplitChunksSizes} minSize
83
84
  * @property {SplitChunksSizes} minSizeReduction
84
85
  * @property {SplitChunksSizes} minRemainingSize
85
86
  * @property {SplitChunksSizes} enforceSizeThreshold
86
87
  * @property {SplitChunksSizes} maxAsyncSize
87
88
  * @property {SplitChunksSizes} maxInitialSize
88
- * @property {number=} minChunks
89
- * @property {number=} maxAsyncRequests
90
- * @property {number=} maxInitialRequests
89
+ * @property {number} minChunks
90
+ * @property {number} maxAsyncRequests
91
+ * @property {number} maxInitialRequests
91
92
  * @property {TemplatePath=} filename
92
- * @property {string=} idHint
93
+ * @property {string} idHint
93
94
  * @property {string} automaticNameDelimiter
94
95
  * @property {boolean} reuseExistingChunk
95
96
  * @property {boolean} usedExports
@@ -118,14 +119,14 @@ const MinMaxSizeWarning = require("./MinMaxSizeWarning");
118
119
  * @callback GetCacheGroups
119
120
  * @param {Module} module
120
121
  * @param {CacheGroupsContext} context
121
- * @returns {CacheGroupSource[]}
122
+ * @returns {CacheGroupSource[] | null}
122
123
  */
123
124
 
124
125
  /**
125
126
  * @callback GetName
126
- * @param {Module=} module
127
- * @param {Chunk[]=} chunks
128
- * @param {string=} key
127
+ * @param {Module} module
128
+ * @param {Chunk[]} chunks
129
+ * @param {string} key
129
130
  * @returns {string=}
130
131
  */
131
132
 
@@ -143,7 +144,7 @@ const MinMaxSizeWarning = require("./MinMaxSizeWarning");
143
144
  * @property {number} maxAsyncRequests
144
145
  * @property {number} maxInitialRequests
145
146
  * @property {boolean} hidePathInfo
146
- * @property {TemplatePath} filename
147
+ * @property {TemplatePath=} filename
147
148
  * @property {string} automaticNameDelimiter
148
149
  * @property {GetCacheGroups} getCacheGroups
149
150
  * @property {GetName} getName
@@ -156,17 +157,18 @@ const MinMaxSizeWarning = require("./MinMaxSizeWarning");
156
157
  * @property {SortableSet<Module>} modules
157
158
  * @property {CacheGroup} cacheGroup
158
159
  * @property {number} cacheGroupIndex
159
- * @property {string} name
160
+ * @property {string=} name
160
161
  * @property {Record<string, number>} sizes
161
162
  * @property {Set<Chunk>} chunks
162
163
  * @property {Set<Chunk>} reusableChunks
163
164
  * @property {Set<bigint | Chunk>} chunksKeys
164
165
  */
165
166
 
166
- const defaultGetName = /** @type {GetName} */ (() => {});
167
+ /** @type {GetName} */
168
+ const defaultGetName = () => undefined;
167
169
 
168
170
  const deterministicGroupingForModules =
169
- /** @type {function(DeterministicGroupingOptionsForModule): DeterministicGroupingGroupedItemsForModule[]} */
171
+ /** @type {(options: DeterministicGroupingOptionsForModule) => DeterministicGroupingGroupedItemsForModule[]} */
170
172
  (deterministicGrouping);
171
173
 
172
174
  /** @type {WeakMap<Module, string>} */
@@ -181,7 +183,7 @@ const hashFilename = (name, outputOptions) => {
181
183
  const digest =
182
184
  /** @type {string} */
183
185
  (
184
- createHash(outputOptions.hashFunction)
186
+ createHash(/** @type {Algorithm} */ (outputOptions.hashFunction))
185
187
  .update(name)
186
188
  .digest(outputOptions.hashDigest)
187
189
  );
@@ -404,7 +406,7 @@ const totalSize = sizes => {
404
406
  };
405
407
 
406
408
  /**
407
- * @param {false|string|Function|undefined} name the chunk name
409
+ * @param {OptimizationSplitChunksCacheGroup["name"]} name the chunk name
408
410
  * @returns {GetName | undefined} a function to get the name of the chunk
409
411
  */
410
412
  const normalizeName = name => {
@@ -418,7 +420,7 @@ const normalizeName = name => {
418
420
 
419
421
  /**
420
422
  * @param {OptimizationSplitChunksCacheGroup["chunks"]} chunks the chunk filter option
421
- * @returns {ChunkFilterFunction} the chunk filter function
423
+ * @returns {ChunkFilterFunction | undefined} the chunk filter function
422
424
  */
423
425
  const normalizeChunksFilter = chunks => {
424
426
  if (chunks === "initial") {
@@ -439,7 +441,7 @@ const normalizeChunksFilter = chunks => {
439
441
  };
440
442
 
441
443
  /**
442
- * @param {GetCacheGroups | Record<string, false|string|RegExp|OptimizationSplitChunksGetCacheGroups|OptimizationSplitChunksCacheGroup>} cacheGroups the cache group options
444
+ * @param {undefined | GetCacheGroups | Record<string, false | string | RegExp | OptimizationSplitChunksGetCacheGroups | OptimizationSplitChunksCacheGroup>} cacheGroups the cache group options
443
445
  * @param {string[]} defaultSizeTypes the default size types
444
446
  * @returns {GetCacheGroups} a function to get the cache groups
445
447
  */
@@ -448,7 +450,7 @@ const normalizeCacheGroups = (cacheGroups, defaultSizeTypes) => {
448
450
  return cacheGroups;
449
451
  }
450
452
  if (typeof cacheGroups === "object" && cacheGroups !== null) {
451
- /** @type {(function(Module, CacheGroupsContext, CacheGroupSource[]): void)[]} */
453
+ /** @type {((module: Module, context: CacheGroupsContext, results: CacheGroupSource[]) => void)[]} */
452
454
  const handlers = [];
453
455
  for (const key of Object.keys(cacheGroups)) {
454
456
  const option = cacheGroups[key];
@@ -516,7 +518,7 @@ const normalizeCacheGroups = (cacheGroups, defaultSizeTypes) => {
516
518
  };
517
519
 
518
520
  /**
519
- * @param {undefined|boolean|string|RegExp|Function} test test option
521
+ * @param {OptimizationSplitChunksCacheGroup["test"]} test test option
520
522
  * @param {Module} module the module
521
523
  * @param {CacheGroupsContext} context context object
522
524
  * @returns {boolean} true, if the module should be selected
@@ -529,17 +531,17 @@ const checkTest = (test, module, context) => {
529
531
  if (typeof test === "boolean") return test;
530
532
  if (typeof test === "string") {
531
533
  const name = module.nameForCondition();
532
- return name && name.startsWith(test);
534
+ return name ? name.startsWith(test) : false;
533
535
  }
534
536
  if (test instanceof RegExp) {
535
537
  const name = module.nameForCondition();
536
- return name && test.test(name);
538
+ return name ? test.test(name) : false;
537
539
  }
538
540
  return false;
539
541
  };
540
542
 
541
543
  /**
542
- * @param {undefined|string|RegExp|Function} test type option
544
+ * @param {OptimizationSplitChunksCacheGroup["type"]} test type option
543
545
  * @param {Module} module the module
544
546
  * @returns {boolean} true, if the module should be selected
545
547
  */
@@ -560,7 +562,7 @@ const checkModuleType = (test, module) => {
560
562
  };
561
563
 
562
564
  /**
563
- * @param {undefined|string|RegExp|Function} test type option
565
+ * @param {OptimizationSplitChunksCacheGroup["layer"]} test type option
564
566
  * @param {Module} module the module
565
567
  * @returns {boolean} true, if the module should be selected
566
568
  */
@@ -571,11 +573,11 @@ const checkModuleLayer = (test, module) => {
571
573
  }
572
574
  if (typeof test === "string") {
573
575
  const layer = module.layer;
574
- return test === "" ? !layer : layer && layer.startsWith(test);
576
+ return test === "" ? !layer : layer ? layer.startsWith(test) : false;
575
577
  }
576
578
  if (test instanceof RegExp) {
577
579
  const layer = module.layer;
578
- return test.test(layer);
580
+ return layer ? test.test(layer) : false;
579
581
  }
580
582
  return false;
581
583
  };
@@ -647,7 +649,9 @@ module.exports = class SplitChunksPlugin {
647
649
 
648
650
  /** @type {SplitChunksOptions} */
649
651
  this.options = {
650
- chunksFilter: normalizeChunksFilter(options.chunks || "all"),
652
+ chunksFilter:
653
+ /** @type {ChunkFilterFunction} */
654
+ (normalizeChunksFilter(options.chunks || "all")),
651
655
  defaultSizeTypes,
652
656
  minSize,
653
657
  minSizeReduction,
@@ -676,13 +680,19 @@ module.exports = class SplitChunksPlugin {
676
680
  options.cacheGroups,
677
681
  defaultSizeTypes
678
682
  ),
679
- getName: options.name ? normalizeName(options.name) : defaultGetName,
680
- automaticNameDelimiter: options.automaticNameDelimiter,
681
- usedExports: options.usedExports,
683
+ getName: options.name
684
+ ? /** @type {GetName} */ (normalizeName(options.name))
685
+ : defaultGetName,
686
+ automaticNameDelimiter: options.automaticNameDelimiter || "-",
687
+ usedExports: options.usedExports || false,
682
688
  fallbackCacheGroup: {
683
- chunksFilter: normalizeChunksFilter(
684
- fallbackCacheGroup.chunks || options.chunks || "all"
685
- ),
689
+ chunksFilter:
690
+ /** @type {ChunkFilterFunction} */
691
+ (
692
+ normalizeChunksFilter(
693
+ fallbackCacheGroup.chunks || options.chunks || "all"
694
+ )
695
+ ),
686
696
  minSize: mergeSizes(
687
697
  normalizeSizes(fallbackCacheGroup.minSize, defaultSizeTypes),
688
698
  minSize
@@ -733,6 +743,7 @@ module.exports = class SplitChunksPlugin {
733
743
  cacheGroupSource.enforceSizeThreshold,
734
744
  cacheGroupSource.enforce ? undefined : this.options.enforceSizeThreshold
735
745
  );
746
+ /** @type {CacheGroup} */
736
747
  const cacheGroup = {
737
748
  key: cacheGroupSource.key,
738
749
  priority: cacheGroupSource.priority || 0,
@@ -853,10 +864,11 @@ module.exports = class SplitChunksPlugin {
853
864
  result = iterator.next();
854
865
  if (result.done) return first;
855
866
  let key =
856
- chunkIndexMap.get(first) | chunkIndexMap.get(result.value);
867
+ /** @type {bigint} */ (chunkIndexMap.get(first)) |
868
+ /** @type {bigint} */ (chunkIndexMap.get(result.value));
857
869
  while (!(result = iterator.next()).done) {
858
870
  const raw = chunkIndexMap.get(result.value);
859
- key = key ^ raw;
871
+ key = key ^ /** @type {bigint} */ (raw);
860
872
  }
861
873
  return key;
862
874
  };
@@ -866,7 +878,7 @@ module.exports = class SplitChunksPlugin {
866
878
  */
867
879
  const keyToString = key => {
868
880
  if (typeof key === "bigint") return key.toString(16);
869
- return chunkIndexMap.get(key).toString(16);
881
+ return /** @type {bigint} */ (chunkIndexMap.get(key)).toString(16);
870
882
  };
871
883
 
872
884
  const getChunkSetsInGraph = memoize(() => {
@@ -911,7 +923,7 @@ module.exports = class SplitChunksPlugin {
911
923
  const groupedByExportsMap = new Map();
912
924
 
913
925
  const getExportsChunkSetsInGraph = memoize(() => {
914
- /** @type {Map<bigint, Set<Chunk>>} */
926
+ /** @type {Map<bigint | Chunk, Set<Chunk>>} */
915
927
  const chunkSetsInGraph = new Map();
916
928
  /** @type {Set<Chunk>} */
917
929
  const singleChunkSets = new Set();
@@ -922,7 +934,7 @@ module.exports = class SplitChunksPlugin {
922
934
  if (chunks.length === 1) {
923
935
  singleChunkSets.add(chunks[0]);
924
936
  } else {
925
- const chunksKey = /** @type {bigint} */ (getKey(chunks));
937
+ const chunksKey = getKey(chunks);
926
938
  if (!chunkSetsInGraph.has(chunksKey)) {
927
939
  chunkSetsInGraph.set(chunksKey, new Set(chunks));
928
940
  }
@@ -965,6 +977,12 @@ module.exports = class SplitChunksPlugin {
965
977
  );
966
978
 
967
979
  // Create a list of possible combinations
980
+ /**
981
+ * @param {Map<bigint | Chunk, Set<Chunk>>} chunkSets chunk sets
982
+ * @param {Set<Chunk>} singleChunkSets single chunks sets
983
+ * @param {Map<number, Set<Chunk>[]>} chunkSetsByCount chunk sets by count
984
+ * @returns {(key: bigint | Chunk) => (Set<Chunk> | Chunk)[]} combinations
985
+ */
968
986
  const createGetCombinations = (
969
987
  chunkSets,
970
988
  singleChunkSets,
@@ -981,7 +999,9 @@ module.exports = class SplitChunksPlugin {
981
999
  combinationsCache.set(key, result);
982
1000
  return result;
983
1001
  }
984
- const chunksSet = chunkSets.get(key);
1002
+ const chunksSet =
1003
+ /** @type {Set<Chunk>} */
1004
+ (chunkSets.get(key));
985
1005
  /** @type {(Set<Chunk> | Chunk)[]} */
986
1006
  const array = [chunksSet];
987
1007
  for (const [count, setArray] of chunkSetsByCount) {
@@ -1012,6 +1032,11 @@ module.exports = class SplitChunksPlugin {
1012
1032
  getChunkSetsByCount()
1013
1033
  );
1014
1034
  });
1035
+
1036
+ /**
1037
+ * @param {bigint | Chunk} key key
1038
+ * @returns {(Set<Chunk> | Chunk)[]} combinations by key
1039
+ */
1015
1040
  const getCombinations = key => getCombinationsFactory()(key);
1016
1041
 
1017
1042
  const getExportsCombinationsFactory = memoize(() => {
@@ -1023,6 +1048,10 @@ module.exports = class SplitChunksPlugin {
1023
1048
  getExportsChunkSetsByCount()
1024
1049
  );
1025
1050
  });
1051
+ /**
1052
+ * @param {bigint | Chunk} key key
1053
+ * @returns {(Set<Chunk> | Chunk)[]} exports combinations by key
1054
+ */
1026
1055
  const getExportsCombinations = key =>
1027
1056
  getExportsCombinationsFactory()(key);
1028
1057
 
@@ -1098,11 +1127,12 @@ module.exports = class SplitChunksPlugin {
1098
1127
  // Break if minimum number of chunks is not reached
1099
1128
  if (selectedChunks.length < cacheGroup.minChunks) return;
1100
1129
  // Determine name for split chunk
1130
+
1101
1131
  const name =
1102
- /** @type {string} */
1103
- (cacheGroup.getName(module, selectedChunks, cacheGroup.key));
1132
+ /** @type {GetName} */
1133
+ (cacheGroup.getName)(module, selectedChunks, cacheGroup.key);
1104
1134
  // Check if the name is ok
1105
- const existingChunk = compilation.namedChunks.get(name);
1135
+ const existingChunk = name && compilation.namedChunks.get(name);
1106
1136
  if (existingChunk) {
1107
1137
  const parentValidationKey = `${name}|${
1108
1138
  typeof selectedChunksKey === "bigint"
@@ -1167,7 +1197,7 @@ module.exports = class SplitChunksPlugin {
1167
1197
  ? ` name:${name}`
1168
1198
  : ` chunks:${keyToString(selectedChunksKey)}`);
1169
1199
  // Add module to maps
1170
- let info = /** @type {ChunksInfoItem} */ (chunksInfoMap.get(key));
1200
+ let info = chunksInfoMap.get(key);
1171
1201
  if (info === undefined) {
1172
1202
  chunksInfoMap.set(
1173
1203
  key,
@@ -1260,7 +1290,8 @@ module.exports = class SplitChunksPlugin {
1260
1290
  const { chunks: selectedChunks, key: selectedChunksKey } =
1261
1291
  getSelectedChunks(
1262
1292
  chunkCombination,
1263
- /** @type {ChunkFilterFunction} */ (cacheGroup.chunksFilter)
1293
+ /** @type {ChunkFilterFunction} */
1294
+ (cacheGroup.chunksFilter)
1264
1295
  );
1265
1296
 
1266
1297
  addModuleToChunksInfoMap(
@@ -1428,18 +1459,14 @@ module.exports = class SplitChunksPlugin {
1428
1459
  ) {
1429
1460
  for (const chunk of usedChunks) {
1430
1461
  // respect max requests
1431
- const maxRequests = /** @type {number} */ (
1432
- chunk.isOnlyInitial()
1433
- ? item.cacheGroup.maxInitialRequests
1434
- : chunk.canBeInitial()
1435
- ? Math.min(
1436
- /** @type {number} */
1437
- (item.cacheGroup.maxInitialRequests),
1438
- /** @type {number} */
1439
- (item.cacheGroup.maxAsyncRequests)
1440
- )
1441
- : item.cacheGroup.maxAsyncRequests
1442
- );
1462
+ const maxRequests = chunk.isOnlyInitial()
1463
+ ? item.cacheGroup.maxInitialRequests
1464
+ : chunk.canBeInitial()
1465
+ ? Math.min(
1466
+ item.cacheGroup.maxInitialRequests,
1467
+ item.cacheGroup.maxAsyncRequests
1468
+ )
1469
+ : item.cacheGroup.maxAsyncRequests;
1443
1470
  if (
1444
1471
  Number.isFinite(maxRequests) &&
1445
1472
  getRequests(chunk) >= maxRequests
@@ -1461,10 +1488,7 @@ module.exports = class SplitChunksPlugin {
1461
1488
  if (usedChunks.size < item.chunks.size) {
1462
1489
  if (isExistingChunk)
1463
1490
  usedChunks.add(/** @type {Chunk} */ (newChunk));
1464
- if (
1465
- /** @type {number} */ (usedChunks.size) >=
1466
- /** @type {number} */ (item.cacheGroup.minChunks)
1467
- ) {
1491
+ if (usedChunks.size >= item.cacheGroup.minChunks) {
1468
1492
  const chunksArr = Array.from(usedChunks);
1469
1493
  for (const module of item.modules) {
1470
1494
  addModuleToChunksInfoMap(
@@ -1738,9 +1762,7 @@ module.exports = class SplitChunksPlugin {
1738
1762
  hashFilename(name, outputOptions);
1739
1763
  }
1740
1764
  if (i !== results.length - 1) {
1741
- const newPart = compilation.addChunk(
1742
- /** @type {Chunk["name"]} */ (name)
1743
- );
1765
+ const newPart = compilation.addChunk(name);
1744
1766
  chunk.split(newPart);
1745
1767
  newPart.chunkReason = chunk.chunkReason;
1746
1768
  if (chunk.filenameTemplate) {
@@ -1758,7 +1780,7 @@ module.exports = class SplitChunksPlugin {
1758
1780
  }
1759
1781
  } else {
1760
1782
  // change the chunk to be a part
1761
- chunk.name = /** @type {Chunk["name"]} */ (name);
1783
+ chunk.name = name;
1762
1784
  }
1763
1785
  }
1764
1786
  }
@@ -8,9 +8,17 @@
8
8
  /** @typedef {import("../../declarations/WebpackOptions").RuleSetRule} RuleSetRule */
9
9
  /** @typedef {import("./RuleSetCompiler")} RuleSetCompiler */
10
10
 
11
+ /**
12
+ * @template T
13
+ * @template {T[keyof T]} V
14
+ * @typedef {import("./RuleSetCompiler").KeysOfTypes<T, V>} KeysOfTypes
15
+ */
16
+
17
+ /** @typedef {KeysOfTypes<RuleSetRule, string | boolean | { [k: string]: EXPECTED_ANY }>} BasicEffectRuleKeys */
18
+
11
19
  class BasicEffectRulePlugin {
12
20
  /**
13
- * @param {string} ruleProperty the rule property
21
+ * @param {BasicEffectRuleKeys} ruleProperty the rule property
14
22
  * @param {string=} effectType the effect type
15
23
  */
16
24
  constructor(ruleProperty, effectType) {
@@ -5,13 +5,24 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ /** @typedef {import("../../declarations/WebpackOptions").RuleSetConditionOrConditions} RuleSetConditionOrConditions */
9
+ /** @typedef {import("../../declarations/WebpackOptions").RuleSetConditionOrConditionsAbsolute} RuleSetConditionOrConditionsAbsolute */
10
+ /** @typedef {import("../../declarations/WebpackOptions").RuleSetLoaderOptions} RuleSetLoaderOptions */
8
11
  /** @typedef {import("../../declarations/WebpackOptions").RuleSetRule} RuleSetRule */
9
12
  /** @typedef {import("./RuleSetCompiler")} RuleSetCompiler */
10
13
  /** @typedef {import("./RuleSetCompiler").RuleCondition} RuleCondition */
11
14
 
15
+ /**
16
+ * @template T
17
+ * @template {T[keyof T]} V
18
+ * @typedef {import("./RuleSetCompiler").KeysOfTypes<T, V>} KeysOfTypes
19
+ */
20
+
21
+ /** @typedef {KeysOfTypes<RuleSetRule, RuleSetConditionOrConditions | RuleSetConditionOrConditionsAbsolute>} BasicMatcherRuleKeys */
22
+
12
23
  class BasicMatcherRulePlugin {
13
24
  /**
14
- * @param {string} ruleProperty the rule property
25
+ * @param {BasicMatcherRuleKeys} ruleProperty the rule property
15
26
  * @param {string=} dataProperty the data property
16
27
  * @param {boolean=} invert if true, inverts the condition
17
28
  */
@@ -31,11 +42,11 @@ class BasicMatcherRulePlugin {
31
42
  (path, rule, unhandledProperties, result) => {
32
43
  if (unhandledProperties.has(this.ruleProperty)) {
33
44
  unhandledProperties.delete(this.ruleProperty);
34
- const value =
35
- rule[/** @type {keyof RuleSetRule} */ (this.ruleProperty)];
45
+ const value = rule[this.ruleProperty];
36
46
  const condition = ruleSetCompiler.compileCondition(
37
47
  `${path}.${this.ruleProperty}`,
38
- value
48
+ /** @type {RuleSetConditionOrConditions | RuleSetConditionOrConditionsAbsolute} */
49
+ (value)
39
50
  );
40
51
  const fn = condition.fn;
41
52
  result.conditions.push({
@@ -5,14 +5,23 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ /** @typedef {import("../../declarations/WebpackOptions").RuleSetConditionOrConditions} RuleSetConditionOrConditions */
8
9
  /** @typedef {import("../../declarations/WebpackOptions").RuleSetRule} RuleSetRule */
9
10
  /** @typedef {import("./RuleSetCompiler")} RuleSetCompiler */
10
11
  /** @typedef {import("./RuleSetCompiler").RuleCondition} RuleCondition */
11
12
  /** @typedef {import("./RuleSetCompiler").RuleConditionFunction} RuleConditionFunction */
12
13
 
14
+ /**
15
+ * @template T
16
+ * @template {T[keyof T]} V
17
+ * @typedef {import("./RuleSetCompiler").KeysOfTypes<T, V>} KeysOfTypes
18
+ */
19
+
20
+ /** @typedef {KeysOfTypes<RuleSetRule, { [k: string]: RuleSetConditionOrConditions }>} ObjectMatcherRuleKeys */
21
+
13
22
  class ObjectMatcherRulePlugin {
14
23
  /**
15
- * @param {string} ruleProperty the rule property
24
+ * @param {ObjectMatcherRuleKeys} ruleProperty the rule property
16
25
  * @param {string=} dataProperty the data property
17
26
  * @param {RuleConditionFunction=} additionalConditionFunction need to check
18
27
  */
@@ -34,8 +43,8 @@ class ObjectMatcherRulePlugin {
34
43
  if (unhandledProperties.has(ruleProperty)) {
35
44
  unhandledProperties.delete(ruleProperty);
36
45
  const value =
37
- /** @type {Record<string, any>} */
38
- (rule[/** @type {keyof RuleSetRule} */ (ruleProperty)]);
46
+ /** @type {Record<string, RuleSetConditionOrConditions>} */
47
+ (rule[ruleProperty]);
39
48
  for (const property of Object.keys(value)) {
40
49
  const nestedDataProperties = property.split(".");
41
50
  const condition = ruleSetCompiler.compileCondition(
@@ -7,10 +7,13 @@
7
7
 
8
8
  const { SyncHook } = require("tapable");
9
9
 
10
+ /** @typedef {import("../../declarations/WebpackOptions").Falsy} Falsy */
11
+ /** @typedef {import("../../declarations/WebpackOptions").RuleSetLoaderOptions} RuleSetLoaderOptions */
10
12
  /** @typedef {import("../../declarations/WebpackOptions").RuleSetRule} RuleSetRule */
11
- /** @typedef {import("../../declarations/WebpackOptions").RuleSetRules} RuleSetRules */
12
13
 
13
- /** @typedef {function(string | EffectData): boolean} RuleConditionFunction */
14
+ /** @typedef {(Falsy | RuleSetRule)[]} RuleSetRules */
15
+
16
+ /** @typedef {(value: string | EffectData) => boolean} RuleConditionFunction */
14
17
 
15
18
  /**
16
19
  * @typedef {object} RuleCondition
@@ -32,7 +35,7 @@ const { SyncHook } = require("tapable");
32
35
  /**
33
36
  * @typedef {object} CompiledRule
34
37
  * @property {RuleCondition[]} conditions
35
- * @property {(Effect|function(EffectData): Effect[])[]} effects
38
+ * @property {(Effect | ((effectData: EffectData) => Effect[]))[]} effects
36
39
  * @property {CompiledRule[]=} rules
37
40
  * @property {CompiledRule[]=} oneOf
38
41
  */
@@ -40,16 +43,24 @@ const { SyncHook } = require("tapable");
40
43
  /**
41
44
  * @typedef {object} Effect
42
45
  * @property {string} type
43
- * @property {any} value
46
+ * @property {TODO} value
44
47
  */
45
48
 
49
+ /** @typedef {Map<string, RuleSetLoaderOptions>} References */
50
+
46
51
  /**
47
52
  * @typedef {object} RuleSet
48
- * @property {Map<string, any>} references map of references in the rule set (may grow over time)
49
- * @property {function(EffectData): Effect[]} exec execute the rule set
53
+ * @property {References} references map of references in the rule set (may grow over time)
54
+ * @property {(effectData: EffectData) => Effect[]} exec execute the rule set
55
+ */
56
+
57
+ /**
58
+ * @template T
59
+ * @template {T[keyof T]} V
60
+ * @typedef {({ [P in keyof Required<T>]: Required<T>[P] extends V ? P : never })[keyof T]} KeysOfTypes
50
61
  */
51
62
 
52
- /** @typedef {{ apply: (function(RuleSetCompiler): void) }} RuleSetPlugin */
63
+ /** @typedef {{ apply: (ruleSetCompiler: RuleSetCompiler) => void }} RuleSetPlugin */
53
64
 
54
65
  class RuleSetCompiler {
55
66
  /**
@@ -57,7 +68,7 @@ class RuleSetCompiler {
57
68
  */
58
69
  constructor(plugins) {
59
70
  this.hooks = Object.freeze({
60
- /** @type {SyncHook<[string, RuleSetRule, Set<string>, CompiledRule, Map<string | undefined, any>]>} */
71
+ /** @type {SyncHook<[string, RuleSetRule, Set<string>, CompiledRule, References]>} */
61
72
  rule: new SyncHook([
62
73
  "path",
63
74
  "rule",
@@ -74,7 +85,7 @@ class RuleSetCompiler {
74
85
  }
75
86
 
76
87
  /**
77
- * @param {TODO[]} ruleSet raw user provided rules
88
+ * @param {RuleSetRules} ruleSet raw user provided rules
78
89
  * @returns {RuleSet} compiled RuleSet
79
90
  */
80
91
  compile(ruleSet) {
@@ -161,7 +172,7 @@ class RuleSetCompiler {
161
172
  /**
162
173
  * @param {string} path current path
163
174
  * @param {RuleSetRules} rules the raw rules provided by user
164
- * @param {Map<string, any>} refs references
175
+ * @param {References} refs references
165
176
  * @returns {CompiledRule[]} rules
166
177
  */
167
178
  compileRules(path, rules, refs) {
@@ -179,7 +190,7 @@ class RuleSetCompiler {
179
190
  /**
180
191
  * @param {string} path current path
181
192
  * @param {RuleSetRule} rule the raw rule provided by user
182
- * @param {Map<string, any>} refs references
193
+ * @param {References} refs references
183
194
  * @returns {CompiledRule} normalized and compiled rule for processing
184
195
  */
185
196
  compileRule(path, rule, refs) {
@@ -228,7 +239,7 @@ class RuleSetCompiler {
228
239
 
229
240
  /**
230
241
  * @param {string} path current path
231
- * @param {any} condition user provided condition value
242
+ * @param {RuleSetLoaderOptions} condition user provided condition value
232
243
  * @returns {Condition} compiled condition
233
244
  */
234
245
  compileCondition(path, condition) {
@@ -255,7 +266,7 @@ class RuleSetCompiler {
255
266
  try {
256
267
  return {
257
268
  matchWhenEmpty: condition(""),
258
- fn: condition
269
+ fn: /** @type {RuleConditionFunction} */ (condition)
259
270
  };
260
271
  } catch (_err) {
261
272
  throw this.error(
@@ -386,7 +397,7 @@ class RuleSetCompiler {
386
397
 
387
398
  /**
388
399
  * @param {string} path current path
389
- * @param {any} value value at the error location
400
+ * @param {EXPECTED_ANY} value value at the error location
390
401
  * @param {string} message message explaining the problem
391
402
  * @returns {Error} an error object
392
403
  */