webpack 5.101.2 → 5.102.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 +21 -26
- package/lib/APIPlugin.js +30 -36
- package/lib/AsyncDependenciesBlock.js +1 -4
- package/lib/BannerPlugin.js +0 -1
- package/lib/Cache.js +7 -6
- package/lib/CacheFacade.js +0 -1
- package/lib/Chunk.js +49 -31
- package/lib/ChunkGraph.js +35 -25
- package/lib/ChunkGroup.js +8 -10
- package/lib/ChunkTemplate.js +1 -1
- package/lib/CleanPlugin.js +3 -3
- package/lib/CodeGenerationResults.js +2 -1
- package/lib/CompatibilityPlugin.js +29 -12
- package/lib/Compilation.js +204 -185
- package/lib/Compiler.js +36 -35
- package/lib/ConcatenationScope.js +6 -1
- package/lib/ConditionalInitFragment.js +1 -1
- package/lib/ConstPlugin.js +18 -10
- package/lib/ContextExclusionPlugin.js +0 -1
- package/lib/ContextModule.js +22 -20
- package/lib/ContextModuleFactory.js +30 -11
- package/lib/ContextReplacementPlugin.js +38 -15
- package/lib/DefinePlugin.js +18 -8
- package/lib/DelegatedModule.js +7 -11
- package/lib/DependenciesBlock.js +0 -2
- package/lib/Dependency.js +9 -11
- package/lib/DependencyTemplates.js +1 -3
- package/lib/DllModule.js +1 -7
- package/lib/DllReferencePlugin.js +2 -4
- package/lib/DynamicEntryPlugin.js +0 -2
- package/lib/EntryOptionPlugin.js +0 -5
- package/lib/EnvironmentNotSupportAsyncWarning.js +0 -3
- package/lib/EvalDevToolModulePlugin.js +4 -3
- package/lib/EvalSourceMapDevToolPlugin.js +3 -4
- package/lib/ExportsInfo.js +50 -49
- package/lib/ExternalModule.js +84 -52
- package/lib/ExternalModuleFactoryPlugin.js +27 -7
- package/lib/ExternalsPlugin.js +24 -17
- package/lib/FileSystemInfo.js +96 -78
- package/lib/FlagDependencyUsagePlugin.js +3 -4
- package/lib/Generator.js +2 -13
- package/lib/GraphHelpers.js +0 -3
- package/lib/HookWebpackError.js +0 -2
- package/lib/HotModuleReplacementPlugin.js +22 -24
- package/lib/HotUpdateChunk.js +0 -3
- package/lib/IgnorePlugin.js +5 -2
- package/lib/InitFragment.js +41 -29
- package/lib/InvalidDependenciesModuleWarning.js +0 -1
- package/lib/LibManifestPlugin.js +4 -6
- package/lib/LoaderOptionsPlugin.js +1 -10
- package/lib/MainTemplate.js +8 -19
- package/lib/Module.js +32 -20
- package/lib/ModuleFactory.js +1 -1
- package/lib/ModuleFilenameHelpers.js +41 -24
- package/lib/ModuleGraph.js +30 -16
- package/lib/ModuleInfoHeaderPlugin.js +0 -1
- package/lib/ModuleTemplate.js +0 -2
- package/lib/ModuleTypeConstants.js +11 -1
- package/lib/MultiCompiler.js +23 -15
- package/lib/MultiWatching.js +6 -10
- package/lib/NodeStuffPlugin.js +2 -10
- package/lib/NormalModule.js +145 -88
- package/lib/NormalModuleFactory.js +59 -40
- package/lib/OptionsApply.js +1 -1
- package/lib/Parser.js +1 -1
- package/lib/ProgressPlugin.js +6 -10
- package/lib/ProvidePlugin.js +5 -7
- package/lib/RawModule.js +1 -6
- package/lib/RecordIdsPlugin.js +10 -6
- package/lib/ResolverFactory.js +0 -2
- package/lib/RuntimeGlobals.js +5 -0
- package/lib/RuntimeModule.js +1 -3
- package/lib/RuntimePlugin.js +26 -22
- package/lib/RuntimeTemplate.js +12 -11
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +2 -2
- package/lib/SourceMapDevToolPlugin.js +6 -11
- package/lib/Stats.js +0 -1
- package/lib/Template.js +6 -11
- package/lib/TemplatedPathPlugin.js +2 -1
- package/lib/WatchIgnorePlugin.js +2 -3
- package/lib/Watching.js +15 -15
- package/lib/WebpackIsIncludedPlugin.js +0 -2
- package/lib/WebpackOptionsApply.js +74 -107
- package/lib/asset/AssetBytesGenerator.js +166 -0
- package/lib/asset/AssetBytesParser.js +37 -0
- package/lib/asset/AssetGenerator.js +20 -34
- package/lib/asset/AssetModulesPlugin.js +34 -16
- package/lib/asset/AssetParser.js +7 -3
- package/lib/asset/AssetSourceGenerator.js +1 -1
- package/lib/asset/RawDataUrlModule.js +3 -2
- package/lib/async-modules/AsyncModuleHelpers.js +6 -4
- package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -1
- package/lib/buildChunkGraph.js +0 -1
- package/lib/cache/MemoryCachePlugin.js +0 -2
- package/lib/cache/MemoryWithGcCachePlugin.js +0 -2
- package/lib/cache/PackFileCacheStrategy.js +14 -1
- package/lib/cache/ResolverCachePlugin.js +9 -15
- package/lib/config/defaults.js +155 -21
- package/lib/config/normalization.js +18 -3
- package/lib/container/ContainerEntryDependency.js +0 -1
- package/lib/container/ContainerEntryModule.js +3 -7
- package/lib/container/ContainerPlugin.js +1 -2
- package/lib/container/ContainerReferencePlugin.js +0 -1
- package/lib/container/FallbackDependency.js +2 -1
- package/lib/container/FallbackModule.js +6 -7
- package/lib/container/ModuleFederationPlugin.js +0 -1
- package/lib/container/RemoteModule.js +8 -8
- package/lib/container/RemoteRuntimeModule.js +2 -2
- package/lib/css/CssGenerator.js +3 -6
- package/lib/css/CssLoadingRuntimeModule.js +6 -9
- package/lib/css/CssModulesPlugin.js +11 -13
- package/lib/css/CssParser.js +3 -3
- package/lib/css/walkCssTokens.js +1 -1
- package/lib/debug/ProfilingPlugin.js +35 -8
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +12 -17
- package/lib/dependencies/AMDPlugin.js +2 -2
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +1 -2
- package/lib/dependencies/CachedConstDependency.js +0 -4
- package/lib/dependencies/CommonJsExportRequireDependency.js +20 -14
- package/lib/dependencies/CommonJsExportsDependency.js +2 -1
- package/lib/dependencies/CommonJsExportsParserPlugin.js +20 -5
- package/lib/dependencies/CommonJsFullRequireDependency.js +6 -4
- package/lib/dependencies/CommonJsImportsParserPlugin.js +16 -7
- package/lib/dependencies/CommonJsRequireContextDependency.js +1 -1
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +4 -4
- package/lib/dependencies/ConstDependency.js +2 -2
- package/lib/dependencies/ContextDependency.js +9 -4
- package/lib/dependencies/ContextDependencyHelpers.js +2 -2
- package/lib/dependencies/ContextDependencyTemplateAsId.js +9 -9
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +9 -9
- package/lib/dependencies/ContextElementDependency.js +22 -11
- package/lib/dependencies/CssIcssImportDependency.js +0 -2
- package/lib/dependencies/CssIcssSymbolDependency.js +2 -2
- package/lib/dependencies/CssImportDependency.js +0 -8
- package/lib/dependencies/CssLocalIdentifierDependency.js +3 -4
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +2 -2
- package/lib/dependencies/CssUrlDependency.js +0 -6
- package/lib/dependencies/ExportsInfoDependency.js +7 -9
- package/lib/dependencies/ExternalModuleDependency.js +0 -3
- package/lib/dependencies/ExternalModuleInitFragment.js +1 -1
- package/lib/dependencies/HarmonyAcceptDependency.js +1 -1
- package/lib/dependencies/HarmonyAcceptImportDependency.js +0 -4
- package/lib/dependencies/HarmonyCompatibilityDependency.js +0 -1
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +0 -14
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +3 -3
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +4 -1
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +29 -35
- package/lib/dependencies/HarmonyImportDependency.js +30 -14
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +38 -24
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +0 -4
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +46 -31
- package/lib/dependencies/HarmonyModulesPlugin.js +3 -3
- package/lib/dependencies/ImportDependency.js +18 -6
- package/lib/dependencies/ImportEagerDependency.js +2 -3
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +8 -5
- package/lib/dependencies/ImportMetaContextPlugin.js +0 -1
- package/lib/dependencies/ImportMetaPlugin.js +8 -1
- package/lib/dependencies/ImportParserPlugin.js +294 -45
- package/lib/dependencies/ImportWeakDependency.js +2 -3
- package/lib/dependencies/JsonExportsDependency.js +0 -1
- package/lib/dependencies/LoaderDependency.js +0 -3
- package/lib/dependencies/LoaderImportDependency.js +0 -3
- package/lib/dependencies/LoaderPlugin.js +11 -5
- package/lib/dependencies/ModuleDecoratorDependency.js +2 -4
- package/lib/dependencies/ModuleDependency.js +3 -9
- package/lib/dependencies/NullDependency.js +2 -0
- package/lib/dependencies/ProvidedDependency.js +6 -8
- package/lib/dependencies/PureExpressionDependency.js +0 -1
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +0 -1
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +1 -2
- package/lib/dependencies/RequireIncludeDependency.js +2 -2
- package/lib/dependencies/RequireResolveDependency.js +2 -2
- package/lib/dependencies/RuntimeRequirementsDependency.js +2 -3
- package/lib/dependencies/StaticExportsDependency.js +3 -5
- package/lib/dependencies/URLDependency.js +2 -7
- package/lib/dependencies/URLPlugin.js +1 -2
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +2 -2
- package/lib/dependencies/WebAssemblyImportDependency.js +2 -2
- package/lib/dependencies/WebpackIsIncludedDependency.js +2 -3
- package/lib/dependencies/WorkerDependency.js +2 -3
- package/lib/dependencies/WorkerPlugin.js +3 -9
- package/lib/dependencies/processExportInfo.js +2 -3
- package/lib/esm/ModuleChunkFormatPlugin.js +0 -3
- package/lib/esm/ModuleChunkLoadingPlugin.js +2 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +7 -7
- package/lib/hmr/LazyCompilationPlugin.js +6 -4
- package/lib/hmr/lazyCompilationBackend.js +13 -10
- package/lib/ids/DeterministicChunkIdsPlugin.js +0 -1
- package/lib/ids/NamedChunkIdsPlugin.js +1 -6
- package/lib/ids/NamedModuleIdsPlugin.js +1 -5
- package/lib/ids/NaturalChunkIdsPlugin.js +0 -1
- package/lib/ids/NaturalModuleIdsPlugin.js +0 -1
- package/lib/ids/OccurrenceChunkIdsPlugin.js +0 -1
- package/lib/ids/OccurrenceModuleIdsPlugin.js +0 -1
- package/lib/ids/SyncModuleIdsPlugin.js +4 -3
- package/lib/index.js +8 -7
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +4 -1
- package/lib/javascript/BasicEvaluatedExpression.js +13 -6
- package/lib/javascript/ChunkFormatHelpers.js +1 -1
- package/lib/javascript/CommonJsChunkFormatPlugin.js +0 -1
- package/lib/javascript/JavascriptGenerator.js +2 -3
- package/lib/javascript/JavascriptModulesPlugin.js +44 -21
- package/lib/javascript/JavascriptParser.js +159 -93
- package/lib/javascript/JavascriptParserHelpers.js +2 -2
- package/lib/javascript/StartupHelpers.js +2 -4
- package/lib/json/JsonData.js +1 -1
- package/lib/json/JsonGenerator.js +4 -5
- package/lib/json/JsonModulesPlugin.js +0 -3
- package/lib/json/JsonParser.js +4 -2
- package/lib/library/AbstractLibraryPlugin.js +2 -2
- package/lib/library/AmdLibraryPlugin.js +0 -1
- package/lib/library/AssignLibraryPlugin.js +23 -12
- package/lib/library/EnableLibraryPlugin.js +7 -11
- package/lib/library/ExportPropertyLibraryPlugin.js +8 -20
- package/lib/library/JsonpLibraryPlugin.js +5 -2
- package/lib/library/ModuleLibraryPlugin.js +88 -43
- package/lib/library/SystemLibraryPlugin.js +0 -1
- package/lib/library/UmdLibraryPlugin.js +12 -18
- package/lib/logging/Logger.js +12 -10
- package/lib/logging/createConsoleLogger.js +15 -14
- package/lib/logging/truncateArgs.js +1 -1
- package/lib/node/CommonJsChunkLoadingPlugin.js +2 -1
- package/lib/node/NodeWatchFileSystem.js +4 -4
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -2
- package/lib/node/RequireChunkLoadingRuntimeModule.js +5 -2
- package/lib/node/nodeConsole.js +2 -2
- package/lib/optimize/AggressiveSplittingPlugin.js +2 -0
- package/lib/optimize/ConcatenatedModule.js +142 -100
- package/lib/optimize/InnerGraph.js +17 -11
- package/lib/optimize/InnerGraphPlugin.js +0 -3
- package/lib/optimize/ModuleConcatenationPlugin.js +3 -4
- package/lib/optimize/RuntimeChunkPlugin.js +0 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +3 -10
- package/lib/optimize/SplitChunksPlugin.js +46 -40
- package/lib/performance/SizeLimitsPlugin.js +2 -1
- package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +5 -7
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +0 -2
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +0 -1
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +2 -2
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +2 -2
- package/lib/rules/BasicMatcherRulePlugin.js +0 -2
- package/lib/rules/ObjectMatcherRulePlugin.js +0 -1
- package/lib/rules/RuleSetCompiler.js +8 -6
- package/lib/runtime/BaseUriRuntimeModule.js +2 -2
- package/lib/runtime/CompatRuntimeModule.js +0 -1
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +8 -9
- package/lib/runtime/LoadScriptRuntimeModule.js +0 -2
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +1 -1
- package/lib/runtime/PublicPathRuntimeModule.js +2 -2
- package/lib/runtime/StartupEntrypointRuntimeModule.js +0 -1
- package/lib/runtime/SystemContextRuntimeModule.js +0 -2
- package/lib/runtime/ToBinaryRuntimeModule.js +64 -0
- package/lib/schemes/DataUriPlugin.js +2 -28
- package/lib/schemes/FileUriPlugin.js +5 -2
- package/lib/schemes/HttpUriPlugin.js +4 -2
- package/lib/schemes/VirtualUrlPlugin.js +11 -11
- package/lib/serialization/NullPrototypeObjectSerializer.js +5 -3
- package/lib/serialization/ObjectMiddleware.js +30 -19
- package/lib/serialization/SerializerMiddleware.js +1 -3
- package/lib/serialization/types.js +1 -1
- package/lib/sharing/ConsumeSharedModule.js +3 -5
- package/lib/sharing/ConsumeSharedPlugin.js +2 -4
- package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -6
- package/lib/sharing/ProvideSharedModule.js +3 -7
- package/lib/sharing/SharePlugin.js +0 -2
- package/lib/sharing/ShareRuntimeModule.js +4 -1
- package/lib/sharing/resolveMatchedConfigs.js +14 -6
- package/lib/sharing/utils.js +0 -6
- package/lib/stats/DefaultStatsFactoryPlugin.js +178 -94
- package/lib/stats/DefaultStatsPresetPlugin.js +15 -9
- package/lib/stats/DefaultStatsPrinterPlugin.js +77 -113
- package/lib/stats/StatsFactory.js +14 -11
- package/lib/url/URLParserPlugin.js +2 -4
- package/lib/util/ArrayHelpers.js +4 -4
- package/lib/util/AsyncQueue.js +1 -0
- package/lib/util/LazySet.js +2 -2
- package/lib/util/StackedCacheMap.js +0 -2
- package/lib/util/TupleSet.js +9 -4
- package/lib/util/URLAbsoluteSpecifier.js +0 -1
- package/lib/util/WeakTupleMap.js +1 -1
- package/lib/util/chainedImports.js +3 -1
- package/lib/util/cleverMerge.js +15 -18
- package/lib/util/comparators.js +2 -4
- package/lib/util/compileBooleanMatcher.js +11 -9
- package/lib/util/concatenate.js +1 -2
- package/lib/util/create-schema-validation.js +0 -1
- package/lib/util/dataURL.js +39 -0
- package/lib/util/deprecation.js +29 -31
- package/lib/util/deterministicGrouping.js +34 -30
- package/lib/util/extractSourceMap.js +319 -0
- package/lib/util/findGraphRoots.js +15 -5
- package/lib/util/fs.js +29 -8
- package/lib/util/semver.js +9 -8
- package/lib/util/smartGrouping.js +41 -26
- package/lib/util/traverseDestructuringAssignmentProperties.js +45 -0
- package/lib/wasm/EnableWasmLoadingPlugin.js +3 -2
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +5 -1
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +2 -13
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +2 -9
- package/lib/wasm-async/AsyncWebAssemblyParser.js +2 -1
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +6 -4
- package/lib/wasm-sync/WebAssemblyGenerator.js +1 -3
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +1 -4
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +2 -7
- package/lib/wasm-sync/WebAssemblyParser.js +1 -4
- package/lib/web/JsonpChunkLoadingPlugin.js +2 -1
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -1
- package/lib/web/JsonpTemplatePlugin.js +0 -1
- package/lib/webpack.js +21 -8
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +2 -1
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +1 -1
- package/package.json +13 -13
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +77 -93
- package/schemas/plugins/BannerPlugin.check.js +1 -1
- package/schemas/plugins/BannerPlugin.json +4 -0
- package/schemas/plugins/IgnorePlugin.json +1 -1
- package/schemas/plugins/ProgressPlugin.json +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.json +5 -1
- package/schemas/plugins/schemes/VirtualUrlPlugin.json +3 -3
- package/types.d.ts +1140 -505
- package/SECURITY.md +0 -9
package/lib/util/cleverMerge.js
CHANGED
|
@@ -92,7 +92,7 @@ const cachedSetProperty = (obj, property, value) => {
|
|
|
92
92
|
* @template T
|
|
93
93
|
* @typedef {object} ObjectParsedPropertyEntry
|
|
94
94
|
* @property {T[keyof T] | undefined} base base value
|
|
95
|
-
* @property {string | undefined} byProperty the name of the selector property
|
|
95
|
+
* @property {`by${string}` | undefined} byProperty the name of the selector property
|
|
96
96
|
* @property {ByValues | undefined} byValues value depending on selector property, merged with base
|
|
97
97
|
*/
|
|
98
98
|
|
|
@@ -105,7 +105,7 @@ const cachedSetProperty = (obj, property, value) => {
|
|
|
105
105
|
|
|
106
106
|
/**
|
|
107
107
|
* @template {object} T
|
|
108
|
-
* @typedef {{ byProperty: string
|
|
108
|
+
* @typedef {{ byProperty: `by${string}`, fn: DynamicFunction }} ParsedObjectDynamic
|
|
109
109
|
*/
|
|
110
110
|
|
|
111
111
|
/**
|
|
@@ -169,7 +169,7 @@ const parseObject = (obj) => {
|
|
|
169
169
|
for (const key of Object.keys(obj)) {
|
|
170
170
|
const entry = getInfo(/** @type {keyof T} */ (key));
|
|
171
171
|
if (entry.byProperty === undefined) {
|
|
172
|
-
entry.byProperty = byProperty;
|
|
172
|
+
entry.byProperty = /** @type {`by${string}`} */ (byProperty);
|
|
173
173
|
entry.byValues = new Map();
|
|
174
174
|
} else if (entry.byProperty !== byProperty) {
|
|
175
175
|
throw new Error(
|
|
@@ -196,7 +196,7 @@ const parseObject = (obj) => {
|
|
|
196
196
|
} else if (typeof byObj === "function") {
|
|
197
197
|
if (dynamicInfo === undefined) {
|
|
198
198
|
dynamicInfo = {
|
|
199
|
-
byProperty: key,
|
|
199
|
+
byProperty: /** @type {`by${string}`} */ (key),
|
|
200
200
|
fn: byObj
|
|
201
201
|
};
|
|
202
202
|
} else {
|
|
@@ -222,17 +222,16 @@ const parseObject = (obj) => {
|
|
|
222
222
|
/**
|
|
223
223
|
* @template {object} T
|
|
224
224
|
* @param {ParsedObjectStatic<T>} info static properties (key is property name)
|
|
225
|
-
* @param {{ byProperty: string
|
|
225
|
+
* @param {{ byProperty: `by${string}`, fn: DynamicFunction } | undefined} dynamicInfo dynamic part
|
|
226
226
|
* @returns {T} the object
|
|
227
227
|
*/
|
|
228
228
|
const serializeObject = (info, dynamicInfo) => {
|
|
229
|
-
const obj = /** @type {
|
|
229
|
+
const obj = /** @type {EXPECTED_ANY} */ ({});
|
|
230
230
|
// Setup byProperty structure
|
|
231
231
|
for (const entry of info.values()) {
|
|
232
232
|
if (entry.byProperty !== undefined) {
|
|
233
|
-
const byProperty =
|
|
234
|
-
const byObj = (obj[byProperty] =
|
|
235
|
-
obj[byProperty] || /** @type {TODO} */ ({}));
|
|
233
|
+
const byProperty = entry.byProperty;
|
|
234
|
+
const byObj = (obj[byProperty] = obj[byProperty] || {});
|
|
236
235
|
for (const byValue of /** @type {ByValues} */ (entry.byValues).keys()) {
|
|
237
236
|
byObj[byValue] = byObj[byValue] || {};
|
|
238
237
|
}
|
|
@@ -240,13 +239,12 @@ const serializeObject = (info, dynamicInfo) => {
|
|
|
240
239
|
}
|
|
241
240
|
for (const [key, entry] of info) {
|
|
242
241
|
if (entry.base !== undefined) {
|
|
243
|
-
obj[
|
|
242
|
+
obj[key] = entry.base;
|
|
244
243
|
}
|
|
245
244
|
// Fill byProperty structure
|
|
246
245
|
if (entry.byProperty !== undefined) {
|
|
247
|
-
const byProperty =
|
|
248
|
-
const byObj = (obj[byProperty] =
|
|
249
|
-
obj[byProperty] || /** @type {TODO} */ ({}));
|
|
246
|
+
const byProperty = entry.byProperty;
|
|
247
|
+
const byObj = (obj[byProperty] = obj[byProperty] || {});
|
|
250
248
|
for (const byValue of Object.keys(byObj)) {
|
|
251
249
|
const value = getFromByValues(
|
|
252
250
|
/** @type {ByValues} */
|
|
@@ -258,8 +256,7 @@ const serializeObject = (info, dynamicInfo) => {
|
|
|
258
256
|
}
|
|
259
257
|
}
|
|
260
258
|
if (dynamicInfo !== undefined) {
|
|
261
|
-
|
|
262
|
-
(obj)[dynamicInfo.byProperty] = dynamicInfo.fn;
|
|
259
|
+
obj[dynamicInfo.byProperty] = dynamicInfo.fn;
|
|
263
260
|
}
|
|
264
261
|
return obj;
|
|
265
262
|
};
|
|
@@ -384,7 +381,7 @@ const _cleverMerge = (first, second, internalCaching = false) => {
|
|
|
384
381
|
* @param {ObjectParsedPropertyEntry<T>} firstEntry a
|
|
385
382
|
* @param {ObjectParsedPropertyEntry<O>} secondEntry b
|
|
386
383
|
* @param {boolean} internalCaching should parsing of objects and nested merges be cached
|
|
387
|
-
* @returns {ObjectParsedPropertyEntry<
|
|
384
|
+
* @returns {ObjectParsedPropertyEntry<T> | ObjectParsedPropertyEntry<O> | ObjectParsedPropertyEntry<T & O>} new entry
|
|
388
385
|
*/
|
|
389
386
|
const mergeEntries = (firstEntry, secondEntry, internalCaching) => {
|
|
390
387
|
switch (getValueType(secondEntry.base)) {
|
|
@@ -479,7 +476,7 @@ const mergeEntries = (firstEntry, secondEntry, internalCaching) => {
|
|
|
479
476
|
if (!secondEntry.byProperty) {
|
|
480
477
|
// = first.base + (first.byProperty + second.base)
|
|
481
478
|
return {
|
|
482
|
-
base: newBase,
|
|
479
|
+
base: /** @type {T[keyof T] & O[keyof O]} */ (newBase),
|
|
483
480
|
byProperty: firstEntry.byProperty,
|
|
484
481
|
byValues: intermediateByValues
|
|
485
482
|
};
|
|
@@ -499,7 +496,7 @@ const mergeEntries = (firstEntry, secondEntry, internalCaching) => {
|
|
|
499
496
|
);
|
|
500
497
|
}
|
|
501
498
|
return {
|
|
502
|
-
base: newBase,
|
|
499
|
+
base: /** @type {T[keyof T] & O[keyof O]} */ (newBase),
|
|
503
500
|
byProperty: firstEntry.byProperty,
|
|
504
501
|
byValues: newByValues
|
|
505
502
|
};
|
package/lib/util/comparators.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
const { compareRuntime } = require("./runtime");
|
|
9
9
|
|
|
10
10
|
/** @typedef {import("../Chunk")} Chunk */
|
|
11
|
+
/** @typedef {import("../Chunk").ChunkName} ChunkName */
|
|
11
12
|
/** @typedef {import("../Chunk").ChunkId} ChunkId */
|
|
12
13
|
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
|
13
14
|
/** @typedef {import("../ChunkGraph").ModuleId} ModuleId */
|
|
@@ -490,10 +491,7 @@ const compareChunksNatural = (chunkGraph) => {
|
|
|
490
491
|
const cmpFn = module.exports.compareModulesById(chunkGraph);
|
|
491
492
|
const cmpIterableFn = compareIterables(cmpFn);
|
|
492
493
|
return concatComparators(
|
|
493
|
-
compareSelect(
|
|
494
|
-
(chunk) => /** @type {string|number} */ (chunk.name),
|
|
495
|
-
compareIds
|
|
496
|
-
),
|
|
494
|
+
compareSelect((chunk) => /** @type {ChunkName} */ (chunk.name), compareIds),
|
|
497
495
|
compareSelect((chunk) => chunk.runtime, compareRuntime),
|
|
498
496
|
compareSelect(
|
|
499
497
|
/**
|
|
@@ -56,28 +56,30 @@ const compileBooleanMatcherFromLists = (positiveItems, negativeItems) => {
|
|
|
56
56
|
return (value) => `!/^${negativeRegexp}$/.test(${value})`;
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
+
/** @typedef {string[][]} ListOfCommonItems */
|
|
60
|
+
|
|
59
61
|
/**
|
|
60
62
|
* @param {Set<string>} itemsSet items set
|
|
61
63
|
* @param {(str: string) => string | false} getKey get key function
|
|
62
|
-
* @param {(str:
|
|
63
|
-
* @returns {
|
|
64
|
+
* @param {(str: string[]) => boolean} condition condition
|
|
65
|
+
* @returns {ListOfCommonItems} list of common items
|
|
64
66
|
*/
|
|
65
67
|
const popCommonItems = (itemsSet, getKey, condition) => {
|
|
66
|
-
/** @type {Map<string,
|
|
68
|
+
/** @type {Map<string, string[]>} */
|
|
67
69
|
const map = new Map();
|
|
68
70
|
for (const item of itemsSet) {
|
|
69
71
|
const key = getKey(item);
|
|
70
72
|
if (key) {
|
|
71
73
|
let list = map.get(key);
|
|
72
74
|
if (list === undefined) {
|
|
73
|
-
/** @type {
|
|
75
|
+
/** @type {string[]} */
|
|
74
76
|
list = [];
|
|
75
77
|
map.set(key, list);
|
|
76
78
|
}
|
|
77
79
|
list.push(item);
|
|
78
80
|
}
|
|
79
81
|
}
|
|
80
|
-
/** @type {
|
|
82
|
+
/** @type {ListOfCommonItems} */
|
|
81
83
|
const result = [];
|
|
82
84
|
for (const list of map.values()) {
|
|
83
85
|
if (condition(list)) {
|
|
@@ -91,7 +93,7 @@ const popCommonItems = (itemsSet, getKey, condition) => {
|
|
|
91
93
|
};
|
|
92
94
|
|
|
93
95
|
/**
|
|
94
|
-
* @param {
|
|
96
|
+
* @param {string[]} items items
|
|
95
97
|
* @returns {string} common prefix
|
|
96
98
|
*/
|
|
97
99
|
const getCommonPrefix = (items) => {
|
|
@@ -109,7 +111,7 @@ const getCommonPrefix = (items) => {
|
|
|
109
111
|
};
|
|
110
112
|
|
|
111
113
|
/**
|
|
112
|
-
* @param {
|
|
114
|
+
* @param {string[]} items items
|
|
113
115
|
* @returns {string} common suffix
|
|
114
116
|
*/
|
|
115
117
|
const getCommonSuffix = (items) => {
|
|
@@ -127,14 +129,14 @@ const getCommonSuffix = (items) => {
|
|
|
127
129
|
};
|
|
128
130
|
|
|
129
131
|
/**
|
|
130
|
-
* @param {
|
|
132
|
+
* @param {string[]} itemsArr array of items
|
|
131
133
|
* @returns {string} regexp
|
|
132
134
|
*/
|
|
133
135
|
const itemsToRegexp = (itemsArr) => {
|
|
134
136
|
if (itemsArr.length === 1) {
|
|
135
137
|
return quoteMeta(itemsArr[0]);
|
|
136
138
|
}
|
|
137
|
-
/** @type {
|
|
139
|
+
/** @type {string[]} */
|
|
138
140
|
const finishedItems = [];
|
|
139
141
|
|
|
140
142
|
// merge single char items: (a|b|c|d|ef) => ([abcd]|ef)
|
package/lib/util/concatenate.js
CHANGED
|
@@ -12,7 +12,6 @@ const Template = require("../Template");
|
|
|
12
12
|
/** @typedef {import("eslint-scope").Variable} Variable */
|
|
13
13
|
/** @typedef {import("estree").Node} Node */
|
|
14
14
|
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
|
15
|
-
/** @typedef {import("../javascript/JavascriptParser").Program} Program */
|
|
16
15
|
/** @typedef {Set<string>} UsedNames */
|
|
17
16
|
|
|
18
17
|
const DEFAULT_EXPORT = "__WEBPACK_DEFAULT_EXPORT__";
|
|
@@ -72,7 +71,7 @@ const getPathInAst = (ast, node) => {
|
|
|
72
71
|
}
|
|
73
72
|
} else if (ast && typeof ast === "object") {
|
|
74
73
|
const keys =
|
|
75
|
-
/** @type {
|
|
74
|
+
/** @type {(keyof Node)[]} */
|
|
76
75
|
(Object.keys(ast));
|
|
77
76
|
for (let i = 0; i < keys.length; i++) {
|
|
78
77
|
// We are making the faster check in `enterNode` using `n.range`
|
|
@@ -9,7 +9,6 @@ const memoize = require("./memoize");
|
|
|
9
9
|
|
|
10
10
|
/** @typedef {import("schema-utils").Schema} Schema */
|
|
11
11
|
/** @typedef {import("schema-utils/declarations/validate").ValidationErrorConfiguration} ValidationErrorConfiguration */
|
|
12
|
-
/** @typedef {import("./fs").JsonObject} JsonObject */
|
|
13
12
|
|
|
14
13
|
const getValidate = memoize(() => require("schema-utils").validate);
|
|
15
14
|
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Natsu @xiaoxiaojx
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
// data URL scheme: "data:text/javascript;charset=utf-8;base64,some-string"
|
|
9
|
+
// http://www.ietf.org/rfc/rfc2397.txt
|
|
10
|
+
const URIRegEx = /^data:([^;,]+)?((?:;[^;,]+)*?)(?:;(base64)?)?,(.*)$/i;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @param {string} uri data URI
|
|
14
|
+
* @returns {Buffer | null} decoded data
|
|
15
|
+
*/
|
|
16
|
+
const decodeDataURI = (uri) => {
|
|
17
|
+
const match = URIRegEx.exec(uri);
|
|
18
|
+
if (!match) return null;
|
|
19
|
+
|
|
20
|
+
const isBase64 = match[3];
|
|
21
|
+
const body = match[4];
|
|
22
|
+
|
|
23
|
+
if (isBase64) {
|
|
24
|
+
return Buffer.from(body, "base64");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// CSS allows to use `data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg"><rect width="100%" height="100%" style="stroke: rgb(223,224,225); stroke-width: 2px; fill: none; stroke-dasharray: 6px 3px" /></svg>`
|
|
28
|
+
// so we return original body if we can't `decodeURIComponent`
|
|
29
|
+
try {
|
|
30
|
+
return Buffer.from(decodeURIComponent(body), "ascii");
|
|
31
|
+
} catch (_) {
|
|
32
|
+
return Buffer.from(body, "ascii");
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
module.exports = {
|
|
37
|
+
URIRegEx,
|
|
38
|
+
decodeDataURI
|
|
39
|
+
};
|
package/lib/util/deprecation.js
CHANGED
|
@@ -75,38 +75,37 @@ const DISABLED_METHODS = [
|
|
|
75
75
|
|
|
76
76
|
/**
|
|
77
77
|
* @template T
|
|
78
|
-
* @typedef {Set<T> & {[Symbol.isConcatSpreadable]
|
|
78
|
+
* @typedef {Set<T> & { [Symbol.isConcatSpreadable]: boolean } & { push: (...items: T[]) => void, length?: number } & { [P in DISABLED_METHODS_NAMES]: () => void } & { [P in COPY_METHODS_NAMES]: P extends keyof Array<T> ? () => Pick<Array<T>, P> : never }} SetWithDeprecatedArrayMethods
|
|
79
79
|
*/
|
|
80
80
|
|
|
81
81
|
/**
|
|
82
82
|
* @template T
|
|
83
|
-
* @param {
|
|
83
|
+
* @param {Set<T>} set new set
|
|
84
84
|
* @param {string} name property name
|
|
85
85
|
* @returns {void}
|
|
86
86
|
*/
|
|
87
87
|
module.exports.arrayToSetDeprecation = (set, name) => {
|
|
88
88
|
for (const method of COPY_METHODS) {
|
|
89
|
-
if (set[method]) continue;
|
|
89
|
+
if (/** @type {SetWithDeprecatedArrayMethods<T>} */ (set)[method]) continue;
|
|
90
90
|
const d = createDeprecation(
|
|
91
91
|
`${name} was changed from Array to Set (using Array method '${method}' is deprecated)`,
|
|
92
92
|
"ARRAY_TO_SET"
|
|
93
93
|
);
|
|
94
|
-
/**
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
};
|
|
94
|
+
/** @type {EXPECTED_ANY} */
|
|
95
|
+
(set)[method] =
|
|
96
|
+
// eslint-disable-next-line func-names
|
|
97
|
+
function () {
|
|
98
|
+
d();
|
|
99
|
+
// eslint-disable-next-line unicorn/prefer-spread
|
|
100
|
+
const array = Array.from(this);
|
|
101
|
+
return Array.prototype[
|
|
102
|
+
/** @type {keyof COPY_METHODS} */ (method)
|
|
103
|
+
].apply(
|
|
104
|
+
array,
|
|
105
|
+
// eslint-disable-next-line prefer-rest-params
|
|
106
|
+
arguments
|
|
107
|
+
);
|
|
108
|
+
};
|
|
110
109
|
}
|
|
111
110
|
const dPush = createDeprecation(
|
|
112
111
|
`${name} was changed from Array to Set (using Array method 'push' is deprecated)`,
|
|
@@ -120,12 +119,8 @@ module.exports.arrayToSetDeprecation = (set, name) => {
|
|
|
120
119
|
`${name} was changed from Array to Set (indexing Array is deprecated)`,
|
|
121
120
|
"ARRAY_TO_SET_INDEXER"
|
|
122
121
|
);
|
|
123
|
-
/**
|
|
124
|
-
|
|
125
|
-
* @this {Set<T>}
|
|
126
|
-
* @returns {number} count
|
|
127
|
-
*/
|
|
128
|
-
set.push = function push() {
|
|
122
|
+
/** @type {SetWithDeprecatedArrayMethods<T>} */
|
|
123
|
+
(set).push = function push() {
|
|
129
124
|
dPush();
|
|
130
125
|
// eslint-disable-next-line prefer-rest-params, unicorn/prefer-spread
|
|
131
126
|
for (const item of Array.from(arguments)) {
|
|
@@ -134,9 +129,10 @@ module.exports.arrayToSetDeprecation = (set, name) => {
|
|
|
134
129
|
return this.size;
|
|
135
130
|
};
|
|
136
131
|
for (const method of DISABLED_METHODS) {
|
|
137
|
-
if (set[method]) continue;
|
|
132
|
+
if (/** @type {SetWithDeprecatedArrayMethods<T>} */ (set)[method]) continue;
|
|
138
133
|
|
|
139
|
-
|
|
134
|
+
/** @type {SetWithDeprecatedArrayMethods<T>} */
|
|
135
|
+
(set)[method] = () => {
|
|
140
136
|
throw new Error(
|
|
141
137
|
`${name} was changed from Array to Set (using Array method '${method}' is not possible)`
|
|
142
138
|
);
|
|
@@ -191,13 +187,14 @@ module.exports.arrayToSetDeprecation = (set, name) => {
|
|
|
191
187
|
);
|
|
192
188
|
}
|
|
193
189
|
});
|
|
194
|
-
|
|
190
|
+
/** @type {SetWithDeprecatedArrayMethods<T>} */
|
|
191
|
+
(set)[Symbol.isConcatSpreadable] = true;
|
|
195
192
|
};
|
|
196
193
|
|
|
197
194
|
/**
|
|
198
195
|
* @template T
|
|
199
196
|
* @param {string} name name
|
|
200
|
-
* @returns {{ new <T = any>(values?:
|
|
197
|
+
* @returns {{ new <T = any>(values?: ReadonlyArray<T> | null): SetDeprecatedArray<T> }} SetDeprecatedArray
|
|
201
198
|
*/
|
|
202
199
|
module.exports.createArrayToSetDeprecationSet = (name) => {
|
|
203
200
|
let initialized = false;
|
|
@@ -207,14 +204,15 @@ module.exports.createArrayToSetDeprecationSet = (name) => {
|
|
|
207
204
|
*/
|
|
208
205
|
class SetDeprecatedArray extends Set {
|
|
209
206
|
/**
|
|
210
|
-
* @param {
|
|
207
|
+
* @param {ReadonlyArray<T> | null=} items items
|
|
211
208
|
*/
|
|
212
209
|
constructor(items) {
|
|
213
210
|
super(items);
|
|
214
211
|
if (!initialized) {
|
|
215
212
|
initialized = true;
|
|
216
213
|
module.exports.arrayToSetDeprecation(
|
|
217
|
-
|
|
214
|
+
/** @type {SetWithDeprecatedArrayMethods<T>} */
|
|
215
|
+
(SetDeprecatedArray.prototype),
|
|
218
216
|
name
|
|
219
217
|
);
|
|
220
218
|
}
|
|
@@ -70,9 +70,11 @@ const getName = (a, b, usedNames) => {
|
|
|
70
70
|
return a;
|
|
71
71
|
};
|
|
72
72
|
|
|
73
|
+
/** @typedef {Record<string, number>} Sizes */
|
|
74
|
+
|
|
73
75
|
/**
|
|
74
|
-
* @param {
|
|
75
|
-
* @param {
|
|
76
|
+
* @param {Sizes} total total size
|
|
77
|
+
* @param {Sizes} size single size
|
|
76
78
|
* @returns {void}
|
|
77
79
|
*/
|
|
78
80
|
const addSizeTo = (total, size) => {
|
|
@@ -82,8 +84,8 @@ const addSizeTo = (total, size) => {
|
|
|
82
84
|
};
|
|
83
85
|
|
|
84
86
|
/**
|
|
85
|
-
* @param {
|
|
86
|
-
* @param {
|
|
87
|
+
* @param {Sizes} total total size
|
|
88
|
+
* @param {Sizes} size single size
|
|
87
89
|
* @returns {void}
|
|
88
90
|
*/
|
|
89
91
|
const subtractSizeFrom = (total, size) => {
|
|
@@ -95,7 +97,7 @@ const subtractSizeFrom = (total, size) => {
|
|
|
95
97
|
/**
|
|
96
98
|
* @template T
|
|
97
99
|
* @param {Iterable<Node<T>>} nodes some nodes
|
|
98
|
-
* @returns {
|
|
100
|
+
* @returns {Sizes} total size
|
|
99
101
|
*/
|
|
100
102
|
const sumSize = (nodes) => {
|
|
101
103
|
const sum = Object.create(null);
|
|
@@ -106,8 +108,8 @@ const sumSize = (nodes) => {
|
|
|
106
108
|
};
|
|
107
109
|
|
|
108
110
|
/**
|
|
109
|
-
* @param {
|
|
110
|
-
* @param {
|
|
111
|
+
* @param {Sizes} size size
|
|
112
|
+
* @param {Sizes} maxSize minimum size
|
|
111
113
|
* @returns {boolean} true, when size is too big
|
|
112
114
|
*/
|
|
113
115
|
const isTooBig = (size, maxSize) => {
|
|
@@ -121,8 +123,8 @@ const isTooBig = (size, maxSize) => {
|
|
|
121
123
|
};
|
|
122
124
|
|
|
123
125
|
/**
|
|
124
|
-
* @param {
|
|
125
|
-
* @param {
|
|
126
|
+
* @param {Sizes} size size
|
|
127
|
+
* @param {Sizes} minSize minimum size
|
|
126
128
|
* @returns {boolean} true, when size is too small
|
|
127
129
|
*/
|
|
128
130
|
const isTooSmall = (size, minSize) => {
|
|
@@ -136,8 +138,8 @@ const isTooSmall = (size, minSize) => {
|
|
|
136
138
|
};
|
|
137
139
|
|
|
138
140
|
/**
|
|
139
|
-
* @param {
|
|
140
|
-
* @param {
|
|
141
|
+
* @param {Sizes} size size
|
|
142
|
+
* @param {Sizes} minSize minimum size
|
|
141
143
|
* @returns {Set<string>} set of types that are too small
|
|
142
144
|
*/
|
|
143
145
|
const getTooSmallTypes = (size, minSize) => {
|
|
@@ -166,7 +168,7 @@ const getNumberOfMatchingSizeTypes = (size, types) => {
|
|
|
166
168
|
};
|
|
167
169
|
|
|
168
170
|
/**
|
|
169
|
-
* @param {
|
|
171
|
+
* @param {Sizes} size size
|
|
170
172
|
* @param {Set<string>} types types
|
|
171
173
|
* @returns {number} selective size sum
|
|
172
174
|
*/
|
|
@@ -185,7 +187,7 @@ class Node {
|
|
|
185
187
|
/**
|
|
186
188
|
* @param {T} item item
|
|
187
189
|
* @param {string} key key
|
|
188
|
-
* @param {
|
|
190
|
+
* @param {Sizes} size size
|
|
189
191
|
*/
|
|
190
192
|
constructor(item, key, size) {
|
|
191
193
|
this.item = item;
|
|
@@ -194,14 +196,16 @@ class Node {
|
|
|
194
196
|
}
|
|
195
197
|
}
|
|
196
198
|
|
|
199
|
+
/** @typedef {number[]} Similarities */
|
|
200
|
+
|
|
197
201
|
/**
|
|
198
202
|
* @template T
|
|
199
203
|
*/
|
|
200
204
|
class Group {
|
|
201
205
|
/**
|
|
202
206
|
* @param {Node<T>[]} nodes nodes
|
|
203
|
-
* @param {
|
|
204
|
-
* @param {
|
|
207
|
+
* @param {Similarities | null} similarities similarities between the nodes (length = nodes.length - 1)
|
|
208
|
+
* @param {Sizes=} size size of the group
|
|
205
209
|
*/
|
|
206
210
|
constructor(nodes, similarities, size) {
|
|
207
211
|
this.nodes = nodes;
|
|
@@ -228,7 +232,7 @@ class Group {
|
|
|
228
232
|
if (newNodes.length > 0) {
|
|
229
233
|
newSimilarities.push(
|
|
230
234
|
lastNode === this.nodes[i - 1]
|
|
231
|
-
? /** @type {
|
|
235
|
+
? /** @type {Similarities} */ (this.similarities)[i - 1]
|
|
232
236
|
: similarity(/** @type {Node<T>} */ (lastNode).key, node.key)
|
|
233
237
|
);
|
|
234
238
|
}
|
|
@@ -247,11 +251,11 @@ class Group {
|
|
|
247
251
|
/**
|
|
248
252
|
* @template T
|
|
249
253
|
* @param {Iterable<Node<T>>} nodes nodes
|
|
250
|
-
* @returns {
|
|
254
|
+
* @returns {Similarities} similarities
|
|
251
255
|
*/
|
|
252
256
|
const getSimilarities = (nodes) => {
|
|
253
257
|
// calculate similarities between lexically adjacent nodes
|
|
254
|
-
/** @type {
|
|
258
|
+
/** @type {Similarities} */
|
|
255
259
|
const similarities = [];
|
|
256
260
|
let last;
|
|
257
261
|
for (const node of nodes) {
|
|
@@ -268,16 +272,16 @@ const getSimilarities = (nodes) => {
|
|
|
268
272
|
* @typedef {object} GroupedItems<T>
|
|
269
273
|
* @property {string} key
|
|
270
274
|
* @property {T[]} items
|
|
271
|
-
* @property {
|
|
275
|
+
* @property {Sizes} size
|
|
272
276
|
*/
|
|
273
277
|
|
|
274
278
|
/**
|
|
275
279
|
* @template T
|
|
276
280
|
* @typedef {object} Options
|
|
277
|
-
* @property {
|
|
278
|
-
* @property {
|
|
281
|
+
* @property {Sizes} maxSize maximum size of a group
|
|
282
|
+
* @property {Sizes} minSize minimum size of a group (preferred over maximum size)
|
|
279
283
|
* @property {Iterable<T>} items a list of items
|
|
280
|
-
* @property {(item: T) =>
|
|
284
|
+
* @property {(item: T) => Sizes} getSize function to get size of an item
|
|
281
285
|
* @property {(item: T) => string} getKey function to get the key of an item
|
|
282
286
|
*/
|
|
283
287
|
|
|
@@ -320,7 +324,7 @@ module.exports = ({ maxSize, minSize, items, getSize, getKey }) => {
|
|
|
320
324
|
|
|
321
325
|
/**
|
|
322
326
|
* @param {Group<T>} group group
|
|
323
|
-
* @param {
|
|
327
|
+
* @param {Sizes} consideredSize size of the group to consider
|
|
324
328
|
* @returns {boolean} true, if the group was modified
|
|
325
329
|
*/
|
|
326
330
|
const removeProblematicNodes = (group, consideredSize = group.size) => {
|
|
@@ -455,9 +459,9 @@ module.exports = ({ maxSize, minSize, items, getSize, getKey }) => {
|
|
|
455
459
|
// rightSize ^^^^^^^^^^^^^^^
|
|
456
460
|
|
|
457
461
|
while (pos <= right + 1) {
|
|
458
|
-
const similarity =
|
|
459
|
-
|
|
460
|
-
|
|
462
|
+
const similarity =
|
|
463
|
+
/** @type {Similarities} */
|
|
464
|
+
(group.similarities)[pos - 1];
|
|
461
465
|
if (
|
|
462
466
|
similarity < bestSimilarity &&
|
|
463
467
|
!isTooSmall(leftSize, minSize) &&
|
|
@@ -484,22 +488,22 @@ module.exports = ({ maxSize, minSize, items, getSize, getKey }) => {
|
|
|
484
488
|
// create two new groups for left and right area
|
|
485
489
|
// and queue them up
|
|
486
490
|
const rightNodes = [group.nodes[right + 1]];
|
|
487
|
-
/** @type {
|
|
491
|
+
/** @type {Similarities} */
|
|
488
492
|
const rightSimilarities = [];
|
|
489
493
|
for (let i = right + 2; i < group.nodes.length; i++) {
|
|
490
494
|
rightSimilarities.push(
|
|
491
|
-
/** @type {
|
|
495
|
+
/** @type {Similarities} */ (group.similarities)[i - 1]
|
|
492
496
|
);
|
|
493
497
|
rightNodes.push(group.nodes[i]);
|
|
494
498
|
}
|
|
495
499
|
queue.push(new Group(rightNodes, rightSimilarities));
|
|
496
500
|
|
|
497
501
|
const leftNodes = [group.nodes[0]];
|
|
498
|
-
/** @type {
|
|
502
|
+
/** @type {Similarities} */
|
|
499
503
|
const leftSimilarities = [];
|
|
500
504
|
for (let i = 1; i < left; i++) {
|
|
501
505
|
leftSimilarities.push(
|
|
502
|
-
/** @type {
|
|
506
|
+
/** @type {Similarities} */ (group.similarities)[i - 1]
|
|
503
507
|
);
|
|
504
508
|
leftNodes.push(group.nodes[i]);
|
|
505
509
|
}
|