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
@@ -10,12 +10,25 @@ const SortableSet = require("./SortableSet");
10
10
 
11
11
  /**
12
12
  * @template T
13
- * @typedef {LazyBucketSortedSet<T, any> | SortableSet<T>} Entry
13
+ * @template K
14
+ * @typedef {(item: T) => K} GetKey
15
+ */
16
+
17
+ /**
18
+ * @template T
19
+ * @typedef {(a: T, n: T) => number} Comparator
14
20
  */
15
21
 
16
22
  /**
17
23
  * @template T
18
- * @typedef {(function(T): any) | (function(any, any): number)} Arg
24
+ * @template K
25
+ * @typedef {LazyBucketSortedSet<T, K> | SortableSet<T>} Entry
26
+ */
27
+
28
+ /**
29
+ * @template T
30
+ * @template K
31
+ * @typedef {GetKey<T, K> | Comparator<K> | Comparator<T>} Arg
19
32
  */
20
33
 
21
34
  /**
@@ -32,17 +45,16 @@ const SortableSet = require("./SortableSet");
32
45
  */
33
46
  class LazyBucketSortedSet {
34
47
  /**
35
- * @param {function(T): K} getKey function to get key from item
36
- * @param {function(K, K): number} comparator comparator to sort keys
37
- * @param {...Arg<T>} args more pairs of getKey and comparator plus optional final comparator for the last layer
48
+ * @param {GetKey<T, K>} getKey function to get key from item
49
+ * @param {Comparator<K>=} comparator comparator to sort keys
50
+ * @param {...Arg<T, K>} args more pairs of getKey and comparator plus optional final comparator for the last layer
38
51
  */
39
52
  constructor(getKey, comparator, ...args) {
40
53
  this._getKey = getKey;
41
- /** @type {Arg<T>[]} */
42
54
  this._innerArgs = args;
43
55
  this._leaf = args.length <= 1;
44
56
  this._keys = new SortableSet(undefined, comparator);
45
- /** @type {Map<K, Entry<T>>} */
57
+ /** @type {Map<K, Entry<T, K>>} */
46
58
  this._map = new Map();
47
59
  this._unsortedItems = new Set();
48
60
  this.size = 0;
@@ -65,18 +77,20 @@ class LazyBucketSortedSet {
65
77
  _addInternal(key, item) {
66
78
  let entry = this._map.get(key);
67
79
  if (entry === undefined) {
68
- entry =
69
- /** @type {Entry<T>} */
70
- (
71
- this._leaf
72
- ? new SortableSet(undefined, this._innerArgs[0])
73
- : new /** @type {TODO} */ (LazyBucketSortedSet)(...this._innerArgs)
74
- );
80
+ entry = this._leaf
81
+ ? new SortableSet(
82
+ undefined,
83
+ /** @type {Comparator<T>} */
84
+ (this._innerArgs[0])
85
+ )
86
+ : new LazyBucketSortedSet(
87
+ .../** @type {[GetKey<T, K>, Comparator<K>]} */
88
+ (this._innerArgs)
89
+ );
75
90
  this._keys.add(key);
76
91
  this._map.set(key, entry);
77
92
  }
78
- /** @type {Entry<T>} */
79
- (entry).add(item);
93
+ entry.add(item);
80
94
  }
81
95
 
82
96
  /**
@@ -90,7 +104,7 @@ class LazyBucketSortedSet {
90
104
  return;
91
105
  }
92
106
  const key = this._getKey(item);
93
- const entry = /** @type {Entry<T>} */ (this._map.get(key));
107
+ const entry = /** @type {Entry<T, K>} */ (this._map.get(key));
94
108
  entry.delete(item);
95
109
  if (entry.size === 0) {
96
110
  this._deleteKey(key);
@@ -132,7 +146,9 @@ class LazyBucketSortedSet {
132
146
  }
133
147
  return item;
134
148
  }
135
- const nodeEntry = /** @type {LazyBucketSortedSet<T, any>} */ (entry);
149
+ const nodeEntry =
150
+ /** @type {LazyBucketSortedSet<T, K>} */
151
+ (entry);
136
152
  const item = nodeEntry.popFirst();
137
153
  if (nodeEntry.size === 0) {
138
154
  this._deleteKey(key);
@@ -142,7 +158,7 @@ class LazyBucketSortedSet {
142
158
 
143
159
  /**
144
160
  * @param {T} item to be updated item
145
- * @returns {function(true=): void} finish update
161
+ * @returns {(remove?: true) => void} finish update
146
162
  */
147
163
  startUpdate(item) {
148
164
  if (this._unsortedItems.has(item)) {
@@ -178,9 +194,9 @@ class LazyBucketSortedSet {
178
194
  }
179
195
  };
180
196
  }
181
- const oldEntry = /** @type {LazyBucketSortedSet<T, any>} */ (
182
- this._map.get(key)
183
- );
197
+ const oldEntry =
198
+ /** @type {LazyBucketSortedSet<T, K>} */
199
+ (this._map.get(key));
184
200
  const finishUpdate = oldEntry.startUpdate(item);
185
201
  return remove => {
186
202
  if (remove) {
@@ -218,7 +234,9 @@ class LazyBucketSortedSet {
218
234
  const iterator = leafEntry[Symbol.iterator]();
219
235
  iterators.push(iterator);
220
236
  } else {
221
- const nodeEntry = /** @type {LazyBucketSortedSet<T, any>} */ (entry);
237
+ const nodeEntry =
238
+ /** @type {LazyBucketSortedSet<T, K>} */
239
+ (entry);
222
240
  nodeEntry._appendIterators(iterators);
223
241
  }
224
242
  }
@@ -148,8 +148,9 @@ class LazySet {
148
148
  }
149
149
 
150
150
  /**
151
- * @param {function(T, T, Set<T>): void} callbackFn function called for each entry
152
- * @param {any} thisArg this argument for the callbackFn
151
+ * @template K
152
+ * @param {(value: T, value2: T, set: Set<T>) => void} callbackFn function called for each entry
153
+ * @param {K} thisArg this argument for the callbackFn
153
154
  * @returns {void}
154
155
  */
155
156
  forEach(callbackFn, thisArg) {
@@ -13,7 +13,7 @@
13
13
  * @template V
14
14
  * @param {Map<K, V>} map The map object to check
15
15
  * @param {K} key The key to check
16
- * @param {function(): V} computer function which will compute the value if it doesn't exist
16
+ * @param {() => V} computer function which will compute the value if it doesn't exist
17
17
  * @returns {V} The value from the map, or the computed value
18
18
  * @example
19
19
  * ```js
@@ -7,7 +7,7 @@
7
7
 
8
8
  const binarySearchBounds = require("./binarySearchBounds");
9
9
 
10
- /** @typedef {function(number): void} Callback */
10
+ /** @typedef {(value: number) => void} Callback */
11
11
 
12
12
  class ParallelismFactorCalculator {
13
13
  constructor() {
@@ -13,14 +13,14 @@ class Semaphore {
13
13
  */
14
14
  constructor(available) {
15
15
  this.available = available;
16
- /** @type {(function(): void)[]} */
16
+ /** @type {(() => void)[]} */
17
17
  this.waiters = [];
18
18
  /** @private */
19
19
  this._continue = this._continue.bind(this);
20
20
  }
21
21
 
22
22
  /**
23
- * @param {function(): void} callback function block to capture and run
23
+ * @param {() => void} callback function block to capture and run
24
24
  * @returns {void}
25
25
  */
26
26
  acquire(callback) {
@@ -42,7 +42,7 @@ class Semaphore {
42
42
  _continue() {
43
43
  if (this.available > 0 && this.waiters.length > 0) {
44
44
  this.available--;
45
- const callback = /** @type {(function(): void)} */ (this.waiters.pop());
45
+ const callback = /** @type {(() => void)} */ (this.waiters.pop());
46
46
  callback();
47
47
  }
48
48
  }
@@ -54,7 +54,7 @@ const isSubset = (bigSet, smallSet) => {
54
54
  /**
55
55
  * @template T
56
56
  * @param {Set<T>} set a set
57
- * @param {function(T): boolean} fn selector function
57
+ * @param {(set: T) => boolean} fn selector function
58
58
  * @returns {T | undefined} found item
59
59
  */
60
60
  const find = (set, fn) => {
@@ -16,8 +16,8 @@ class SortableSet extends Set {
16
16
  /**
17
17
  * Create a new sortable set
18
18
  * @template T
19
+ * @typedef {(a: T, b: T) => number} SortFunction
19
20
  * @param {Iterable<T>=} initialIterable The initial iterable value
20
- * @typedef {function(T, T): number} SortFunction
21
21
  * @param {SortFunction<T>=} defaultSort Default sorting function
22
22
  */
23
23
  constructor(initialIterable, defaultSort) {
@@ -29,17 +29,19 @@ class SortableSet extends Set {
29
29
  this._sortFn = defaultSort;
30
30
  /**
31
31
  * @private
32
- * @type {typeof NONE | undefined | function(T, T): number}}
32
+ * @type {typeof NONE | undefined | ((a: T, b: T) => number)}}
33
33
  */
34
34
  this._lastActiveSortFn = NONE;
35
35
  /**
36
36
  * @private
37
- * @type {Map<Function, any> | undefined}
37
+ * @template R
38
+ * @type {Map<(set: SortableSet<T>) => EXPECTED_ANY, EXPECTED_ANY> | undefined}
38
39
  */
39
40
  this._cache = undefined;
40
41
  /**
41
42
  * @private
42
- * @type {Map<Function, any> | undefined}
43
+ * @template R
44
+ * @type {Map<(set: SortableSet<T>) => EXPECTED_ANY, EXPECTED_ANY> | undefined}
43
45
  */
44
46
  this._cacheOrderIndependent = undefined;
45
47
  }
@@ -102,8 +104,8 @@ class SortableSet extends Set {
102
104
 
103
105
  /**
104
106
  * Get data from cache
105
- * @template R
106
- * @param {function(SortableSet<T>): R} fn function to calculate value
107
+ * @template {EXPECTED_ANY} R
108
+ * @param {(set: SortableSet<T>) => R} fn function to calculate value
107
109
  * @returns {R} returns result of fn(this), cached until set changes
108
110
  */
109
111
  getFromCache(fn) {
@@ -124,7 +126,7 @@ class SortableSet extends Set {
124
126
  /**
125
127
  * Get data from cache (ignoring sorting)
126
128
  * @template R
127
- * @param {function(SortableSet<T>): R} fn function to calculate value
129
+ * @param {(set: SortableSet<T>) => R} fn function to calculate value
128
130
  * @returns {R} returns result of fn(this), cached until set changes
129
131
  */
130
132
  getFromUnorderedCache(fn) {
@@ -8,21 +8,22 @@
8
8
  const TupleSet = require("./TupleSet");
9
9
 
10
10
  /**
11
- * @template {any[]} T
11
+ * @template T
12
+ * @template V
12
13
  */
13
14
  class TupleQueue {
14
15
  /**
15
- * @param {Iterable<T>=} items The initial elements.
16
+ * @param {Iterable<[T, V]>=} items The initial elements.
16
17
  */
17
18
  constructor(items) {
18
19
  /**
19
20
  * @private
20
- * @type {TupleSet<T>}
21
+ * @type {TupleSet<[T, V]>}
21
22
  */
22
23
  this._set = new TupleSet(items);
23
24
  /**
24
25
  * @private
25
- * @type {Iterator<T>}
26
+ * @type {Iterator<[T, V]>}
26
27
  */
27
28
  this._iterator = this._set[Symbol.iterator]();
28
29
  }
@@ -37,7 +38,7 @@ class TupleQueue {
37
38
 
38
39
  /**
39
40
  * Appends the specified element to this queue.
40
- * @param {T} item The element to add.
41
+ * @param {[T, V]} item The element to add.
41
42
  * @returns {void}
42
43
  */
43
44
  enqueue(...item) {
@@ -46,20 +47,20 @@ class TupleQueue {
46
47
 
47
48
  /**
48
49
  * Retrieves and removes the head of this queue.
49
- * @returns {T | undefined} The head of the queue of `undefined` if this queue is empty.
50
+ * @returns {[T, V] | undefined} The head of the queue of `undefined` if this queue is empty.
50
51
  */
51
52
  dequeue() {
52
53
  const result = this._iterator.next();
53
54
  if (result.done) {
54
55
  if (this._set.size > 0) {
55
56
  this._iterator = this._set[Symbol.iterator]();
56
- const value = this._iterator.next().value;
57
+ const value = /** @type {[T, V]} */ (this._iterator.next().value);
57
58
  this._set.delete(...value);
58
59
  return value;
59
60
  }
60
61
  return;
61
62
  }
62
- this._set.delete(...result.value);
63
+ this._set.delete(.../** @type {[T, V]} */ (result.value));
63
64
  return result.value;
64
65
  }
65
66
  }
@@ -24,7 +24,7 @@ class TupleSet {
24
24
  }
25
25
 
26
26
  /**
27
- * @param {T} args tuple
27
+ * @param {T} args tuple
28
28
  * @returns {void}
29
29
  */
30
30
  add(...args) {
@@ -52,7 +52,7 @@ class TupleSet {
52
52
  }
53
53
 
54
54
  /**
55
- * @param {T} args tuple
55
+ * @param {T} args tuple
56
56
  * @returns {boolean} true, if the tuple is in the Set
57
57
  */
58
58
  has(...args) {
@@ -6,18 +6,19 @@
6
6
  "use strict";
7
7
 
8
8
  /**
9
- * @template {any[]} T
9
+ * @template T
10
10
  * @template V
11
- * @typedef {Map<object, WeakTupleMap<T, V>>} M
11
+ * @typedef {Map<EXPECTED_ANY, WeakTupleMap<T[], V>>} M
12
12
  */
13
+
13
14
  /**
14
- * @template {any[]} T
15
+ * @template T
15
16
  * @template V
16
- * @typedef {WeakMap<object, WeakTupleMap<T, V>>} W
17
+ * @typedef {WeakMap<EXPECTED_OBJECT, WeakTupleMap<T[], V>>} W
17
18
  */
18
19
 
19
20
  /**
20
- * @param {any} thing thing
21
+ * @param {EXPECTED_ANY} thing thing
21
22
  * @returns {boolean} true if is weak
22
23
  */
23
24
  const isWeakKey = thing => typeof thing === "object" && thing !== null;
@@ -32,7 +33,7 @@ class WeakTupleMap {
32
33
  this.f = 0;
33
34
  /**
34
35
  * @private
35
- * @type {any}
36
+ * @type {V | undefined}
36
37
  */
37
38
  this.v = undefined;
38
39
  /**
@@ -89,7 +90,7 @@ class WeakTupleMap {
89
90
  }
90
91
 
91
92
  /**
92
- * @param {[...T, function(): V]} args tuple
93
+ * @param {[...T, () => V]} args tuple
93
94
  * @returns {V} the value
94
95
  */
95
96
  provide(...args) {
@@ -98,7 +99,7 @@ class WeakTupleMap {
98
99
  for (let i = 0; i < args.length - 1; i++) {
99
100
  node = node._get(args[i]);
100
101
  }
101
- if (node._hasValue()) return node._getValue();
102
+ if (node._hasValue()) return /** @type {V} */ (node._getValue());
102
103
  const fn = args[args.length - 1];
103
104
  const newValue = fn(...args.slice(0, -1));
104
105
  node._setValue(newValue);
@@ -138,7 +139,7 @@ class WeakTupleMap {
138
139
  }
139
140
 
140
141
  /**
141
- * @param {any} v value
142
+ * @param {V} v value
142
143
  * @private
143
144
  */
144
145
  _setValue(v) {
@@ -152,7 +153,7 @@ class WeakTupleMap {
152
153
  }
153
154
 
154
155
  /**
155
- * @param {any} thing thing
156
+ * @param {EXPECTED_ANY} thing thing
156
157
  * @returns {WeakTupleMap<T, V> | undefined} thing
157
158
  * @private
158
159
  */
@@ -167,7 +168,7 @@ class WeakTupleMap {
167
168
 
168
169
  /**
169
170
  * @private
170
- * @param {any} thing thing
171
+ * @param {EXPECTED_ANY} thing thing
171
172
  * @returns {WeakTupleMap<T, V>} value
172
173
  */
173
174
  _get(thing) {
@@ -69,11 +69,12 @@ const compileSearch = (funcName, predicate, reversed, extraArgs, earlyOut) => {
69
69
  * A(): Performs a binary search on an array using the comparison operator specified.
70
70
  * P(): Performs a binary search on an array using a _custom comparison function_
71
71
  * `c(x,y)` **and** comparison operator specified by `predicate`.
72
+ * @template T
72
73
  * @param {BinarySearchPredicate} predicate The predicate / comparison operator to be used in the binary search.
73
74
  * @param {boolean} reversed Whether the search should be reversed.
74
75
  * @param {SearchPredicateSuffix} suffix The suffix to be used in the function name.
75
76
  * @param {boolean=} earlyOut Whether the search should return as soon as a match is found.
76
- * @returns {Function} The compiled binary search function.
77
+ * @returns {(items: T[], start: number, compareFn?: number | ((item: T, needle: number) => number), l?: number, h?: number) => number} The compiled binary search function.
77
78
  */
78
79
  const compileBoundsSearch = (predicate, reversed, suffix, earlyOut) => {
79
80
  const arg1 = compileSearch("A", `x${predicate}y`, reversed, ["y"], earlyOut);