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.
- package/README.md +7 -3
- package/lib/AsyncDependenciesBlock.js +3 -1
- package/lib/BannerPlugin.js +1 -1
- package/lib/Cache.js +9 -7
- package/lib/CacheFacade.js +5 -5
- package/lib/Chunk.js +2 -2
- package/lib/ChunkGraph.js +21 -16
- package/lib/ChunkTemplate.js +6 -6
- package/lib/CleanPlugin.js +10 -10
- package/lib/CodeGenerationResults.js +4 -3
- package/lib/CompatibilityPlugin.js +4 -1
- package/lib/Compilation.js +326 -152
- package/lib/Compiler.js +13 -18
- package/lib/ConditionalInitFragment.js +1 -1
- package/lib/ConstPlugin.js +5 -3
- package/lib/ContextModule.js +4 -2
- package/lib/ContextModuleFactory.js +3 -3
- package/lib/ContextReplacementPlugin.js +43 -16
- package/lib/DefinePlugin.js +25 -24
- package/lib/DelegatedModule.js +4 -2
- package/lib/DelegatedModuleFactoryPlugin.js +2 -1
- package/lib/Dependency.js +19 -13
- package/lib/DependencyTemplates.js +4 -3
- package/lib/DllModule.js +4 -2
- package/lib/DllModuleFactory.js +2 -2
- package/lib/DllReferencePlugin.js +2 -1
- package/lib/DynamicEntryPlugin.js +1 -1
- package/lib/EnvironmentPlugin.js +4 -2
- package/lib/ExportsInfo.js +72 -40
- package/lib/ExternalModule.js +14 -5
- package/lib/ExternalModuleFactoryPlugin.js +24 -12
- package/lib/FileSystemInfo.js +129 -94
- package/lib/FlagDependencyExportsPlugin.js +6 -4
- package/lib/FlagDependencyUsagePlugin.js +1 -1
- package/lib/Generator.js +29 -1
- package/lib/HookWebpackError.js +2 -2
- package/lib/HotModuleReplacementPlugin.js +3 -9
- package/lib/IgnoreErrorModuleFactory.js +2 -2
- package/lib/IgnorePlugin.js +0 -5
- package/lib/InitFragment.js +1 -1
- package/lib/LoaderOptionsPlugin.js +8 -5
- package/lib/MainTemplate.js +7 -7
- package/lib/Module.js +40 -17
- package/lib/ModuleBuildError.js +3 -1
- package/lib/ModuleDependencyError.js +4 -3
- package/lib/ModuleDependencyWarning.js +4 -3
- package/lib/ModuleFactory.js +9 -3
- package/lib/ModuleFilenameHelpers.js +13 -13
- package/lib/ModuleGraph.js +20 -14
- package/lib/ModuleGraphConnection.js +7 -13
- package/lib/ModuleNotFoundError.js +1 -1
- package/lib/ModuleParseError.js +2 -1
- package/lib/ModuleSourceTypesConstants.js +11 -0
- package/lib/ModuleTemplate.js +5 -5
- package/lib/ModuleTypeConstants.js +15 -0
- package/lib/MultiCompiler.js +4 -4
- package/lib/MultiStats.js +1 -1
- package/lib/NormalModule.js +101 -54
- package/lib/NormalModuleFactory.js +38 -33
- package/lib/NormalModuleReplacementPlugin.js +3 -2
- package/lib/NullFactory.js +2 -2
- package/lib/Parser.js +4 -3
- package/lib/ProgressPlugin.js +1 -2
- package/lib/RawModule.js +4 -2
- package/lib/RecordIdsPlugin.js +6 -2
- package/lib/RequestShortener.js +3 -1
- package/lib/ResolverFactory.js +12 -9
- package/lib/RuntimeModule.js +4 -2
- package/lib/RuntimeTemplate.js +2 -1
- package/lib/SelfModuleFactory.js +2 -2
- package/lib/SourceMapDevToolPlugin.js +0 -8
- package/lib/Template.js +6 -5
- package/lib/TemplatedPathPlugin.js +15 -12
- package/lib/WebpackOptionsApply.js +1 -1
- package/lib/asset/AssetGenerator.js +237 -170
- package/lib/asset/AssetModulesPlugin.js +50 -8
- package/lib/asset/AssetSourceGenerator.js +18 -0
- package/lib/asset/RawDataUrlModule.js +4 -2
- package/lib/buildChunkGraph.js +14 -4
- package/lib/cache/MemoryWithGcCachePlugin.js +6 -2
- package/lib/cache/PackFileCacheStrategy.js +137 -121
- package/lib/cache/ResolverCachePlugin.js +15 -7
- package/lib/cache/getLazyHashedEtag.js +4 -3
- package/lib/cli.js +23 -15
- package/lib/config/defaults.js +93 -26
- package/lib/config/normalization.js +14 -13
- package/lib/config/target.js +8 -8
- package/lib/container/ContainerEntryModule.js +4 -2
- package/lib/container/ContainerEntryModuleFactory.js +2 -2
- package/lib/container/FallbackModule.js +4 -2
- package/lib/container/FallbackModuleFactory.js +2 -2
- package/lib/container/RemoteModule.js +4 -2
- package/lib/container/options.js +5 -5
- package/lib/css/CssGenerator.js +71 -9
- package/lib/css/CssModulesPlugin.js +30 -5
- package/lib/css/CssParser.js +37 -17
- package/lib/css/walkCssTokens.js +17 -17
- package/lib/debug/ProfilingPlugin.js +98 -38
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +10 -4
- package/lib/dependencies/AMDPlugin.js +5 -2
- package/lib/dependencies/AMDRequireArrayDependency.js +4 -3
- package/lib/dependencies/AMDRequireContextDependency.js +2 -1
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +15 -7
- package/lib/dependencies/AMDRuntimeModules.js +3 -1
- package/lib/dependencies/CommonJsExportRequireDependency.js +4 -5
- package/lib/dependencies/CommonJsExportsParserPlugin.js +3 -3
- package/lib/dependencies/CommonJsImportsParserPlugin.js +8 -7
- package/lib/dependencies/CommonJsRequireContextDependency.js +2 -1
- package/lib/dependencies/ContextDependencyHelpers.js +13 -6
- package/lib/dependencies/CssIcssExportDependency.js +15 -12
- package/lib/dependencies/CssIcssImportDependency.js +4 -1
- package/lib/dependencies/CssLocalIdentifierDependency.js +17 -14
- package/lib/dependencies/ExportsInfoDependency.js +6 -1
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +5 -5
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +22 -15
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +23 -8
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +2 -2
- package/lib/dependencies/HarmonyImportDependency.js +8 -6
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +19 -14
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +5 -5
- package/lib/dependencies/ImportContextDependency.js +2 -1
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +8 -4
- package/lib/dependencies/JsonExportsDependency.js +24 -8
- package/lib/dependencies/LoaderPlugin.js +4 -14
- package/lib/dependencies/RequireContextDependency.js +2 -1
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +6 -3
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +3 -2
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +11 -5
- package/lib/dependencies/RequireResolveContextDependency.js +1 -1
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +1 -1
- package/lib/dependencies/WorkerDependency.js +6 -3
- package/lib/dependencies/WorkerPlugin.js +100 -41
- package/lib/esm/ModuleChunkFormatPlugin.js +5 -0
- package/lib/hmr/HotModuleReplacement.runtime.js +1 -0
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +1 -0
- package/lib/hmr/LazyCompilationPlugin.js +32 -24
- package/lib/hmr/lazyCompilationBackend.js +1 -1
- package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
- package/lib/ids/HashedModuleIdsPlugin.js +2 -1
- package/lib/ids/IdHelpers.js +15 -14
- package/lib/ids/SyncModuleIdsPlugin.js +9 -5
- package/lib/index.js +5 -5
- package/lib/javascript/BasicEvaluatedExpression.js +6 -6
- package/lib/javascript/JavascriptGenerator.js +11 -1
- package/lib/javascript/JavascriptModulesPlugin.js +51 -31
- package/lib/javascript/JavascriptParser.js +272 -188
- package/lib/javascript/JavascriptParserHelpers.js +10 -9
- package/lib/javascript/StartupHelpers.js +4 -1
- package/lib/json/JsonData.js +4 -4
- package/lib/json/JsonGenerator.js +54 -22
- package/lib/json/JsonModulesPlugin.js +16 -2
- package/lib/json/JsonParser.js +8 -4
- package/lib/library/AbstractLibraryPlugin.js +7 -3
- package/lib/library/AssignLibraryPlugin.js +29 -1
- package/lib/library/EnableLibraryPlugin.js +7 -10
- package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
- package/lib/library/ModuleLibraryPlugin.js +121 -15
- package/lib/logging/Logger.js +2 -2
- package/lib/logging/createConsoleLogger.js +4 -4
- package/lib/node/NodeEnvironmentPlugin.js +6 -2
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +1 -2
- package/lib/node/ReadFileCompileWasmPlugin.js +1 -2
- package/lib/node/nodeConsole.js +3 -1
- package/lib/optimize/AggressiveSplittingPlugin.js +1 -1
- package/lib/optimize/ConcatenatedModule.js +19 -12
- package/lib/optimize/InnerGraph.js +3 -2
- package/lib/optimize/InnerGraphPlugin.js +13 -7
- package/lib/optimize/LimitChunkCountPlugin.js +20 -0
- package/lib/optimize/ModuleConcatenationPlugin.js +10 -7
- package/lib/optimize/RealContentHashPlugin.js +8 -4
- package/lib/optimize/SideEffectsFlagPlugin.js +4 -2
- package/lib/optimize/SplitChunksPlugin.js +87 -65
- package/lib/rules/BasicEffectRulePlugin.js +9 -1
- package/lib/rules/BasicMatcherRulePlugin.js +15 -4
- package/lib/rules/ObjectMatcherRulePlugin.js +12 -3
- package/lib/rules/RuleSetCompiler.js +25 -14
- package/lib/rules/UseEffectRulePlugin.js +47 -17
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +6 -6
- package/lib/schemes/HttpUriPlugin.js +38 -17
- package/lib/serialization/BinaryMiddleware.js +52 -19
- package/lib/serialization/FileMiddleware.js +78 -48
- package/lib/serialization/ObjectMiddleware.js +78 -29
- package/lib/serialization/PlainObjectSerializer.js +1 -1
- package/lib/serialization/Serializer.js +15 -10
- package/lib/serialization/SerializerMiddleware.js +80 -41
- package/lib/serialization/SingleItemMiddleware.js +10 -7
- package/lib/serialization/types.js +1 -1
- package/lib/sharing/ConsumeSharedModule.js +4 -2
- package/lib/sharing/ProvideSharedModule.js +4 -2
- package/lib/sharing/ProvideSharedModuleFactory.js +5 -3
- package/lib/sharing/utils.js +2 -2
- package/lib/stats/DefaultStatsFactoryPlugin.js +80 -78
- package/lib/stats/DefaultStatsPresetPlugin.js +43 -23
- package/lib/stats/DefaultStatsPrinterPlugin.js +85 -43
- package/lib/stats/StatsFactory.js +11 -11
- package/lib/stats/StatsPrinter.js +7 -7
- package/lib/util/ArrayHelpers.js +2 -4
- package/lib/util/ArrayQueue.js +1 -1
- package/lib/util/AsyncQueue.js +4 -4
- package/lib/util/IterableHelpers.js +1 -1
- package/lib/util/LazyBucketSortedSet.js +41 -23
- package/lib/util/LazySet.js +3 -2
- package/lib/util/MapHelpers.js +1 -1
- package/lib/util/ParallelismFactorCalculator.js +1 -1
- package/lib/util/Semaphore.js +3 -3
- package/lib/util/SetHelpers.js +1 -1
- package/lib/util/SortableSet.js +9 -7
- package/lib/util/TupleQueue.js +9 -8
- package/lib/util/TupleSet.js +2 -2
- package/lib/util/WeakTupleMap.js +12 -11
- package/lib/util/binarySearchBounds.js +2 -1
- package/lib/util/cleverMerge.js +84 -54
- package/lib/util/comparators.js +22 -21
- package/lib/util/compileBooleanMatcher.js +3 -3
- package/lib/util/concatenate.js +6 -4
- package/lib/util/create-schema-validation.js +4 -4
- package/lib/util/createHash.js +2 -2
- package/lib/util/deprecation.js +35 -33
- package/lib/util/deterministicGrouping.js +6 -6
- package/lib/util/findGraphRoots.js +1 -1
- package/lib/util/fs.js +39 -39
- package/lib/util/hash/wasm-hash.js +2 -2
- package/lib/util/identifier.js +15 -18
- package/lib/util/makeSerializable.js +1 -1
- package/lib/util/memoize.js +4 -1
- package/lib/util/objectToMap.js +3 -2
- package/lib/util/processAsyncTree.js +2 -2
- package/lib/util/propertyName.js +0 -1
- package/lib/util/registerExternalSerializer.js +15 -18
- package/lib/util/removeBOM.js +25 -0
- package/lib/util/runtime.js +34 -27
- package/lib/util/serialization.js +5 -16
- package/lib/util/smartGrouping.js +3 -3
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +3 -3
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +11 -0
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +10 -0
- package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +4 -0
- package/lib/wasm-sync/WebAssemblyGenerator.js +28 -12
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +10 -0
- package/lib/wasm-sync/WebAssemblyParser.js +9 -4
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -0
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +30 -25
- package/package.json +19 -17
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +48 -13
- package/schemas/plugins/JsonModulesPluginGenerator.check.d.ts +7 -0
- package/schemas/plugins/JsonModulesPluginGenerator.check.js +6 -0
- package/schemas/plugins/JsonModulesPluginGenerator.json +11 -0
- package/schemas/plugins/SourceMapDevToolPlugin.json +2 -2
- package/types.d.ts +918 -615
- package/lib/library/ModernModuleLibraryPlugin.js +0 -144
@@ -10,12 +10,25 @@ const SortableSet = require("./SortableSet");
|
|
10
10
|
|
11
11
|
/**
|
12
12
|
* @template T
|
13
|
-
* @
|
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
|
-
* @
|
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 {
|
36
|
-
* @param {
|
37
|
-
* @param
|
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
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
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
|
-
|
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 =
|
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 {
|
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 =
|
182
|
-
|
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 =
|
237
|
+
const nodeEntry =
|
238
|
+
/** @type {LazyBucketSortedSet<T, K>} */
|
239
|
+
(entry);
|
222
240
|
nodeEntry._appendIterators(iterators);
|
223
241
|
}
|
224
242
|
}
|
package/lib/util/LazySet.js
CHANGED
@@ -148,8 +148,9 @@ class LazySet {
|
|
148
148
|
}
|
149
149
|
|
150
150
|
/**
|
151
|
-
* @
|
152
|
-
* @param {
|
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) {
|
package/lib/util/MapHelpers.js
CHANGED
@@ -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 {
|
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
|
package/lib/util/Semaphore.js
CHANGED
@@ -13,14 +13,14 @@ class Semaphore {
|
|
13
13
|
*/
|
14
14
|
constructor(available) {
|
15
15
|
this.available = available;
|
16
|
-
/** @type {(
|
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 {
|
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 {(
|
45
|
+
const callback = /** @type {(() => void)} */ (this.waiters.pop());
|
46
46
|
callback();
|
47
47
|
}
|
48
48
|
}
|
package/lib/util/SetHelpers.js
CHANGED
@@ -54,7 +54,7 @@ const isSubset = (bigSet, smallSet) => {
|
|
54
54
|
/**
|
55
55
|
* @template T
|
56
56
|
* @param {Set<T>} set a set
|
57
|
-
* @param {
|
57
|
+
* @param {(set: T) => boolean} fn selector function
|
58
58
|
* @returns {T | undefined} found item
|
59
59
|
*/
|
60
60
|
const find = (set, fn) => {
|
package/lib/util/SortableSet.js
CHANGED
@@ -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 |
|
32
|
+
* @type {typeof NONE | undefined | ((a: T, b: T) => number)}}
|
33
33
|
*/
|
34
34
|
this._lastActiveSortFn = NONE;
|
35
35
|
/**
|
36
36
|
* @private
|
37
|
-
* @
|
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
|
-
* @
|
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 {
|
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 {
|
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) {
|
package/lib/util/TupleQueue.js
CHANGED
@@ -8,21 +8,22 @@
|
|
8
8
|
const TupleSet = require("./TupleSet");
|
9
9
|
|
10
10
|
/**
|
11
|
-
* @template
|
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(
|
63
|
+
this._set.delete(.../** @type {[T, V]} */ (result.value));
|
63
64
|
return result.value;
|
64
65
|
}
|
65
66
|
}
|
package/lib/util/TupleSet.js
CHANGED
@@ -24,7 +24,7 @@ class TupleSet {
|
|
24
24
|
}
|
25
25
|
|
26
26
|
/**
|
27
|
-
* @param
|
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
|
55
|
+
* @param {T} args tuple
|
56
56
|
* @returns {boolean} true, if the tuple is in the Set
|
57
57
|
*/
|
58
58
|
has(...args) {
|
package/lib/util/WeakTupleMap.js
CHANGED
@@ -6,18 +6,19 @@
|
|
6
6
|
"use strict";
|
7
7
|
|
8
8
|
/**
|
9
|
-
* @template
|
9
|
+
* @template T
|
10
10
|
* @template V
|
11
|
-
* @typedef {Map<
|
11
|
+
* @typedef {Map<EXPECTED_ANY, WeakTupleMap<T[], V>>} M
|
12
12
|
*/
|
13
|
+
|
13
14
|
/**
|
14
|
-
* @template
|
15
|
+
* @template T
|
15
16
|
* @template V
|
16
|
-
* @typedef {WeakMap<
|
17
|
+
* @typedef {WeakMap<EXPECTED_OBJECT, WeakTupleMap<T[], V>>} W
|
17
18
|
*/
|
18
19
|
|
19
20
|
/**
|
20
|
-
* @param {
|
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 {
|
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,
|
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 {
|
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 {
|
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 {
|
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 {
|
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);
|