webpack 5.93.0 → 5.95.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 +8 -5
- package/bin/webpack.js +6 -7
- package/hot/log.js +1 -2
- package/hot/only-dev-server.js +1 -1
- package/hot/poll.js +1 -1
- package/hot/signal.js +1 -1
- package/lib/APIPlugin.js +4 -3
- package/lib/AbstractMethodError.js +10 -5
- package/lib/AutomaticPrefetchPlugin.js +1 -1
- package/lib/BannerPlugin.js +12 -6
- package/lib/Cache.js +8 -10
- package/lib/CacheFacade.js +3 -3
- package/lib/CaseSensitiveModulesWarning.js +5 -7
- package/lib/Chunk.js +14 -11
- package/lib/ChunkGraph.js +58 -36
- package/lib/ChunkGroup.js +2 -3
- package/lib/ChunkTemplate.js +43 -0
- package/lib/CleanPlugin.js +10 -11
- package/lib/CodeGenerationResults.js +6 -5
- package/lib/CommentCompilationWarning.js +0 -1
- package/lib/Compilation.js +223 -191
- package/lib/Compiler.js +81 -82
- package/lib/ConcatenationScope.js +3 -6
- package/lib/ConditionalInitFragment.js +6 -7
- package/lib/ConstPlugin.js +7 -15
- package/lib/ContextExclusionPlugin.js +3 -3
- package/lib/ContextModule.js +33 -20
- package/lib/ContextModuleFactory.js +89 -44
- package/lib/ContextReplacementPlugin.js +10 -9
- package/lib/DefinePlugin.js +75 -68
- package/lib/DelegatedModule.js +7 -3
- package/lib/DelegatedModuleFactoryPlugin.js +36 -22
- package/lib/DelegatedPlugin.js +4 -0
- package/lib/DependenciesBlock.js +0 -1
- package/lib/Dependency.js +10 -14
- package/lib/DllEntryPlugin.js +4 -2
- package/lib/DllModuleFactory.js +1 -0
- package/lib/DllPlugin.js +9 -7
- package/lib/DllReferencePlugin.js +30 -15
- package/lib/EntryPlugin.js +1 -3
- package/lib/EnvironmentPlugin.js +6 -2
- package/lib/ErrorHelpers.js +11 -12
- package/lib/EvalDevToolModulePlugin.js +10 -12
- package/lib/EvalSourceMapDevToolPlugin.js +15 -13
- package/lib/ExportsInfo.js +185 -120
- package/lib/ExternalModule.js +41 -15
- package/lib/ExternalModuleFactoryPlugin.js +23 -10
- package/lib/FileSystemInfo.js +791 -422
- package/lib/FlagAllModulesAsUsedPlugin.js +1 -1
- package/lib/FlagDependencyExportsPlugin.js +12 -11
- package/lib/FlagDependencyUsagePlugin.js +1 -1
- package/lib/Generator.js +2 -5
- package/lib/GraphHelpers.js +3 -2
- package/lib/HookWebpackError.js +8 -10
- package/lib/HotModuleReplacementPlugin.js +78 -64
- package/lib/IgnoreErrorModuleFactory.js +3 -3
- package/lib/IgnorePlugin.js +1 -3
- package/lib/IgnoreWarningsPlugin.js +6 -9
- package/lib/InitFragment.js +2 -3
- package/lib/LibManifestPlugin.js +4 -3
- package/lib/MainTemplate.js +72 -19
- package/lib/Module.js +25 -9
- package/lib/ModuleBuildError.js +4 -11
- package/lib/ModuleDependencyError.js +5 -5
- package/lib/ModuleDependencyWarning.js +5 -5
- package/lib/ModuleError.js +1 -5
- package/lib/ModuleFilenameHelpers.js +29 -46
- package/lib/ModuleGraph.js +7 -6
- package/lib/ModuleGraphConnection.js +6 -6
- package/lib/ModuleInfoHeaderPlugin.js +82 -30
- package/lib/ModuleParseError.js +8 -9
- package/lib/ModuleRestoreError.js +1 -1
- package/lib/ModuleStoreError.js +1 -1
- package/lib/ModuleTemplate.js +33 -1
- package/lib/ModuleTypeConstants.js +21 -22
- package/lib/ModuleWarning.js +1 -5
- package/lib/MultiCompiler.js +24 -26
- package/lib/MultiStats.js +73 -31
- package/lib/MultiWatching.js +1 -1
- package/lib/NormalModule.js +130 -69
- package/lib/NormalModuleFactory.js +53 -49
- package/lib/OptimizationStages.js +3 -3
- package/lib/ProgressPlugin.js +9 -9
- package/lib/ProvidePlugin.js +4 -4
- package/lib/RuntimeGlobals.js +71 -70
- package/lib/RuntimeModule.js +1 -1
- package/lib/RuntimePlugin.js +24 -12
- package/lib/RuntimeTemplate.js +40 -44
- package/lib/SizeFormatHelpers.js +2 -4
- package/lib/SourceMapDevToolPlugin.js +42 -34
- package/lib/Stats.js +5 -11
- package/lib/Template.js +18 -24
- package/lib/TemplatedPathPlugin.js +21 -13
- package/lib/WarnDeprecatedOptionPlugin.js +0 -1
- package/lib/WatchIgnorePlugin.js +26 -9
- package/lib/Watching.js +10 -5
- package/lib/WebpackOptionsApply.js +84 -62
- package/lib/asset/AssetGenerator.js +107 -42
- package/lib/asset/AssetModulesPlugin.js +29 -23
- package/lib/asset/AssetSourceGenerator.js +2 -7
- package/lib/async-modules/AwaitDependenciesInitFragment.js +6 -7
- package/lib/buildChunkGraph.js +93 -81
- package/lib/cache/IdleFileCachePlugin.js +4 -4
- package/lib/cache/MemoryWithGcCachePlugin.js +5 -5
- package/lib/cache/PackFileCacheStrategy.js +51 -50
- package/lib/cache/ResolverCachePlugin.js +6 -6
- package/lib/cache/mergeEtags.js +16 -21
- package/lib/cli.js +148 -104
- package/lib/config/browserslistTargetHandler.js +16 -13
- package/lib/config/defaults.js +32 -28
- package/lib/config/normalization.js +335 -344
- package/lib/config/target.js +42 -52
- package/lib/container/ContainerEntryModule.js +2 -2
- package/lib/container/ContainerPlugin.js +1 -1
- package/lib/container/RemoteRuntimeModule.js +11 -8
- package/lib/container/options.js +18 -4
- package/lib/css/CssExportsGenerator.js +26 -24
- package/lib/css/CssGenerator.js +9 -4
- package/lib/css/CssLoadingRuntimeModule.js +10 -10
- package/lib/css/CssModulesPlugin.js +127 -47
- package/lib/css/CssParser.js +20 -18
- package/lib/css/walkCssTokens.js +80 -95
- package/lib/debug/ProfilingPlugin.js +19 -20
- package/lib/dependencies/AMDDefineDependency.js +1 -1
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +83 -47
- package/lib/dependencies/AMDRequireArrayDependency.js +9 -10
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +22 -16
- package/lib/dependencies/AMDRuntimeModules.js +2 -2
- package/lib/dependencies/CommonJsDependencyHelpers.js +6 -2
- package/lib/dependencies/CommonJsExportRequireDependency.js +37 -41
- package/lib/dependencies/CommonJsExportsDependency.js +0 -1
- package/lib/dependencies/CommonJsExportsParserPlugin.js +19 -23
- package/lib/dependencies/CommonJsFullRequireDependency.js +1 -1
- package/lib/dependencies/CommonJsImportsParserPlugin.js +52 -61
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +6 -8
- package/lib/dependencies/ConstDependency.js +1 -1
- package/lib/dependencies/ContextDependency.js +7 -2
- package/lib/dependencies/ContextDependencyHelpers.js +31 -34
- package/lib/dependencies/ContextElementDependency.js +35 -8
- package/lib/dependencies/CriticalDependencyWarning.js +1 -1
- package/lib/dependencies/CssExportDependency.js +7 -7
- package/lib/dependencies/CssImportDependency.js +0 -2
- package/lib/dependencies/CssLocalIdentifierDependency.js +3 -3
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +2 -1
- package/lib/dependencies/CssUrlDependency.js +4 -5
- package/lib/dependencies/DynamicExports.js +5 -5
- package/lib/dependencies/ExportsInfoDependency.js +1 -2
- package/lib/dependencies/HarmonyAcceptImportDependency.js +1 -1
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +4 -5
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +27 -16
- package/lib/dependencies/HarmonyExportExpressionDependency.js +1 -1
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +107 -64
- package/lib/dependencies/HarmonyExports.js +2 -2
- package/lib/dependencies/HarmonyImportDependency.js +2 -4
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +19 -4
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +40 -15
- package/lib/dependencies/ImportDependency.js +1 -1
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +5 -5
- package/lib/dependencies/ImportMetaPlugin.js +11 -13
- package/lib/dependencies/ImportParserPlugin.js +39 -44
- package/lib/dependencies/JsonExportsDependency.js +22 -18
- package/lib/dependencies/LoaderPlugin.js +47 -36
- package/lib/dependencies/LocalModule.js +1 -1
- package/lib/dependencies/LocalModulesHelpers.js +4 -4
- package/lib/dependencies/ModuleDecoratorDependency.js +1 -1
- package/lib/dependencies/ProvidedDependency.js +1 -1
- package/lib/dependencies/PureExpressionDependency.js +6 -6
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -1
- package/lib/dependencies/RuntimeRequirementsDependency.js +1 -1
- package/lib/dependencies/SystemPlugin.js +1 -1
- package/lib/dependencies/URLDependency.js +3 -3
- package/lib/dependencies/URLPlugin.js +66 -12
- package/lib/dependencies/WorkerPlugin.js +25 -24
- package/lib/dependencies/processExportInfo.js +3 -1
- package/lib/electron/ElectronTargetPlugin.js +1 -0
- package/lib/esm/ModuleChunkFormatPlugin.js +3 -3
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +7 -3
- package/lib/formatLocation.js +1 -2
- package/lib/hmr/HotModuleReplacement.runtime.js +4 -5
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -0
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +9 -12
- package/lib/hmr/LazyCompilationPlugin.js +27 -12
- package/lib/hmr/lazyCompilationBackend.js +64 -40
- package/lib/ids/ChunkModuleIdRangePlugin.js +1 -3
- package/lib/ids/DeterministicChunkIdsPlugin.js +2 -4
- package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
- package/lib/ids/HashedModuleIdsPlugin.js +5 -1
- package/lib/ids/IdHelpers.js +29 -39
- package/lib/ids/SyncModuleIdsPlugin.js +7 -2
- package/lib/index.js +1 -5
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +5 -4
- package/lib/javascript/BasicEvaluatedExpression.js +4 -19
- package/lib/javascript/ChunkHelpers.js +1 -1
- package/lib/javascript/CommonJsChunkFormatPlugin.js +3 -2
- package/lib/javascript/EnableChunkLoadingPlugin.js +7 -6
- package/lib/javascript/JavascriptGenerator.js +23 -7
- package/lib/javascript/JavascriptModulesPlugin.js +133 -86
- package/lib/javascript/JavascriptParser.js +179 -200
- package/lib/javascript/JavascriptParserHelpers.js +20 -21
- package/lib/javascript/StartupHelpers.js +41 -13
- package/lib/json/JsonGenerator.js +7 -13
- package/lib/json/JsonModulesPlugin.js +1 -4
- package/lib/json/JsonParser.js +5 -3
- package/lib/library/AmdLibraryPlugin.js +12 -16
- package/lib/library/AssignLibraryPlugin.js +8 -10
- package/lib/library/EnableLibraryPlugin.js +15 -14
- package/lib/library/JsonpLibraryPlugin.js +2 -1
- package/lib/library/ModernModuleLibraryPlugin.js +8 -6
- package/lib/library/ModuleLibraryPlugin.js +2 -1
- package/lib/library/SystemLibraryPlugin.js +2 -1
- package/lib/library/UmdLibraryPlugin.js +66 -92
- package/lib/logging/Logger.js +32 -4
- package/lib/logging/createConsoleLogger.js +12 -13
- package/lib/logging/runtime.js +7 -8
- package/lib/logging/truncateArgs.js +5 -8
- package/lib/node/NodeWatchFileSystem.js +3 -18
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -2
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +1 -0
- package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -2
- package/lib/node/nodeConsole.js +22 -22
- package/lib/optimize/AggressiveMergingPlugin.js +2 -4
- package/lib/optimize/AggressiveSplittingPlugin.js +16 -19
- package/lib/optimize/ConcatenatedModule.js +81 -51
- package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -1
- package/lib/optimize/FlagIncludedChunksPlugin.js +3 -3
- package/lib/optimize/InnerGraph.js +17 -17
- package/lib/optimize/InnerGraphPlugin.js +8 -7
- package/lib/optimize/LimitChunkCountPlugin.js +2 -3
- package/lib/optimize/MangleExportsPlugin.js +1 -0
- package/lib/optimize/MergeDuplicateChunksPlugin.js +2 -2
- package/lib/optimize/MinMaxSizeWarning.js +1 -1
- package/lib/optimize/ModuleConcatenationPlugin.js +54 -78
- package/lib/optimize/RealContentHashPlugin.js +7 -10
- package/lib/optimize/RemoveParentModulesPlugin.js +3 -3
- package/lib/optimize/SideEffectsFlagPlugin.js +6 -2
- package/lib/optimize/SplitChunksPlugin.js +34 -30
- package/lib/performance/SizeLimitsPlugin.js +2 -2
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +1 -1
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +1 -1
- package/lib/rules/BasicEffectRulePlugin.js +3 -1
- package/lib/rules/BasicMatcherRulePlugin.js +3 -1
- package/lib/rules/ObjectMatcherRulePlugin.js +4 -1
- package/lib/rules/RuleSetCompiler.js +41 -22
- package/lib/rules/UseEffectRulePlugin.js +36 -32
- package/lib/runtime/AsyncModuleRuntimeModule.js +1 -1
- package/lib/runtime/AutoPublicPathRuntimeModule.js +8 -3
- package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +2 -2
- package/lib/runtime/DefinePropertyGettersRuntimeModule.js +1 -1
- package/lib/runtime/EnsureChunkRuntimeModule.js +10 -11
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +11 -17
- package/lib/runtime/LoadScriptRuntimeModule.js +17 -18
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -3
- package/lib/schemes/DataUriPlugin.js +1 -1
- package/lib/schemes/HttpUriPlugin.js +241 -126
- package/lib/serialization/BinaryMiddleware.js +44 -28
- package/lib/serialization/DateObjectSerializer.js +1 -0
- package/lib/serialization/ErrorObjectSerializer.js +2 -0
- package/lib/serialization/FileMiddleware.js +154 -106
- package/lib/serialization/MapObjectSerializer.js +2 -1
- package/lib/serialization/NullPrototypeObjectSerializer.js +3 -2
- package/lib/serialization/ObjectMiddleware.js +52 -56
- package/lib/serialization/PlainObjectSerializer.js +32 -6
- package/lib/serialization/RegExpObjectSerializer.js +1 -0
- package/lib/serialization/Serializer.js +4 -5
- package/lib/serialization/SerializerMiddleware.js +6 -6
- package/lib/serialization/SetObjectSerializer.js +2 -1
- package/lib/sharing/ConsumeSharedPlugin.js +116 -97
- package/lib/sharing/ConsumeSharedRuntimeModule.js +4 -4
- package/lib/sharing/ProvideForSharedDependency.js +0 -1
- package/lib/sharing/ProvideSharedPlugin.js +2 -2
- package/lib/sharing/resolveMatchedConfigs.js +2 -1
- package/lib/sharing/utils.js +15 -27
- package/lib/stats/DefaultStatsFactoryPlugin.js +424 -281
- package/lib/stats/DefaultStatsPresetPlugin.js +73 -18
- package/lib/stats/DefaultStatsPrinterPlugin.js +370 -101
- package/lib/stats/StatsFactory.js +127 -56
- package/lib/stats/StatsPrinter.js +75 -44
- package/lib/util/ArrayHelpers.js +8 -4
- package/lib/util/ArrayQueue.js +1 -1
- package/lib/util/AsyncQueue.js +31 -12
- package/lib/util/IterableHelpers.js +3 -4
- package/lib/util/LazyBucketSortedSet.js +60 -44
- package/lib/util/LazySet.js +13 -0
- package/lib/util/MapHelpers.js +1 -3
- package/lib/util/ParallelismFactorCalculator.js +1 -1
- package/lib/util/Queue.js +1 -1
- package/lib/util/Semaphore.js +4 -7
- package/lib/util/SetHelpers.js +5 -5
- package/lib/util/SortableSet.js +4 -3
- package/lib/util/StackedCacheMap.js +4 -6
- package/lib/util/StackedMap.js +1 -3
- package/lib/util/StringXor.js +0 -5
- package/lib/util/TupleQueue.js +1 -1
- package/lib/util/TupleSet.js +15 -5
- package/lib/util/URLAbsoluteSpecifier.js +7 -7
- package/lib/util/WeakTupleMap.js +19 -21
- package/lib/util/binarySearchBounds.js +5 -12
- package/lib/util/chainedImports.js +1 -1
- package/lib/util/cleverMerge.js +21 -19
- package/lib/util/comparators.js +57 -52
- package/lib/util/compileBooleanMatcher.js +3 -6
- package/lib/util/conventions.js +8 -11
- package/lib/util/createHash.js +9 -6
- package/lib/util/deprecation.js +22 -12
- package/lib/util/deterministicGrouping.js +19 -26
- package/lib/util/findGraphRoots.js +2 -2
- package/lib/util/fs.js +32 -32
- package/lib/util/hash/md4.js +2 -2
- package/lib/util/hash/wasm-hash.js +7 -7
- package/lib/util/hash/xxhash64.js +2 -2
- package/lib/util/identifier.js +81 -59
- package/lib/util/memoize.js +8 -10
- package/lib/util/mergeScope.js +6 -9
- package/lib/util/nonNumericOnlyHash.js +2 -2
- package/lib/util/numberHash.js +1 -6
- package/lib/util/objectToMap.js +0 -1
- package/lib/util/propertyAccess.js +2 -5
- package/lib/util/propertyName.js +1 -3
- package/lib/util/registerExternalSerializer.js +1 -1
- package/lib/util/runtime.js +109 -113
- package/lib/util/semver.js +29 -27
- package/lib/util/serialization.js +16 -1
- package/lib/util/smartGrouping.js +5 -5
- package/lib/util/source.js +1 -1
- package/lib/wasm/EnableWasmLoadingPlugin.js +5 -4
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +3 -3
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -6
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -3
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +20 -19
- package/lib/wasm-sync/WebAssemblyGenerator.js +14 -29
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +1 -1
- package/lib/wasm-sync/WebAssemblyUtils.js +2 -2
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -3
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -1
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +1 -1
- package/package.json +18 -17
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +5 -0
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
- package/schemas/plugins/container/ExternalsType.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.json +1 -0
- package/types.d.ts +681 -355
package/lib/ExportsInfo.js
CHANGED
@@ -71,9 +71,12 @@ makeSerializable(
|
|
71
71
|
"RestoreProvidedData"
|
72
72
|
);
|
73
73
|
|
74
|
+
/** @typedef {Map<string, ExportInfo>} Exports */
|
75
|
+
/** @typedef {string | string[] | false} UsedName */
|
76
|
+
|
74
77
|
class ExportsInfo {
|
75
78
|
constructor() {
|
76
|
-
/** @type {
|
79
|
+
/** @type {Exports} */
|
77
80
|
this._exports = new Map();
|
78
81
|
this._otherExportsInfo = new ExportInfo(null);
|
79
82
|
this._sideEffectsOnlyInfo = new ExportInfo("*side effects only*");
|
@@ -144,6 +147,10 @@ class ExportsInfo {
|
|
144
147
|
return this._otherExportsInfo;
|
145
148
|
}
|
146
149
|
|
150
|
+
/**
|
151
|
+
* @param {Exports} exports exports
|
152
|
+
* @private
|
153
|
+
*/
|
147
154
|
_sortExportsMap(exports) {
|
148
155
|
if (exports.size > 1) {
|
149
156
|
const namesInOrder = [];
|
@@ -159,7 +166,7 @@ class ExportsInfo {
|
|
159
166
|
}
|
160
167
|
for (; i < namesInOrder.length; i++) {
|
161
168
|
const name = namesInOrder[i];
|
162
|
-
const correctEntry = exports.get(name);
|
169
|
+
const correctEntry = /** @type {ExportInfo} */ (exports.get(name));
|
163
170
|
exports.delete(name);
|
164
171
|
exports.set(name, correctEntry);
|
165
172
|
}
|
@@ -261,7 +268,7 @@ class ExportsInfo {
|
|
261
268
|
getReadOnlyExportInfoRecursive(name) {
|
262
269
|
const exportInfo = this.getReadOnlyExportInfo(name[0]);
|
263
270
|
if (name.length === 1) return exportInfo;
|
264
|
-
if (!exportInfo.exportsInfo) return
|
271
|
+
if (!exportInfo.exportsInfo) return;
|
265
272
|
return exportInfo.exportsInfo.getReadOnlyExportInfoRecursive(name.slice(1));
|
266
273
|
}
|
267
274
|
|
@@ -272,7 +279,7 @@ class ExportsInfo {
|
|
272
279
|
getNestedExportsInfo(name) {
|
273
280
|
if (Array.isArray(name) && name.length > 0) {
|
274
281
|
const info = this.getReadOnlyExportInfo(name[0]);
|
275
|
-
if (!info.exportsInfo) return
|
282
|
+
if (!info.exportsInfo) return;
|
276
283
|
return info.exportsInfo.getNestedExportsInfo(name.slice(1));
|
277
284
|
}
|
278
285
|
return this;
|
@@ -451,10 +458,8 @@ class ExportsInfo {
|
|
451
458
|
if (this._redirectTo.isUsed(runtime)) {
|
452
459
|
return true;
|
453
460
|
}
|
454
|
-
} else {
|
455
|
-
|
456
|
-
return true;
|
457
|
-
}
|
461
|
+
} else if (this._otherExportsInfo.getUsed(runtime) !== UsageState.Unused) {
|
462
|
+
return true;
|
458
463
|
}
|
459
464
|
for (const exportInfo of this._exports.values()) {
|
460
465
|
if (exportInfo.getUsed(runtime) !== UsageState.Unused) {
|
@@ -522,7 +527,7 @@ class ExportsInfo {
|
|
522
527
|
return false;
|
523
528
|
}
|
524
529
|
}
|
525
|
-
return new SortableSet(array);
|
530
|
+
return /** @type {SortableSet<string>} */ (new SortableSet(array));
|
526
531
|
}
|
527
532
|
|
528
533
|
/**
|
@@ -633,13 +638,11 @@ class ExportsInfo {
|
|
633
638
|
isEquallyUsed(runtimeA, runtimeB) {
|
634
639
|
if (this._redirectTo !== undefined) {
|
635
640
|
if (!this._redirectTo.isEquallyUsed(runtimeA, runtimeB)) return false;
|
636
|
-
} else
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
return false;
|
642
|
-
}
|
641
|
+
} else if (
|
642
|
+
this._otherExportsInfo.getUsed(runtimeA) !==
|
643
|
+
this._otherExportsInfo.getUsed(runtimeB)
|
644
|
+
) {
|
645
|
+
return false;
|
643
646
|
}
|
644
647
|
if (
|
645
648
|
this._sideEffectsOnlyInfo.getUsed(runtimeA) !==
|
@@ -662,20 +665,20 @@ class ExportsInfo {
|
|
662
665
|
getUsed(name, runtime) {
|
663
666
|
if (Array.isArray(name)) {
|
664
667
|
if (name.length === 0) return this.otherExportsInfo.getUsed(runtime);
|
665
|
-
|
668
|
+
const info = this.getReadOnlyExportInfo(name[0]);
|
666
669
|
if (info.exportsInfo && name.length > 1) {
|
667
670
|
return info.exportsInfo.getUsed(name.slice(1), runtime);
|
668
671
|
}
|
669
672
|
return info.getUsed(runtime);
|
670
673
|
}
|
671
|
-
|
674
|
+
const info = this.getReadOnlyExportInfo(name);
|
672
675
|
return info.getUsed(runtime);
|
673
676
|
}
|
674
677
|
|
675
678
|
/**
|
676
|
-
* @param {string | string[]
|
679
|
+
* @param {string | string[]} name the export name
|
677
680
|
* @param {RuntimeSpec} runtime check usage for this runtime only
|
678
|
-
* @returns {
|
681
|
+
* @returns {UsedName} the used name
|
679
682
|
*/
|
680
683
|
getUsedName(name, runtime) {
|
681
684
|
if (Array.isArray(name)) {
|
@@ -684,10 +687,12 @@ class ExportsInfo {
|
|
684
687
|
if (!this.isUsed(runtime)) return false;
|
685
688
|
return name;
|
686
689
|
}
|
687
|
-
|
690
|
+
const info = this.getReadOnlyExportInfo(name[0]);
|
688
691
|
const x = info.getUsedName(name[0], runtime);
|
689
692
|
if (x === false) return false;
|
690
|
-
const arr =
|
693
|
+
const arr =
|
694
|
+
/** @type {string[]} */
|
695
|
+
(x === name[0] && name.length === 1 ? name : [x]);
|
691
696
|
if (name.length === 1) {
|
692
697
|
return arr;
|
693
698
|
}
|
@@ -698,14 +703,12 @@ class ExportsInfo {
|
|
698
703
|
const nested = info.exportsInfo.getUsedName(name.slice(1), runtime);
|
699
704
|
if (!nested) return false;
|
700
705
|
return arr.concat(nested);
|
701
|
-
} else {
|
702
|
-
return arr.concat(name.slice(1));
|
703
706
|
}
|
704
|
-
|
705
|
-
let info = this.getReadOnlyExportInfo(name);
|
706
|
-
const usedName = info.getUsedName(name, runtime);
|
707
|
-
return usedName;
|
707
|
+
return arr.concat(name.slice(1));
|
708
708
|
}
|
709
|
+
const info = this.getReadOnlyExportInfo(name);
|
710
|
+
const usedName = info.getUsedName(name, runtime);
|
711
|
+
return usedName;
|
709
712
|
}
|
710
713
|
|
711
714
|
/**
|
@@ -738,6 +741,9 @@ class ExportsInfo {
|
|
738
741
|
}
|
739
742
|
}
|
740
743
|
|
744
|
+
/**
|
745
|
+
* @returns {RestoreProvidedData} restore provided data
|
746
|
+
*/
|
741
747
|
getRestoreProvidedData() {
|
742
748
|
const otherProvided = this._otherExportsInfo.provided;
|
743
749
|
const otherCanMangleProvide = this._otherExportsInfo.canMangleProvide;
|
@@ -756,7 +762,8 @@ class ExportsInfo {
|
|
756
762
|
canMangleProvide: exportInfo.canMangleProvide,
|
757
763
|
terminalBinding: exportInfo.terminalBinding,
|
758
764
|
exportsInfo: exportInfo.exportsInfoOwned
|
759
|
-
?
|
765
|
+
? /** @type {NonNullable<ExportInfo["exportsInfo"]>} */
|
766
|
+
(exportInfo.exportsInfo).getRestoreProvidedData()
|
760
767
|
: undefined
|
761
768
|
});
|
762
769
|
}
|
@@ -802,6 +809,10 @@ class ExportsInfo {
|
|
802
809
|
}
|
803
810
|
}
|
804
811
|
|
812
|
+
/** @typedef {{ module: Module, export: string[] }} TargetItemWithoutConnection */
|
813
|
+
/** @typedef {{ module: Module, connection: ModuleGraphConnection, export: string[] | undefined }} TargetItem */
|
814
|
+
/** @typedef {Map<any, { connection: ModuleGraphConnection | null, export: string[], priority: number }>} Target */
|
815
|
+
|
805
816
|
class ExportInfo {
|
806
817
|
/**
|
807
818
|
* @param {string} name the original name of the export
|
@@ -817,7 +828,7 @@ class ExportInfo {
|
|
817
828
|
this._usedName = initFrom ? initFrom._usedName : null;
|
818
829
|
/**
|
819
830
|
* @private
|
820
|
-
* @type {UsageStateType}
|
831
|
+
* @type {UsageStateType | undefined}
|
821
832
|
*/
|
822
833
|
this._globalUsed = initFrom ? initFrom._globalUsed : undefined;
|
823
834
|
/**
|
@@ -864,9 +875,9 @@ class ExportInfo {
|
|
864
875
|
this.canMangleUse = initFrom ? initFrom.canMangleUse : undefined;
|
865
876
|
/** @type {boolean} */
|
866
877
|
this.exportsInfoOwned = false;
|
867
|
-
/** @type {ExportsInfo
|
878
|
+
/** @type {ExportsInfo | undefined} */
|
868
879
|
this.exportsInfo = undefined;
|
869
|
-
/** @type {
|
880
|
+
/** @type {Target | undefined} */
|
870
881
|
this._target = undefined;
|
871
882
|
if (initFrom && initFrom._target) {
|
872
883
|
this._target = new Map();
|
@@ -878,19 +889,11 @@ class ExportInfo {
|
|
878
889
|
});
|
879
890
|
}
|
880
891
|
}
|
881
|
-
/** @type {
|
892
|
+
/** @type {Target | undefined} */
|
882
893
|
this._maxTarget = undefined;
|
883
894
|
}
|
884
895
|
|
885
896
|
// TODO webpack 5 remove
|
886
|
-
/** @private */
|
887
|
-
get used() {
|
888
|
-
throw new Error("REMOVED");
|
889
|
-
}
|
890
|
-
/** @private */
|
891
|
-
get usedName() {
|
892
|
-
throw new Error("REMOVED");
|
893
|
-
}
|
894
897
|
/**
|
895
898
|
* @private
|
896
899
|
* @param {*} v v
|
@@ -898,6 +901,14 @@ class ExportInfo {
|
|
898
901
|
set used(v) {
|
899
902
|
throw new Error("REMOVED");
|
900
903
|
}
|
904
|
+
|
905
|
+
// TODO webpack 5 remove
|
906
|
+
/** @private */
|
907
|
+
get used() {
|
908
|
+
throw new Error("REMOVED");
|
909
|
+
}
|
910
|
+
|
911
|
+
// TODO webpack 5 remove
|
901
912
|
/**
|
902
913
|
* @private
|
903
914
|
* @param {*} v v
|
@@ -906,6 +917,12 @@ class ExportInfo {
|
|
906
917
|
throw new Error("REMOVED");
|
907
918
|
}
|
908
919
|
|
920
|
+
// TODO webpack 5 remove
|
921
|
+
/** @private */
|
922
|
+
get usedName() {
|
923
|
+
throw new Error("REMOVED");
|
924
|
+
}
|
925
|
+
|
909
926
|
get canMangle() {
|
910
927
|
switch (this.canMangleProvide) {
|
911
928
|
case undefined:
|
@@ -973,7 +990,8 @@ class ExportInfo {
|
|
973
990
|
this.canMangleUse = true;
|
974
991
|
}
|
975
992
|
if (this.exportsInfoOwned) {
|
976
|
-
|
993
|
+
/** @type {ExportsInfo} */
|
994
|
+
(this.exportsInfo).setHasUseInfo();
|
977
995
|
}
|
978
996
|
}
|
979
997
|
|
@@ -988,25 +1006,26 @@ class ExportInfo {
|
|
988
1006
|
if (this._globalUsed === undefined) {
|
989
1007
|
this._globalUsed = newValue;
|
990
1008
|
return true;
|
991
|
-
}
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
}
|
1009
|
+
}
|
1010
|
+
if (this._globalUsed !== newValue && condition(this._globalUsed)) {
|
1011
|
+
this._globalUsed = newValue;
|
1012
|
+
return true;
|
996
1013
|
}
|
997
1014
|
} else if (this._usedInRuntime === undefined) {
|
998
1015
|
if (newValue !== UsageState.Unused && condition(UsageState.Unused)) {
|
999
1016
|
this._usedInRuntime = new Map();
|
1000
1017
|
forEachRuntime(runtime, runtime =>
|
1001
|
-
this._usedInRuntime.set(runtime, newValue)
|
1018
|
+
this._usedInRuntime.set(/** @type {string} */ (runtime), newValue)
|
1002
1019
|
);
|
1003
1020
|
return true;
|
1004
1021
|
}
|
1005
1022
|
} else {
|
1006
1023
|
let changed = false;
|
1007
|
-
forEachRuntime(runtime,
|
1008
|
-
/** @type {
|
1009
|
-
let oldValue =
|
1024
|
+
forEachRuntime(runtime, _runtime => {
|
1025
|
+
const runtime = /** @type {string} */ (_runtime);
|
1026
|
+
let oldValue =
|
1027
|
+
/** @type {UsageStateType} */
|
1028
|
+
(this._usedInRuntime.get(runtime));
|
1010
1029
|
if (oldValue === undefined) oldValue = UsageState.Unused;
|
1011
1030
|
if (newValue !== oldValue && condition(oldValue)) {
|
1012
1031
|
if (newValue === UsageState.Unused) {
|
@@ -1040,15 +1059,17 @@ class ExportInfo {
|
|
1040
1059
|
if (newValue !== UsageState.Unused) {
|
1041
1060
|
this._usedInRuntime = new Map();
|
1042
1061
|
forEachRuntime(runtime, runtime =>
|
1043
|
-
this._usedInRuntime.set(runtime, newValue)
|
1062
|
+
this._usedInRuntime.set(/** @type {string} */ (runtime), newValue)
|
1044
1063
|
);
|
1045
1064
|
return true;
|
1046
1065
|
}
|
1047
1066
|
} else {
|
1048
1067
|
let changed = false;
|
1049
|
-
forEachRuntime(runtime,
|
1050
|
-
/** @type {
|
1051
|
-
let oldValue =
|
1068
|
+
forEachRuntime(runtime, _runtime => {
|
1069
|
+
const runtime = /** @type {string} */ (_runtime);
|
1070
|
+
let oldValue =
|
1071
|
+
/** @type {UsageStateType} */
|
1072
|
+
(this._usedInRuntime.get(runtime));
|
1052
1073
|
if (oldValue === undefined) oldValue = UsageState.Unused;
|
1053
1074
|
if (newValue !== oldValue) {
|
1054
1075
|
if (newValue === UsageState.Unused) {
|
@@ -1083,7 +1104,7 @@ class ExportInfo {
|
|
1083
1104
|
/**
|
1084
1105
|
* @param {any} key the key
|
1085
1106
|
* @param {ModuleGraphConnection} connection the target module if a single one
|
1086
|
-
* @param {string[]=} exportName the exported name
|
1107
|
+
* @param {(string[] | null)=} exportName the exported name
|
1087
1108
|
* @param {number=} priority priority
|
1088
1109
|
* @returns {boolean} true, if something has changed
|
1089
1110
|
*/
|
@@ -1091,13 +1112,21 @@ class ExportInfo {
|
|
1091
1112
|
if (exportName) exportName = [...exportName];
|
1092
1113
|
if (!this._target) {
|
1093
1114
|
this._target = new Map();
|
1094
|
-
this._target.set(key, {
|
1115
|
+
this._target.set(key, {
|
1116
|
+
connection,
|
1117
|
+
export: /** @type {string[]} */ (exportName),
|
1118
|
+
priority
|
1119
|
+
});
|
1095
1120
|
return true;
|
1096
1121
|
}
|
1097
1122
|
const oldTarget = this._target.get(key);
|
1098
1123
|
if (!oldTarget) {
|
1099
1124
|
if (oldTarget === null && !connection) return false;
|
1100
|
-
this._target.set(key, {
|
1125
|
+
this._target.set(key, {
|
1126
|
+
connection,
|
1127
|
+
export: /** @type {string[]} */ (exportName),
|
1128
|
+
priority
|
1129
|
+
});
|
1101
1130
|
this._maxTarget = undefined;
|
1102
1131
|
return true;
|
1103
1132
|
}
|
@@ -1109,7 +1138,7 @@ class ExportInfo {
|
|
1109
1138
|
: oldTarget.export)
|
1110
1139
|
) {
|
1111
1140
|
oldTarget.connection = connection;
|
1112
|
-
oldTarget.export = exportName;
|
1141
|
+
oldTarget.export = /** @type {string[]} */ (exportName);
|
1113
1142
|
oldTarget.priority = priority;
|
1114
1143
|
this._maxTarget = undefined;
|
1115
1144
|
return true;
|
@@ -1139,20 +1168,20 @@ class ExportInfo {
|
|
1139
1168
|
if (max < value) max = value;
|
1140
1169
|
}
|
1141
1170
|
return max;
|
1142
|
-
}
|
1143
|
-
|
1144
|
-
|
1145
|
-
|
1146
|
-
|
1147
|
-
|
1148
|
-
|
1149
|
-
|
1150
|
-
|
1151
|
-
if (max < value) max = value;
|
1171
|
+
}
|
1172
|
+
|
1173
|
+
/** @type {UsageStateType} */
|
1174
|
+
let max = UsageState.Unused;
|
1175
|
+
for (const item of runtime) {
|
1176
|
+
const value = this._usedInRuntime.get(item);
|
1177
|
+
if (value !== undefined) {
|
1178
|
+
if (value === UsageState.Used) {
|
1179
|
+
return UsageState.Used;
|
1152
1180
|
}
|
1181
|
+
if (max < value) max = value;
|
1153
1182
|
}
|
1154
|
-
return max;
|
1155
1183
|
}
|
1184
|
+
return max;
|
1156
1185
|
}
|
1157
1186
|
|
1158
1187
|
/**
|
@@ -1171,19 +1200,18 @@ class ExportInfo {
|
|
1171
1200
|
if (!this._usedInRuntime.has(runtime)) {
|
1172
1201
|
return false;
|
1173
1202
|
}
|
1174
|
-
} else if (
|
1175
|
-
|
1176
|
-
|
1177
|
-
|
1178
|
-
|
1179
|
-
|
1180
|
-
|
1181
|
-
}
|
1203
|
+
} else if (
|
1204
|
+
runtime !== undefined &&
|
1205
|
+
Array.from(runtime).every(
|
1206
|
+
runtime => !this._usedInRuntime.has(runtime)
|
1207
|
+
)
|
1208
|
+
) {
|
1209
|
+
return false;
|
1182
1210
|
}
|
1183
1211
|
}
|
1184
1212
|
}
|
1185
1213
|
if (this._usedName !== null) return this._usedName;
|
1186
|
-
return this.name || fallbackName;
|
1214
|
+
return /** @type {string | false} */ (this.name || fallbackName);
|
1187
1215
|
}
|
1188
1216
|
|
1189
1217
|
/**
|
@@ -1204,13 +1232,13 @@ class ExportInfo {
|
|
1204
1232
|
|
1205
1233
|
/**
|
1206
1234
|
* @param {ModuleGraph} moduleGraph the module graph
|
1207
|
-
* @param {function(
|
1235
|
+
* @param {function(TargetItem): boolean} resolveTargetFilter filter function to further resolve target
|
1208
1236
|
* @returns {ExportInfo | ExportsInfo | undefined} the terminal binding export(s) info if known
|
1209
1237
|
*/
|
1210
1238
|
getTerminalBinding(moduleGraph, resolveTargetFilter = RETURNS_TRUE) {
|
1211
1239
|
if (this.terminalBinding) return this;
|
1212
1240
|
const target = this.getTarget(moduleGraph, resolveTargetFilter);
|
1213
|
-
if (!target) return
|
1241
|
+
if (!target) return;
|
1214
1242
|
const exportsInfo = moduleGraph.getExportsInfo(target.module);
|
1215
1243
|
if (!target.export) return exportsInfo;
|
1216
1244
|
return exportsInfo.getReadOnlyExportInfoRecursive(target.export);
|
@@ -1222,10 +1250,11 @@ class ExportInfo {
|
|
1222
1250
|
|
1223
1251
|
_getMaxTarget() {
|
1224
1252
|
if (this._maxTarget !== undefined) return this._maxTarget;
|
1225
|
-
if (this._target.size <= 1)
|
1253
|
+
if (/** @type {Target} */ (this._target).size <= 1)
|
1254
|
+
return (this._maxTarget = this._target);
|
1226
1255
|
let maxPriority = -Infinity;
|
1227
1256
|
let minPriority = Infinity;
|
1228
|
-
for (const { priority } of this._target.values()) {
|
1257
|
+
for (const { priority } of /** @type {Target} */ (this._target).values()) {
|
1229
1258
|
if (maxPriority < priority) maxPriority = priority;
|
1230
1259
|
if (minPriority > priority) minPriority = priority;
|
1231
1260
|
}
|
@@ -1234,7 +1263,7 @@ class ExportInfo {
|
|
1234
1263
|
|
1235
1264
|
// This is an edge case
|
1236
1265
|
const map = new Map();
|
1237
|
-
for (const [key, value] of this._target) {
|
1266
|
+
for (const [key, value] of /** @type {Target} */ (this._target)) {
|
1238
1267
|
if (maxPriority === value.priority) {
|
1239
1268
|
map.set(key, value);
|
1240
1269
|
}
|
@@ -1246,7 +1275,7 @@ class ExportInfo {
|
|
1246
1275
|
/**
|
1247
1276
|
* @param {ModuleGraph} moduleGraph the module graph
|
1248
1277
|
* @param {function(Module): boolean} validTargetModuleFilter a valid target module
|
1249
|
-
* @returns {
|
1278
|
+
* @returns {TargetItemWithoutConnection | null | undefined | false} the target, undefined when there is no target, false when no target is valid
|
1250
1279
|
*/
|
1251
1280
|
findTarget(moduleGraph, validTargetModuleFilter) {
|
1252
1281
|
return this._findTarget(moduleGraph, validTargetModuleFilter, new Set());
|
@@ -1256,13 +1285,15 @@ class ExportInfo {
|
|
1256
1285
|
* @param {ModuleGraph} moduleGraph the module graph
|
1257
1286
|
* @param {function(Module): boolean} validTargetModuleFilter a valid target module
|
1258
1287
|
* @param {Set<ExportInfo>} alreadyVisited set of already visited export info to avoid circular references
|
1259
|
-
* @returns {
|
1288
|
+
* @returns {TargetItemWithoutConnection | null | undefined | false} the target, undefined when there is no target, false when no target is valid
|
1260
1289
|
*/
|
1261
1290
|
_findTarget(moduleGraph, validTargetModuleFilter, alreadyVisited) {
|
1262
|
-
if (!this._target || this._target.size === 0) return
|
1263
|
-
|
1264
|
-
|
1265
|
-
|
1291
|
+
if (!this._target || this._target.size === 0) return;
|
1292
|
+
const rawTarget =
|
1293
|
+
/** @type {Target} */
|
1294
|
+
(this._getMaxTarget()).values().next().value;
|
1295
|
+
if (!rawTarget) return;
|
1296
|
+
/** @type {TargetItemWithoutConnection} */
|
1266
1297
|
let target = {
|
1267
1298
|
module: rawTarget.connection.module,
|
1268
1299
|
export: rawTarget.export
|
@@ -1293,26 +1324,26 @@ class ExportInfo {
|
|
1293
1324
|
|
1294
1325
|
/**
|
1295
1326
|
* @param {ModuleGraph} moduleGraph the module graph
|
1296
|
-
* @param {function(
|
1297
|
-
* @returns {
|
1327
|
+
* @param {function(TargetItem): boolean} resolveTargetFilter filter function to further resolve target
|
1328
|
+
* @returns {TargetItem | undefined} the target
|
1298
1329
|
*/
|
1299
1330
|
getTarget(moduleGraph, resolveTargetFilter = RETURNS_TRUE) {
|
1300
1331
|
const result = this._getTarget(moduleGraph, resolveTargetFilter, undefined);
|
1301
|
-
if (result === CIRCULAR) return
|
1332
|
+
if (result === CIRCULAR) return;
|
1302
1333
|
return result;
|
1303
1334
|
}
|
1304
1335
|
|
1305
1336
|
/**
|
1306
1337
|
* @param {ModuleGraph} moduleGraph the module graph
|
1307
|
-
* @param {function(
|
1338
|
+
* @param {function(TargetItem): boolean} resolveTargetFilter filter function to further resolve target
|
1308
1339
|
* @param {Set<ExportInfo> | undefined} alreadyVisited set of already visited export info to avoid circular references
|
1309
|
-
* @returns {
|
1340
|
+
* @returns {TargetItem | CIRCULAR | undefined} the target
|
1310
1341
|
*/
|
1311
1342
|
_getTarget(moduleGraph, resolveTargetFilter, alreadyVisited) {
|
1312
1343
|
/**
|
1313
|
-
* @param {
|
1344
|
+
* @param {TargetItem | null} inputTarget unresolved target
|
1314
1345
|
* @param {Set<ExportInfo>} alreadyVisited set of already visited export info to avoid circular references
|
1315
|
-
* @returns {
|
1346
|
+
* @returns {TargetItem | CIRCULAR | null} resolved target
|
1316
1347
|
*/
|
1317
1348
|
const resolveTarget = (inputTarget, alreadyVisited) => {
|
1318
1349
|
if (!inputTarget) return null;
|
@@ -1323,7 +1354,7 @@ class ExportInfo {
|
|
1323
1354
|
export: undefined
|
1324
1355
|
};
|
1325
1356
|
}
|
1326
|
-
/** @type {
|
1357
|
+
/** @type {TargetItem} */
|
1327
1358
|
let target = {
|
1328
1359
|
module: inputTarget.connection.module,
|
1329
1360
|
connection: inputTarget.connection,
|
@@ -1333,7 +1364,10 @@ class ExportInfo {
|
|
1333
1364
|
let alreadyVisitedOwned = false;
|
1334
1365
|
for (;;) {
|
1335
1366
|
const exportsInfo = moduleGraph.getExportsInfo(target.module);
|
1336
|
-
const exportInfo = exportsInfo.getExportInfo(
|
1367
|
+
const exportInfo = exportsInfo.getExportInfo(
|
1368
|
+
/** @type {NonNullable<TargetItem["export"]>} */
|
1369
|
+
(target.export)[0]
|
1370
|
+
);
|
1337
1371
|
if (!exportInfo) return target;
|
1338
1372
|
if (alreadyVisited.has(exportInfo)) return CIRCULAR;
|
1339
1373
|
const newTarget = exportInfo._getTarget(
|
@@ -1343,7 +1377,10 @@ class ExportInfo {
|
|
1343
1377
|
);
|
1344
1378
|
if (newTarget === CIRCULAR) return CIRCULAR;
|
1345
1379
|
if (!newTarget) return target;
|
1346
|
-
if (
|
1380
|
+
if (
|
1381
|
+
/** @type {NonNullable<TargetItem["export"]>} */
|
1382
|
+
(target.export).length === 1
|
1383
|
+
) {
|
1347
1384
|
target = newTarget;
|
1348
1385
|
if (!target.export) return target;
|
1349
1386
|
} else {
|
@@ -1351,8 +1388,12 @@ class ExportInfo {
|
|
1351
1388
|
module: newTarget.module,
|
1352
1389
|
connection: newTarget.connection,
|
1353
1390
|
export: newTarget.export
|
1354
|
-
? newTarget.export.concat(
|
1355
|
-
|
1391
|
+
? newTarget.export.concat(
|
1392
|
+
/** @type {NonNullable<TargetItem["export"]>} */
|
1393
|
+
(target.export).slice(1)
|
1394
|
+
)
|
1395
|
+
: /** @type {NonNullable<TargetItem["export"]>} */
|
1396
|
+
(target.export).slice(1)
|
1356
1397
|
};
|
1357
1398
|
}
|
1358
1399
|
if (!resolveTargetFilter(target)) return target;
|
@@ -1364,26 +1405,26 @@ class ExportInfo {
|
|
1364
1405
|
}
|
1365
1406
|
};
|
1366
1407
|
|
1367
|
-
if (!this._target || this._target.size === 0) return
|
1408
|
+
if (!this._target || this._target.size === 0) return;
|
1368
1409
|
if (alreadyVisited && alreadyVisited.has(this)) return CIRCULAR;
|
1369
1410
|
const newAlreadyVisited = new Set(alreadyVisited);
|
1370
1411
|
newAlreadyVisited.add(this);
|
1371
|
-
const values = this._getMaxTarget().values();
|
1412
|
+
const values = /** @type {Target} */ (this._getMaxTarget()).values();
|
1372
1413
|
const target = resolveTarget(values.next().value, newAlreadyVisited);
|
1373
1414
|
if (target === CIRCULAR) return CIRCULAR;
|
1374
|
-
if (target === null) return
|
1415
|
+
if (target === null) return;
|
1375
1416
|
let result = values.next();
|
1376
1417
|
while (!result.done) {
|
1377
1418
|
const t = resolveTarget(result.value, newAlreadyVisited);
|
1378
1419
|
if (t === CIRCULAR) return CIRCULAR;
|
1379
|
-
if (t === null) return
|
1380
|
-
if (t.module !== target.module) return
|
1381
|
-
if (!t.export !== !target.export) return
|
1420
|
+
if (t === null) return;
|
1421
|
+
if (t.module !== target.module) return;
|
1422
|
+
if (!t.export !== !target.export) return;
|
1382
1423
|
if (
|
1383
1424
|
target.export &&
|
1384
1425
|
!equals(/** @type {ArrayLike<string>} */ (t.export), target.export)
|
1385
1426
|
)
|
1386
|
-
return
|
1427
|
+
return;
|
1387
1428
|
result = values.next();
|
1388
1429
|
}
|
1389
1430
|
return target;
|
@@ -1392,34 +1433,42 @@ class ExportInfo {
|
|
1392
1433
|
/**
|
1393
1434
|
* Move the target forward as long resolveTargetFilter is fulfilled
|
1394
1435
|
* @param {ModuleGraph} moduleGraph the module graph
|
1395
|
-
* @param {function(
|
1396
|
-
* @param {function(
|
1397
|
-
* @returns {
|
1436
|
+
* @param {function(TargetItem): boolean} resolveTargetFilter filter function to further resolve target
|
1437
|
+
* @param {function(TargetItem): ModuleGraphConnection=} updateOriginalConnection updates the original connection instead of using the target connection
|
1438
|
+
* @returns {TargetItem | undefined} the resolved target when moved
|
1398
1439
|
*/
|
1399
1440
|
moveTarget(moduleGraph, resolveTargetFilter, updateOriginalConnection) {
|
1400
1441
|
const target = this._getTarget(moduleGraph, resolveTargetFilter, undefined);
|
1401
|
-
if (target === CIRCULAR) return
|
1402
|
-
if (!target) return
|
1403
|
-
const originalTarget =
|
1442
|
+
if (target === CIRCULAR) return;
|
1443
|
+
if (!target) return;
|
1444
|
+
const originalTarget =
|
1445
|
+
/** @type {Target} */
|
1446
|
+
(this._getMaxTarget()).values().next().value;
|
1404
1447
|
if (
|
1405
1448
|
originalTarget.connection === target.connection &&
|
1406
1449
|
originalTarget.export === target.export
|
1407
1450
|
) {
|
1408
|
-
return
|
1451
|
+
return;
|
1409
1452
|
}
|
1410
|
-
|
1411
|
-
this._target.
|
1453
|
+
/** @type {Target} */
|
1454
|
+
(this._target).clear();
|
1455
|
+
/** @type {Target} */
|
1456
|
+
(this._target).set(undefined, {
|
1412
1457
|
connection: updateOriginalConnection
|
1413
1458
|
? updateOriginalConnection(target)
|
1414
1459
|
: target.connection,
|
1415
|
-
export: target.export,
|
1460
|
+
export: /** @type {NonNullable<TargetItem["export"]>} */ (target.export),
|
1416
1461
|
priority: 0
|
1417
1462
|
});
|
1418
1463
|
return target;
|
1419
1464
|
}
|
1420
1465
|
|
1466
|
+
/**
|
1467
|
+
* @returns {ExportsInfo} an exports info
|
1468
|
+
*/
|
1421
1469
|
createNestedExportsInfo() {
|
1422
|
-
if (this.exportsInfoOwned)
|
1470
|
+
if (this.exportsInfoOwned)
|
1471
|
+
return /** @type {ExportsInfo} */ (this.exportsInfo);
|
1423
1472
|
this.exportsInfoOwned = true;
|
1424
1473
|
const oldExportsInfo = this.exportsInfo;
|
1425
1474
|
this.exportsInfo = new ExportsInfo();
|
@@ -1434,6 +1483,11 @@ class ExportInfo {
|
|
1434
1483
|
return this.exportsInfo;
|
1435
1484
|
}
|
1436
1485
|
|
1486
|
+
/**
|
1487
|
+
* @param {ExportInfo} baseInfo base info
|
1488
|
+
* @param {RuntimeSpec} runtime runtime
|
1489
|
+
* @returns {boolean} true when has info, otherwise false
|
1490
|
+
*/
|
1437
1491
|
hasInfo(baseInfo, runtime) {
|
1438
1492
|
return (
|
1439
1493
|
(this._usedName && this._usedName !== this.name) ||
|
@@ -1443,10 +1497,20 @@ class ExportInfo {
|
|
1443
1497
|
);
|
1444
1498
|
}
|
1445
1499
|
|
1500
|
+
/**
|
1501
|
+
* @param {Hash} hash the hash
|
1502
|
+
* @param {RuntimeSpec} runtime the runtime
|
1503
|
+
* @returns {void}
|
1504
|
+
*/
|
1446
1505
|
updateHash(hash, runtime) {
|
1447
1506
|
this._updateHash(hash, runtime, new Set());
|
1448
1507
|
}
|
1449
1508
|
|
1509
|
+
/**
|
1510
|
+
* @param {Hash} hash the hash
|
1511
|
+
* @param {RuntimeSpec} runtime the runtime
|
1512
|
+
* @param {Set<ExportsInfo>} alreadyVisitedExportsInfo for circular references
|
1513
|
+
*/
|
1450
1514
|
_updateHash(hash, runtime, alreadyVisitedExportsInfo) {
|
1451
1515
|
hash.update(
|
1452
1516
|
`${this._usedName || this.name}${this.getUsed(runtime)}${this.provided}${
|
@@ -1480,6 +1544,7 @@ class ExportInfo {
|
|
1480
1544
|
if (list !== undefined) list.push(runtime);
|
1481
1545
|
else map.set(used, [runtime]);
|
1482
1546
|
}
|
1547
|
+
// eslint-disable-next-line array-callback-return
|
1483
1548
|
const specificInfo = Array.from(map, ([used, runtimes]) => {
|
1484
1549
|
switch (used) {
|
1485
1550
|
case UsageState.NoInfo:
|