webpack 5.104.1 → 5.105.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/bin/webpack.js +6 -3
- package/lib/APIPlugin.js +85 -15
- package/lib/AbstractMethodError.js +1 -0
- package/lib/AsyncDependenciesBlock.js +13 -1
- package/lib/AsyncDependencyToInitialChunkError.js +1 -0
- package/lib/AutomaticPrefetchPlugin.js +1 -1
- package/lib/BannerPlugin.js +2 -0
- package/lib/CacheFacade.js +2 -2
- package/lib/CaseSensitiveModulesWarning.js +1 -0
- package/lib/Chunk.js +8 -4
- package/lib/ChunkGraph.js +30 -9
- package/lib/ChunkGroup.js +6 -3
- package/lib/ChunkRenderError.js +2 -0
- package/lib/CleanPlugin.js +4 -1
- package/lib/CodeGenerationError.js +7 -1
- package/lib/CodeGenerationResults.js +10 -3
- package/lib/CommentCompilationWarning.js +2 -1
- package/lib/Compilation.js +280 -236
- package/lib/Compiler.js +3 -2
- package/lib/ConcatenationScope.js +2 -1
- package/lib/ConcurrentCompilationError.js +3 -3
- package/lib/ContextModule.js +248 -111
- package/lib/ContextModuleFactory.js +14 -2
- package/lib/DefinePlugin.js +3 -1
- package/lib/DelegatedModule.js +6 -0
- package/lib/DelegatedModuleFactoryPlugin.js +2 -0
- package/lib/Dependency.js +6 -1
- package/lib/DependencyTemplates.js +3 -2
- package/lib/DllModule.js +2 -0
- package/lib/DllReferencePlugin.js +1 -0
- package/lib/DotenvPlugin.js +11 -5
- package/lib/DynamicEntryPlugin.js +1 -0
- package/lib/EnvironmentNotSupportAsyncWarning.js +1 -0
- package/lib/EvalSourceMapDevToolPlugin.js +17 -13
- package/lib/ExportsInfo.js +8 -4
- package/lib/ExternalModule.js +16 -0
- package/lib/FalseIIFEUmdWarning.js +1 -0
- package/lib/FileSystemInfo.js +49 -25
- package/lib/FlagDependencyExportsPlugin.js +8 -1
- package/lib/FlagDependencyUsagePlugin.js +9 -7
- package/lib/HarmonyLinkingError.js +1 -0
- package/lib/HookWebpackError.js +2 -0
- package/lib/HotModuleReplacementPlugin.js +16 -2
- package/lib/InitFragment.js +1 -0
- package/lib/InvalidDependenciesModuleWarning.js +1 -0
- package/lib/LibManifestPlugin.js +1 -0
- package/lib/ManifestPlugin.js +4 -1
- package/lib/Module.js +7 -4
- package/lib/ModuleBuildError.js +3 -1
- package/lib/ModuleDependencyError.js +1 -0
- package/lib/ModuleDependencyWarning.js +1 -0
- package/lib/ModuleError.js +2 -1
- package/lib/ModuleFilenameHelpers.js +2 -1
- package/lib/ModuleGraph.js +3 -0
- package/lib/ModuleGraphConnection.js +10 -1
- package/lib/ModuleHashingError.js +2 -0
- package/lib/ModuleInfoHeaderPlugin.js +6 -1
- package/lib/ModuleNotFoundError.js +1 -0
- package/lib/ModuleParseError.js +5 -1
- package/lib/ModuleProfile.js +1 -1
- package/lib/ModuleRestoreError.js +2 -0
- package/lib/ModuleSourceTypeConstants.js +1 -11
- package/lib/ModuleStoreError.js +2 -0
- package/lib/ModuleWarning.js +3 -1
- package/lib/MultiCompiler.js +11 -7
- package/lib/MultiWatching.js +2 -2
- package/lib/NoModeWarning.js +1 -0
- package/lib/NodeStuffInWebError.js +1 -0
- package/lib/NormalModule.js +26 -5
- package/lib/NormalModuleFactory.js +20 -4
- package/lib/OptionsApply.js +3 -1
- package/lib/ProgressPlugin.js +4 -0
- package/lib/RawModule.js +2 -0
- package/lib/RuntimeModule.js +10 -0
- package/lib/RuntimePlugin.js +7 -9
- package/lib/RuntimeTemplate.js +14 -7
- package/lib/SourceMapDevToolPlugin.js +30 -23
- package/lib/Template.js +10 -5
- package/lib/TemplatedPathPlugin.js +4 -2
- package/lib/UnhandledSchemeError.js +1 -0
- package/lib/UnsupportedFeatureWarning.js +1 -0
- package/lib/WarnDeprecatedOptionPlugin.js +1 -0
- package/lib/WatchIgnorePlugin.js +1 -1
- package/lib/Watching.js +5 -0
- package/lib/WebpackError.js +4 -0
- package/lib/WebpackOptionsApply.js +60 -40
- package/lib/asset/AssetBytesGenerator.js +1 -0
- package/lib/asset/AssetGenerator.js +9 -3
- package/lib/asset/AssetModulesPlugin.js +33 -2
- package/lib/asset/AssetSourceGenerator.js +1 -0
- package/lib/asset/RawDataUrlModule.js +4 -0
- package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -1
- package/lib/buildChunkGraph.js +31 -2
- package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
- package/lib/cache/PackFileCacheStrategy.js +41 -8
- package/lib/cache/getLazyHashedEtag.js +13 -4
- package/lib/cache/mergeEtags.js +3 -1
- package/lib/cli.js +3 -1
- package/lib/config/defaults.js +65 -44
- package/lib/config/normalization.js +96 -0
- package/lib/container/ContainerEntryModule.js +4 -0
- package/lib/container/FallbackModule.js +2 -0
- package/lib/container/HoistContainerReferencesPlugin.js +6 -0
- package/lib/container/RemoteModule.js +19 -0
- package/lib/css/CssGenerator.js +31 -4
- package/lib/css/CssModulesPlugin.js +26 -30
- package/lib/css/CssParser.js +12 -9
- package/lib/debug/ProfilingPlugin.js +1 -0
- package/lib/dependencies/AMDDefineDependency.js +3 -1
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -0
- package/lib/dependencies/AMDPlugin.js +1 -1
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +7 -1
- package/lib/dependencies/CachedConstDependency.js +1 -0
- package/lib/dependencies/CommonJsDependencyHelpers.js +2 -0
- package/lib/dependencies/CommonJsExportRequireDependency.js +1 -0
- package/lib/dependencies/CommonJsFullRequireDependency.js +2 -0
- package/lib/dependencies/CommonJsImportsParserPlugin.js +3 -0
- package/lib/dependencies/CommonJsRequireContextDependency.js +2 -2
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +1 -0
- package/lib/dependencies/ConstDependency.js +1 -0
- package/lib/dependencies/ContextDependencyHelpers.js +11 -4
- package/lib/dependencies/ContextElementDependency.js +1 -0
- package/lib/dependencies/CriticalDependencyWarning.js +1 -0
- package/lib/dependencies/CssIcssExportDependency.js +5 -4
- package/lib/dependencies/CssIcssSymbolDependency.js +1 -0
- package/lib/dependencies/CssUrlDependency.js +2 -3
- package/lib/dependencies/ExternalModuleInitFragment.js +4 -1
- package/lib/dependencies/ExternalModuleInitFragmentDependency.js +0 -9
- package/lib/dependencies/HarmonyAcceptDependency.js +3 -0
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +1 -0
- package/lib/dependencies/HarmonyExportExpressionDependency.js +4 -0
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +8 -1
- package/lib/dependencies/HarmonyExportInitFragment.js +17 -3
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +4 -0
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +266 -5
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +22 -3
- package/lib/dependencies/ImportDependency.js +1 -0
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -0
- package/lib/dependencies/ImportMetaPlugin.js +53 -11
- package/lib/dependencies/ImportParserPlugin.js +7 -12
- package/lib/dependencies/LoaderPlugin.js +3 -0
- package/lib/dependencies/ModuleDecoratorDependency.js +1 -0
- package/lib/dependencies/ModuleDependency.js +1 -0
- package/lib/dependencies/ModuleInitFragmentDependency.js +87 -0
- package/lib/dependencies/ProvidedDependency.js +1 -0
- package/lib/dependencies/RequireContextPlugin.js +1 -0
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +7 -2
- package/lib/dependencies/RuntimeRequirementsDependency.js +1 -0
- package/lib/dependencies/WorkerDependency.js +9 -3
- package/lib/dependencies/WorkerPlugin.js +1 -0
- package/lib/dependencies/getFunctionExpression.js +3 -1
- package/lib/errors/BuildCycleError.js +4 -1
- package/lib/esm/ModuleChunkFormatPlugin.js +6 -4
- package/lib/esm/ModuleChunkLoadingPlugin.js +1 -0
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -0
- package/lib/hmr/LazyCompilationPlugin.js +5 -0
- package/lib/hmr/lazyCompilationBackend.js +3 -2
- package/lib/ids/ChunkModuleIdRangePlugin.js +2 -0
- package/lib/ids/IdHelpers.js +10 -8
- package/lib/ids/OccurrenceModuleIdsPlugin.js +15 -7
- package/lib/ids/SyncModuleIdsPlugin.js +5 -1
- package/lib/javascript/BasicEvaluatedExpression.js +1 -0
- package/lib/javascript/EnableChunkLoadingPlugin.js +5 -2
- package/lib/javascript/JavascriptModulesPlugin.js +29 -8
- package/lib/javascript/JavascriptParser.js +47 -14
- package/lib/json/JsonParser.js +6 -0
- package/lib/library/AbstractLibraryPlugin.js +4 -1
- package/lib/library/AmdLibraryPlugin.js +2 -1
- package/lib/library/AssignLibraryPlugin.js +6 -2
- package/lib/library/EnableLibraryPlugin.js +1 -0
- package/lib/library/ExportPropertyLibraryPlugin.js +1 -1
- package/lib/library/JsonpLibraryPlugin.js +1 -1
- package/lib/library/ModuleLibraryPlugin.js +130 -13
- package/lib/library/SystemLibraryPlugin.js +4 -1
- package/lib/library/UmdLibraryPlugin.js +4 -3
- package/lib/logging/createConsoleLogger.js +3 -0
- package/lib/logging/truncateArgs.js +1 -1
- package/lib/node/CommonJsChunkLoadingPlugin.js +1 -0
- package/lib/node/NodeTargetPlugin.js +1 -0
- package/lib/node/NodeWatchFileSystem.js +3 -0
- package/lib/node/nodeConsole.js +18 -1
- package/lib/optimize/AggressiveMergingPlugin.js +2 -1
- package/lib/optimize/AggressiveSplittingPlugin.js +10 -6
- package/lib/optimize/ConcatenatedModule.js +33 -19
- package/lib/optimize/FlagIncludedChunksPlugin.js +11 -1
- package/lib/optimize/InnerGraph.js +5 -3
- package/lib/optimize/InnerGraphPlugin.js +25 -25
- package/lib/optimize/MangleExportsPlugin.js +14 -2
- package/lib/optimize/MergeDuplicateChunksPlugin.js +3 -0
- package/lib/optimize/MinChunkSizePlugin.js +5 -2
- package/lib/optimize/ModuleConcatenationPlugin.js +19 -4
- package/lib/optimize/RealContentHashPlugin.js +35 -27
- package/lib/optimize/RemoveParentModulesPlugin.js +12 -3
- package/lib/optimize/SideEffectsFlagPlugin.js +3 -0
- package/lib/optimize/SplitChunksPlugin.js +14 -3
- package/lib/performance/AssetsOverSizeLimitWarning.js +6 -2
- package/lib/performance/EntrypointsOverSizeLimitWarning.js +6 -2
- package/lib/performance/NoAsyncChunksWarning.js +1 -0
- package/lib/rules/BasicEffectRulePlugin.js +2 -0
- package/lib/rules/BasicMatcherRulePlugin.js +3 -0
- package/lib/rules/ObjectMatcherRulePlugin.js +5 -1
- package/lib/rules/RuleSetCompiler.js +2 -0
- package/lib/runtime/AsyncModuleRuntimeModule.js +1 -0
- package/lib/runtime/ChunkNameRuntimeModule.js +1 -0
- package/lib/runtime/CompatRuntimeModule.js +1 -0
- package/lib/runtime/EnsureChunkRuntimeModule.js +1 -0
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +4 -0
- package/lib/runtime/GetMainFilenameRuntimeModule.js +2 -0
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -0
- package/lib/runtime/LoadScriptRuntimeModule.js +2 -0
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +15 -32
- package/lib/runtime/PublicPathRuntimeModule.js +1 -0
- package/lib/runtime/StartupChunkDependenciesPlugin.js +2 -0
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -0
- package/lib/runtime/StartupEntrypointRuntimeModule.js +1 -0
- package/lib/schemes/HttpUriPlugin.js +27 -7
- package/lib/schemes/VirtualUrlPlugin.js +7 -2
- package/lib/serialization/BinaryMiddleware.js +4 -0
- package/lib/serialization/FileMiddleware.js +9 -4
- package/lib/serialization/ObjectMiddleware.js +34 -11
- package/lib/serialization/PlainObjectSerializer.js +2 -0
- package/lib/sharing/ConsumeSharedModule.js +60 -0
- package/lib/sharing/ConsumeSharedPlugin.js +5 -4
- package/lib/sharing/ProvideSharedModule.js +4 -0
- package/lib/sharing/ProvideSharedPlugin.js +24 -25
- package/lib/sharing/resolveMatchedConfigs.js +2 -2
- package/lib/sharing/utils.js +8 -6
- package/lib/stats/DefaultStatsFactoryPlugin.js +14 -12
- package/lib/stats/DefaultStatsPrinterPlugin.js +6 -5
- package/lib/stats/StatsFactory.js +2 -2
- package/lib/url/URLParserPlugin.js +4 -3
- package/lib/util/AppendOnlyStackedSet.js +57 -0
- package/lib/util/Hash.js +1 -0
- package/lib/util/IterableHelpers.js +1 -0
- package/lib/util/LazyBucketSortedSet.js +1 -0
- package/lib/util/LazySet.js +1 -0
- package/lib/util/ParallelismFactorCalculator.js +1 -0
- package/lib/util/SortableSet.js +1 -0
- package/lib/util/StringXor.js +1 -0
- package/lib/util/binarySearchBounds.js +15 -8
- package/lib/util/chainedImports.js +1 -1
- package/lib/util/cleverMerge.js +6 -1
- package/lib/util/comparators.js +21 -1
- package/lib/util/compileBooleanMatcher.js +3 -3
- package/lib/util/concatenate.js +3 -2
- package/lib/util/conventions.js +3 -2
- package/lib/util/deterministicGrouping.js +13 -1
- package/lib/util/extractSourceMap.js +12 -13
- package/lib/util/fs.js +15 -19
- package/lib/util/hash/BatchedHash.js +3 -0
- package/lib/util/hash/BulkUpdateHash.js +7 -1
- package/lib/util/hash/hash-digest.js +1 -0
- package/lib/util/hash/wasm-hash.js +16 -1
- package/lib/util/identifier.js +7 -2
- package/lib/util/magicComment.js +1 -1
- package/lib/util/propertyName.js +1 -1
- package/lib/util/registerExternalSerializer.js +1 -0
- package/lib/util/runtime.js +15 -1
- package/lib/util/semver.js +1 -0
- package/lib/util/serialization.js +2 -2
- package/lib/wasm/EnableWasmLoadingPlugin.js +1 -0
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +11 -3
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -0
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -2
- package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +5 -1
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +3 -0
- package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +2 -0
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +7 -3
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +2 -2
- package/lib/wasm-sync/WebAssemblyParser.js +3 -1
- package/lib/web/FetchCompileWasmPlugin.js +1 -0
- package/lib/web/JsonpChunkLoadingPlugin.js +1 -0
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -0
- package/lib/webpack.js +13 -3
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +1 -0
- package/package.json +20 -28
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +71 -5
- package/types.d.ts +339 -93
|
@@ -72,6 +72,7 @@ const {
|
|
|
72
72
|
/** @typedef {import("../Module").FileSystemDependencies} FileSystemDependencies */
|
|
73
73
|
/** @typedef {import("../Module").BuildMeta} BuildMeta */
|
|
74
74
|
/** @typedef {import("../Module").CodeGenerationContext} CodeGenerationContext */
|
|
75
|
+
/** @typedef {import("../Module").CodeGenerationResultData} CodeGenerationResultData */
|
|
75
76
|
/** @typedef {import("../Module").CodeGenerationResult} CodeGenerationResult */
|
|
76
77
|
/** @typedef {import("../Module").LibIdentOptions} LibIdentOptions */
|
|
77
78
|
/** @typedef {import("../Module").LibIdent} LibIdent */
|
|
@@ -90,7 +91,8 @@ const {
|
|
|
90
91
|
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
|
91
92
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
|
92
93
|
/** @typedef {import("../util/Hash")} Hash */
|
|
93
|
-
/** @typedef {
|
|
94
|
+
/** @typedef {import("../util/Hash").HashFunction} HashFunction */
|
|
95
|
+
/** @typedef {import("../util/concatenate").UsedNames} UsedNames */
|
|
94
96
|
/** @typedef {import("../util/concatenate").ScopeInfo} ScopeInfo */
|
|
95
97
|
/** @typedef {import("../util/fs").InputFileSystem} InputFileSystem */
|
|
96
98
|
/** @typedef {import("../util/identifier").AssociatedObjectForCache} AssociatedObjectForCache */
|
|
@@ -227,6 +229,7 @@ const compareNumbers = (a, b) => {
|
|
|
227
229
|
}
|
|
228
230
|
return 0;
|
|
229
231
|
};
|
|
232
|
+
|
|
230
233
|
const bySourceOrder = createComparator("sourceOrder", compareNumbers);
|
|
231
234
|
const byRangeStart = createComparator("rangeStart", compareNumbers);
|
|
232
235
|
|
|
@@ -653,7 +656,9 @@ const getFinalName = (
|
|
|
653
656
|
);
|
|
654
657
|
{
|
|
655
658
|
const { ids, comment } = binding;
|
|
659
|
+
/** @type {string} */
|
|
656
660
|
let reference;
|
|
661
|
+
/** @type {boolean} */
|
|
657
662
|
let isPropertyAccess;
|
|
658
663
|
if ("rawName" in binding) {
|
|
659
664
|
reference = `${binding.rawName}${comment || ""}${propertyAccess(ids)}`;
|
|
@@ -705,7 +710,7 @@ class ConcatenatedModule extends Module {
|
|
|
705
710
|
* @param {RuntimeSpec} runtime the runtime
|
|
706
711
|
* @param {Compilation} compilation the compilation
|
|
707
712
|
* @param {AssociatedObjectForCache=} associatedObjectForCache object for caching
|
|
708
|
-
* @param {
|
|
713
|
+
* @param {HashFunction=} hashFunction hash function to use
|
|
709
714
|
* @returns {ConcatenatedModule} the module
|
|
710
715
|
*/
|
|
711
716
|
static create(
|
|
@@ -854,6 +859,7 @@ class ConcatenatedModule extends Module {
|
|
|
854
859
|
const { moduleArgument, exportsArgument } =
|
|
855
860
|
/** @type {BuildInfo} */
|
|
856
861
|
(rootModule.buildInfo);
|
|
862
|
+
/** @type {BuildInfo} */
|
|
857
863
|
this.buildInfo = {
|
|
858
864
|
strict: true,
|
|
859
865
|
cacheable: true,
|
|
@@ -872,8 +878,7 @@ class ConcatenatedModule extends Module {
|
|
|
872
878
|
for (const m of this._modules) {
|
|
873
879
|
// populate cacheable
|
|
874
880
|
if (!(/** @type {BuildInfo} */ (m.buildInfo).cacheable)) {
|
|
875
|
-
|
|
876
|
-
(this.buildInfo).cacheable = false;
|
|
881
|
+
this.buildInfo.cacheable = false;
|
|
877
882
|
}
|
|
878
883
|
|
|
879
884
|
// populate dependencies
|
|
@@ -911,7 +916,7 @@ class ConcatenatedModule extends Module {
|
|
|
911
916
|
const { assets, assetsInfo, topLevelDeclarations, needCreateRequire } =
|
|
912
917
|
/** @type {BuildInfo} */ (m.buildInfo);
|
|
913
918
|
|
|
914
|
-
const buildInfo =
|
|
919
|
+
const buildInfo = this.buildInfo;
|
|
915
920
|
|
|
916
921
|
// populate topLevelDeclarations
|
|
917
922
|
if (topLevelDeclarations) {
|
|
@@ -1209,7 +1214,7 @@ class ConcatenatedModule extends Module {
|
|
|
1209
1214
|
* @param {Module} rootModule the root module of the concatenation
|
|
1210
1215
|
* @param {Set<Module>} modules all modules in the concatenation (including the root module)
|
|
1211
1216
|
* @param {AssociatedObjectForCache=} associatedObjectForCache object for caching
|
|
1212
|
-
* @param {
|
|
1217
|
+
* @param {HashFunction=} hashFunction hash function to use
|
|
1213
1218
|
* @returns {string} the identifier
|
|
1214
1219
|
*/
|
|
1215
1220
|
static _createIdentifier(
|
|
@@ -1222,6 +1227,7 @@ class ConcatenatedModule extends Module {
|
|
|
1222
1227
|
/** @type {string} */ (rootModule.context),
|
|
1223
1228
|
associatedObjectForCache
|
|
1224
1229
|
);
|
|
1230
|
+
/** @type {string[]} */
|
|
1225
1231
|
const identifiers = [];
|
|
1226
1232
|
for (const module of modules) {
|
|
1227
1233
|
identifiers.push(cachedMakePathsRelative(module.identifier()));
|
|
@@ -1316,6 +1322,7 @@ class ConcatenatedModule extends Module {
|
|
|
1316
1322
|
const usedNamesInScopeInfo = new Map();
|
|
1317
1323
|
|
|
1318
1324
|
// Set of already checked scopes
|
|
1325
|
+
/** @type {Set<Scope>} */
|
|
1319
1326
|
const ignoredScopes = new Set();
|
|
1320
1327
|
|
|
1321
1328
|
// get all global names
|
|
@@ -1329,14 +1336,17 @@ class ConcatenatedModule extends Module {
|
|
|
1329
1336
|
// The super class expression in class scopes behaves weird
|
|
1330
1337
|
// We get ranges of all super class expressions to make
|
|
1331
1338
|
// renaming to work correctly
|
|
1339
|
+
/** @typedef {{ range: Range, variables: Variable[] }} ClassInfo */
|
|
1340
|
+
/** @type {WeakMap<Scope, ClassInfo[]>} */
|
|
1332
1341
|
const superClassCache = new WeakMap();
|
|
1333
1342
|
/**
|
|
1334
1343
|
* @param {Scope} scope scope
|
|
1335
|
-
* @returns {
|
|
1344
|
+
* @returns {ClassInfo[]} result
|
|
1336
1345
|
*/
|
|
1337
1346
|
const getSuperClassExpressions = (scope) => {
|
|
1338
1347
|
const cacheEntry = superClassCache.get(scope);
|
|
1339
1348
|
if (cacheEntry !== undefined) return cacheEntry;
|
|
1349
|
+
/** @type {ClassInfo[]} */
|
|
1340
1350
|
const superClassExpressions = [];
|
|
1341
1351
|
for (const childScope of scope.childScopes) {
|
|
1342
1352
|
if (childScope.type !== "class") continue;
|
|
@@ -1462,6 +1472,7 @@ class ConcatenatedModule extends Module {
|
|
|
1462
1472
|
info.module.identifier(),
|
|
1463
1473
|
name
|
|
1464
1474
|
);
|
|
1475
|
+
/** @type {UsedNames} */
|
|
1465
1476
|
const referencesUsedNames = new Set();
|
|
1466
1477
|
for (const ref of references) {
|
|
1467
1478
|
addScopeSymbols(
|
|
@@ -1533,11 +1544,12 @@ class ConcatenatedModule extends Module {
|
|
|
1533
1544
|
topLevelDeclarations.add(name);
|
|
1534
1545
|
}
|
|
1535
1546
|
}
|
|
1547
|
+
/** @type {string} */
|
|
1536
1548
|
let namespaceObjectName;
|
|
1537
1549
|
if (info.namespaceExportSymbol) {
|
|
1538
|
-
namespaceObjectName =
|
|
1539
|
-
|
|
1540
|
-
|
|
1550
|
+
namespaceObjectName =
|
|
1551
|
+
/** @type {string} */
|
|
1552
|
+
(info.internalNames.get(info.namespaceExportSymbol));
|
|
1541
1553
|
} else {
|
|
1542
1554
|
namespaceObjectName = findNewName(
|
|
1543
1555
|
"namespaceObject",
|
|
@@ -1547,13 +1559,8 @@ class ConcatenatedModule extends Module {
|
|
|
1547
1559
|
);
|
|
1548
1560
|
allUsedNames.add(namespaceObjectName);
|
|
1549
1561
|
}
|
|
1550
|
-
info.namespaceObjectName =
|
|
1551
|
-
|
|
1552
|
-
(namespaceObjectName);
|
|
1553
|
-
topLevelDeclarations.add(
|
|
1554
|
-
/** @type {string} */
|
|
1555
|
-
(namespaceObjectName)
|
|
1556
|
-
);
|
|
1562
|
+
info.namespaceObjectName = namespaceObjectName;
|
|
1563
|
+
topLevelDeclarations.add(namespaceObjectName);
|
|
1557
1564
|
break;
|
|
1558
1565
|
}
|
|
1559
1566
|
case "external": {
|
|
@@ -1636,13 +1643,15 @@ class ConcatenatedModule extends Module {
|
|
|
1636
1643
|
if (info.type === "concatenated") {
|
|
1637
1644
|
const globalScope = /** @type {Scope} */ (info.globalScope);
|
|
1638
1645
|
// group references by name
|
|
1646
|
+
/** @type {Map<string, Reference[]>} */
|
|
1639
1647
|
const referencesByName = new Map();
|
|
1640
1648
|
for (const reference of globalScope.through) {
|
|
1641
1649
|
const name = reference.identifier.name;
|
|
1642
1650
|
if (!referencesByName.has(name)) {
|
|
1643
1651
|
referencesByName.set(name, []);
|
|
1644
1652
|
}
|
|
1645
|
-
|
|
1653
|
+
/** @type {Reference[]} */
|
|
1654
|
+
(referencesByName.get(name)).push(reference);
|
|
1646
1655
|
}
|
|
1647
1656
|
for (const [name, references] of referencesByName) {
|
|
1648
1657
|
const match = ConcatenationScope.matchModuleReference(name);
|
|
@@ -1775,6 +1784,7 @@ class ConcatenatedModule extends Module {
|
|
|
1775
1784
|
|
|
1776
1785
|
// define exports
|
|
1777
1786
|
if (exportsMap.size > 0) {
|
|
1787
|
+
/** @type {string[]} */
|
|
1778
1788
|
const definitions = [];
|
|
1779
1789
|
for (const [key, value] of exportsMap) {
|
|
1780
1790
|
definitions.push(
|
|
@@ -1826,9 +1836,11 @@ class ConcatenatedModule extends Module {
|
|
|
1826
1836
|
}
|
|
1827
1837
|
|
|
1828
1838
|
// generate namespace objects
|
|
1839
|
+
/** @type {Map<ConcatenatedModuleInfo, string>} */
|
|
1829
1840
|
const namespaceObjectSources = new Map();
|
|
1830
1841
|
for (const info of neededNamespaceObjects) {
|
|
1831
1842
|
if (info.namespaceExportSymbol) continue;
|
|
1843
|
+
/** @type {string[]} */
|
|
1832
1844
|
const nsObj = [];
|
|
1833
1845
|
const exportsInfo = moduleGraph.getExportsInfo(info.module);
|
|
1834
1846
|
for (const exportInfo of exportsInfo.orderedExports) {
|
|
@@ -1924,6 +1936,7 @@ ${defineGetters}`
|
|
|
1924
1936
|
|
|
1925
1937
|
// evaluate modules in order
|
|
1926
1938
|
for (const rawInfo of modulesWithInfo) {
|
|
1939
|
+
/** @type {undefined | string} */
|
|
1927
1940
|
let name;
|
|
1928
1941
|
let isConditional = false;
|
|
1929
1942
|
const info = rawInfo.type === "reference" ? rawInfo.target : rawInfo;
|
|
@@ -2012,6 +2025,7 @@ ${defineGetters}`
|
|
|
2012
2025
|
}
|
|
2013
2026
|
}
|
|
2014
2027
|
|
|
2028
|
+
/** @type {CodeGenerationResultData} */
|
|
2015
2029
|
const data = new Map();
|
|
2016
2030
|
if (chunkInitFragments.length > 0) {
|
|
2017
2031
|
data.set("chunkInitFragments", chunkInitFragments);
|
|
@@ -2038,7 +2052,7 @@ ${defineGetters}`
|
|
|
2038
2052
|
* @param {RuntimeSpec} runtime runtime
|
|
2039
2053
|
* @param {RuntimeSpec[]} runtimes runtimes
|
|
2040
2054
|
* @param {CodeGenerationResults} codeGenerationResults codeGenerationResults
|
|
2041
|
-
* @param {
|
|
2055
|
+
* @param {UsedNames} usedNames used names
|
|
2042
2056
|
*/
|
|
2043
2057
|
_analyseModule(
|
|
2044
2058
|
modulesMap,
|
|
@@ -42,7 +42,16 @@ class FlagIncludedChunksPlugin {
|
|
|
42
42
|
|
|
43
43
|
// precalculate the modulo values for each bit
|
|
44
44
|
const modulo = 1 / (1 / modulesCount) ** (1 / 31);
|
|
45
|
-
|
|
45
|
+
/** @type {number[]} */
|
|
46
|
+
const modulos = Array.from(
|
|
47
|
+
{ length: 31 },
|
|
48
|
+
/**
|
|
49
|
+
* @param {number} x x
|
|
50
|
+
* @param {number} i i
|
|
51
|
+
* @returns {number} result
|
|
52
|
+
*/
|
|
53
|
+
(x, i) => (modulo ** i) | 0
|
|
54
|
+
);
|
|
46
55
|
|
|
47
56
|
// iterate all modules to generate bit values
|
|
48
57
|
let i = 0;
|
|
@@ -72,6 +81,7 @@ class FlagIncludedChunksPlugin {
|
|
|
72
81
|
(chunkModulesHash.get(chunkA));
|
|
73
82
|
const chunkAModulesCount = chunkGraph.getNumberOfChunkModules(chunkA);
|
|
74
83
|
if (chunkAModulesCount === 0) continue;
|
|
84
|
+
/** @type {undefined | Module} */
|
|
75
85
|
let bestModule;
|
|
76
86
|
for (const module of chunkGraph.getChunkModulesIterable(chunkA)) {
|
|
77
87
|
if (
|
|
@@ -35,6 +35,7 @@ class TopLevelSymbol {
|
|
|
35
35
|
* @param {string} name name of the variable
|
|
36
36
|
*/
|
|
37
37
|
constructor(name) {
|
|
38
|
+
/** @type {string} */
|
|
38
39
|
this.name = name;
|
|
39
40
|
}
|
|
40
41
|
}
|
|
@@ -310,6 +311,7 @@ module.exports.onUsage = (state, onUsageCallback) => {
|
|
|
310
311
|
let callbacks = usageCallbackMap.get(currentTopLevelSymbol);
|
|
311
312
|
|
|
312
313
|
if (callbacks === undefined) {
|
|
314
|
+
/** @type {Set<UsageCallback>} */
|
|
313
315
|
callbacks = new Set();
|
|
314
316
|
usageCallbackMap.set(currentTopLevelSymbol, callbacks);
|
|
315
317
|
}
|
|
@@ -353,14 +355,14 @@ module.exports.tagTopLevelSymbol = (parser, name) => {
|
|
|
353
355
|
return existingTag;
|
|
354
356
|
}
|
|
355
357
|
|
|
356
|
-
const
|
|
358
|
+
const symbol = new TopLevelSymbol(name);
|
|
357
359
|
parser.tagVariable(
|
|
358
360
|
name,
|
|
359
361
|
topLevelSymbolTag,
|
|
360
|
-
|
|
362
|
+
symbol,
|
|
361
363
|
JavascriptParser.VariableInfoFlags.Normal
|
|
362
364
|
);
|
|
363
|
-
return
|
|
365
|
+
return symbol;
|
|
364
366
|
};
|
|
365
367
|
|
|
366
368
|
module.exports.topLevelSymbolTag = topLevelSymbolTag;
|
|
@@ -120,10 +120,10 @@ class InnerGraphPlugin {
|
|
|
120
120
|
statement.type === "FunctionDeclaration"
|
|
121
121
|
) {
|
|
122
122
|
const name = statement.id ? statement.id.name : "*default*";
|
|
123
|
-
const
|
|
123
|
+
const symbol =
|
|
124
124
|
/** @type {TopLevelSymbol} */
|
|
125
125
|
(InnerGraph.tagTopLevelSymbol(parser, name));
|
|
126
|
-
statementWithTopLevelSymbol.set(statement,
|
|
126
|
+
statementWithTopLevelSymbol.set(statement, symbol);
|
|
127
127
|
return true;
|
|
128
128
|
}
|
|
129
129
|
});
|
|
@@ -140,15 +140,15 @@ class InnerGraphPlugin {
|
|
|
140
140
|
)
|
|
141
141
|
) {
|
|
142
142
|
const name = statement.id ? statement.id.name : "*default*";
|
|
143
|
-
const
|
|
143
|
+
const symbol = /** @type {TopLevelSymbol} */ (
|
|
144
144
|
InnerGraph.tagTopLevelSymbol(parser, name)
|
|
145
145
|
);
|
|
146
|
-
classWithTopLevelSymbol.set(statement,
|
|
146
|
+
classWithTopLevelSymbol.set(statement, symbol);
|
|
147
147
|
return true;
|
|
148
148
|
}
|
|
149
149
|
if (statement.type === "ExportDefaultDeclaration") {
|
|
150
150
|
const name = "*default*";
|
|
151
|
-
const
|
|
151
|
+
const symbol =
|
|
152
152
|
/** @type {TopLevelSymbol} */
|
|
153
153
|
(InnerGraph.tagTopLevelSymbol(parser, name));
|
|
154
154
|
const decl = statement.declaration;
|
|
@@ -165,7 +165,7 @@ class InnerGraphPlugin {
|
|
|
165
165
|
classWithTopLevelSymbol.set(
|
|
166
166
|
/** @type {ClassExpression | ClassDeclaration} */
|
|
167
167
|
(decl),
|
|
168
|
-
|
|
168
|
+
symbol
|
|
169
169
|
);
|
|
170
170
|
} else if (
|
|
171
171
|
parser.isPure(
|
|
@@ -175,7 +175,7 @@ class InnerGraphPlugin {
|
|
|
175
175
|
(statement.range)[0]
|
|
176
176
|
)
|
|
177
177
|
) {
|
|
178
|
-
statementWithTopLevelSymbol.set(statement,
|
|
178
|
+
statementWithTopLevelSymbol.set(statement, symbol);
|
|
179
179
|
if (
|
|
180
180
|
!decl.type.endsWith("FunctionExpression") &&
|
|
181
181
|
!decl.type.endsWith("Declaration") &&
|
|
@@ -207,20 +207,20 @@ class InnerGraphPlugin {
|
|
|
207
207
|
/** @type {Range} */ (decl.id.range)[1]
|
|
208
208
|
)
|
|
209
209
|
) {
|
|
210
|
-
const
|
|
210
|
+
const symbol =
|
|
211
211
|
/** @type {TopLevelSymbol} */
|
|
212
212
|
(InnerGraph.tagTopLevelSymbol(parser, name));
|
|
213
|
-
classWithTopLevelSymbol.set(decl.init,
|
|
213
|
+
classWithTopLevelSymbol.set(decl.init, symbol);
|
|
214
214
|
} else if (
|
|
215
215
|
parser.isPure(
|
|
216
216
|
decl.init,
|
|
217
217
|
/** @type {Range} */ (decl.id.range)[1]
|
|
218
218
|
)
|
|
219
219
|
) {
|
|
220
|
-
const
|
|
220
|
+
const symbol =
|
|
221
221
|
/** @type {TopLevelSymbol} */
|
|
222
222
|
(InnerGraph.tagTopLevelSymbol(parser, name));
|
|
223
|
-
declWithTopLevelSymbol.set(decl,
|
|
223
|
+
declWithTopLevelSymbol.set(decl, symbol);
|
|
224
224
|
if (
|
|
225
225
|
!decl.init.type.endsWith("FunctionExpression") &&
|
|
226
226
|
decl.init.type !== "Literal"
|
|
@@ -252,9 +252,9 @@ class InnerGraphPlugin {
|
|
|
252
252
|
if (parser.scope.topLevelScope === true) {
|
|
253
253
|
InnerGraph.setTopLevelSymbol(parser.state, undefined);
|
|
254
254
|
|
|
255
|
-
const
|
|
256
|
-
if (
|
|
257
|
-
InnerGraph.setTopLevelSymbol(parser.state,
|
|
255
|
+
const symbol = statementWithTopLevelSymbol.get(statement);
|
|
256
|
+
if (symbol) {
|
|
257
|
+
InnerGraph.setTopLevelSymbol(parser.state, symbol);
|
|
258
258
|
const purePart = statementPurePart.get(statement);
|
|
259
259
|
if (purePart) {
|
|
260
260
|
InnerGraph.onUsage(parser.state, (usedByExports) => {
|
|
@@ -285,9 +285,9 @@ class InnerGraphPlugin {
|
|
|
285
285
|
(expr, statement) => {
|
|
286
286
|
if (!InnerGraph.isEnabled(parser.state)) return;
|
|
287
287
|
if (parser.scope.topLevelScope === true) {
|
|
288
|
-
const
|
|
288
|
+
const symbol = classWithTopLevelSymbol.get(statement);
|
|
289
289
|
if (
|
|
290
|
-
|
|
290
|
+
symbol &&
|
|
291
291
|
parser.isPure(
|
|
292
292
|
expr,
|
|
293
293
|
statement.id
|
|
@@ -295,7 +295,7 @@ class InnerGraphPlugin {
|
|
|
295
295
|
: /** @type {Range} */ (statement.range)[0]
|
|
296
296
|
)
|
|
297
297
|
) {
|
|
298
|
-
InnerGraph.setTopLevelSymbol(parser.state,
|
|
298
|
+
InnerGraph.setTopLevelSymbol(parser.state, symbol);
|
|
299
299
|
onUsageSuper(expr);
|
|
300
300
|
}
|
|
301
301
|
}
|
|
@@ -307,8 +307,8 @@ class InnerGraphPlugin {
|
|
|
307
307
|
(element, classDefinition) => {
|
|
308
308
|
if (!InnerGraph.isEnabled(parser.state)) return;
|
|
309
309
|
if (parser.scope.topLevelScope === true) {
|
|
310
|
-
const
|
|
311
|
-
if (
|
|
310
|
+
const symbol = classWithTopLevelSymbol.get(classDefinition);
|
|
311
|
+
if (symbol) {
|
|
312
312
|
InnerGraph.setTopLevelSymbol(parser.state, undefined);
|
|
313
313
|
}
|
|
314
314
|
}
|
|
@@ -320,8 +320,8 @@ class InnerGraphPlugin {
|
|
|
320
320
|
(expression, element, classDefinition) => {
|
|
321
321
|
if (!InnerGraph.isEnabled(parser.state)) return;
|
|
322
322
|
if (parser.scope.topLevelScope === true) {
|
|
323
|
-
const
|
|
324
|
-
if (
|
|
323
|
+
const symbol = classWithTopLevelSymbol.get(classDefinition);
|
|
324
|
+
if (symbol) {
|
|
325
325
|
if (
|
|
326
326
|
!element.static ||
|
|
327
327
|
parser.isPure(
|
|
@@ -331,7 +331,7 @@ class InnerGraphPlugin {
|
|
|
331
331
|
: /** @type {Range} */ (element.range)[0]
|
|
332
332
|
)
|
|
333
333
|
) {
|
|
334
|
-
InnerGraph.setTopLevelSymbol(parser.state,
|
|
334
|
+
InnerGraph.setTopLevelSymbol(parser.state, symbol);
|
|
335
335
|
if (element.type !== "MethodDefinition" && element.static) {
|
|
336
336
|
InnerGraph.onUsage(parser.state, (usedByExports) => {
|
|
337
337
|
switch (usedByExports) {
|
|
@@ -362,10 +362,10 @@ class InnerGraphPlugin {
|
|
|
362
362
|
|
|
363
363
|
parser.hooks.declarator.tap(PLUGIN_NAME, (decl, _statement) => {
|
|
364
364
|
if (!InnerGraph.isEnabled(parser.state)) return;
|
|
365
|
-
const
|
|
365
|
+
const symbol = declWithTopLevelSymbol.get(decl);
|
|
366
366
|
|
|
367
|
-
if (
|
|
368
|
-
InnerGraph.setTopLevelSymbol(parser.state,
|
|
367
|
+
if (symbol) {
|
|
368
|
+
InnerGraph.setTopLevelSymbol(parser.state, symbol);
|
|
369
369
|
if (pureDeclarators.has(decl)) {
|
|
370
370
|
if (
|
|
371
371
|
/** @type {ClassExpression} */
|
|
@@ -17,6 +17,12 @@ const { compareSelect, compareStringsNumeric } = require("../util/comparators");
|
|
|
17
17
|
/** @typedef {import("../Compiler")} Compiler */
|
|
18
18
|
/** @typedef {import("../ExportsInfo")} ExportsInfo */
|
|
19
19
|
/** @typedef {import("../ExportsInfo").ExportInfo} ExportInfo */
|
|
20
|
+
/** @typedef {import("../util/concatenate").UsedNames} UsedNames */
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @template T
|
|
24
|
+
* @typedef {import("../util/comparators").Comparator<T>} Comparator
|
|
25
|
+
*/
|
|
20
26
|
|
|
21
27
|
/**
|
|
22
28
|
* @param {ExportsInfo} exportsInfo exports info
|
|
@@ -36,6 +42,7 @@ const canMangle = (exportsInfo) => {
|
|
|
36
42
|
};
|
|
37
43
|
|
|
38
44
|
// Sort by name
|
|
45
|
+
/** @type {Comparator<ExportInfo>} */
|
|
39
46
|
const comparator = compareSelect((e) => e.name, compareStringsNumeric);
|
|
40
47
|
/**
|
|
41
48
|
* @param {boolean} deterministic use deterministic names
|
|
@@ -45,6 +52,7 @@ const comparator = compareSelect((e) => e.name, compareStringsNumeric);
|
|
|
45
52
|
*/
|
|
46
53
|
const mangleExportsInfo = (deterministic, exportsInfo, isNamespace) => {
|
|
47
54
|
if (!canMangle(exportsInfo)) return;
|
|
55
|
+
/** @type {UsedNames} */
|
|
48
56
|
const usedNames = new Set();
|
|
49
57
|
/** @type {ExportInfo[]} */
|
|
50
58
|
const mangleableExports = [];
|
|
@@ -69,11 +77,11 @@ const mangleExportsInfo = (deterministic, exportsInfo, isNamespace) => {
|
|
|
69
77
|
// Can the export be mangled?
|
|
70
78
|
exportInfo.canMangle !== true ||
|
|
71
79
|
// Never rename 1 char exports
|
|
72
|
-
(name.length === 1 && /^[a-
|
|
80
|
+
(name.length === 1 && /^[a-z0-9_$]/i.test(name)) ||
|
|
73
81
|
// Don't rename 2 char exports in deterministic mode
|
|
74
82
|
(deterministic &&
|
|
75
83
|
name.length === 2 &&
|
|
76
|
-
/^[a-
|
|
84
|
+
/^[a-z_$][a-z0-9_$]|^[1-9][0-9]/i.test(name)) ||
|
|
77
85
|
// Don't rename exports that are not provided
|
|
78
86
|
(avoidMangleNonProvided && exportInfo.provided !== true)
|
|
79
87
|
) {
|
|
@@ -119,7 +127,9 @@ const mangleExportsInfo = (deterministic, exportsInfo, isNamespace) => {
|
|
|
119
127
|
usedNames.size
|
|
120
128
|
);
|
|
121
129
|
} else {
|
|
130
|
+
/** @type {ExportInfo[]} */
|
|
122
131
|
const usedExports = [];
|
|
132
|
+
/** @type {ExportInfo[]} */
|
|
123
133
|
const unusedExports = [];
|
|
124
134
|
for (const exportInfo of mangleableExports) {
|
|
125
135
|
if (exportInfo.getUsed(undefined) === UsageState.Unused) {
|
|
@@ -133,6 +143,7 @@ const mangleExportsInfo = (deterministic, exportsInfo, isNamespace) => {
|
|
|
133
143
|
let i = 0;
|
|
134
144
|
for (const list of [usedExports, unusedExports]) {
|
|
135
145
|
for (const exportInfo of list) {
|
|
146
|
+
/** @type {string} */
|
|
136
147
|
let name;
|
|
137
148
|
do {
|
|
138
149
|
name = numberToIdentifier(i++);
|
|
@@ -150,6 +161,7 @@ class MangleExportsPlugin {
|
|
|
150
161
|
* @param {boolean} deterministic use deterministic names
|
|
151
162
|
*/
|
|
152
163
|
constructor(deterministic) {
|
|
164
|
+
/** @type {boolean} */
|
|
153
165
|
this._deterministic = deterministic;
|
|
154
166
|
}
|
|
155
167
|
|
|
@@ -11,6 +11,7 @@ const { runtimeEqual } = require("../util/runtime");
|
|
|
11
11
|
|
|
12
12
|
/** @typedef {import("../../declarations/plugins/optimize/MergeDuplicateChunksPlugin").MergeDuplicateChunksPluginOptions} MergeDuplicateChunksPluginOptions */
|
|
13
13
|
/** @typedef {import("../Compiler")} Compiler */
|
|
14
|
+
/** @typedef {import("../Chunk")} Chunk */
|
|
14
15
|
|
|
15
16
|
const validate = createSchemaValidation(
|
|
16
17
|
require("../../schemas/plugins/optimize/MergeDuplicateChunksPlugin.check"),
|
|
@@ -48,11 +49,13 @@ class MergeDuplicateChunksPlugin {
|
|
|
48
49
|
const { chunkGraph, moduleGraph } = compilation;
|
|
49
50
|
|
|
50
51
|
// remember already tested chunks for performance
|
|
52
|
+
/** @type {Set<Chunk>} */
|
|
51
53
|
const notDuplicates = new Set();
|
|
52
54
|
|
|
53
55
|
// for each chunk
|
|
54
56
|
for (const chunk of chunks) {
|
|
55
57
|
// track a Set of all chunk that could be duplicates
|
|
58
|
+
/** @type {Set<Chunk> | undefined} */
|
|
56
59
|
let possibleDuplicates;
|
|
57
60
|
for (const module of chunkGraph.getChunkModulesIterable(chunk)) {
|
|
58
61
|
if (possibleDuplicates === undefined) {
|
|
@@ -29,6 +29,7 @@ class MinChunkSizePlugin {
|
|
|
29
29
|
*/
|
|
30
30
|
constructor(options) {
|
|
31
31
|
validate(options);
|
|
32
|
+
/** @type {MinChunkSizePluginOptions} */
|
|
32
33
|
this.options = options;
|
|
33
34
|
}
|
|
34
35
|
|
|
@@ -53,11 +54,13 @@ class MinChunkSizePlugin {
|
|
|
53
54
|
entryChunkMultiplicator: 1
|
|
54
55
|
};
|
|
55
56
|
|
|
57
|
+
/** @type {Map<Chunk, number>} */
|
|
56
58
|
const chunkSizesMap = new Map();
|
|
57
59
|
/** @type {[Chunk, Chunk][]} */
|
|
58
60
|
const combinations = [];
|
|
59
61
|
/** @type {Chunk[]} */
|
|
60
62
|
const smallChunks = [];
|
|
63
|
+
/** @type {Chunk[]} */
|
|
61
64
|
const visitedChunks = [];
|
|
62
65
|
for (const a of chunks) {
|
|
63
66
|
// check if one of the chunks sizes is smaller than the minChunkSize
|
|
@@ -83,8 +86,8 @@ class MinChunkSizePlugin {
|
|
|
83
86
|
const sortedSizeFilteredExtendedPairCombinations = combinations
|
|
84
87
|
.map((pair) => {
|
|
85
88
|
// extend combination pairs with size and integrated size
|
|
86
|
-
const a = chunkSizesMap.get(pair[0]);
|
|
87
|
-
const b = chunkSizesMap.get(pair[1]);
|
|
89
|
+
const a = /** @type {number} */ (chunkSizesMap.get(pair[0]));
|
|
90
|
+
const b = /** @type {number} */ (chunkSizesMap.get(pair[1]));
|
|
88
91
|
const ab = chunkGraph.getIntegratedChunksSize(
|
|
89
92
|
pair[0],
|
|
90
93
|
pair[1],
|
|
@@ -28,6 +28,8 @@ const ConcatenatedModule = require("./ConcatenatedModule");
|
|
|
28
28
|
/** @typedef {import("../RequestShortener")} RequestShortener */
|
|
29
29
|
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
|
30
30
|
|
|
31
|
+
/** @typedef {Module | ((requestShortener: RequestShortener) => string)} Problem */
|
|
32
|
+
|
|
31
33
|
/**
|
|
32
34
|
* @typedef {object} Statistics
|
|
33
35
|
* @property {number} cached
|
|
@@ -104,7 +106,7 @@ class ModuleConcatenationPlugin {
|
|
|
104
106
|
|
|
105
107
|
/**
|
|
106
108
|
* @param {Module} module the module
|
|
107
|
-
* @param {
|
|
109
|
+
* @param {Problem} problem the problem
|
|
108
110
|
* @returns {(requestShortener: RequestShortener) => string} the reason
|
|
109
111
|
*/
|
|
110
112
|
const formatBailoutWarning = (module, problem) => (requestShortener) => {
|
|
@@ -143,7 +145,9 @@ class ModuleConcatenationPlugin {
|
|
|
143
145
|
"webpack.ModuleConcatenationPlugin"
|
|
144
146
|
);
|
|
145
147
|
const { chunkGraph, moduleGraph } = compilation;
|
|
148
|
+
/** @type {Module[]} */
|
|
146
149
|
const relevantModules = [];
|
|
150
|
+
/** @type {Set<Module>} */
|
|
147
151
|
const possibleInners = new Set();
|
|
148
152
|
const context = {
|
|
149
153
|
chunkGraph,
|
|
@@ -265,7 +269,9 @@ class ModuleConcatenationPlugin {
|
|
|
265
269
|
let statsEmptyConfigurations = 0;
|
|
266
270
|
|
|
267
271
|
logger.time("find modules to concatenate");
|
|
272
|
+
/** @type {ConcatConfiguration[]} */
|
|
268
273
|
const concatConfigurations = [];
|
|
274
|
+
/** @type {Set<Module>} */
|
|
269
275
|
const usedAsInner = new Set();
|
|
270
276
|
for (const currentRoot of relevantModules) {
|
|
271
277
|
// when used by another configuration as inner:
|
|
@@ -273,6 +279,7 @@ class ModuleConcatenationPlugin {
|
|
|
273
279
|
// TODO reconsider that when it's only used in a different runtime
|
|
274
280
|
if (usedAsInner.has(currentRoot)) continue;
|
|
275
281
|
|
|
282
|
+
/** @type {RuntimeSpec} */
|
|
276
283
|
let chunkRuntime;
|
|
277
284
|
for (const r of chunkGraph.getModuleRuntimes(currentRoot)) {
|
|
278
285
|
chunkRuntime = mergeRuntimeOwned(chunkRuntime, r);
|
|
@@ -295,6 +302,7 @@ class ModuleConcatenationPlugin {
|
|
|
295
302
|
);
|
|
296
303
|
|
|
297
304
|
// cache failures to add modules
|
|
305
|
+
/** @type {Map<Module, Problem>} */
|
|
298
306
|
const failureCache = new Map();
|
|
299
307
|
|
|
300
308
|
// potential optional import candidates
|
|
@@ -311,6 +319,7 @@ class ModuleConcatenationPlugin {
|
|
|
311
319
|
}
|
|
312
320
|
|
|
313
321
|
for (const imp of candidates) {
|
|
322
|
+
/** @type {Set<Module>} */
|
|
314
323
|
const impCandidates = new Set();
|
|
315
324
|
const problem = this._tryToAdd(
|
|
316
325
|
compilation,
|
|
@@ -373,6 +382,7 @@ class ModuleConcatenationPlugin {
|
|
|
373
382
|
logger.time("sort concat configurations");
|
|
374
383
|
concatConfigurations.sort((a, b) => b.modules.size - a.modules.size);
|
|
375
384
|
logger.timeEnd("sort concat configurations");
|
|
385
|
+
/** @type {Set<Module>} */
|
|
376
386
|
const usedModules = new Set();
|
|
377
387
|
|
|
378
388
|
logger.time("create concatenated modules");
|
|
@@ -515,6 +525,7 @@ class ModuleConcatenationPlugin {
|
|
|
515
525
|
*/
|
|
516
526
|
_getImports(compilation, module, runtime) {
|
|
517
527
|
const moduleGraph = compilation.moduleGraph;
|
|
528
|
+
/** @type {Set<Module>} */
|
|
518
529
|
const set = new Set();
|
|
519
530
|
for (const dep of module.dependencies) {
|
|
520
531
|
// Get reference info only for harmony Dependencies
|
|
@@ -555,11 +566,11 @@ class ModuleConcatenationPlugin {
|
|
|
555
566
|
* @param {RuntimeSpec} activeRuntime the runtime scope of the root module
|
|
556
567
|
* @param {Set<Module>} possibleModules modules that are candidates
|
|
557
568
|
* @param {Set<Module>} candidates list of potential candidates (will be added to)
|
|
558
|
-
* @param {Map<Module,
|
|
569
|
+
* @param {Map<Module, Problem>} failureCache cache for problematic modules to be more performant
|
|
559
570
|
* @param {ChunkGraph} chunkGraph the chunk graph
|
|
560
571
|
* @param {boolean} avoidMutateOnFailure avoid mutating the config when adding fails
|
|
561
572
|
* @param {Statistics} statistics gathering metrics
|
|
562
|
-
* @returns {null |
|
|
573
|
+
* @returns {null | Problem} the problematic module
|
|
563
574
|
*/
|
|
564
575
|
_tryToAdd(
|
|
565
576
|
compilation,
|
|
@@ -646,6 +657,7 @@ class ModuleConcatenationPlugin {
|
|
|
646
657
|
* @returns {string} problem description
|
|
647
658
|
*/
|
|
648
659
|
const problem = (requestShortener) => {
|
|
660
|
+
/** @type {Set<string>} */
|
|
649
661
|
const importingExplanations = new Set(
|
|
650
662
|
activeNonModulesConnections
|
|
651
663
|
.map((c) => c.explanation)
|
|
@@ -674,6 +686,7 @@ class ModuleConcatenationPlugin {
|
|
|
674
686
|
if (chunkGraph.getNumberOfModuleChunks(originModule) === 0) continue;
|
|
675
687
|
|
|
676
688
|
// We don't care for connections from other runtimes
|
|
689
|
+
/** @type {RuntimeSpec} */
|
|
677
690
|
let originRuntime;
|
|
678
691
|
for (const r of chunkGraph.getModuleRuntimes(originModule)) {
|
|
679
692
|
originRuntime = mergeRuntimeOwned(originRuntime, r);
|
|
@@ -822,6 +835,7 @@ class ModuleConcatenationPlugin {
|
|
|
822
835
|
}
|
|
823
836
|
}
|
|
824
837
|
|
|
838
|
+
/** @type {undefined | number} */
|
|
825
839
|
let backup;
|
|
826
840
|
if (avoidMutateOnFailure) {
|
|
827
841
|
backup = config.snapshot();
|
|
@@ -864,7 +878,6 @@ class ModuleConcatenationPlugin {
|
|
|
864
878
|
}
|
|
865
879
|
}
|
|
866
880
|
|
|
867
|
-
/** @typedef {Module | ((requestShortener: RequestShortener) => string)} Problem */
|
|
868
881
|
/** @typedef {Map<Module, Problem>} Warnings */
|
|
869
882
|
|
|
870
883
|
class ConcatConfiguration {
|
|
@@ -873,7 +886,9 @@ class ConcatConfiguration {
|
|
|
873
886
|
* @param {RuntimeSpec} runtime the runtime
|
|
874
887
|
*/
|
|
875
888
|
constructor(rootModule, runtime) {
|
|
889
|
+
/** @type {Module} */
|
|
876
890
|
this.rootModule = rootModule;
|
|
891
|
+
/** @type {RuntimeSpec} */
|
|
877
892
|
this.runtime = runtime;
|
|
878
893
|
/** @type {Set<Module>} */
|
|
879
894
|
this.modules = new Set();
|