webpack 5.99.9 → 5.100.1
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/bin/webpack.js +8 -2
- package/hot/log.js +15 -15
- package/hot/poll.js +1 -0
- package/lib/APIPlugin.js +3 -3
- package/lib/AbstractMethodError.js +1 -0
- package/lib/AutomaticPrefetchPlugin.js +1 -0
- package/lib/BannerPlugin.js +1 -1
- package/lib/CaseSensitiveModulesWarning.js +4 -4
- package/lib/Chunk.js +6 -6
- package/lib/ChunkGraph.js +37 -31
- package/lib/ChunkGroup.js +4 -4
- package/lib/ChunkTemplate.js +1 -1
- package/lib/CleanPlugin.js +94 -17
- package/lib/CodeGenerationResults.js +1 -1
- package/lib/CompatibilityPlugin.js +5 -2
- package/lib/Compilation.js +67 -45
- package/lib/Compiler.js +46 -16
- package/lib/ConcatenationScope.js +15 -6
- package/lib/ConstPlugin.js +5 -3
- package/lib/ContextModule.js +16 -12
- package/lib/ContextModuleFactory.js +4 -3
- package/lib/ContextReplacementPlugin.js +4 -2
- package/lib/CssModule.js +2 -2
- package/lib/DefinePlugin.js +111 -3
- package/lib/DelegatedModuleFactoryPlugin.js +18 -18
- package/lib/Dependency.js +11 -4
- package/lib/DependencyTemplate.js +1 -0
- package/lib/DllEntryPlugin.js +3 -1
- package/lib/DllPlugin.js +4 -3
- package/lib/DllReferencePlugin.js +2 -2
- package/lib/DynamicEntryPlugin.js +1 -1
- package/lib/EntryOptionPlugin.js +5 -0
- package/lib/ErrorHelpers.js +4 -4
- package/lib/EvalDevToolModulePlugin.js +3 -3
- package/lib/EvalSourceMapDevToolPlugin.js +7 -7
- package/lib/ExportsInfo.js +48 -39
- package/lib/ExternalModule.js +15 -11
- package/lib/ExternalModuleFactoryPlugin.js +5 -2
- package/lib/FileSystemInfo.js +51 -36
- package/lib/FlagDependencyExportsPlugin.js +14 -7
- package/lib/FlagDependencyUsagePlugin.js +1 -1
- package/lib/Generator.js +14 -1
- package/lib/HookWebpackError.js +1 -0
- package/lib/HotModuleReplacementPlugin.js +77 -50
- package/lib/IgnorePlugin.js +5 -2
- package/lib/InvalidDependenciesModuleWarning.js +1 -1
- package/lib/JavascriptMetaInfoPlugin.js +0 -1
- package/lib/LibManifestPlugin.js +4 -2
- package/lib/LoaderOptionsPlugin.js +6 -4
- package/lib/MainTemplate.js +2 -2
- package/lib/Module.js +21 -6
- package/lib/ModuleFactory.js +1 -0
- package/lib/ModuleGraph.js +24 -2
- package/lib/ModuleGraphConnection.js +5 -5
- package/lib/ModuleInfoHeaderPlugin.js +2 -1
- package/lib/ModuleParseError.js +1 -0
- package/lib/ModuleSourceTypesConstants.js +12 -12
- package/lib/ModuleTemplate.js +1 -1
- package/lib/ModuleTypeConstants.js +21 -21
- package/lib/MultiCompiler.js +6 -6
- package/lib/NormalModule.js +31 -44
- package/lib/NormalModuleFactory.js +34 -20
- package/lib/NormalModuleReplacementPlugin.js +1 -1
- package/lib/NullFactory.js +1 -0
- package/lib/OptimizationStages.js +1 -1
- package/lib/Parser.js +1 -0
- package/lib/ProgressPlugin.js +12 -5
- package/lib/ProvidePlugin.js +5 -1
- package/lib/RawModule.js +14 -0
- package/lib/RecordIdsPlugin.js +3 -3
- package/lib/RuntimeGlobals.js +175 -155
- package/lib/RuntimeModule.js +1 -0
- package/lib/RuntimePlugin.js +33 -7
- package/lib/RuntimeTemplate.js +111 -11
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +15 -25
- package/lib/SourceMapDevToolPlugin.js +19 -17
- package/lib/Template.js +2 -2
- package/lib/TemplatedPathPlugin.js +1 -1
- package/lib/WarnDeprecatedOptionPlugin.js +7 -8
- package/lib/WatchIgnorePlugin.js +4 -3
- package/lib/WebpackIsIncludedPlugin.js +2 -1
- package/lib/WebpackOptionsApply.js +115 -27
- package/lib/asset/AssetGenerator.js +15 -11
- package/lib/asset/AssetModulesPlugin.js +19 -17
- package/lib/asset/AssetSourceGenerator.js +4 -4
- package/lib/asset/RawDataUrlModule.js +4 -2
- package/lib/async-modules/AwaitDependenciesInitFragment.js +1 -1
- package/lib/buildChunkGraph.js +6 -3
- package/lib/cache/AddBuildDependenciesPlugin.js +5 -6
- package/lib/cache/IdleFileCachePlugin.js +7 -4
- package/lib/cache/MemoryCachePlugin.js +1 -0
- package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
- package/lib/cache/PackFileCacheStrategy.js +26 -20
- package/lib/cache/ResolverCachePlugin.js +16 -8
- package/lib/cli.js +15 -10
- package/lib/config/browserslistTargetHandler.js +3 -3
- package/lib/config/defaults.js +25 -17
- package/lib/config/normalization.js +2 -1
- package/lib/config/target.js +6 -5
- package/lib/container/ContainerPlugin.js +1 -1
- package/lib/container/ContainerReferencePlugin.js +1 -1
- package/lib/container/FallbackModule.js +2 -1
- package/lib/container/HoistContainerReferencesPlugin.js +1 -1
- package/lib/container/ModuleFederationPlugin.js +2 -2
- package/lib/container/RemoteModule.js +1 -1
- package/lib/css/CssGenerator.js +9 -6
- package/lib/css/CssModulesPlugin.js +44 -31
- package/lib/css/CssParser.js +6 -4
- package/lib/css/walkCssTokens.js +33 -37
- package/lib/debug/ProfilingPlugin.js +6 -6
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +8 -8
- package/lib/dependencies/AMDPlugin.js +12 -8
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +28 -26
- package/lib/dependencies/CachedConstDependency.js +1 -5
- package/lib/dependencies/CommonJsExportRequireDependency.js +6 -4
- package/lib/dependencies/CommonJsExportsParserPlugin.js +22 -25
- package/lib/dependencies/CommonJsFullRequireDependency.js +1 -9
- package/lib/dependencies/CommonJsImportsParserPlugin.js +100 -114
- package/lib/dependencies/CommonJsPlugin.js +15 -16
- package/lib/dependencies/ContextDependencyHelpers.js +2 -1
- package/lib/dependencies/ContextDependencyTemplateAsId.js +1 -0
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +1 -0
- package/lib/dependencies/CssIcssExportDependency.js +1 -1
- package/lib/dependencies/CssLocalIdentifierDependency.js +2 -2
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +2 -1
- package/lib/dependencies/DynamicExports.js +9 -9
- package/lib/dependencies/ExportsInfoDependency.js +1 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +122 -101
- package/lib/dependencies/HarmonyExportExpressionDependency.js +1 -1
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +95 -19
- package/lib/dependencies/HarmonyExportInitFragment.js +1 -1
- package/lib/dependencies/HarmonyImportDependency.js +11 -5
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +238 -162
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -1
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +20 -9
- package/lib/dependencies/HarmonyModulesPlugin.js +23 -12
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -0
- package/lib/dependencies/ImportMetaContextPlugin.js +2 -1
- package/lib/dependencies/ImportMetaPlugin.js +2 -2
- package/lib/dependencies/ImportParserPlugin.js +40 -9
- package/lib/dependencies/ImportPlugin.js +3 -1
- package/lib/dependencies/LoaderPlugin.js +1 -0
- package/lib/dependencies/ModuleDependency.js +3 -1
- package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +1 -0
- package/lib/dependencies/RequireContextPlugin.js +3 -1
- package/lib/dependencies/RequireEnsurePlugin.js +6 -6
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +33 -34
- package/lib/dependencies/RequireIncludePlugin.js +1 -0
- package/lib/dependencies/RuntimeRequirementsDependency.js +1 -1
- package/lib/dependencies/SystemPlugin.js +1 -1
- package/lib/dependencies/URLContextDependency.js +65 -0
- package/lib/dependencies/URLPlugin.js +17 -157
- package/lib/dependencies/WorkerPlugin.js +23 -10
- package/lib/dependencies/processExportInfo.js +2 -1
- package/lib/esm/ModuleChunkFormatPlugin.js +269 -185
- package/lib/esm/ModuleChunkLoadingPlugin.js +39 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +70 -3
- package/lib/hmr/HotModuleReplacement.runtime.js +0 -1
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
- package/lib/hmr/JavascriptHotModuleReplacementHelper.js +37 -0
- package/lib/hmr/LazyCompilationPlugin.js +4 -2
- package/lib/hmr/lazyCompilationBackend.js +4 -2
- package/lib/ids/ChunkModuleIdRangePlugin.js +6 -3
- package/lib/ids/DeterministicChunkIdsPlugin.js +30 -35
- package/lib/ids/DeterministicModuleIdsPlugin.js +4 -3
- package/lib/ids/HashedModuleIdsPlugin.js +5 -4
- package/lib/ids/IdHelpers.js +21 -17
- package/lib/ids/NamedChunkIdsPlugin.js +5 -5
- package/lib/ids/NamedModuleIdsPlugin.js +4 -4
- package/lib/ids/NaturalChunkIdsPlugin.js +2 -1
- package/lib/ids/NaturalModuleIdsPlugin.js +1 -1
- package/lib/ids/OccurrenceChunkIdsPlugin.js +3 -2
- package/lib/ids/OccurrenceModuleIdsPlugin.js +1 -1
- package/lib/ids/SyncModuleIdsPlugin.js +1 -1
- package/lib/index.js +13 -3
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +113 -119
- package/lib/javascript/BasicEvaluatedExpression.js +2 -1
- package/lib/javascript/ChunkHelpers.js +1 -0
- package/lib/javascript/CommonJsChunkFormatPlugin.js +121 -136
- package/lib/javascript/EnableChunkLoadingPlugin.js +6 -3
- package/lib/javascript/JavascriptGenerator.js +14 -2
- package/lib/javascript/JavascriptModulesPlugin.js +68 -27
- package/lib/javascript/JavascriptParser.js +117 -76
- package/lib/javascript/JavascriptParserHelpers.js +41 -41
- package/lib/javascript/StartupHelpers.js +17 -17
- package/lib/json/JsonGenerator.js +4 -2
- package/lib/json/JsonModulesPlugin.js +2 -2
- package/lib/json/JsonParser.js +1 -1
- package/lib/library/AbstractLibraryPlugin.js +6 -2
- package/lib/library/AssignLibraryPlugin.js +21 -6
- package/lib/library/EnableLibraryPlugin.js +23 -3
- package/lib/library/UmdLibraryPlugin.js +15 -6
- package/lib/logging/createConsoleLogger.js +3 -3
- package/lib/logging/runtime.js +9 -9
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +4 -22
- package/lib/node/RequireChunkLoadingRuntimeModule.js +4 -22
- package/lib/node/nodeConsole.js +4 -2
- package/lib/optimize/AggressiveMergingPlugin.js +45 -46
- package/lib/optimize/AggressiveSplittingPlugin.js +13 -12
- package/lib/optimize/ConcatenatedModule.js +227 -57
- package/lib/optimize/EnsureChunkConditionsPlugin.js +58 -58
- package/lib/optimize/FlagIncludedChunksPlugin.js +3 -1
- package/lib/optimize/InnerGraph.js +115 -112
- package/lib/optimize/InnerGraphPlugin.js +2 -2
- package/lib/optimize/LimitChunkCountPlugin.js +4 -2
- package/lib/optimize/MangleExportsPlugin.js +4 -3
- package/lib/optimize/MergeDuplicateChunksPlugin.js +80 -81
- package/lib/optimize/MinChunkSizePlugin.js +6 -3
- package/lib/optimize/ModuleConcatenationPlugin.js +31 -22
- package/lib/optimize/RealContentHashPlugin.js +26 -20
- package/lib/optimize/RemoveEmptyChunksPlugin.js +2 -1
- package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
- package/lib/optimize/SideEffectsFlagPlugin.js +3 -2
- package/lib/optimize/SplitChunksPlugin.js +16 -13
- package/lib/rules/BasicEffectRulePlugin.js +4 -2
- package/lib/rules/BasicMatcherRulePlugin.js +3 -1
- package/lib/rules/ObjectMatcherRulePlugin.js +3 -1
- package/lib/rules/RuleSetCompiler.js +19 -5
- package/lib/rules/UseEffectRulePlugin.js +17 -9
- package/lib/runtime/AsyncModuleRuntimeModule.js +64 -9
- package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +1 -1
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +214 -0
- package/lib/runtime/RuntimeIdRuntimeModule.js +2 -1
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +8 -7
- package/lib/schemes/FileUriPlugin.js +1 -1
- package/lib/schemes/HttpUriPlugin.js +27 -19
- package/lib/schemes/VirtualUrlPlugin.js +222 -0
- package/lib/serialization/AggregateErrorSerializer.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +5 -4
- package/lib/serialization/FileMiddleware.js +7 -4
- package/lib/serialization/ObjectMiddleware.js +14 -8
- package/lib/serialization/Serializer.js +5 -3
- package/lib/serialization/SerializerMiddleware.js +2 -0
- package/lib/sharing/ConsumeSharedModule.js +1 -1
- package/lib/sharing/ConsumeSharedPlugin.js +3 -3
- package/lib/sharing/ConsumeSharedRuntimeModule.js +2 -2
- package/lib/sharing/ProvideSharedModule.js +1 -1
- package/lib/sharing/ProvideSharedPlugin.js +3 -2
- package/lib/sharing/SharePlugin.js +2 -1
- package/lib/sharing/ShareRuntimeModule.js +3 -5
- package/lib/sharing/utils.js +34 -34
- package/lib/stats/DefaultStatsFactoryPlugin.js +49 -46
- package/lib/stats/DefaultStatsPresetPlugin.js +13 -13
- package/lib/stats/DefaultStatsPrinterPlugin.js +15 -9
- package/lib/stats/StatsFactory.js +6 -3
- package/lib/stats/StatsPrinter.js +6 -7
- package/lib/url/URLParserPlugin.js +266 -0
- package/lib/util/ArrayQueue.js +1 -1
- package/lib/util/AsyncQueue.js +1 -1
- package/lib/util/Hash.js +2 -0
- package/lib/util/IterableHelpers.js +1 -1
- package/lib/util/LazyBucketSortedSet.js +2 -1
- package/lib/util/LazySet.js +11 -6
- package/lib/util/ParallelismFactorCalculator.js +1 -1
- package/lib/util/SetHelpers.js +3 -3
- package/lib/util/SortableSet.js +2 -2
- package/lib/util/StackedCacheMap.js +3 -1
- package/lib/util/StackedMap.js +2 -2
- package/lib/util/StringXor.js +1 -0
- package/lib/util/TupleSet.js +1 -0
- package/lib/util/URLAbsoluteSpecifier.js +1 -1
- package/lib/util/cleverMerge.js +95 -58
- package/lib/util/comparators.js +154 -127
- package/lib/util/compileBooleanMatcher.js +8 -3
- package/lib/util/concatenate.js +8 -7
- package/lib/util/conventions.js +72 -73
- package/lib/util/create-schema-validation.js +2 -1
- package/lib/util/createHash.js +10 -4
- package/lib/util/deprecation.js +69 -66
- package/lib/util/deterministicGrouping.js +4 -2
- package/lib/util/extractUrlAndGlobal.js +1 -1
- package/lib/util/findGraphRoots.js +2 -2
- package/lib/util/fs.js +30 -23
- package/lib/util/hash/md4.js +2 -2
- package/lib/util/hash/wasm-hash.js +4 -2
- package/lib/util/identifier.js +13 -12
- package/lib/util/internalSerializables.js +2 -0
- package/lib/util/magicComment.js +5 -5
- package/lib/util/processAsyncTree.js +1 -1
- package/lib/util/propertyAccess.js +1 -1
- package/lib/util/propertyName.js +1 -1
- package/lib/util/registerExternalSerializer.js +1 -2
- package/lib/util/removeBOM.js +1 -1
- package/lib/util/runtime.js +29 -21
- package/lib/util/semver.js +1 -1
- package/lib/util/serialization.js +3 -0
- package/lib/util/source.js +3 -2
- package/lib/validateSchema.js +1 -0
- package/lib/wasm/EnableWasmLoadingPlugin.js +6 -3
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -1
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +46 -49
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +2 -2
- package/lib/wasm-sync/WebAssemblyGenerator.js +2 -3
- package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +3 -2
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +3 -0
- package/lib/wasm-sync/WebAssemblyUtils.js +1 -1
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +4 -22
- package/lib/webpack.js +4 -5
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +1 -0
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +6 -24
- package/lib/webworker/WebWorkerTemplatePlugin.js +1 -0
- package/package.json +119 -113
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +17 -0
- package/schemas/plugins/schemes/VirtualUrlPlugin.check.d.ts +7 -0
- package/schemas/plugins/schemes/VirtualUrlPlugin.check.js +6 -0
- package/schemas/plugins/schemes/VirtualUrlPlugin.json +77 -0
- package/types.d.ts +1243 -409
package/lib/util/cleverMerge.js
CHANGED
|
@@ -30,10 +30,12 @@ const DYNAMIC_INFO = Symbol("cleverMerge dynamic info");
|
|
|
30
30
|
const cachedCleverMerge = (first, second) => {
|
|
31
31
|
if (second === undefined) return /** @type {T} */ (first);
|
|
32
32
|
if (first === undefined) return /** @type {O} */ (second);
|
|
33
|
-
if (typeof second !== "object" || second === null)
|
|
33
|
+
if (typeof second !== "object" || second === null) {
|
|
34
34
|
return /** @type {O} */ (second);
|
|
35
|
-
|
|
35
|
+
}
|
|
36
|
+
if (typeof first !== "object" || first === null) {
|
|
36
37
|
return /** @type {T} */ (first);
|
|
38
|
+
}
|
|
37
39
|
|
|
38
40
|
let innerCache = mergeCache.get(first);
|
|
39
41
|
if (innerCache === undefined) {
|
|
@@ -83,32 +85,43 @@ const cachedSetProperty = (obj, property, value) => {
|
|
|
83
85
|
};
|
|
84
86
|
|
|
85
87
|
/**
|
|
86
|
-
* @
|
|
87
|
-
* @typedef {Map<string, V | undefined>} ByValues
|
|
88
|
+
* @typedef {Map<string, EXPECTED_ANY>} ByValues
|
|
88
89
|
*/
|
|
89
90
|
|
|
90
91
|
/**
|
|
92
|
+
* @template T
|
|
91
93
|
* @typedef {object} ObjectParsedPropertyEntry
|
|
92
|
-
* @property {
|
|
94
|
+
* @property {T[keyof T] | undefined} base base value
|
|
93
95
|
* @property {string | undefined} byProperty the name of the selector property
|
|
94
|
-
* @property {ByValues
|
|
96
|
+
* @property {ByValues | undefined} byValues value depending on selector property, merged with base
|
|
95
97
|
*/
|
|
96
98
|
|
|
97
99
|
/** @typedef {(function(...EXPECTED_ANY): object) & { [DYNAMIC_INFO]: [DynamicFunction, object] }} DynamicFunction */
|
|
98
100
|
|
|
99
101
|
/**
|
|
102
|
+
* @template {object} T
|
|
103
|
+
* @typedef {Map<keyof T, ObjectParsedPropertyEntry<T>>} ParsedObjectStatic
|
|
104
|
+
*/
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* @template {object} T
|
|
108
|
+
* @typedef {{ byProperty: string, fn: DynamicFunction }} ParsedObjectDynamic
|
|
109
|
+
*/
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* @template {object} T
|
|
100
113
|
* @typedef {object} ParsedObject
|
|
101
|
-
* @property {
|
|
102
|
-
* @property {
|
|
114
|
+
* @property {ParsedObjectStatic<T>} static static properties (key is property name)
|
|
115
|
+
* @property {ParsedObjectDynamic<T> | undefined} dynamic dynamic part
|
|
103
116
|
*/
|
|
104
117
|
|
|
105
|
-
/** @type {WeakMap<EXPECTED_OBJECT, ParsedObject
|
|
118
|
+
/** @type {WeakMap<EXPECTED_OBJECT, ParsedObject<EXPECTED_ANY>>} */
|
|
106
119
|
const parseCache = new WeakMap();
|
|
107
120
|
|
|
108
121
|
/**
|
|
109
122
|
* @template {object} T
|
|
110
123
|
* @param {T} obj the object
|
|
111
|
-
* @returns {ParsedObject} parsed object
|
|
124
|
+
* @returns {ParsedObject<T>} parsed object
|
|
112
125
|
*/
|
|
113
126
|
const cachedParseObject = obj => {
|
|
114
127
|
const entry = parseCache.get(/** @type {EXPECTED_OBJECT} */ (obj));
|
|
@@ -118,18 +131,21 @@ const cachedParseObject = obj => {
|
|
|
118
131
|
return result;
|
|
119
132
|
};
|
|
120
133
|
|
|
134
|
+
/** @typedef {{ [p: string]: { [p: string]: EXPECTED_ANY } } | DynamicFunction} ByObject */
|
|
135
|
+
|
|
121
136
|
/**
|
|
122
137
|
* @template {object} T
|
|
123
|
-
* @template V
|
|
124
138
|
* @param {T} obj the object
|
|
125
|
-
* @returns {ParsedObject} parsed object
|
|
139
|
+
* @returns {ParsedObject<T>} parsed object
|
|
126
140
|
*/
|
|
127
141
|
const parseObject = obj => {
|
|
142
|
+
/** @type {ParsedObjectStatic<T>} */
|
|
128
143
|
const info = new Map();
|
|
144
|
+
/** @type {ParsedObjectDynamic<T> | undefined} */
|
|
129
145
|
let dynamicInfo;
|
|
130
146
|
/**
|
|
131
|
-
* @param {
|
|
132
|
-
* @returns {Partial<ObjectParsedPropertyEntry
|
|
147
|
+
* @param {keyof T} p path
|
|
148
|
+
* @returns {Partial<ObjectParsedPropertyEntry<T>>} object parsed property entry
|
|
133
149
|
*/
|
|
134
150
|
const getInfo = p => {
|
|
135
151
|
const entry = info.get(p);
|
|
@@ -142,38 +158,37 @@ const parseObject = obj => {
|
|
|
142
158
|
info.set(p, newEntry);
|
|
143
159
|
return newEntry;
|
|
144
160
|
};
|
|
145
|
-
for (const
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const
|
|
161
|
+
for (const key_ of Object.keys(obj)) {
|
|
162
|
+
const key = /** @type {keyof T} */ (key_);
|
|
163
|
+
if (typeof key === "string" && key.startsWith("by")) {
|
|
164
|
+
const byProperty = key;
|
|
165
|
+
const byObj = /** @type {ByObject} */ (obj[byProperty]);
|
|
149
166
|
if (typeof byObj === "object") {
|
|
150
167
|
for (const byValue of Object.keys(byObj)) {
|
|
151
168
|
const obj = byObj[/** @type {keyof (keyof T)} */ (byValue)];
|
|
152
169
|
for (const key of Object.keys(obj)) {
|
|
153
|
-
const entry = getInfo(key);
|
|
170
|
+
const entry = getInfo(/** @type {keyof T} */ (key));
|
|
154
171
|
if (entry.byProperty === undefined) {
|
|
155
|
-
entry.byProperty =
|
|
172
|
+
entry.byProperty = byProperty;
|
|
156
173
|
entry.byValues = new Map();
|
|
157
174
|
} else if (entry.byProperty !== byProperty) {
|
|
158
175
|
throw new Error(
|
|
159
176
|
`${/** @type {string} */ (byProperty)} and ${entry.byProperty} for a single property is not supported`
|
|
160
177
|
);
|
|
161
178
|
}
|
|
162
|
-
/** @type {ByValues
|
|
163
|
-
(entry.byValues).set(
|
|
164
|
-
byValue,
|
|
165
|
-
obj[/** @type {keyof (keyof T)} */ (key)]
|
|
166
|
-
);
|
|
179
|
+
/** @type {ByValues} */
|
|
180
|
+
(entry.byValues).set(byValue, obj[key]);
|
|
167
181
|
if (byValue === "default") {
|
|
168
182
|
for (const otherByValue of Object.keys(byObj)) {
|
|
169
183
|
if (
|
|
170
184
|
!(
|
|
171
|
-
/** @type {ByValues
|
|
185
|
+
/** @type {ByValues} */
|
|
172
186
|
(entry.byValues).has(otherByValue)
|
|
173
187
|
)
|
|
174
|
-
)
|
|
175
|
-
/** @type {ByValues
|
|
188
|
+
) {
|
|
189
|
+
/** @type {ByValues} */
|
|
176
190
|
(entry.byValues).set(otherByValue, undefined);
|
|
191
|
+
}
|
|
177
192
|
}
|
|
178
193
|
}
|
|
179
194
|
}
|
|
@@ -191,11 +206,11 @@ const parseObject = obj => {
|
|
|
191
206
|
}
|
|
192
207
|
} else {
|
|
193
208
|
const entry = getInfo(key);
|
|
194
|
-
entry.base = obj[
|
|
209
|
+
entry.base = obj[key];
|
|
195
210
|
}
|
|
196
211
|
} else {
|
|
197
212
|
const entry = getInfo(key);
|
|
198
|
-
entry.base = obj[
|
|
213
|
+
entry.base = obj[key];
|
|
199
214
|
}
|
|
200
215
|
}
|
|
201
216
|
return {
|
|
@@ -206,8 +221,8 @@ const parseObject = obj => {
|
|
|
206
221
|
|
|
207
222
|
/**
|
|
208
223
|
* @template {object} T
|
|
209
|
-
* @param {
|
|
210
|
-
* @param {{ byProperty: string, fn:
|
|
224
|
+
* @param {ParsedObjectStatic<T>} info static properties (key is property name)
|
|
225
|
+
* @param {{ byProperty: string, fn: DynamicFunction } | undefined} dynamicInfo dynamic part
|
|
211
226
|
* @returns {T} the object
|
|
212
227
|
*/
|
|
213
228
|
const serializeObject = (info, dynamicInfo) => {
|
|
@@ -218,7 +233,7 @@ const serializeObject = (info, dynamicInfo) => {
|
|
|
218
233
|
const byProperty = /** @type {keyof T} */ (entry.byProperty);
|
|
219
234
|
const byObj = (obj[byProperty] =
|
|
220
235
|
obj[byProperty] || /** @type {TODO} */ ({}));
|
|
221
|
-
for (const byValue of entry.byValues.keys()) {
|
|
236
|
+
for (const byValue of /** @type {ByValues} */ (entry.byValues).keys()) {
|
|
222
237
|
byObj[byValue] = byObj[byValue] || {};
|
|
223
238
|
}
|
|
224
239
|
}
|
|
@@ -233,7 +248,11 @@ const serializeObject = (info, dynamicInfo) => {
|
|
|
233
248
|
const byObj = (obj[byProperty] =
|
|
234
249
|
obj[byProperty] || /** @type {TODO} */ ({}));
|
|
235
250
|
for (const byValue of Object.keys(byObj)) {
|
|
236
|
-
const value = getFromByValues(
|
|
251
|
+
const value = getFromByValues(
|
|
252
|
+
/** @type {ByValues} */
|
|
253
|
+
(entry.byValues),
|
|
254
|
+
byValue
|
|
255
|
+
);
|
|
237
256
|
if (value !== undefined) byObj[byValue][key] = value;
|
|
238
257
|
}
|
|
239
258
|
}
|
|
@@ -314,7 +333,7 @@ const _cleverMerge = (first, second, internalCaching = false) => {
|
|
|
314
333
|
const fnInfo = fn[DYNAMIC_INFO];
|
|
315
334
|
if (fnInfo) {
|
|
316
335
|
second =
|
|
317
|
-
/** @type {
|
|
336
|
+
/** @type {O} */
|
|
318
337
|
(
|
|
319
338
|
internalCaching
|
|
320
339
|
? cachedCleverMerge(fnInfo[1], second)
|
|
@@ -340,10 +359,12 @@ const _cleverMerge = (first, second, internalCaching = false) => {
|
|
|
340
359
|
? cachedParseObject(second)
|
|
341
360
|
: parseObject(second);
|
|
342
361
|
const { static: secondInfo, dynamic: secondDynamicInfo } = secondObject;
|
|
343
|
-
/** @type {Map<string, ObjectParsedPropertyEntry>} */
|
|
344
362
|
const resultInfo = new Map();
|
|
345
363
|
for (const [key, firstEntry] of firstInfo) {
|
|
346
|
-
const secondEntry = secondInfo.get(
|
|
364
|
+
const secondEntry = secondInfo.get(
|
|
365
|
+
/** @type {keyof (T | O)} */
|
|
366
|
+
(key)
|
|
367
|
+
);
|
|
347
368
|
const entry =
|
|
348
369
|
secondEntry !== undefined
|
|
349
370
|
? mergeEntries(firstEntry, secondEntry, internalCaching)
|
|
@@ -351,7 +372,7 @@ const _cleverMerge = (first, second, internalCaching = false) => {
|
|
|
351
372
|
resultInfo.set(key, entry);
|
|
352
373
|
}
|
|
353
374
|
for (const [key, secondEntry] of secondInfo) {
|
|
354
|
-
if (!firstInfo.has(key)) {
|
|
375
|
+
if (!firstInfo.has(/** @type {keyof (T | O)} */ (key))) {
|
|
355
376
|
resultInfo.set(key, secondEntry);
|
|
356
377
|
}
|
|
357
378
|
}
|
|
@@ -359,10 +380,11 @@ const _cleverMerge = (first, second, internalCaching = false) => {
|
|
|
359
380
|
};
|
|
360
381
|
|
|
361
382
|
/**
|
|
362
|
-
* @
|
|
363
|
-
* @param {ObjectParsedPropertyEntry}
|
|
383
|
+
* @template T, O
|
|
384
|
+
* @param {ObjectParsedPropertyEntry<T>} firstEntry a
|
|
385
|
+
* @param {ObjectParsedPropertyEntry<O>} secondEntry b
|
|
364
386
|
* @param {boolean} internalCaching should parsing of objects and nested merges be cached
|
|
365
|
-
* @returns {ObjectParsedPropertyEntry} new entry
|
|
387
|
+
* @returns {ObjectParsedPropertyEntry<TODO>} new entry
|
|
366
388
|
*/
|
|
367
389
|
const mergeEntries = (firstEntry, secondEntry, internalCaching) => {
|
|
368
390
|
switch (getValueType(secondEntry.base)) {
|
|
@@ -388,8 +410,14 @@ const mergeEntries = (firstEntry, secondEntry, internalCaching) => {
|
|
|
388
410
|
// = first.base + (first.byProperty + second.byProperty)
|
|
389
411
|
// need to merge first and second byValues
|
|
390
412
|
const newByValues = new Map(firstEntry.byValues);
|
|
391
|
-
for (const [key, value] of
|
|
392
|
-
|
|
413
|
+
for (const [key, value] of /** @type {ByValues} */ (
|
|
414
|
+
secondEntry.byValues
|
|
415
|
+
)) {
|
|
416
|
+
const firstValue = getFromByValues(
|
|
417
|
+
/** @type {ByValues} */
|
|
418
|
+
(firstEntry.byValues),
|
|
419
|
+
key
|
|
420
|
+
);
|
|
393
421
|
newByValues.set(
|
|
394
422
|
key,
|
|
395
423
|
mergeSingleValue(firstValue, value, internalCaching)
|
|
@@ -406,11 +434,15 @@ const mergeEntries = (firstEntry, secondEntry, internalCaching) => {
|
|
|
406
434
|
// The simple case
|
|
407
435
|
// = (first.base + second.base) + second.byProperty
|
|
408
436
|
return {
|
|
409
|
-
base:
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
437
|
+
base:
|
|
438
|
+
/** @type {T[keyof T] & O[keyof O]} */
|
|
439
|
+
(
|
|
440
|
+
mergeSingleValue(
|
|
441
|
+
firstEntry.base,
|
|
442
|
+
secondEntry.base,
|
|
443
|
+
internalCaching
|
|
444
|
+
)
|
|
445
|
+
),
|
|
414
446
|
byProperty: secondEntry.byProperty,
|
|
415
447
|
byValues: secondEntry.byValues
|
|
416
448
|
};
|
|
@@ -424,10 +456,12 @@ const mergeEntries = (firstEntry, secondEntry, internalCaching) => {
|
|
|
424
456
|
);
|
|
425
457
|
}
|
|
426
458
|
if (
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
459
|
+
[.../** @type {ByValues} */ (firstEntry.byValues).values()].every(
|
|
460
|
+
value => {
|
|
461
|
+
const type = getValueType(value);
|
|
462
|
+
return type === VALUE_TYPE_ATOM || type === VALUE_TYPE_DELETE;
|
|
463
|
+
}
|
|
464
|
+
)
|
|
431
465
|
) {
|
|
432
466
|
// = (first.base + second.base) + ((first.byProperty + second.base) + second.byProperty)
|
|
433
467
|
newBase = mergeSingleValue(
|
|
@@ -438,8 +472,9 @@ const mergeEntries = (firstEntry, secondEntry, internalCaching) => {
|
|
|
438
472
|
} else {
|
|
439
473
|
// = first.base + ((first.byProperty (+default) + second.base) + second.byProperty)
|
|
440
474
|
newBase = firstEntry.base;
|
|
441
|
-
if (!intermediateByValues.has("default"))
|
|
475
|
+
if (!intermediateByValues.has("default")) {
|
|
442
476
|
intermediateByValues.set("default", secondEntry.base);
|
|
477
|
+
}
|
|
443
478
|
}
|
|
444
479
|
if (!secondEntry.byProperty) {
|
|
445
480
|
// = first.base + (first.byProperty + second.base)
|
|
@@ -454,7 +489,9 @@ const mergeEntries = (firstEntry, secondEntry, internalCaching) => {
|
|
|
454
489
|
);
|
|
455
490
|
}
|
|
456
491
|
const newByValues = new Map(intermediateByValues);
|
|
457
|
-
for (const [key, value] of
|
|
492
|
+
for (const [key, value] of /** @type {ByValues} */ (
|
|
493
|
+
secondEntry.byValues
|
|
494
|
+
)) {
|
|
458
495
|
const firstValue = getFromByValues(intermediateByValues, key);
|
|
459
496
|
newByValues.set(
|
|
460
497
|
key,
|
|
@@ -472,7 +509,7 @@ const mergeEntries = (firstEntry, secondEntry, internalCaching) => {
|
|
|
472
509
|
|
|
473
510
|
/**
|
|
474
511
|
* @template V
|
|
475
|
-
* @param {ByValues
|
|
512
|
+
* @param {ByValues} byValues all values
|
|
476
513
|
* @param {string} key value of the selector
|
|
477
514
|
* @returns {V | undefined} value
|
|
478
515
|
*/
|
|
@@ -629,9 +666,9 @@ const resolveByProperty = (obj, byProperty, ...values) => {
|
|
|
629
666
|
return obj;
|
|
630
667
|
};
|
|
631
668
|
|
|
632
|
-
module.exports.
|
|
669
|
+
module.exports.DELETE = DELETE;
|
|
633
670
|
module.exports.cachedCleverMerge = cachedCleverMerge;
|
|
671
|
+
module.exports.cachedSetProperty = cachedSetProperty;
|
|
634
672
|
module.exports.cleverMerge = cleverMerge;
|
|
635
|
-
module.exports.resolveByProperty = resolveByProperty;
|
|
636
673
|
module.exports.removeOperations = removeOperations;
|
|
637
|
-
module.exports.
|
|
674
|
+
module.exports.resolveByProperty = resolveByProperty;
|