webpack 5.97.1 → 5.104.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/README.md +368 -434
- package/bin/webpack.js +15 -9
- package/hot/dev-server.js +18 -3
- package/hot/emitter-event-target.js +7 -0
- package/hot/lazy-compilation-node.js +45 -29
- package/hot/lazy-compilation-universal.js +18 -0
- package/hot/lazy-compilation-web.js +15 -5
- package/hot/load-http.js +7 -0
- package/hot/log.js +15 -15
- package/hot/only-dev-server.js +19 -4
- package/hot/poll.js +1 -0
- package/lib/APIPlugin.js +48 -50
- package/lib/AbstractMethodError.js +1 -0
- package/lib/AsyncDependenciesBlock.js +4 -5
- package/lib/AutomaticPrefetchPlugin.js +22 -22
- package/lib/BannerPlugin.js +35 -40
- package/lib/Cache.js +12 -9
- package/lib/CacheFacade.js +13 -13
- package/lib/CaseSensitiveModulesWarning.js +6 -6
- package/lib/Chunk.js +68 -47
- package/lib/ChunkGraph.js +174 -95
- package/lib/ChunkGroup.js +32 -24
- package/lib/ChunkTemplate.js +8 -8
- package/lib/CleanPlugin.js +90 -42
- package/lib/CodeGenerationResults.js +12 -9
- package/lib/CompatibilityPlugin.js +70 -21
- package/lib/Compilation.js +827 -550
- package/lib/Compiler.js +137 -109
- package/lib/ConcatenationScope.js +45 -8
- package/lib/ConditionalInitFragment.js +1 -1
- package/lib/ConstPlugin.js +89 -59
- package/lib/ContextExclusionPlugin.js +5 -4
- package/lib/ContextModule.js +66 -51
- package/lib/ContextModuleFactory.js +51 -30
- package/lib/ContextReplacementPlugin.js +89 -34
- package/lib/CssModule.js +8 -4
- package/lib/DefinePlugin.js +209 -57
- package/lib/DelegatedModule.js +34 -23
- package/lib/DelegatedModuleFactoryPlugin.js +27 -24
- package/lib/DelegatedPlugin.js +4 -2
- package/lib/DependenciesBlock.js +0 -2
- package/lib/Dependency.js +37 -19
- package/lib/DependencyTemplate.js +2 -0
- package/lib/DependencyTemplates.js +5 -6
- package/lib/DllEntryPlugin.js +8 -4
- package/lib/DllModule.js +11 -12
- package/lib/DllModuleFactory.js +2 -2
- package/lib/DllPlugin.js +9 -6
- package/lib/DllReferencePlugin.js +60 -65
- package/lib/DotenvPlugin.js +462 -0
- package/lib/DynamicEntryPlugin.js +8 -8
- package/lib/EntryOptionPlugin.js +8 -6
- package/lib/EntryPlugin.js +5 -3
- package/lib/Entrypoint.js +19 -0
- package/lib/EnvironmentNotSupportAsyncWarning.js +0 -3
- package/lib/EnvironmentPlugin.js +26 -19
- package/lib/ErrorHelpers.js +6 -6
- package/lib/EvalDevToolModulePlugin.js +17 -14
- package/lib/EvalSourceMapDevToolPlugin.js +156 -142
- package/lib/ExportsInfo.js +180 -115
- package/lib/ExportsInfoApiPlugin.js +2 -2
- package/lib/ExternalModule.js +256 -102
- package/lib/ExternalModuleFactoryPlugin.js +66 -29
- package/lib/ExternalsPlugin.js +57 -2
- package/lib/FileSystemInfo.js +313 -247
- package/lib/FlagAllModulesAsUsedPlugin.js +2 -2
- package/lib/FlagDependencyExportsPlugin.js +29 -19
- package/lib/FlagDependencyUsagePlugin.js +9 -10
- package/lib/FlagEntryExportAsUsedPlugin.js +1 -1
- package/lib/Generator.js +43 -10
- package/lib/GraphHelpers.js +11 -3
- package/lib/HookWebpackError.js +35 -7
- package/lib/HotModuleReplacementPlugin.js +149 -108
- package/lib/HotUpdateChunk.js +0 -3
- package/lib/IgnoreErrorModuleFactory.js +2 -2
- package/lib/IgnorePlugin.js +16 -13
- package/lib/IgnoreWarningsPlugin.js +6 -4
- package/lib/InitFragment.js +41 -23
- package/lib/InvalidDependenciesModuleWarning.js +2 -3
- package/lib/JavascriptMetaInfoPlugin.js +2 -4
- package/lib/LibManifestPlugin.js +12 -13
- package/lib/LoaderOptionsPlugin.js +12 -14
- package/lib/LoaderTargetPlugin.js +5 -3
- package/lib/MainTemplate.js +18 -29
- package/lib/ManifestPlugin.js +235 -0
- package/lib/Module.js +138 -60
- package/lib/ModuleBuildError.js +4 -2
- package/lib/ModuleDependencyError.js +4 -3
- package/lib/ModuleDependencyWarning.js +4 -3
- package/lib/ModuleError.js +1 -1
- package/lib/ModuleFactory.js +10 -3
- package/lib/ModuleFilenameHelpers.js +63 -60
- package/lib/ModuleGraph.js +195 -70
- package/lib/ModuleGraphConnection.js +14 -20
- package/lib/ModuleInfoHeaderPlugin.js +15 -16
- package/lib/ModuleNotFoundError.js +1 -1
- package/lib/ModuleParseError.js +8 -4
- package/lib/ModuleSourceTypeConstants.js +189 -0
- package/lib/ModuleTemplate.js +7 -8
- package/lib/ModuleTypeConstants.js +37 -15
- package/lib/ModuleWarning.js +1 -1
- package/lib/MultiCompiler.js +64 -49
- package/lib/MultiStats.js +19 -14
- package/lib/MultiWatching.js +7 -11
- package/lib/NoEmitOnErrorsPlugin.js +5 -3
- package/lib/NodeStuffPlugin.js +438 -126
- package/lib/NormalModule.js +322 -201
- package/lib/NormalModuleFactory.js +230 -117
- package/lib/NormalModuleReplacementPlugin.js +37 -39
- package/lib/NullFactory.js +3 -2
- package/lib/OptimizationStages.js +1 -1
- package/lib/OptionsApply.js +1 -1
- package/lib/Parser.js +5 -3
- package/lib/PlatformPlugin.js +3 -1
- package/lib/PrefetchPlugin.js +6 -4
- package/lib/ProgressPlugin.js +48 -49
- package/lib/ProvidePlugin.js +7 -5
- package/lib/RawModule.js +26 -12
- package/lib/RecordIdsPlugin.js +88 -110
- package/lib/RequestShortener.js +3 -1
- package/lib/ResolverFactory.js +15 -14
- package/lib/RuntimeGlobals.js +216 -153
- package/lib/RuntimeModule.js +7 -6
- package/lib/RuntimePlugin.js +115 -62
- package/lib/RuntimeTemplate.js +248 -76
- package/lib/SelfModuleFactory.js +2 -2
- package/lib/SizeFormatHelpers.js +2 -2
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +17 -27
- package/lib/SourceMapDevToolPlugin.js +72 -59
- package/lib/Stats.js +2 -3
- package/lib/Template.js +31 -24
- package/lib/TemplatedPathPlugin.js +24 -21
- package/lib/UseStrictPlugin.js +1 -1
- package/lib/WarnCaseSensitiveModulesPlugin.js +36 -37
- package/lib/WarnDeprecatedOptionPlugin.js +7 -8
- package/lib/WarnNoModeSetPlugin.js +3 -1
- package/lib/WatchIgnorePlugin.js +11 -9
- package/lib/Watching.js +27 -29
- package/lib/WebpackError.js +10 -3
- package/lib/WebpackIsIncludedPlugin.js +4 -5
- package/lib/WebpackOptionsApply.js +263 -135
- package/lib/asset/AssetBytesGenerator.js +171 -0
- package/lib/asset/AssetBytesParser.js +37 -0
- package/lib/asset/AssetGenerator.js +285 -223
- package/lib/asset/AssetModulesPlugin.js +103 -41
- package/lib/asset/AssetParser.js +7 -3
- package/lib/asset/AssetSourceGenerator.js +41 -17
- package/lib/asset/RawDataUrlModule.js +17 -9
- package/lib/async-modules/AsyncModuleHelpers.js +52 -0
- package/lib/async-modules/AwaitDependenciesInitFragment.js +39 -24
- package/lib/async-modules/InferAsyncModulesPlugin.js +25 -26
- package/lib/buildChunkGraph.js +36 -17
- package/lib/cache/AddBuildDependenciesPlugin.js +5 -6
- package/lib/cache/IdleFileCachePlugin.js +22 -20
- package/lib/cache/MemoryCachePlugin.js +3 -3
- package/lib/cache/MemoryWithGcCachePlugin.js +17 -11
- package/lib/cache/PackFileCacheStrategy.js +198 -170
- package/lib/cache/ResolverCachePlugin.js +58 -48
- package/lib/cache/getLazyHashedEtag.js +5 -4
- package/lib/cli.js +197 -39
- package/lib/config/browserslistTargetHandler.js +110 -85
- package/lib/config/defaults.js +514 -113
- package/lib/config/normalization.js +91 -64
- package/lib/config/target.js +30 -18
- package/lib/container/ContainerEntryDependency.js +0 -1
- package/lib/container/ContainerEntryModule.js +16 -15
- package/lib/container/ContainerEntryModuleFactory.js +2 -2
- package/lib/container/ContainerPlugin.js +5 -6
- package/lib/container/ContainerReferencePlugin.js +27 -30
- package/lib/container/FallbackDependency.js +2 -1
- package/lib/container/FallbackModule.js +19 -14
- package/lib/container/FallbackModuleFactory.js +2 -2
- package/lib/container/HoistContainerReferencesPlugin.js +7 -7
- package/lib/container/ModuleFederationPlugin.js +4 -4
- package/lib/container/RemoteModule.js +14 -14
- package/lib/container/RemoteRuntimeModule.js +2 -2
- package/lib/container/options.js +9 -9
- package/lib/css/CssGenerator.js +366 -74
- package/lib/css/CssLoadingRuntimeModule.js +26 -16
- package/lib/css/CssMergeStyleSheetsRuntimeModule.js +56 -0
- package/lib/css/CssModulesPlugin.js +191 -142
- package/lib/css/CssParser.js +1756 -740
- package/lib/css/walkCssTokens.js +180 -67
- package/lib/debug/ProfilingPlugin.js +135 -51
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +29 -28
- package/lib/dependencies/AMDPlugin.js +18 -11
- package/lib/dependencies/AMDRequireArrayDependency.js +5 -4
- package/lib/dependencies/AMDRequireContextDependency.js +2 -1
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +35 -26
- package/lib/dependencies/AMDRuntimeModules.js +3 -1
- package/lib/dependencies/CachedConstDependency.js +24 -18
- package/lib/dependencies/CommonJsExportRequireDependency.js +31 -24
- package/lib/dependencies/CommonJsExportsDependency.js +2 -1
- package/lib/dependencies/CommonJsExportsParserPlugin.js +50 -36
- package/lib/dependencies/CommonJsFullRequireDependency.js +7 -13
- package/lib/dependencies/CommonJsImportsParserPlugin.js +146 -127
- package/lib/dependencies/CommonJsPlugin.js +29 -18
- package/lib/dependencies/CommonJsRequireContextDependency.js +4 -3
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +4 -4
- package/lib/dependencies/ConstDependency.js +2 -2
- package/lib/dependencies/ContextDependency.js +10 -5
- package/lib/dependencies/ContextDependencyHelpers.js +21 -13
- package/lib/dependencies/ContextDependencyTemplateAsId.js +10 -9
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +13 -10
- package/lib/dependencies/ContextElementDependency.js +23 -12
- package/lib/dependencies/CssIcssExportDependency.js +402 -22
- package/lib/dependencies/CssIcssImportDependency.js +116 -51
- package/lib/dependencies/CssIcssSymbolDependency.js +33 -35
- package/lib/dependencies/CssImportDependency.js +17 -14
- package/lib/dependencies/CssUrlDependency.js +8 -13
- package/lib/dependencies/DynamicExports.js +19 -19
- package/lib/dependencies/ExportsInfoDependency.js +13 -10
- package/lib/dependencies/ExternalModuleDependency.js +7 -7
- package/lib/dependencies/ExternalModuleInitFragment.js +3 -2
- package/lib/dependencies/ExternalModuleInitFragmentDependency.js +96 -0
- package/lib/dependencies/HarmonyAcceptDependency.js +96 -5
- package/lib/dependencies/HarmonyAcceptImportDependency.js +2 -5
- package/lib/dependencies/HarmonyCompatibilityDependency.js +0 -1
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +10 -30
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +19 -8
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +136 -99
- package/lib/dependencies/HarmonyExportExpressionDependency.js +1 -1
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +152 -61
- package/lib/dependencies/HarmonyExportInitFragment.js +2 -2
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +2 -2
- package/lib/dependencies/HarmonyExports.js +5 -5
- package/lib/dependencies/HarmonyImportDependency.js +92 -45
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +201 -163
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +5 -6
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +69 -42
- package/lib/dependencies/HarmonyModulesPlugin.js +16 -11
- package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -15
- package/lib/dependencies/ImportContextDependency.js +15 -1
- package/lib/dependencies/ImportDependency.js +25 -7
- package/lib/dependencies/ImportEagerDependency.js +7 -5
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +23 -13
- package/lib/dependencies/ImportMetaContextPlugin.js +2 -2
- package/lib/dependencies/ImportMetaPlugin.js +172 -20
- package/lib/dependencies/ImportParserPlugin.js +327 -49
- package/lib/dependencies/ImportPhase.js +121 -0
- package/lib/dependencies/ImportPlugin.js +3 -1
- package/lib/dependencies/ImportWeakDependency.js +7 -5
- package/lib/dependencies/JsonExportsDependency.js +54 -28
- package/lib/dependencies/LoaderDependency.js +0 -3
- package/lib/dependencies/LoaderImportDependency.js +0 -3
- package/lib/dependencies/LoaderPlugin.js +24 -25
- package/lib/dependencies/LocalModulesHelpers.js +4 -4
- package/lib/dependencies/ModuleDecoratorDependency.js +2 -4
- package/lib/dependencies/ModuleDependency.js +14 -13
- package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +1 -0
- package/lib/dependencies/ModuleHotAcceptDependency.js +1 -1
- package/lib/dependencies/NullDependency.js +2 -0
- package/lib/dependencies/ProvidedDependency.js +8 -10
- package/lib/dependencies/PureExpressionDependency.js +1 -2
- package/lib/dependencies/RequireContextDependency.js +2 -1
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +47 -44
- package/lib/dependencies/RequireContextPlugin.js +5 -2
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +3 -3
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +101 -99
- package/lib/dependencies/RequireEnsurePlugin.js +6 -6
- package/lib/dependencies/RequireIncludeDependency.js +2 -2
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +33 -34
- package/lib/dependencies/RequireIncludePlugin.js +1 -0
- package/lib/dependencies/RequireResolveContextDependency.js +1 -1
- package/lib/dependencies/RequireResolveDependency.js +3 -3
- package/lib/dependencies/RuntimeRequirementsDependency.js +3 -4
- package/lib/dependencies/StaticExportsDependency.js +3 -5
- package/lib/dependencies/SystemPlugin.js +4 -4
- package/lib/dependencies/URLContextDependency.js +65 -0
- package/lib/dependencies/URLDependency.js +3 -8
- package/lib/dependencies/URLPlugin.js +18 -159
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +3 -3
- package/lib/dependencies/WebAssemblyImportDependency.js +2 -2
- package/lib/dependencies/WebpackIsIncludedDependency.js +2 -3
- package/lib/dependencies/WorkerDependency.js +8 -6
- package/lib/dependencies/WorkerPlugin.js +131 -67
- package/lib/dependencies/getFunctionExpression.js +2 -2
- package/lib/dependencies/processExportInfo.js +4 -4
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -1
- package/lib/esm/ModuleChunkFormatPlugin.js +232 -179
- package/lib/esm/ModuleChunkLoadingPlugin.js +112 -57
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +102 -28
- package/lib/formatLocation.js +2 -2
- package/lib/hmr/HotModuleReplacement.runtime.js +41 -29
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +43 -33
- package/lib/hmr/JavascriptHotModuleReplacementHelper.js +37 -0
- package/lib/hmr/LazyCompilationPlugin.js +67 -54
- package/lib/hmr/lazyCompilationBackend.js +23 -18
- package/lib/ids/ChunkModuleIdRangePlugin.js +14 -11
- package/lib/ids/DeterministicChunkIdsPlugin.js +32 -37
- package/lib/ids/DeterministicModuleIdsPlugin.js +52 -52
- package/lib/ids/HashedModuleIdsPlugin.js +15 -13
- package/lib/ids/IdHelpers.js +66 -49
- package/lib/ids/NamedChunkIdsPlugin.js +14 -17
- package/lib/ids/NamedModuleIdsPlugin.js +12 -14
- package/lib/ids/NaturalChunkIdsPlugin.js +6 -4
- package/lib/ids/NaturalModuleIdsPlugin.js +4 -3
- package/lib/ids/OccurrenceChunkIdsPlugin.js +7 -5
- package/lib/ids/OccurrenceModuleIdsPlugin.js +8 -7
- package/lib/ids/SyncModuleIdsPlugin.js +18 -13
- package/lib/index.js +54 -14
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +116 -119
- package/lib/javascript/BasicEvaluatedExpression.js +26 -18
- package/lib/javascript/ChunkFormatHelpers.js +70 -0
- package/lib/javascript/ChunkHelpers.js +17 -5
- package/lib/javascript/CommonJsChunkFormatPlugin.js +114 -141
- package/lib/javascript/EnableChunkLoadingPlugin.js +7 -4
- package/lib/javascript/JavascriptGenerator.js +122 -100
- package/lib/javascript/JavascriptModulesPlugin.js +332 -152
- package/lib/javascript/JavascriptParser.js +1488 -1052
- package/lib/javascript/JavascriptParserHelpers.js +48 -47
- package/lib/javascript/StartupHelpers.js +23 -22
- package/lib/json/JsonData.js +4 -4
- package/lib/json/JsonGenerator.js +66 -32
- package/lib/json/JsonModulesPlugin.js +16 -6
- package/lib/json/JsonParser.js +23 -8
- package/lib/library/AbstractLibraryPlugin.js +45 -10
- package/lib/library/AmdLibraryPlugin.js +7 -5
- package/lib/library/AssignLibraryPlugin.js +71 -17
- package/lib/library/EnableLibraryPlugin.js +51 -25
- package/lib/library/ExportPropertyLibraryPlugin.js +12 -18
- package/lib/library/JsonpLibraryPlugin.js +5 -2
- package/lib/library/ModuleLibraryPlugin.js +230 -18
- package/lib/library/SystemLibraryPlugin.js +29 -11
- package/lib/library/UmdLibraryPlugin.js +35 -32
- package/lib/logging/Logger.js +18 -15
- package/lib/logging/createConsoleLogger.js +27 -27
- package/lib/logging/runtime.js +11 -11
- package/lib/logging/truncateArgs.js +5 -5
- package/lib/node/CommonJsChunkLoadingPlugin.js +72 -75
- package/lib/node/NodeEnvironmentPlugin.js +9 -3
- package/lib/node/NodeTargetPlugin.js +9 -1
- package/lib/node/NodeTemplatePlugin.js +2 -2
- package/lib/node/NodeWatchFileSystem.js +4 -4
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +22 -38
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +10 -11
- package/lib/node/ReadFileCompileWasmPlugin.js +11 -14
- package/lib/node/RequireChunkLoadingRuntimeModule.js +22 -30
- package/lib/node/nodeConsole.js +12 -7
- package/lib/optimize/AggressiveMergingPlugin.js +46 -47
- package/lib/optimize/AggressiveSplittingPlugin.js +233 -238
- package/lib/optimize/ConcatenatedModule.js +620 -251
- package/lib/optimize/EnsureChunkConditionsPlugin.js +58 -58
- package/lib/optimize/FlagIncludedChunksPlugin.js +93 -96
- package/lib/optimize/InnerGraph.js +139 -124
- package/lib/optimize/InnerGraphPlugin.js +29 -24
- package/lib/optimize/LimitChunkCountPlugin.js +32 -8
- package/lib/optimize/MangleExportsPlugin.js +22 -22
- package/lib/optimize/MergeDuplicateChunksPlugin.js +80 -81
- package/lib/optimize/MinChunkSizePlugin.js +12 -7
- package/lib/optimize/ModuleConcatenationPlugin.js +92 -71
- package/lib/optimize/RealContentHashPlugin.js +58 -44
- package/lib/optimize/RemoveEmptyChunksPlugin.js +8 -5
- package/lib/optimize/RemoveParentModulesPlugin.js +7 -4
- package/lib/optimize/RuntimeChunkPlugin.js +22 -25
- package/lib/optimize/SideEffectsFlagPlugin.js +44 -26
- package/lib/optimize/SplitChunksPlugin.js +209 -158
- package/lib/performance/AssetsOverSizeLimitWarning.js +1 -1
- package/lib/performance/EntrypointsOverSizeLimitWarning.js +2 -2
- package/lib/performance/SizeLimitsPlugin.js +8 -5
- package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +5 -7
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +61 -64
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +3 -4
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +2 -2
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +2 -2
- package/lib/rules/BasicEffectRulePlugin.js +14 -5
- package/lib/rules/BasicMatcherRulePlugin.js +18 -7
- package/lib/rules/ObjectMatcherRulePlugin.js +17 -6
- package/lib/rules/RuleSetCompiler.js +73 -32
- package/lib/rules/UseEffectRulePlugin.js +61 -25
- package/lib/runtime/AsyncModuleRuntimeModule.js +74 -9
- package/lib/runtime/AutoPublicPathRuntimeModule.js +9 -4
- package/lib/runtime/BaseUriRuntimeModule.js +2 -2
- package/lib/runtime/CompatRuntimeModule.js +0 -1
- package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +1 -1
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +34 -35
- package/lib/runtime/GetMainFilenameRuntimeModule.js +1 -1
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -1
- package/lib/runtime/LoadScriptRuntimeModule.js +0 -2
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +248 -0
- package/lib/runtime/PublicPathRuntimeModule.js +2 -2
- package/lib/runtime/RuntimeIdRuntimeModule.js +2 -1
- package/lib/runtime/StartupChunkDependenciesPlugin.js +39 -42
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +10 -9
- package/lib/runtime/StartupEntrypointRuntimeModule.js +0 -1
- package/lib/runtime/SystemContextRuntimeModule.js +0 -2
- package/lib/runtime/ToBinaryRuntimeModule.js +64 -0
- package/lib/schemes/DataUriPlugin.js +9 -31
- package/lib/schemes/FileUriPlugin.js +11 -6
- package/lib/schemes/HttpUriPlugin.js +381 -261
- package/lib/schemes/VirtualUrlPlugin.js +222 -0
- package/lib/serialization/AggregateErrorSerializer.js +41 -0
- package/lib/serialization/BinaryMiddleware.js +51 -33
- package/lib/serialization/ErrorObjectSerializer.js +7 -2
- package/lib/serialization/FileMiddleware.js +101 -71
- package/lib/serialization/NullPrototypeObjectSerializer.js +5 -3
- package/lib/serialization/ObjectMiddleware.js +130 -54
- package/lib/serialization/PlainObjectSerializer.js +1 -1
- package/lib/serialization/Serializer.js +38 -20
- package/lib/serialization/SerializerMiddleware.js +121 -49
- package/lib/serialization/SingleItemMiddleware.js +9 -7
- package/lib/serialization/types.js +1 -1
- package/lib/sharing/ConsumeSharedModule.js +9 -9
- package/lib/sharing/ConsumeSharedPlugin.js +14 -14
- package/lib/sharing/ConsumeSharedRuntimeModule.js +11 -8
- package/lib/sharing/ProvideSharedModule.js +9 -11
- package/lib/sharing/ProvideSharedModuleFactory.js +5 -3
- package/lib/sharing/ProvideSharedPlugin.js +15 -10
- package/lib/sharing/SharePlugin.js +3 -4
- package/lib/sharing/ShareRuntimeModule.js +7 -6
- package/lib/sharing/resolveMatchedConfigs.js +27 -13
- package/lib/sharing/utils.js +37 -43
- package/lib/stats/DefaultStatsFactoryPlugin.js +455 -286
- package/lib/stats/DefaultStatsPresetPlugin.js +77 -46
- package/lib/stats/DefaultStatsPrinterPlugin.js +583 -419
- package/lib/stats/StatsFactory.js +75 -32
- package/lib/stats/StatsPrinter.js +71 -51
- package/lib/url/URLParserPlugin.js +264 -0
- package/lib/util/ArrayHelpers.js +6 -8
- package/lib/util/ArrayQueue.js +1 -1
- package/lib/util/AsyncQueue.js +11 -10
- package/lib/util/Hash.js +37 -5
- package/lib/util/IterableHelpers.js +4 -4
- package/lib/util/LazyBucketSortedSet.js +46 -27
- package/lib/util/LazySet.js +16 -10
- package/lib/util/MapHelpers.js +1 -1
- package/lib/util/ParallelismFactorCalculator.js +2 -2
- package/lib/util/Semaphore.js +3 -3
- package/lib/util/SetHelpers.js +6 -6
- package/lib/util/SortableSet.js +11 -9
- package/lib/util/StackedCacheMap.js +2 -2
- package/lib/util/StackedMap.js +3 -3
- package/lib/util/StringXor.js +2 -1
- package/lib/util/TupleQueue.js +11 -8
- package/lib/util/TupleSet.js +44 -19
- package/lib/util/URLAbsoluteSpecifier.js +3 -4
- package/lib/util/WeakTupleMap.js +56 -42
- package/lib/util/binarySearchBounds.js +4 -3
- package/lib/util/chainedImports.js +3 -1
- package/lib/util/cleverMerge.js +171 -107
- package/lib/util/comparators.js +265 -162
- package/lib/util/compileBooleanMatcher.js +120 -41
- package/lib/util/concatenate.js +20 -16
- package/lib/util/conventions.js +73 -74
- package/lib/util/create-schema-validation.js +8 -8
- package/lib/util/createHash.js +32 -135
- package/lib/util/dataURL.js +39 -0
- package/lib/util/deprecation.js +119 -116
- package/lib/util/deterministicGrouping.js +56 -47
- package/lib/util/extractSourceMap.js +319 -0
- package/lib/util/extractUrlAndGlobal.js +1 -1
- package/lib/util/findGraphRoots.js +19 -9
- package/lib/util/fs.js +169 -141
- package/lib/util/hash/BatchedHash.js +50 -10
- package/lib/util/hash/BulkUpdateHash.js +138 -0
- package/lib/util/hash/DebugHash.js +75 -0
- package/lib/util/hash/hash-digest.js +216 -0
- package/lib/util/hash/md4.js +2 -2
- package/lib/util/hash/wasm-hash.js +59 -17
- package/lib/util/identifier.js +124 -61
- package/lib/util/internalSerializables.js +4 -6
- package/lib/util/magicComment.js +9 -5
- package/lib/util/makeSerializable.js +2 -2
- package/lib/util/memoize.js +5 -2
- package/lib/util/objectToMap.js +3 -2
- package/lib/util/processAsyncTree.js +5 -5
- package/lib/util/propertyAccess.js +1 -1
- package/lib/util/propertyName.js +2 -3
- package/lib/util/registerExternalSerializer.js +16 -20
- package/lib/util/removeBOM.js +25 -0
- package/lib/util/runtime.js +72 -56
- package/lib/util/semver.js +44 -33
- package/lib/util/serialization.js +56 -56
- package/lib/util/smartGrouping.js +42 -27
- package/lib/util/source.js +5 -4
- package/lib/util/traverseDestructuringAssignmentProperties.js +45 -0
- package/lib/validateSchema.js +7 -9
- package/lib/wasm/EnableWasmLoadingPlugin.js +22 -12
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +9 -5
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +15 -3
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +28 -22
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +47 -57
- package/lib/wasm-async/AsyncWebAssemblyParser.js +2 -10
- package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +8 -4
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +23 -17
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +55 -57
- package/lib/wasm-sync/WebAssemblyGenerator.js +56 -41
- package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +6 -3
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +25 -10
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +11 -12
- package/lib/wasm-sync/WebAssemblyParser.js +10 -17
- package/lib/wasm-sync/WebAssemblyUtils.js +1 -1
- package/lib/web/FetchCompileAsyncWasmPlugin.js +4 -4
- package/lib/web/FetchCompileWasmPlugin.js +6 -8
- package/lib/web/JsonpChunkLoadingPlugin.js +74 -74
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +10 -26
- package/lib/web/JsonpTemplatePlugin.js +0 -1
- package/lib/webpack.js +107 -87
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +79 -75
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +38 -51
- package/lib/webworker/WebWorkerTemplatePlugin.js +1 -0
- package/module.d.ts +5 -0
- package/package.json +149 -129
- package/schemas/WebpackOptions.check.d.ts +1 -1
- package/schemas/WebpackOptions.check.js +2 -2
- package/schemas/WebpackOptions.json +543 -190
- package/schemas/plugins/BannerPlugin.check.d.ts +1 -1
- package/schemas/plugins/BannerPlugin.check.js +2 -2
- package/schemas/plugins/BannerPlugin.json +4 -0
- package/schemas/plugins/DllPlugin.check.d.ts +1 -1
- package/schemas/plugins/DllPlugin.check.js +1 -1
- package/schemas/plugins/DllReferencePlugin.check.d.ts +1 -1
- package/schemas/plugins/DllReferencePlugin.check.js +1 -1
- package/schemas/plugins/IgnorePlugin.check.d.ts +1 -1
- package/schemas/plugins/IgnorePlugin.check.js +1 -1
- package/schemas/plugins/IgnorePlugin.json +1 -1
- package/schemas/plugins/LoaderOptionsPlugin.check.d.ts +1 -1
- package/schemas/plugins/LoaderOptionsPlugin.check.js +1 -1
- package/schemas/plugins/{HashedModuleIdsPlugin.check.d.ts → ManifestPlugin.check.d.ts} +2 -2
- package/schemas/plugins/ManifestPlugin.check.js +6 -0
- package/schemas/plugins/ManifestPlugin.json +98 -0
- package/schemas/plugins/ProgressPlugin.check.d.ts +1 -1
- package/schemas/plugins/ProgressPlugin.check.js +1 -1
- package/schemas/plugins/ProgressPlugin.json +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.check.d.ts +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +2 -2
- package/schemas/plugins/SourceMapDevToolPlugin.json +23 -6
- package/schemas/plugins/WatchIgnorePlugin.check.d.ts +1 -1
- package/schemas/plugins/WatchIgnorePlugin.check.js +1 -1
- package/schemas/plugins/asset/AssetGeneratorOptions.check.d.ts +1 -1
- package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.d.ts +1 -1
- package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetParserOptions.check.d.ts +1 -1
- package/schemas/plugins/asset/AssetParserOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.d.ts +1 -1
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
- package/schemas/plugins/container/ContainerPlugin.check.d.ts +1 -1
- package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.check.d.ts +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +2 -2
- package/schemas/plugins/container/ContainerReferencePlugin.json +4 -1
- package/schemas/plugins/container/ExternalsType.check.d.ts +1 -1
- package/schemas/plugins/container/ExternalsType.check.js +2 -2
- package/schemas/plugins/container/ModuleFederationPlugin.check.d.ts +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +2 -2
- package/schemas/plugins/container/ModuleFederationPlugin.json +4 -1
- package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +2 -2
- package/schemas/plugins/css/CssModuleParserOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssModuleParserOptions.check.js +2 -2
- package/schemas/plugins/css/CssParserOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssParserOptions.check.js +2 -2
- package/schemas/plugins/debug/ProfilingPlugin.check.d.ts +1 -1
- package/schemas/plugins/debug/ProfilingPlugin.check.js +1 -1
- package/schemas/plugins/ids/HashedModuleIdsPlugin.check.d.ts +7 -0
- package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +6 -0
- package/schemas/plugins/{HashedModuleIdsPlugin.json → ids/HashedModuleIdsPlugin.json} +15 -2
- package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.d.ts +1 -1
- package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.js +1 -1
- package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.d.ts +1 -1
- package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.js +1 -1
- package/schemas/plugins/{css/CssGlobalParserOptions.check.d.ts → json/JsonModulesPluginGenerator.check.d.ts} +1 -1
- package/schemas/plugins/json/JsonModulesPluginGenerator.check.js +6 -0
- package/schemas/plugins/json/JsonModulesPluginGenerator.json +3 -0
- package/schemas/plugins/{css/CssGlobalGeneratorOptions.check.d.ts → json/JsonModulesPluginParser.check.d.ts} +1 -1
- package/schemas/plugins/json/JsonModulesPluginParser.check.js +6 -0
- package/schemas/plugins/json/JsonModulesPluginParser.json +3 -0
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.d.ts +1 -1
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +1 -1
- package/schemas/plugins/optimize/LimitChunkCountPlugin.check.d.ts +1 -1
- package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +1 -1
- package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.d.ts +1 -1
- package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.js +1 -1
- package/schemas/plugins/optimize/MinChunkSizePlugin.check.d.ts +1 -1
- package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +1 -1
- package/schemas/plugins/schemes/HttpUriPlugin.check.d.ts +1 -1
- package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
- 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/schemas/plugins/sharing/ConsumeSharedPlugin.check.d.ts +1 -1
- package/schemas/plugins/sharing/ConsumeSharedPlugin.check.js +1 -1
- package/schemas/plugins/sharing/ProvideSharedPlugin.check.d.ts +1 -1
- package/schemas/plugins/sharing/ProvideSharedPlugin.check.js +1 -1
- package/schemas/plugins/sharing/SharePlugin.check.d.ts +1 -1
- package/schemas/plugins/sharing/SharePlugin.check.js +1 -1
- package/types.d.ts +5115 -1863
- package/SECURITY.md +0 -9
- package/lib/ModuleSourceTypesConstants.js +0 -112
- package/lib/dependencies/CssLocalIdentifierDependency.js +0 -250
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +0 -111
- package/lib/library/ModernModuleLibraryPlugin.js +0 -144
- package/schemas/plugins/HashedModuleIdsPlugin.check.js +0 -6
- package/schemas/plugins/JsonModulesPluginParser.check.d.ts +0 -7
- package/schemas/plugins/JsonModulesPluginParser.check.js +0 -6
- package/schemas/plugins/JsonModulesPluginParser.json +0 -12
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +0 -7
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +0 -6
- package/schemas/plugins/css/CssAutoGeneratorOptions.json +0 -3
- package/schemas/plugins/css/CssAutoParserOptions.check.d.ts +0 -7
- package/schemas/plugins/css/CssAutoParserOptions.check.js +0 -6
- package/schemas/plugins/css/CssAutoParserOptions.json +0 -3
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +0 -6
- package/schemas/plugins/css/CssGlobalGeneratorOptions.json +0 -3
- package/schemas/plugins/css/CssGlobalParserOptions.check.js +0 -6
- package/schemas/plugins/css/CssGlobalParserOptions.json +0 -3
|
@@ -16,19 +16,28 @@ const {
|
|
|
16
16
|
const ConcatenationScope = require("../ConcatenationScope");
|
|
17
17
|
const { UsageState } = require("../ExportsInfo");
|
|
18
18
|
const Module = require("../Module");
|
|
19
|
-
const {
|
|
19
|
+
const {
|
|
20
|
+
JAVASCRIPT_TYPE,
|
|
21
|
+
JAVASCRIPT_TYPES
|
|
22
|
+
} = require("../ModuleSourceTypeConstants");
|
|
20
23
|
const { JAVASCRIPT_MODULE_TYPE_ESM } = require("../ModuleTypeConstants");
|
|
21
24
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
|
22
25
|
const Template = require("../Template");
|
|
26
|
+
const { DEFAULTS } = require("../config/defaults");
|
|
23
27
|
const HarmonyImportDependency = require("../dependencies/HarmonyImportDependency");
|
|
28
|
+
const { ImportPhaseUtils } = require("../dependencies/ImportPhase");
|
|
24
29
|
const JavascriptParser = require("../javascript/JavascriptParser");
|
|
30
|
+
const {
|
|
31
|
+
getMakeDeferredNamespaceModeFromExportsType,
|
|
32
|
+
getOptimizedDeferredModule
|
|
33
|
+
} = require("../runtime/MakeDeferredNamespaceObjectRuntime");
|
|
25
34
|
const { equals } = require("../util/ArrayHelpers");
|
|
26
35
|
const LazySet = require("../util/LazySet");
|
|
27
36
|
const { concatComparators } = require("../util/comparators");
|
|
28
37
|
const {
|
|
29
38
|
RESERVED_NAMES,
|
|
30
|
-
findNewName,
|
|
31
39
|
addScopeSymbols,
|
|
40
|
+
findNewName,
|
|
32
41
|
getAllReferences,
|
|
33
42
|
getPathInAst,
|
|
34
43
|
getUsedNamesInScopeInfo
|
|
@@ -51,41 +60,41 @@ const {
|
|
|
51
60
|
/** @typedef {import("eslint-scope").Scope} Scope */
|
|
52
61
|
/** @typedef {import("eslint-scope").Variable} Variable */
|
|
53
62
|
/** @typedef {import("webpack-sources").Source} Source */
|
|
54
|
-
/** @typedef {import("
|
|
63
|
+
/** @typedef {import("../config/defaults").WebpackOptionsNormalizedWithDefaults} WebpackOptions */
|
|
55
64
|
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
|
56
65
|
/** @typedef {import("../CodeGenerationResults")} CodeGenerationResults */
|
|
57
66
|
/** @typedef {import("../Compilation")} Compilation */
|
|
58
|
-
/** @typedef {import("../Dependency")} Dependency */
|
|
59
67
|
/** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
|
|
60
|
-
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
|
61
68
|
/** @typedef {import("../DependencyTemplates")} DependencyTemplates */
|
|
62
69
|
/** @typedef {import("../ExportsInfo").ExportInfo} ExportInfo */
|
|
70
|
+
/** @typedef {import("../Module").BuildCallback} BuildCallback */
|
|
63
71
|
/** @typedef {import("../Module").BuildInfo} BuildInfo */
|
|
72
|
+
/** @typedef {import("../Module").FileSystemDependencies} FileSystemDependencies */
|
|
64
73
|
/** @typedef {import("../Module").BuildMeta} BuildMeta */
|
|
65
74
|
/** @typedef {import("../Module").CodeGenerationContext} CodeGenerationContext */
|
|
66
75
|
/** @typedef {import("../Module").CodeGenerationResult} CodeGenerationResult */
|
|
67
76
|
/** @typedef {import("../Module").LibIdentOptions} LibIdentOptions */
|
|
77
|
+
/** @typedef {import("../Module").LibIdent} LibIdent */
|
|
78
|
+
/** @typedef {import("../Module").NameForCondition} NameForCondition */
|
|
68
79
|
/** @typedef {import("../Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
|
|
69
80
|
/** @typedef {import("../Module").RuntimeRequirements} RuntimeRequirements */
|
|
70
81
|
/** @typedef {import("../Module").SourceTypes} SourceTypes */
|
|
71
82
|
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
|
72
83
|
/** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
|
|
73
84
|
/** @typedef {import("../ModuleGraphConnection").ConnectionState} ConnectionState */
|
|
74
|
-
/** @typedef {import("../ModuleParseError")} ModuleParseError */
|
|
75
85
|
/** @typedef {import("../RequestShortener")} RequestShortener */
|
|
76
86
|
/** @typedef {import("../ResolverFactory").ResolverWithOptions} ResolverWithOptions */
|
|
77
87
|
/** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
|
|
78
|
-
/** @typedef {import("../WebpackError")} WebpackError */
|
|
79
88
|
/** @typedef {import("../javascript/JavascriptModulesPlugin").ChunkRenderContext} ChunkRenderContext */
|
|
80
89
|
/** @typedef {import("../javascript/JavascriptParser").Program} Program */
|
|
81
90
|
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
|
82
91
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
|
83
92
|
/** @typedef {import("../util/Hash")} Hash */
|
|
84
93
|
/** @typedef {typeof import("../util/Hash")} HashConstructor */
|
|
85
|
-
/** @typedef {import("../util/concatenate").
|
|
94
|
+
/** @typedef {import("../util/concatenate").ScopeInfo} ScopeInfo */
|
|
86
95
|
/** @typedef {import("../util/fs").InputFileSystem} InputFileSystem */
|
|
96
|
+
/** @typedef {import("../util/identifier").AssociatedObjectForCache} AssociatedObjectForCache */
|
|
87
97
|
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
|
88
|
-
|
|
89
98
|
/**
|
|
90
99
|
* @template T
|
|
91
100
|
* @typedef {import("../InitFragment")<T>} InitFragment
|
|
@@ -98,27 +107,23 @@ const {
|
|
|
98
107
|
|
|
99
108
|
// fix eslint-scope to support class properties correctly
|
|
100
109
|
// cspell:word Referencer
|
|
101
|
-
const ReferencerClass =
|
|
110
|
+
const ReferencerClass = Referencer;
|
|
102
111
|
if (!ReferencerClass.prototype.PropertyDefinition) {
|
|
103
112
|
ReferencerClass.prototype.PropertyDefinition =
|
|
104
113
|
ReferencerClass.prototype.Property;
|
|
105
114
|
}
|
|
106
115
|
|
|
107
|
-
/**
|
|
108
|
-
* @typedef {object} ReexportInfo
|
|
109
|
-
* @property {Module} module
|
|
110
|
-
* @property {string[]} export
|
|
111
|
-
*/
|
|
112
|
-
|
|
113
116
|
/** @typedef {RawBinding | SymbolBinding} Binding */
|
|
114
117
|
|
|
118
|
+
/** @typedef {string[]} ExportName */
|
|
119
|
+
|
|
115
120
|
/**
|
|
116
121
|
* @typedef {object} RawBinding
|
|
117
122
|
* @property {ModuleInfo} info
|
|
118
123
|
* @property {string} rawName
|
|
119
124
|
* @property {string=} comment
|
|
120
|
-
* @property {
|
|
121
|
-
* @property {
|
|
125
|
+
* @property {ExportName} ids
|
|
126
|
+
* @property {ExportName} exportName
|
|
122
127
|
*/
|
|
123
128
|
|
|
124
129
|
/**
|
|
@@ -126,12 +131,14 @@ if (!ReferencerClass.prototype.PropertyDefinition) {
|
|
|
126
131
|
* @property {ConcatenatedModuleInfo} info
|
|
127
132
|
* @property {string} name
|
|
128
133
|
* @property {string=} comment
|
|
129
|
-
* @property {
|
|
130
|
-
* @property {
|
|
134
|
+
* @property {ExportName} ids
|
|
135
|
+
* @property {ExportName} exportName
|
|
131
136
|
*/
|
|
132
137
|
|
|
133
|
-
/** @typedef {ConcatenatedModuleInfo | ExternalModuleInfo
|
|
134
|
-
/** @typedef {ConcatenatedModuleInfo | ExternalModuleInfo | ReferenceToModuleInfo
|
|
138
|
+
/** @typedef {ConcatenatedModuleInfo | ExternalModuleInfo} ModuleInfo */
|
|
139
|
+
/** @typedef {ConcatenatedModuleInfo | ExternalModuleInfo | ReferenceToModuleInfo} ModuleInfoOrReference */
|
|
140
|
+
|
|
141
|
+
/** @typedef {Map<string, string>} ExportMap */
|
|
135
142
|
|
|
136
143
|
/**
|
|
137
144
|
* @typedef {object} ConcatenatedModuleInfo
|
|
@@ -146,16 +153,17 @@ if (!ReferencerClass.prototype.PropertyDefinition) {
|
|
|
146
153
|
* @property {Scope | undefined} globalScope
|
|
147
154
|
* @property {Scope | undefined} moduleScope
|
|
148
155
|
* @property {Map<string, string>} internalNames
|
|
149
|
-
* @property {
|
|
150
|
-
* @property {
|
|
156
|
+
* @property {ExportMap | undefined} exportMap
|
|
157
|
+
* @property {ExportMap | undefined} rawExportMap
|
|
151
158
|
* @property {string=} namespaceExportSymbol
|
|
152
159
|
* @property {string | undefined} namespaceObjectName
|
|
153
|
-
* @property {
|
|
154
|
-
* @property {
|
|
155
|
-
* @property {
|
|
156
|
-
* @property {
|
|
157
|
-
* @property {
|
|
158
|
-
* @property {
|
|
160
|
+
* @property {ConcatenationScope | undefined} concatenationScope
|
|
161
|
+
* @property {boolean} interopNamespaceObjectUsed "default-with-named" namespace
|
|
162
|
+
* @property {string | undefined} interopNamespaceObjectName "default-with-named" namespace
|
|
163
|
+
* @property {boolean} interopNamespaceObject2Used "default-only" namespace
|
|
164
|
+
* @property {string | undefined} interopNamespaceObject2Name "default-only" namespace
|
|
165
|
+
* @property {boolean} interopDefaultAccessUsed runtime namespace object that detects "__esModule"
|
|
166
|
+
* @property {string | undefined} interopDefaultAccessName runtime namespace object that detects "__esModule"
|
|
159
167
|
*/
|
|
160
168
|
|
|
161
169
|
/**
|
|
@@ -163,27 +171,33 @@ if (!ReferencerClass.prototype.PropertyDefinition) {
|
|
|
163
171
|
* @property {"external"} type
|
|
164
172
|
* @property {Module} module
|
|
165
173
|
* @property {RuntimeSpec | boolean} runtimeCondition
|
|
174
|
+
* @property {NonDeferAccess} nonDeferAccess
|
|
166
175
|
* @property {number} index
|
|
167
|
-
* @property {string | undefined} name
|
|
168
|
-
* @property {
|
|
169
|
-
* @property {
|
|
170
|
-
* @property {boolean}
|
|
171
|
-
* @property {string | undefined}
|
|
172
|
-
* @property {boolean}
|
|
173
|
-
* @property {string | undefined}
|
|
176
|
+
* @property {string | undefined} name module.exports / harmony namespace object
|
|
177
|
+
* @property {string | undefined} deferredName deferred module.exports / harmony namespace object
|
|
178
|
+
* @property {boolean} deferred the module is deferred at least once
|
|
179
|
+
* @property {boolean} deferredNamespaceObjectUsed deferred namespace object that being used in a not-analyzable way so it must be materialized
|
|
180
|
+
* @property {string | undefined} deferredNamespaceObjectName deferred namespace object that being used in a not-analyzable way so it must be materialized
|
|
181
|
+
* @property {boolean} interopNamespaceObjectUsed "default-with-named" namespace
|
|
182
|
+
* @property {string | undefined} interopNamespaceObjectName "default-with-named" namespace
|
|
183
|
+
* @property {boolean} interopNamespaceObject2Used "default-only" namespace
|
|
184
|
+
* @property {string | undefined} interopNamespaceObject2Name "default-only" namespace
|
|
185
|
+
* @property {boolean} interopDefaultAccessUsed runtime namespace object that detects "__esModule"
|
|
186
|
+
* @property {string | undefined} interopDefaultAccessName runtime namespace object that detects "__esModule"
|
|
174
187
|
*/
|
|
175
188
|
|
|
176
189
|
/**
|
|
177
190
|
* @typedef {object} ReferenceToModuleInfo
|
|
178
191
|
* @property {"reference"} type
|
|
179
192
|
* @property {RuntimeSpec | boolean} runtimeCondition
|
|
193
|
+
* @property {NonDeferAccess} nonDeferAccess
|
|
180
194
|
* @property {ModuleInfo} target
|
|
181
195
|
*/
|
|
182
196
|
|
|
183
197
|
/**
|
|
184
198
|
* @template T
|
|
185
199
|
* @param {string} property property
|
|
186
|
-
* @param {
|
|
200
|
+
* @param {(a: T[keyof T], b: T[keyof T]) => 0 | 1 | -1} comparator comparator
|
|
187
201
|
* @returns {Comparator<T>} comparator
|
|
188
202
|
*/
|
|
189
203
|
|
|
@@ -220,7 +234,7 @@ const byRangeStart = createComparator("rangeStart", compareNumbers);
|
|
|
220
234
|
* @param {Iterable<string>} iterable iterable object
|
|
221
235
|
* @returns {string} joined iterable object
|
|
222
236
|
*/
|
|
223
|
-
const joinIterableWithComma = iterable => {
|
|
237
|
+
const joinIterableWithComma = (iterable) => {
|
|
224
238
|
// This is more performant than Array.from().join(", ")
|
|
225
239
|
// as it doesn't create an array
|
|
226
240
|
let str = "";
|
|
@@ -236,23 +250,45 @@ const joinIterableWithComma = iterable => {
|
|
|
236
250
|
return str;
|
|
237
251
|
};
|
|
238
252
|
|
|
253
|
+
/** @typedef {boolean} NonDeferAccess */
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* @param {NonDeferAccess} a a
|
|
257
|
+
* @param {NonDeferAccess} b b
|
|
258
|
+
* @returns {NonDeferAccess} merged
|
|
259
|
+
*/
|
|
260
|
+
const mergeNonDeferAccess = (a, b) => a || b;
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* @param {NonDeferAccess} a first
|
|
264
|
+
* @param {NonDeferAccess} b second
|
|
265
|
+
* @returns {NonDeferAccess} first - second
|
|
266
|
+
*/
|
|
267
|
+
const subtractNonDeferAccess = (a, b) => a && !b;
|
|
268
|
+
|
|
239
269
|
/**
|
|
240
270
|
* @typedef {object} ConcatenationEntry
|
|
241
271
|
* @property {"concatenated" | "external"} type
|
|
242
272
|
* @property {Module} module
|
|
243
273
|
* @property {RuntimeSpec | boolean} runtimeCondition
|
|
274
|
+
* @property {NonDeferAccess} nonDeferAccess
|
|
244
275
|
*/
|
|
245
276
|
|
|
277
|
+
/** @typedef {Set<ConcatenatedModuleInfo>} NeededNamespaceObjects */
|
|
278
|
+
|
|
279
|
+
/** @typedef {Map<Module, ModuleInfo>} ModuleToInfoMap */
|
|
280
|
+
|
|
246
281
|
/**
|
|
247
282
|
* @param {ModuleGraph} moduleGraph the module graph
|
|
248
283
|
* @param {ModuleInfo} info module info
|
|
249
|
-
* @param {
|
|
250
|
-
* @param {
|
|
284
|
+
* @param {ExportName} exportName exportName
|
|
285
|
+
* @param {ModuleToInfoMap} moduleToInfoMap moduleToInfoMap
|
|
251
286
|
* @param {RuntimeSpec} runtime for which runtime
|
|
252
287
|
* @param {RequestShortener} requestShortener the request shortener
|
|
253
288
|
* @param {RuntimeTemplate} runtimeTemplate the runtime template
|
|
254
|
-
* @param {
|
|
289
|
+
* @param {NeededNamespaceObjects} neededNamespaceObjects modules for which a namespace object should be generated
|
|
255
290
|
* @param {boolean} asCall asCall
|
|
291
|
+
* @param {boolean} depDeferred the dependency is deferred
|
|
256
292
|
* @param {boolean | undefined} strictHarmonyModule strictHarmonyModule
|
|
257
293
|
* @param {boolean | undefined} asiSafe asiSafe
|
|
258
294
|
* @param {Set<ExportInfo>} alreadyVisited alreadyVisited
|
|
@@ -268,6 +304,7 @@ const getFinalBinding = (
|
|
|
268
304
|
runtimeTemplate,
|
|
269
305
|
neededNamespaceObjects,
|
|
270
306
|
asCall,
|
|
307
|
+
depDeferred,
|
|
271
308
|
strictHarmonyModule,
|
|
272
309
|
asiSafe,
|
|
273
310
|
alreadyVisited = new Set()
|
|
@@ -276,21 +313,36 @@ const getFinalBinding = (
|
|
|
276
313
|
moduleGraph,
|
|
277
314
|
strictHarmonyModule
|
|
278
315
|
);
|
|
316
|
+
const moduleDeferred =
|
|
317
|
+
info.type === "external" &&
|
|
318
|
+
info.deferred &&
|
|
319
|
+
!(/** @type {BuildMeta} */ (info.module.buildMeta).async);
|
|
320
|
+
const deferred = depDeferred && moduleDeferred;
|
|
279
321
|
if (exportName.length === 0) {
|
|
280
322
|
switch (exportsType) {
|
|
281
323
|
case "default-only":
|
|
282
|
-
info.
|
|
324
|
+
if (deferred) info.deferredNamespaceObjectUsed = true;
|
|
325
|
+
else info.interopNamespaceObject2Used = true;
|
|
283
326
|
return {
|
|
284
327
|
info,
|
|
285
|
-
rawName: /** @type {string} */ (
|
|
328
|
+
rawName: /** @type {string} */ (
|
|
329
|
+
deferred
|
|
330
|
+
? info.deferredNamespaceObjectName
|
|
331
|
+
: info.interopNamespaceObject2Name
|
|
332
|
+
),
|
|
286
333
|
ids: exportName,
|
|
287
334
|
exportName
|
|
288
335
|
};
|
|
289
336
|
case "default-with-named":
|
|
290
|
-
info.
|
|
337
|
+
if (deferred) info.deferredNamespaceObjectUsed = true;
|
|
338
|
+
else info.interopNamespaceObjectUsed = true;
|
|
291
339
|
return {
|
|
292
340
|
info,
|
|
293
|
-
rawName: /** @type {string} */ (
|
|
341
|
+
rawName: /** @type {string} */ (
|
|
342
|
+
deferred
|
|
343
|
+
? info.deferredNamespaceObjectName
|
|
344
|
+
: info.interopNamespaceObjectName
|
|
345
|
+
),
|
|
294
346
|
ids: exportName,
|
|
295
347
|
exportName
|
|
296
348
|
};
|
|
@@ -344,6 +396,22 @@ const getFinalBinding = (
|
|
|
344
396
|
switch (exportName[0]) {
|
|
345
397
|
case "default": {
|
|
346
398
|
exportName = exportName.slice(1);
|
|
399
|
+
if (deferred) {
|
|
400
|
+
return {
|
|
401
|
+
info,
|
|
402
|
+
rawName: `${info.deferredName}.a`,
|
|
403
|
+
ids: exportName,
|
|
404
|
+
exportName
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
if (moduleDeferred) {
|
|
408
|
+
return {
|
|
409
|
+
info,
|
|
410
|
+
rawName: /** @type {string} */ (info.name),
|
|
411
|
+
ids: exportName,
|
|
412
|
+
exportName
|
|
413
|
+
};
|
|
414
|
+
}
|
|
347
415
|
info.interopDefaultAccessUsed = true;
|
|
348
416
|
const defaultExport = asCall
|
|
349
417
|
? `${info.interopDefaultAccessName}()`
|
|
@@ -385,6 +453,15 @@ const getFinalBinding = (
|
|
|
385
453
|
exportName
|
|
386
454
|
};
|
|
387
455
|
case "external":
|
|
456
|
+
if (deferred) {
|
|
457
|
+
info.deferredNamespaceObjectUsed = true;
|
|
458
|
+
return {
|
|
459
|
+
info,
|
|
460
|
+
rawName: /** @type {string} */ (info.deferredNamespaceObjectName),
|
|
461
|
+
ids: exportName,
|
|
462
|
+
exportName
|
|
463
|
+
};
|
|
464
|
+
}
|
|
388
465
|
return {
|
|
389
466
|
info,
|
|
390
467
|
rawName:
|
|
@@ -421,7 +498,7 @@ const getFinalBinding = (
|
|
|
421
498
|
}
|
|
422
499
|
const directExport = info.exportMap && info.exportMap.get(exportId);
|
|
423
500
|
if (directExport) {
|
|
424
|
-
const usedName = /** @type {
|
|
501
|
+
const usedName = /** @type {ExportName} */ (
|
|
425
502
|
exportsInfo.getUsedName(exportName, runtime)
|
|
426
503
|
);
|
|
427
504
|
if (!usedName) {
|
|
@@ -448,7 +525,7 @@ const getFinalBinding = (
|
|
|
448
525
|
exportName
|
|
449
526
|
};
|
|
450
527
|
}
|
|
451
|
-
const reexport = exportInfo.findTarget(moduleGraph, module =>
|
|
528
|
+
const reexport = exportInfo.findTarget(moduleGraph, (module) =>
|
|
452
529
|
moduleToInfoMap.has(module)
|
|
453
530
|
);
|
|
454
531
|
if (reexport === false) {
|
|
@@ -476,6 +553,7 @@ const getFinalBinding = (
|
|
|
476
553
|
runtimeTemplate,
|
|
477
554
|
neededNamespaceObjects,
|
|
478
555
|
asCall,
|
|
556
|
+
reexport.deferred,
|
|
479
557
|
/** @type {BuildMeta} */
|
|
480
558
|
(info.module.buildMeta).strictHarmonyModule,
|
|
481
559
|
asiSafe,
|
|
@@ -483,7 +561,7 @@ const getFinalBinding = (
|
|
|
483
561
|
);
|
|
484
562
|
}
|
|
485
563
|
if (info.namespaceExportSymbol) {
|
|
486
|
-
const usedName = /** @type {
|
|
564
|
+
const usedName = /** @type {ExportName} */ (
|
|
487
565
|
exportsInfo.getUsedName(exportName, runtime)
|
|
488
566
|
);
|
|
489
567
|
return {
|
|
@@ -501,7 +579,7 @@ const getFinalBinding = (
|
|
|
501
579
|
}
|
|
502
580
|
|
|
503
581
|
case "external": {
|
|
504
|
-
const used = /** @type {
|
|
582
|
+
const used = /** @type {ExportName} */ (
|
|
505
583
|
exportsInfo.getUsedName(exportName, runtime)
|
|
506
584
|
);
|
|
507
585
|
if (!used) {
|
|
@@ -515,7 +593,15 @@ const getFinalBinding = (
|
|
|
515
593
|
const comment = equals(used, exportName)
|
|
516
594
|
? ""
|
|
517
595
|
: Template.toNormalComment(`${exportName.join(".")}`);
|
|
518
|
-
return {
|
|
596
|
+
return {
|
|
597
|
+
info,
|
|
598
|
+
rawName:
|
|
599
|
+
(deferred ? info.deferredName : info.name) +
|
|
600
|
+
(deferred ? ".a" : "") +
|
|
601
|
+
comment,
|
|
602
|
+
ids: used,
|
|
603
|
+
exportName
|
|
604
|
+
};
|
|
519
605
|
}
|
|
520
606
|
}
|
|
521
607
|
};
|
|
@@ -523,13 +609,14 @@ const getFinalBinding = (
|
|
|
523
609
|
/**
|
|
524
610
|
* @param {ModuleGraph} moduleGraph the module graph
|
|
525
611
|
* @param {ModuleInfo} info module info
|
|
526
|
-
* @param {
|
|
527
|
-
* @param {
|
|
612
|
+
* @param {ExportName} exportName exportName
|
|
613
|
+
* @param {ModuleToInfoMap} moduleToInfoMap moduleToInfoMap
|
|
528
614
|
* @param {RuntimeSpec} runtime for which runtime
|
|
529
615
|
* @param {RequestShortener} requestShortener the request shortener
|
|
530
616
|
* @param {RuntimeTemplate} runtimeTemplate the runtime template
|
|
531
|
-
* @param {
|
|
617
|
+
* @param {NeededNamespaceObjects} neededNamespaceObjects modules for which a namespace object should be generated
|
|
532
618
|
* @param {boolean} asCall asCall
|
|
619
|
+
* @param {boolean} depDeferred the dependency is deferred
|
|
533
620
|
* @param {boolean | undefined} callContext callContext
|
|
534
621
|
* @param {boolean | undefined} strictHarmonyModule strictHarmonyModule
|
|
535
622
|
* @param {boolean | undefined} asiSafe asiSafe
|
|
@@ -545,6 +632,7 @@ const getFinalName = (
|
|
|
545
632
|
runtimeTemplate,
|
|
546
633
|
neededNamespaceObjects,
|
|
547
634
|
asCall,
|
|
635
|
+
depDeferred,
|
|
548
636
|
callContext,
|
|
549
637
|
strictHarmonyModule,
|
|
550
638
|
asiSafe
|
|
@@ -559,6 +647,7 @@ const getFinalName = (
|
|
|
559
647
|
runtimeTemplate,
|
|
560
648
|
neededNamespaceObjects,
|
|
561
649
|
asCall,
|
|
650
|
+
depDeferred,
|
|
562
651
|
strictHarmonyModule,
|
|
563
652
|
asiSafe
|
|
564
653
|
);
|
|
@@ -600,9 +689,12 @@ const getFinalName = (
|
|
|
600
689
|
|
|
601
690
|
/**
|
|
602
691
|
* @typedef {object} ConcatenateModuleHooks
|
|
603
|
-
* @property {SyncBailHook<[Record<string, string>], boolean
|
|
692
|
+
* @property {SyncBailHook<[ConcatenatedModule, RuntimeSpec[], string, Record<string, string>], boolean>} onDemandExportsGeneration
|
|
693
|
+
* @property {SyncBailHook<[Partial<ConcatenatedModuleInfo>, ConcatenatedModuleInfo], boolean | void>} concatenatedModuleInfo
|
|
604
694
|
*/
|
|
605
695
|
|
|
696
|
+
/** @typedef {BuildInfo["topLevelDeclarations"]} TopLevelDeclarations */
|
|
697
|
+
|
|
606
698
|
/** @type {WeakMap<Compilation, ConcatenateModuleHooks>} */
|
|
607
699
|
const compilationHooksMap = new WeakMap();
|
|
608
700
|
|
|
@@ -612,7 +704,7 @@ class ConcatenatedModule extends Module {
|
|
|
612
704
|
* @param {Set<Module>} modules all modules in the concatenation (including the root module)
|
|
613
705
|
* @param {RuntimeSpec} runtime the runtime
|
|
614
706
|
* @param {Compilation} compilation the compilation
|
|
615
|
-
* @param {
|
|
707
|
+
* @param {AssociatedObjectForCache=} associatedObjectForCache object for caching
|
|
616
708
|
* @param {string | HashConstructor=} hashFunction hash function to use
|
|
617
709
|
* @returns {ConcatenatedModule} the module
|
|
618
710
|
*/
|
|
@@ -622,7 +714,7 @@ class ConcatenatedModule extends Module {
|
|
|
622
714
|
runtime,
|
|
623
715
|
compilation,
|
|
624
716
|
associatedObjectForCache,
|
|
625
|
-
hashFunction =
|
|
717
|
+
hashFunction = DEFAULTS.HASH_FUNCTION
|
|
626
718
|
) {
|
|
627
719
|
const identifier = ConcatenatedModule._createIdentifier(
|
|
628
720
|
rootModule,
|
|
@@ -647,7 +739,16 @@ class ConcatenatedModule extends Module {
|
|
|
647
739
|
let hooks = compilationHooksMap.get(compilation);
|
|
648
740
|
if (hooks === undefined) {
|
|
649
741
|
hooks = {
|
|
650
|
-
|
|
742
|
+
onDemandExportsGeneration: new SyncBailHook([
|
|
743
|
+
"module",
|
|
744
|
+
"runtimes",
|
|
745
|
+
"exportsFinalName",
|
|
746
|
+
"exportsSource"
|
|
747
|
+
]),
|
|
748
|
+
concatenatedModuleInfo: new SyncBailHook([
|
|
749
|
+
"updatedInfo",
|
|
750
|
+
"concatenatedModuleInfo"
|
|
751
|
+
])
|
|
651
752
|
};
|
|
652
753
|
compilationHooksMap.set(compilation, hooks);
|
|
653
754
|
}
|
|
@@ -674,7 +775,7 @@ class ConcatenatedModule extends Module {
|
|
|
674
775
|
this._modules = modules;
|
|
675
776
|
this._runtime = runtime;
|
|
676
777
|
this.factoryMeta = rootModule && rootModule.factoryMeta;
|
|
677
|
-
/** @type {Compilation
|
|
778
|
+
/** @type {Compilation} */
|
|
678
779
|
this.compilation = compilation;
|
|
679
780
|
}
|
|
680
781
|
|
|
@@ -693,11 +794,11 @@ class ConcatenatedModule extends Module {
|
|
|
693
794
|
* @returns {SourceTypes} types available (do not mutate)
|
|
694
795
|
*/
|
|
695
796
|
getSourceTypes() {
|
|
696
|
-
return
|
|
797
|
+
return JAVASCRIPT_TYPES;
|
|
697
798
|
}
|
|
698
799
|
|
|
699
800
|
get modules() {
|
|
700
|
-
return
|
|
801
|
+
return [...this._modules];
|
|
701
802
|
}
|
|
702
803
|
|
|
703
804
|
/**
|
|
@@ -719,14 +820,14 @@ class ConcatenatedModule extends Module {
|
|
|
719
820
|
|
|
720
821
|
/**
|
|
721
822
|
* @param {LibIdentOptions} options options
|
|
722
|
-
* @returns {
|
|
823
|
+
* @returns {LibIdent | null} an identifier for library inclusion
|
|
723
824
|
*/
|
|
724
825
|
libIdent(options) {
|
|
725
826
|
return this.rootModule.libIdent(options);
|
|
726
827
|
}
|
|
727
828
|
|
|
728
829
|
/**
|
|
729
|
-
* @returns {
|
|
830
|
+
* @returns {NameForCondition | null} absolute path which should be used for condition matching (usually the resource path)
|
|
730
831
|
*/
|
|
731
832
|
nameForCondition() {
|
|
732
833
|
return this.rootModule.nameForCondition();
|
|
@@ -745,7 +846,7 @@ class ConcatenatedModule extends Module {
|
|
|
745
846
|
* @param {Compilation} compilation the compilation
|
|
746
847
|
* @param {ResolverWithOptions} resolver the resolver
|
|
747
848
|
* @param {InputFileSystem} fs the file system
|
|
748
|
-
* @param {
|
|
849
|
+
* @param {BuildCallback} callback callback function
|
|
749
850
|
* @returns {void}
|
|
750
851
|
*/
|
|
751
852
|
build(options, compilation, resolver, fs, callback) {
|
|
@@ -771,15 +872,17 @@ class ConcatenatedModule extends Module {
|
|
|
771
872
|
for (const m of this._modules) {
|
|
772
873
|
// populate cacheable
|
|
773
874
|
if (!(/** @type {BuildInfo} */ (m.buildInfo).cacheable)) {
|
|
774
|
-
|
|
875
|
+
/** @type {BuildInfo} */
|
|
876
|
+
(this.buildInfo).cacheable = false;
|
|
775
877
|
}
|
|
776
878
|
|
|
777
879
|
// populate dependencies
|
|
778
880
|
for (const d of m.dependencies.filter(
|
|
779
|
-
dep =>
|
|
881
|
+
(dep) =>
|
|
780
882
|
!(dep instanceof HarmonyImportDependency) ||
|
|
781
883
|
!this._modules.has(
|
|
782
|
-
/** @type {Module} */
|
|
884
|
+
/** @type {Module} */
|
|
885
|
+
(compilation.moduleGraph.getModule(dep))
|
|
783
886
|
)
|
|
784
887
|
)) {
|
|
785
888
|
this.dependencies.push(d);
|
|
@@ -805,41 +908,45 @@ class ConcatenatedModule extends Module {
|
|
|
805
908
|
}
|
|
806
909
|
}
|
|
807
910
|
|
|
808
|
-
const { assets, assetsInfo, topLevelDeclarations } =
|
|
911
|
+
const { assets, assetsInfo, topLevelDeclarations, needCreateRequire } =
|
|
809
912
|
/** @type {BuildInfo} */ (m.buildInfo);
|
|
810
913
|
|
|
914
|
+
const buildInfo = /** @type {BuildInfo} */ (this.buildInfo);
|
|
915
|
+
|
|
811
916
|
// populate topLevelDeclarations
|
|
812
917
|
if (topLevelDeclarations) {
|
|
813
|
-
const topLevelDeclarations =
|
|
918
|
+
const topLevelDeclarations = buildInfo.topLevelDeclarations;
|
|
814
919
|
if (topLevelDeclarations !== undefined) {
|
|
815
920
|
for (const decl of topLevelDeclarations) {
|
|
816
921
|
topLevelDeclarations.add(decl);
|
|
817
922
|
}
|
|
818
923
|
}
|
|
819
924
|
} else {
|
|
820
|
-
|
|
925
|
+
buildInfo.topLevelDeclarations = undefined;
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
// populate needCreateRequire
|
|
929
|
+
if (needCreateRequire) {
|
|
930
|
+
this.buildInfo.needCreateRequire = true;
|
|
821
931
|
}
|
|
822
932
|
|
|
823
933
|
// populate assets
|
|
824
934
|
if (assets) {
|
|
825
|
-
if (
|
|
826
|
-
|
|
935
|
+
if (buildInfo.assets === undefined) {
|
|
936
|
+
buildInfo.assets = Object.create(null);
|
|
827
937
|
}
|
|
828
938
|
Object.assign(
|
|
829
939
|
/** @type {NonNullable<BuildInfo["assets"]>} */
|
|
830
|
-
(
|
|
831
|
-
/** @type {BuildInfo} */
|
|
832
|
-
(this.buildInfo).assets
|
|
833
|
-
),
|
|
940
|
+
(buildInfo.assets),
|
|
834
941
|
assets
|
|
835
942
|
);
|
|
836
943
|
}
|
|
837
944
|
if (assetsInfo) {
|
|
838
|
-
if (
|
|
839
|
-
|
|
945
|
+
if (buildInfo.assetsInfo === undefined) {
|
|
946
|
+
buildInfo.assetsInfo = new Map();
|
|
840
947
|
}
|
|
841
948
|
for (const [key, value] of assetsInfo) {
|
|
842
|
-
|
|
949
|
+
buildInfo.assetsInfo.set(key, value);
|
|
843
950
|
}
|
|
844
951
|
}
|
|
845
952
|
}
|
|
@@ -870,28 +977,28 @@ class ConcatenatedModule extends Module {
|
|
|
870
977
|
_createConcatenationList(rootModule, modulesSet, runtime, moduleGraph) {
|
|
871
978
|
/** @type {ConcatenationEntry[]} */
|
|
872
979
|
const list = [];
|
|
873
|
-
/** @type {Map<Module, RuntimeSpec | true>} */
|
|
980
|
+
/** @type {Map<Module, { runtimeCondition: RuntimeSpec | true, nonDeferAccess: NonDeferAccess }>} */
|
|
874
981
|
const existingEntries = new Map();
|
|
875
982
|
|
|
876
983
|
/**
|
|
877
984
|
* @param {Module} module a module
|
|
878
|
-
* @returns {Iterable<{ connection: ModuleGraphConnection, runtimeCondition: RuntimeSpec | true }>} imported modules in order
|
|
985
|
+
* @returns {Iterable<{ connection: ModuleGraphConnection, runtimeCondition: RuntimeSpec | true, nonDeferAccess: NonDeferAccess }>} imported modules in order
|
|
879
986
|
*/
|
|
880
|
-
const getConcatenatedImports = module => {
|
|
881
|
-
const connections =
|
|
882
|
-
moduleGraph.getOutgoingConnections(module)
|
|
883
|
-
);
|
|
987
|
+
const getConcatenatedImports = (module) => {
|
|
988
|
+
const connections = [...moduleGraph.getOutgoingConnections(module)];
|
|
884
989
|
if (module === rootModule) {
|
|
885
|
-
for (const c of moduleGraph.getOutgoingConnections(this))
|
|
990
|
+
for (const c of moduleGraph.getOutgoingConnections(this)) {
|
|
886
991
|
connections.push(c);
|
|
992
|
+
}
|
|
887
993
|
}
|
|
888
994
|
/**
|
|
889
|
-
* @type {
|
|
995
|
+
* @type {{ connection: ModuleGraphConnection, sourceOrder: number, rangeStart: number | undefined, defer?: boolean }[]}
|
|
890
996
|
*/
|
|
891
997
|
const references = connections
|
|
892
|
-
.filter(connection => {
|
|
893
|
-
if (!(connection.dependency instanceof HarmonyImportDependency))
|
|
998
|
+
.filter((connection) => {
|
|
999
|
+
if (!(connection.dependency instanceof HarmonyImportDependency)) {
|
|
894
1000
|
return false;
|
|
1001
|
+
}
|
|
895
1002
|
return (
|
|
896
1003
|
connection &&
|
|
897
1004
|
connection.resolvedOriginModule === module &&
|
|
@@ -899,14 +1006,15 @@ class ConcatenatedModule extends Module {
|
|
|
899
1006
|
connection.isTargetActive(runtime)
|
|
900
1007
|
);
|
|
901
1008
|
})
|
|
902
|
-
.map(connection => {
|
|
903
|
-
const dep =
|
|
904
|
-
|
|
905
|
-
|
|
1009
|
+
.map((connection) => {
|
|
1010
|
+
const dep =
|
|
1011
|
+
/** @type {HarmonyImportDependency} */
|
|
1012
|
+
(connection.dependency);
|
|
906
1013
|
return {
|
|
907
1014
|
connection,
|
|
908
|
-
sourceOrder: dep.sourceOrder,
|
|
909
|
-
rangeStart: dep.range && dep.range[0]
|
|
1015
|
+
sourceOrder: /** @type {number} */ (dep.sourceOrder),
|
|
1016
|
+
rangeStart: dep.range && dep.range[0],
|
|
1017
|
+
defer: ImportPhaseUtils.isDefer(dep.phase)
|
|
910
1018
|
};
|
|
911
1019
|
});
|
|
912
1020
|
/**
|
|
@@ -926,17 +1034,22 @@ class ConcatenatedModule extends Module {
|
|
|
926
1034
|
* If there is side-effects-free reexport, we can get simple deterministic result with range start comparison.
|
|
927
1035
|
*/
|
|
928
1036
|
references.sort(concatComparators(bySourceOrder, byRangeStart));
|
|
929
|
-
/** @type {Map<Module, { connection: ModuleGraphConnection, runtimeCondition: RuntimeSpec | true }>} */
|
|
1037
|
+
/** @type {Map<Module, { connection: ModuleGraphConnection, runtimeCondition: RuntimeSpec | true, nonDeferAccess: NonDeferAccess }>} */
|
|
930
1038
|
const referencesMap = new Map();
|
|
931
|
-
for (const { connection } of references) {
|
|
932
|
-
const runtimeCondition = filterRuntime(runtime, r =>
|
|
1039
|
+
for (const { connection, defer } of references) {
|
|
1040
|
+
const runtimeCondition = filterRuntime(runtime, (r) =>
|
|
933
1041
|
connection.isTargetActive(r)
|
|
934
1042
|
);
|
|
935
1043
|
if (runtimeCondition === false) continue;
|
|
1044
|
+
const nonDeferAccess = !defer;
|
|
936
1045
|
const module = connection.module;
|
|
937
1046
|
const entry = referencesMap.get(module);
|
|
938
1047
|
if (entry === undefined) {
|
|
939
|
-
referencesMap.set(module, {
|
|
1048
|
+
referencesMap.set(module, {
|
|
1049
|
+
connection,
|
|
1050
|
+
runtimeCondition,
|
|
1051
|
+
nonDeferAccess
|
|
1052
|
+
});
|
|
940
1053
|
continue;
|
|
941
1054
|
}
|
|
942
1055
|
entry.runtimeCondition = mergeRuntimeConditionNonFalse(
|
|
@@ -944,6 +1057,10 @@ class ConcatenatedModule extends Module {
|
|
|
944
1057
|
runtimeCondition,
|
|
945
1058
|
runtime
|
|
946
1059
|
);
|
|
1060
|
+
entry.nonDeferAccess = mergeNonDeferAccess(
|
|
1061
|
+
entry.nonDeferAccess,
|
|
1062
|
+
nonDeferAccess
|
|
1063
|
+
);
|
|
947
1064
|
}
|
|
948
1065
|
return referencesMap.values();
|
|
949
1066
|
};
|
|
@@ -951,17 +1068,25 @@ class ConcatenatedModule extends Module {
|
|
|
951
1068
|
/**
|
|
952
1069
|
* @param {ModuleGraphConnection} connection graph connection
|
|
953
1070
|
* @param {RuntimeSpec | true} runtimeCondition runtime condition
|
|
1071
|
+
* @param {NonDeferAccess} nonDeferAccess non-defer access
|
|
954
1072
|
* @returns {void}
|
|
955
1073
|
*/
|
|
956
|
-
const enterModule = (connection, runtimeCondition) => {
|
|
1074
|
+
const enterModule = (connection, runtimeCondition, nonDeferAccess) => {
|
|
957
1075
|
const module = connection.module;
|
|
958
1076
|
if (!module) return;
|
|
959
1077
|
const existingEntry = existingEntries.get(module);
|
|
960
|
-
if (
|
|
1078
|
+
if (
|
|
1079
|
+
existingEntry &&
|
|
1080
|
+
existingEntry.runtimeCondition === true &&
|
|
1081
|
+
existingEntry.nonDeferAccess === true
|
|
1082
|
+
) {
|
|
961
1083
|
return;
|
|
962
1084
|
}
|
|
963
1085
|
if (modulesSet.has(module)) {
|
|
964
|
-
existingEntries.set(module,
|
|
1086
|
+
existingEntries.set(module, {
|
|
1087
|
+
runtimeCondition: true,
|
|
1088
|
+
nonDeferAccess: true
|
|
1089
|
+
});
|
|
965
1090
|
if (runtimeCondition !== true) {
|
|
966
1091
|
throw new Error(
|
|
967
1092
|
`Cannot runtime-conditional concatenate a module (${module.identifier()} in ${this.rootModule.identifier()}, ${runtimeConditionToString(
|
|
@@ -969,33 +1094,66 @@ class ConcatenatedModule extends Module {
|
|
|
969
1094
|
)}). This should not happen.`
|
|
970
1095
|
);
|
|
971
1096
|
}
|
|
1097
|
+
if (nonDeferAccess !== true) {
|
|
1098
|
+
throw new Error(
|
|
1099
|
+
`Cannot deferred concatenate a module (${module.identifier()} in ${this.rootModule.identifier()}. This should not happen.`
|
|
1100
|
+
);
|
|
1101
|
+
}
|
|
972
1102
|
const imports = getConcatenatedImports(module);
|
|
973
|
-
for (const {
|
|
974
|
-
|
|
1103
|
+
for (const {
|
|
1104
|
+
connection,
|
|
1105
|
+
runtimeCondition,
|
|
1106
|
+
nonDeferAccess
|
|
1107
|
+
} of imports) {
|
|
1108
|
+
enterModule(connection, runtimeCondition, nonDeferAccess);
|
|
1109
|
+
}
|
|
975
1110
|
list.push({
|
|
976
1111
|
type: "concatenated",
|
|
977
1112
|
module: connection.module,
|
|
978
|
-
runtimeCondition
|
|
1113
|
+
runtimeCondition,
|
|
1114
|
+
nonDeferAccess
|
|
979
1115
|
});
|
|
980
1116
|
} else {
|
|
1117
|
+
/** @type {RuntimeSpec | boolean} */
|
|
1118
|
+
let reducedRuntimeCondition;
|
|
1119
|
+
/** @type {NonDeferAccess} */
|
|
1120
|
+
let reducedNonDeferAccess;
|
|
981
1121
|
if (existingEntry !== undefined) {
|
|
982
|
-
|
|
1122
|
+
reducedRuntimeCondition = subtractRuntimeCondition(
|
|
983
1123
|
runtimeCondition,
|
|
984
|
-
existingEntry,
|
|
1124
|
+
existingEntry.runtimeCondition,
|
|
985
1125
|
runtime
|
|
986
1126
|
);
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
connection.module,
|
|
991
|
-
mergeRuntimeConditionNonFalse(
|
|
992
|
-
existingEntry,
|
|
993
|
-
runtimeCondition,
|
|
994
|
-
runtime
|
|
995
|
-
)
|
|
1127
|
+
reducedNonDeferAccess = subtractNonDeferAccess(
|
|
1128
|
+
nonDeferAccess,
|
|
1129
|
+
existingEntry.nonDeferAccess
|
|
996
1130
|
);
|
|
1131
|
+
if (
|
|
1132
|
+
reducedRuntimeCondition === false &&
|
|
1133
|
+
reducedNonDeferAccess === false
|
|
1134
|
+
) {
|
|
1135
|
+
return;
|
|
1136
|
+
}
|
|
1137
|
+
if (reducedRuntimeCondition !== false) {
|
|
1138
|
+
existingEntry.runtimeCondition = mergeRuntimeConditionNonFalse(
|
|
1139
|
+
existingEntry.runtimeCondition,
|
|
1140
|
+
reducedRuntimeCondition,
|
|
1141
|
+
runtime
|
|
1142
|
+
);
|
|
1143
|
+
}
|
|
1144
|
+
if (reducedNonDeferAccess !== false) {
|
|
1145
|
+
existingEntry.nonDeferAccess = mergeNonDeferAccess(
|
|
1146
|
+
existingEntry.nonDeferAccess,
|
|
1147
|
+
reducedNonDeferAccess
|
|
1148
|
+
);
|
|
1149
|
+
}
|
|
997
1150
|
} else {
|
|
998
|
-
|
|
1151
|
+
reducedRuntimeCondition = runtimeCondition;
|
|
1152
|
+
reducedNonDeferAccess = nonDeferAccess;
|
|
1153
|
+
existingEntries.set(connection.module, {
|
|
1154
|
+
runtimeCondition,
|
|
1155
|
+
nonDeferAccess
|
|
1156
|
+
});
|
|
999
1157
|
}
|
|
1000
1158
|
if (list.length > 0) {
|
|
1001
1159
|
const lastItem = list[list.length - 1];
|
|
@@ -1005,9 +1163,13 @@ class ConcatenatedModule extends Module {
|
|
|
1005
1163
|
) {
|
|
1006
1164
|
lastItem.runtimeCondition = mergeRuntimeCondition(
|
|
1007
1165
|
lastItem.runtimeCondition,
|
|
1008
|
-
|
|
1166
|
+
reducedRuntimeCondition,
|
|
1009
1167
|
runtime
|
|
1010
1168
|
);
|
|
1169
|
+
lastItem.nonDeferAccess = mergeNonDeferAccess(
|
|
1170
|
+
lastItem.nonDeferAccess,
|
|
1171
|
+
reducedNonDeferAccess
|
|
1172
|
+
);
|
|
1011
1173
|
return;
|
|
1012
1174
|
}
|
|
1013
1175
|
}
|
|
@@ -1019,19 +1181,25 @@ class ConcatenatedModule extends Module {
|
|
|
1019
1181
|
// concatenated module)
|
|
1020
1182
|
return connection.module;
|
|
1021
1183
|
},
|
|
1022
|
-
runtimeCondition
|
|
1184
|
+
runtimeCondition: reducedRuntimeCondition,
|
|
1185
|
+
nonDeferAccess: reducedNonDeferAccess
|
|
1023
1186
|
});
|
|
1024
1187
|
}
|
|
1025
1188
|
};
|
|
1026
1189
|
|
|
1027
|
-
existingEntries.set(rootModule,
|
|
1190
|
+
existingEntries.set(rootModule, {
|
|
1191
|
+
runtimeCondition: true,
|
|
1192
|
+
nonDeferAccess: true
|
|
1193
|
+
});
|
|
1028
1194
|
const imports = getConcatenatedImports(rootModule);
|
|
1029
|
-
for (const { connection, runtimeCondition } of imports)
|
|
1030
|
-
enterModule(connection, runtimeCondition);
|
|
1195
|
+
for (const { connection, runtimeCondition, nonDeferAccess } of imports) {
|
|
1196
|
+
enterModule(connection, runtimeCondition, nonDeferAccess);
|
|
1197
|
+
}
|
|
1031
1198
|
list.push({
|
|
1032
1199
|
type: "concatenated",
|
|
1033
1200
|
module: rootModule,
|
|
1034
|
-
runtimeCondition: true
|
|
1201
|
+
runtimeCondition: true,
|
|
1202
|
+
nonDeferAccess: true
|
|
1035
1203
|
});
|
|
1036
1204
|
|
|
1037
1205
|
return list;
|
|
@@ -1040,7 +1208,7 @@ class ConcatenatedModule extends Module {
|
|
|
1040
1208
|
/**
|
|
1041
1209
|
* @param {Module} rootModule the root module of the concatenation
|
|
1042
1210
|
* @param {Set<Module>} modules all modules in the concatenation (including the root module)
|
|
1043
|
-
* @param {
|
|
1211
|
+
* @param {AssociatedObjectForCache=} associatedObjectForCache object for caching
|
|
1044
1212
|
* @param {string | HashConstructor=} hashFunction hash function to use
|
|
1045
1213
|
* @returns {string} the identifier
|
|
1046
1214
|
*/
|
|
@@ -1048,7 +1216,7 @@ class ConcatenatedModule extends Module {
|
|
|
1048
1216
|
rootModule,
|
|
1049
1217
|
modules,
|
|
1050
1218
|
associatedObjectForCache,
|
|
1051
|
-
hashFunction =
|
|
1219
|
+
hashFunction = DEFAULTS.HASH_FUNCTION
|
|
1052
1220
|
) {
|
|
1053
1221
|
const cachedMakePathsRelative = makePathsRelative.bindContextCache(
|
|
1054
1222
|
/** @type {string} */ (rootModule.context),
|
|
@@ -1065,10 +1233,10 @@ class ConcatenatedModule extends Module {
|
|
|
1065
1233
|
}
|
|
1066
1234
|
|
|
1067
1235
|
/**
|
|
1068
|
-
* @param {
|
|
1069
|
-
* @param {
|
|
1070
|
-
* @param {
|
|
1071
|
-
* @param {
|
|
1236
|
+
* @param {FileSystemDependencies} fileDependencies set where file dependencies are added to
|
|
1237
|
+
* @param {FileSystemDependencies} contextDependencies set where context dependencies are added to
|
|
1238
|
+
* @param {FileSystemDependencies} missingDependencies set where missing dependencies are added to
|
|
1239
|
+
* @param {FileSystemDependencies} buildDependencies set where build dependencies are added to
|
|
1072
1240
|
*/
|
|
1073
1241
|
addCacheDependencies(
|
|
1074
1242
|
fileDependencies,
|
|
@@ -1096,8 +1264,13 @@ class ConcatenatedModule extends Module {
|
|
|
1096
1264
|
moduleGraph,
|
|
1097
1265
|
chunkGraph,
|
|
1098
1266
|
runtime: generationRuntime,
|
|
1267
|
+
runtimes,
|
|
1099
1268
|
codeGenerationResults
|
|
1100
1269
|
}) {
|
|
1270
|
+
const { concatenatedModuleInfo } = ConcatenatedModule.getCompilationHooks(
|
|
1271
|
+
this.compilation
|
|
1272
|
+
);
|
|
1273
|
+
|
|
1101
1274
|
/** @type {RuntimeRequirements} */
|
|
1102
1275
|
const runtimeRequirements = new Set();
|
|
1103
1276
|
const runtime = intersectRuntime(generationRuntime, this._runtime);
|
|
@@ -1110,9 +1283,12 @@ class ConcatenatedModule extends Module {
|
|
|
1110
1283
|
);
|
|
1111
1284
|
|
|
1112
1285
|
// Set with modules that need a generated namespace object
|
|
1113
|
-
/** @type {
|
|
1286
|
+
/** @type {NeededNamespaceObjects} */
|
|
1114
1287
|
const neededNamespaceObjects = new Set();
|
|
1115
1288
|
|
|
1289
|
+
// List of all used names to avoid conflicts
|
|
1290
|
+
const allUsedNames = new Set(RESERVED_NAMES);
|
|
1291
|
+
|
|
1116
1292
|
// Generate source code and analyse scopes
|
|
1117
1293
|
// Prepare a ReplaceSource for the final source
|
|
1118
1294
|
for (const info of moduleToInfoMap.values()) {
|
|
@@ -1124,24 +1300,20 @@ class ConcatenatedModule extends Module {
|
|
|
1124
1300
|
moduleGraph,
|
|
1125
1301
|
chunkGraph,
|
|
1126
1302
|
runtime,
|
|
1303
|
+
runtimes,
|
|
1127
1304
|
/** @type {CodeGenerationResults} */
|
|
1128
|
-
(codeGenerationResults)
|
|
1305
|
+
(codeGenerationResults),
|
|
1306
|
+
allUsedNames
|
|
1129
1307
|
);
|
|
1130
1308
|
}
|
|
1131
1309
|
|
|
1132
|
-
// List of all used names to avoid conflicts
|
|
1133
|
-
const allUsedNames = new Set(RESERVED_NAMES);
|
|
1134
1310
|
// Updated Top level declarations are created by renaming
|
|
1311
|
+
/** @type {TopLevelDeclarations} */
|
|
1135
1312
|
const topLevelDeclarations = new Set();
|
|
1136
1313
|
|
|
1137
1314
|
// List of additional names in scope for module references
|
|
1138
|
-
/** @type {Map<string,
|
|
1315
|
+
/** @type {Map<string, ScopeInfo>} */
|
|
1139
1316
|
const usedNamesInScopeInfo = new Map();
|
|
1140
|
-
/**
|
|
1141
|
-
* @param {string} module module identifier
|
|
1142
|
-
* @param {string} id export id
|
|
1143
|
-
* @returns {{ usedNames: UsedNames, alreadyCheckedScopes: Set<TODO> }} info
|
|
1144
|
-
*/
|
|
1145
1317
|
|
|
1146
1318
|
// Set of already checked scopes
|
|
1147
1319
|
const ignoredScopes = new Set();
|
|
@@ -1160,9 +1332,9 @@ class ConcatenatedModule extends Module {
|
|
|
1160
1332
|
const superClassCache = new WeakMap();
|
|
1161
1333
|
/**
|
|
1162
1334
|
* @param {Scope} scope scope
|
|
1163
|
-
* @returns {
|
|
1335
|
+
* @returns {{ range: Range, variables: Variable[] }[]} result
|
|
1164
1336
|
*/
|
|
1165
|
-
const getSuperClassExpressions = scope => {
|
|
1337
|
+
const getSuperClassExpressions = (scope) => {
|
|
1166
1338
|
const cacheEntry = superClassCache.get(scope);
|
|
1167
1339
|
if (cacheEntry !== undefined) return cacheEntry;
|
|
1168
1340
|
const superClassExpressions = [];
|
|
@@ -1175,7 +1347,7 @@ class ConcatenatedModule extends Module {
|
|
|
1175
1347
|
block.superClass
|
|
1176
1348
|
) {
|
|
1177
1349
|
superClassExpressions.push({
|
|
1178
|
-
range: block.superClass.range,
|
|
1350
|
+
range: /** @type {Range} */ (block.superClass.range),
|
|
1179
1351
|
variables: childScope.variables
|
|
1180
1352
|
});
|
|
1181
1353
|
}
|
|
@@ -1192,8 +1364,9 @@ class ConcatenatedModule extends Module {
|
|
|
1192
1364
|
const match = ConcatenationScope.matchModuleReference(name);
|
|
1193
1365
|
if (!match) continue;
|
|
1194
1366
|
const referencedInfo = modulesWithInfo[match.index];
|
|
1195
|
-
if (referencedInfo.type === "reference")
|
|
1367
|
+
if (referencedInfo.type === "reference") {
|
|
1196
1368
|
throw new Error("Module reference can't point to a reference");
|
|
1369
|
+
}
|
|
1197
1370
|
const binding = getFinalBinding(
|
|
1198
1371
|
moduleGraph,
|
|
1199
1372
|
referencedInfo,
|
|
@@ -1204,6 +1377,7 @@ class ConcatenatedModule extends Module {
|
|
|
1204
1377
|
runtimeTemplate,
|
|
1205
1378
|
neededNamespaceObjects,
|
|
1206
1379
|
false,
|
|
1380
|
+
match.deferredImport,
|
|
1207
1381
|
/** @type {BuildMeta} */
|
|
1208
1382
|
(info.module.buildMeta).strictHarmonyModule,
|
|
1209
1383
|
true
|
|
@@ -1241,6 +1415,75 @@ class ConcatenatedModule extends Module {
|
|
|
1241
1415
|
}
|
|
1242
1416
|
}
|
|
1243
1417
|
|
|
1418
|
+
/**
|
|
1419
|
+
* @param {string} name the name to find a new name for
|
|
1420
|
+
* @param {ConcatenatedModuleInfo} info the info of the module
|
|
1421
|
+
* @param {Reference[]} references the references to the name
|
|
1422
|
+
* @returns {string | undefined} the new name or undefined if the name is not found
|
|
1423
|
+
*/
|
|
1424
|
+
const _findNewName = (name, info, references) => {
|
|
1425
|
+
const { usedNames, alreadyCheckedScopes } = getUsedNamesInScopeInfo(
|
|
1426
|
+
usedNamesInScopeInfo,
|
|
1427
|
+
info.module.identifier(),
|
|
1428
|
+
name
|
|
1429
|
+
);
|
|
1430
|
+
if (allUsedNames.has(name) || usedNames.has(name)) {
|
|
1431
|
+
for (const ref of references) {
|
|
1432
|
+
addScopeSymbols(
|
|
1433
|
+
ref.from,
|
|
1434
|
+
usedNames,
|
|
1435
|
+
alreadyCheckedScopes,
|
|
1436
|
+
ignoredScopes
|
|
1437
|
+
);
|
|
1438
|
+
}
|
|
1439
|
+
const newName = findNewName(
|
|
1440
|
+
name,
|
|
1441
|
+
allUsedNames,
|
|
1442
|
+
usedNames,
|
|
1443
|
+
info.module.readableIdentifier(requestShortener)
|
|
1444
|
+
);
|
|
1445
|
+
allUsedNames.add(newName);
|
|
1446
|
+
info.internalNames.set(name, newName);
|
|
1447
|
+
topLevelDeclarations.add(newName);
|
|
1448
|
+
return newName;
|
|
1449
|
+
}
|
|
1450
|
+
};
|
|
1451
|
+
|
|
1452
|
+
/**
|
|
1453
|
+
* @param {string} name the name to find a new name for
|
|
1454
|
+
* @param {ConcatenatedModuleInfo} info the info of the module
|
|
1455
|
+
* @param {Reference[]} references the references to the name
|
|
1456
|
+
* @returns {string | undefined} the new name or undefined if the name is not found
|
|
1457
|
+
*/
|
|
1458
|
+
const _findNewNameForSpecifier = (name, info, references) => {
|
|
1459
|
+
const { usedNames: moduleUsedNames, alreadyCheckedScopes } =
|
|
1460
|
+
getUsedNamesInScopeInfo(
|
|
1461
|
+
usedNamesInScopeInfo,
|
|
1462
|
+
info.module.identifier(),
|
|
1463
|
+
name
|
|
1464
|
+
);
|
|
1465
|
+
const referencesUsedNames = new Set();
|
|
1466
|
+
for (const ref of references) {
|
|
1467
|
+
addScopeSymbols(
|
|
1468
|
+
ref.from,
|
|
1469
|
+
referencesUsedNames,
|
|
1470
|
+
alreadyCheckedScopes,
|
|
1471
|
+
ignoredScopes
|
|
1472
|
+
);
|
|
1473
|
+
}
|
|
1474
|
+
if (moduleUsedNames.has(name) || referencesUsedNames.has(name)) {
|
|
1475
|
+
const newName = findNewName(
|
|
1476
|
+
name,
|
|
1477
|
+
allUsedNames,
|
|
1478
|
+
new Set([...moduleUsedNames, ...referencesUsedNames]),
|
|
1479
|
+
info.module.readableIdentifier(requestShortener)
|
|
1480
|
+
);
|
|
1481
|
+
allUsedNames.add(newName);
|
|
1482
|
+
topLevelDeclarations.add(newName);
|
|
1483
|
+
return newName;
|
|
1484
|
+
}
|
|
1485
|
+
};
|
|
1486
|
+
|
|
1244
1487
|
// generate names for symbols
|
|
1245
1488
|
for (const info of moduleToInfoMap.values()) {
|
|
1246
1489
|
const { usedNames: namespaceObjectUsedNames } = getUsedNamesInScopeInfo(
|
|
@@ -1253,34 +1496,14 @@ class ConcatenatedModule extends Module {
|
|
|
1253
1496
|
const variables = /** @type {Scope} */ (info.moduleScope).variables;
|
|
1254
1497
|
for (const variable of variables) {
|
|
1255
1498
|
const name = variable.name;
|
|
1256
|
-
const
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
name
|
|
1260
|
-
);
|
|
1261
|
-
if (allUsedNames.has(name) || usedNames.has(name)) {
|
|
1262
|
-
const references = getAllReferences(variable);
|
|
1263
|
-
for (const ref of references) {
|
|
1264
|
-
addScopeSymbols(
|
|
1265
|
-
ref.from,
|
|
1266
|
-
usedNames,
|
|
1267
|
-
alreadyCheckedScopes,
|
|
1268
|
-
ignoredScopes
|
|
1269
|
-
);
|
|
1270
|
-
}
|
|
1271
|
-
const newName = findNewName(
|
|
1272
|
-
name,
|
|
1273
|
-
allUsedNames,
|
|
1274
|
-
usedNames,
|
|
1275
|
-
info.module.readableIdentifier(requestShortener)
|
|
1276
|
-
);
|
|
1277
|
-
allUsedNames.add(newName);
|
|
1278
|
-
info.internalNames.set(name, newName);
|
|
1279
|
-
topLevelDeclarations.add(newName);
|
|
1499
|
+
const references = getAllReferences(variable);
|
|
1500
|
+
const newName = _findNewName(name, info, references);
|
|
1501
|
+
if (newName) {
|
|
1280
1502
|
const source = /** @type {ReplaceSource} */ (info.source);
|
|
1281
|
-
const allIdentifiers = new Set(
|
|
1282
|
-
references.map(r => r.identifier)
|
|
1283
|
-
|
|
1503
|
+
const allIdentifiers = new Set([
|
|
1504
|
+
...references.map((r) => r.identifier),
|
|
1505
|
+
...variable.identifiers
|
|
1506
|
+
]);
|
|
1284
1507
|
for (const identifier of allIdentifiers) {
|
|
1285
1508
|
const r = /** @type {Range} */ (identifier.range);
|
|
1286
1509
|
const path = getPathInAst(
|
|
@@ -1327,7 +1550,10 @@ class ConcatenatedModule extends Module {
|
|
|
1327
1550
|
info.namespaceObjectName =
|
|
1328
1551
|
/** @type {string} */
|
|
1329
1552
|
(namespaceObjectName);
|
|
1330
|
-
topLevelDeclarations.add(
|
|
1553
|
+
topLevelDeclarations.add(
|
|
1554
|
+
/** @type {string} */
|
|
1555
|
+
(namespaceObjectName)
|
|
1556
|
+
);
|
|
1331
1557
|
break;
|
|
1332
1558
|
}
|
|
1333
1559
|
case "external": {
|
|
@@ -1340,6 +1566,28 @@ class ConcatenatedModule extends Module {
|
|
|
1340
1566
|
allUsedNames.add(externalName);
|
|
1341
1567
|
info.name = externalName;
|
|
1342
1568
|
topLevelDeclarations.add(externalName);
|
|
1569
|
+
|
|
1570
|
+
if (info.deferred) {
|
|
1571
|
+
const externalName = findNewName(
|
|
1572
|
+
"deferred",
|
|
1573
|
+
allUsedNames,
|
|
1574
|
+
namespaceObjectUsedNames,
|
|
1575
|
+
info.module.readableIdentifier(requestShortener)
|
|
1576
|
+
);
|
|
1577
|
+
allUsedNames.add(externalName);
|
|
1578
|
+
info.deferredName = externalName;
|
|
1579
|
+
topLevelDeclarations.add(externalName);
|
|
1580
|
+
|
|
1581
|
+
const externalNameInterop = findNewName(
|
|
1582
|
+
"deferredNamespaceObject",
|
|
1583
|
+
allUsedNames,
|
|
1584
|
+
namespaceObjectUsedNames,
|
|
1585
|
+
info.module.readableIdentifier(requestShortener)
|
|
1586
|
+
);
|
|
1587
|
+
allUsedNames.add(externalNameInterop);
|
|
1588
|
+
info.deferredNamespaceObjectName = externalNameInterop;
|
|
1589
|
+
topLevelDeclarations.add(externalNameInterop);
|
|
1590
|
+
}
|
|
1343
1591
|
break;
|
|
1344
1592
|
}
|
|
1345
1593
|
}
|
|
@@ -1357,7 +1605,8 @@ class ConcatenatedModule extends Module {
|
|
|
1357
1605
|
}
|
|
1358
1606
|
if (
|
|
1359
1607
|
buildMeta.exportsType === "default" &&
|
|
1360
|
-
buildMeta.defaultObject !== "redirect"
|
|
1608
|
+
buildMeta.defaultObject !== "redirect" &&
|
|
1609
|
+
info.interopNamespaceObject2Used
|
|
1361
1610
|
) {
|
|
1362
1611
|
const externalNameInterop = findNewName(
|
|
1363
1612
|
"namespaceObject2",
|
|
@@ -1386,13 +1635,48 @@ class ConcatenatedModule extends Module {
|
|
|
1386
1635
|
for (const info of moduleToInfoMap.values()) {
|
|
1387
1636
|
if (info.type === "concatenated") {
|
|
1388
1637
|
const globalScope = /** @type {Scope} */ (info.globalScope);
|
|
1638
|
+
// group references by name
|
|
1639
|
+
const referencesByName = new Map();
|
|
1389
1640
|
for (const reference of globalScope.through) {
|
|
1390
1641
|
const name = reference.identifier.name;
|
|
1642
|
+
if (!referencesByName.has(name)) {
|
|
1643
|
+
referencesByName.set(name, []);
|
|
1644
|
+
}
|
|
1645
|
+
referencesByName.get(name).push(reference);
|
|
1646
|
+
}
|
|
1647
|
+
for (const [name, references] of referencesByName) {
|
|
1391
1648
|
const match = ConcatenationScope.matchModuleReference(name);
|
|
1392
1649
|
if (match) {
|
|
1393
1650
|
const referencedInfo = modulesWithInfo[match.index];
|
|
1394
|
-
if (referencedInfo.type === "reference")
|
|
1651
|
+
if (referencedInfo.type === "reference") {
|
|
1395
1652
|
throw new Error("Module reference can't point to a reference");
|
|
1653
|
+
}
|
|
1654
|
+
const concatenationScope = /** @type {ConcatenatedModuleInfo} */ (
|
|
1655
|
+
referencedInfo
|
|
1656
|
+
).concatenationScope;
|
|
1657
|
+
const exportId = match.ids[0];
|
|
1658
|
+
const specifier =
|
|
1659
|
+
concatenationScope && concatenationScope.getRawExport(exportId);
|
|
1660
|
+
if (specifier) {
|
|
1661
|
+
const newName = _findNewNameForSpecifier(
|
|
1662
|
+
specifier,
|
|
1663
|
+
info,
|
|
1664
|
+
references
|
|
1665
|
+
);
|
|
1666
|
+
const initFragmentChanged =
|
|
1667
|
+
newName &&
|
|
1668
|
+
concatenatedModuleInfo.call(
|
|
1669
|
+
{
|
|
1670
|
+
rawExportMap: new Map([
|
|
1671
|
+
[exportId, /** @type {string} */ (newName)]
|
|
1672
|
+
])
|
|
1673
|
+
},
|
|
1674
|
+
/** @type {ConcatenatedModuleInfo} */ (referencedInfo)
|
|
1675
|
+
);
|
|
1676
|
+
if (initFragmentChanged) {
|
|
1677
|
+
concatenationScope.setRawExportMap(exportId, newName);
|
|
1678
|
+
}
|
|
1679
|
+
}
|
|
1396
1680
|
const finalName = getFinalName(
|
|
1397
1681
|
moduleGraph,
|
|
1398
1682
|
referencedInfo,
|
|
@@ -1403,31 +1687,35 @@ class ConcatenatedModule extends Module {
|
|
|
1403
1687
|
runtimeTemplate,
|
|
1404
1688
|
neededNamespaceObjects,
|
|
1405
1689
|
match.call,
|
|
1690
|
+
match.deferredImport,
|
|
1406
1691
|
!match.directImport,
|
|
1407
1692
|
/** @type {BuildMeta} */
|
|
1408
1693
|
(info.module.buildMeta).strictHarmonyModule,
|
|
1409
1694
|
match.asiSafe
|
|
1410
1695
|
);
|
|
1411
|
-
|
|
1412
|
-
const
|
|
1413
|
-
|
|
1414
|
-
|
|
1696
|
+
|
|
1697
|
+
for (const reference of references) {
|
|
1698
|
+
const r = /** @type {Range} */ (reference.identifier.range);
|
|
1699
|
+
const source = /** @type {ReplaceSource} */ (info.source);
|
|
1700
|
+
// range is extended by 2 chars to cover the appended "._"
|
|
1701
|
+
source.replace(r[0], r[1] + 1, finalName);
|
|
1702
|
+
}
|
|
1415
1703
|
}
|
|
1416
1704
|
}
|
|
1417
1705
|
}
|
|
1418
1706
|
}
|
|
1419
1707
|
|
|
1420
1708
|
// Map with all root exposed used exports
|
|
1421
|
-
/** @type {Map<string,
|
|
1709
|
+
/** @type {Map<string, (requestShortener: RequestShortener) => string>} */
|
|
1422
1710
|
const exportsMap = new Map();
|
|
1423
1711
|
|
|
1424
1712
|
// Set with all root exposed unused exports
|
|
1425
1713
|
/** @type {Set<string>} */
|
|
1426
1714
|
const unusedExports = new Set();
|
|
1427
1715
|
|
|
1428
|
-
const rootInfo =
|
|
1429
|
-
|
|
1430
|
-
|
|
1716
|
+
const rootInfo =
|
|
1717
|
+
/** @type {ConcatenatedModuleInfo} */
|
|
1718
|
+
(moduleToInfoMap.get(this.rootModule));
|
|
1431
1719
|
const strictHarmonyModule =
|
|
1432
1720
|
/** @type {BuildMeta} */
|
|
1433
1721
|
(rootInfo.module.buildMeta).strictHarmonyModule;
|
|
@@ -1442,7 +1730,7 @@ class ConcatenatedModule extends Module {
|
|
|
1442
1730
|
unusedExports.add(name);
|
|
1443
1731
|
continue;
|
|
1444
1732
|
}
|
|
1445
|
-
exportsMap.set(used, requestShortener => {
|
|
1733
|
+
exportsMap.set(used, (requestShortener) => {
|
|
1446
1734
|
try {
|
|
1447
1735
|
const finalName = getFinalName(
|
|
1448
1736
|
moduleGraph,
|
|
@@ -1455,6 +1743,7 @@ class ConcatenatedModule extends Module {
|
|
|
1455
1743
|
neededNamespaceObjects,
|
|
1456
1744
|
false,
|
|
1457
1745
|
false,
|
|
1746
|
+
false,
|
|
1458
1747
|
strictHarmonyModule,
|
|
1459
1748
|
true
|
|
1460
1749
|
);
|
|
@@ -1475,19 +1764,17 @@ class ConcatenatedModule extends Module {
|
|
|
1475
1764
|
|
|
1476
1765
|
// add harmony compatibility flag (must be first because of possible circular dependencies)
|
|
1477
1766
|
let shouldAddHarmonyFlag = false;
|
|
1767
|
+
const rootExportsInfo = moduleGraph.getExportsInfo(this);
|
|
1478
1768
|
if (
|
|
1479
|
-
|
|
1480
|
-
|
|
1769
|
+
rootExportsInfo.otherExportsInfo.getUsed(runtime) !== UsageState.Unused ||
|
|
1770
|
+
rootExportsInfo.getReadOnlyExportInfo("__esModule").getUsed(runtime) !==
|
|
1771
|
+
UsageState.Unused
|
|
1481
1772
|
) {
|
|
1482
1773
|
shouldAddHarmonyFlag = true;
|
|
1483
1774
|
}
|
|
1484
1775
|
|
|
1485
1776
|
// define exports
|
|
1486
1777
|
if (exportsMap.size > 0) {
|
|
1487
|
-
const { exportsDefinitions } = ConcatenatedModule.getCompilationHooks(
|
|
1488
|
-
/** @type {Compilation} */ (this.compilation)
|
|
1489
|
-
);
|
|
1490
|
-
|
|
1491
1778
|
const definitions = [];
|
|
1492
1779
|
for (const [key, value] of exportsMap) {
|
|
1493
1780
|
definitions.push(
|
|
@@ -1496,32 +1783,38 @@ class ConcatenatedModule extends Module {
|
|
|
1496
1783
|
)}`
|
|
1497
1784
|
);
|
|
1498
1785
|
}
|
|
1499
|
-
const shouldSkipRenderDefinitions =
|
|
1500
|
-
exportsDefinitions.call(exportsFinalName);
|
|
1501
|
-
|
|
1502
|
-
if (!shouldSkipRenderDefinitions) {
|
|
1503
|
-
runtimeRequirements.add(RuntimeGlobals.exports);
|
|
1504
|
-
runtimeRequirements.add(RuntimeGlobals.definePropertyGetters);
|
|
1505
1786
|
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
result.add(
|
|
1509
|
-
runtimeTemplate.defineEsModuleFlagStatement({
|
|
1510
|
-
exportsArgument: this.exportsArgument,
|
|
1511
|
-
runtimeRequirements
|
|
1512
|
-
})
|
|
1513
|
-
);
|
|
1514
|
-
}
|
|
1787
|
+
runtimeRequirements.add(RuntimeGlobals.exports);
|
|
1788
|
+
runtimeRequirements.add(RuntimeGlobals.definePropertyGetters);
|
|
1515
1789
|
|
|
1516
|
-
|
|
1790
|
+
if (shouldAddHarmonyFlag) {
|
|
1791
|
+
result.add("// ESM COMPAT FLAG\n");
|
|
1517
1792
|
result.add(
|
|
1518
|
-
|
|
1519
|
-
this.exportsArgument
|
|
1520
|
-
|
|
1793
|
+
runtimeTemplate.defineEsModuleFlagStatement({
|
|
1794
|
+
exportsArgument: this.exportsArgument,
|
|
1795
|
+
runtimeRequirements
|
|
1796
|
+
})
|
|
1521
1797
|
);
|
|
1522
|
-
}
|
|
1523
|
-
|
|
1524
|
-
|
|
1798
|
+
}
|
|
1799
|
+
|
|
1800
|
+
const exportsSource =
|
|
1801
|
+
"\n// EXPORTS\n" +
|
|
1802
|
+
`${RuntimeGlobals.definePropertyGetters}(${this.exportsArgument}, {${definitions.join(
|
|
1803
|
+
","
|
|
1804
|
+
)}\n});\n`;
|
|
1805
|
+
|
|
1806
|
+
const { onDemandExportsGeneration } =
|
|
1807
|
+
ConcatenatedModule.getCompilationHooks(this.compilation);
|
|
1808
|
+
|
|
1809
|
+
if (
|
|
1810
|
+
!onDemandExportsGeneration.call(
|
|
1811
|
+
this,
|
|
1812
|
+
runtimes,
|
|
1813
|
+
exportsSource,
|
|
1814
|
+
exportsFinalName
|
|
1815
|
+
)
|
|
1816
|
+
) {
|
|
1817
|
+
result.add(exportsSource);
|
|
1525
1818
|
}
|
|
1526
1819
|
}
|
|
1527
1820
|
|
|
@@ -1552,6 +1845,7 @@ class ConcatenatedModule extends Module {
|
|
|
1552
1845
|
runtimeTemplate,
|
|
1553
1846
|
neededNamespaceObjects,
|
|
1554
1847
|
false,
|
|
1848
|
+
false,
|
|
1555
1849
|
undefined,
|
|
1556
1850
|
/** @type {BuildMeta} */
|
|
1557
1851
|
(info.module.buildMeta).strictHarmonyModule,
|
|
@@ -1571,8 +1865,9 @@ class ConcatenatedModule extends Module {
|
|
|
1571
1865
|
","
|
|
1572
1866
|
)}\n});\n`
|
|
1573
1867
|
: "";
|
|
1574
|
-
if (nsObj.length > 0)
|
|
1868
|
+
if (nsObj.length > 0) {
|
|
1575
1869
|
runtimeRequirements.add(RuntimeGlobals.definePropertyGetters);
|
|
1870
|
+
}
|
|
1576
1871
|
namespaceObjectSources.set(
|
|
1577
1872
|
info,
|
|
1578
1873
|
`
|
|
@@ -1591,8 +1886,40 @@ ${defineGetters}`
|
|
|
1591
1886
|
if (!source) continue;
|
|
1592
1887
|
result.add(source);
|
|
1593
1888
|
}
|
|
1889
|
+
|
|
1890
|
+
if (info.type === "external" && info.deferred) {
|
|
1891
|
+
const moduleId = JSON.stringify(chunkGraph.getModuleId(info.module));
|
|
1892
|
+
const loader = getOptimizedDeferredModule(
|
|
1893
|
+
moduleId,
|
|
1894
|
+
info.module.getExportsType(
|
|
1895
|
+
moduleGraph,
|
|
1896
|
+
/** @type {BuildMeta} */
|
|
1897
|
+
(this.rootModule.buildMeta).strictHarmonyModule
|
|
1898
|
+
),
|
|
1899
|
+
// an async module will opt-out of the concat module optimization.
|
|
1900
|
+
[],
|
|
1901
|
+
runtimeRequirements
|
|
1902
|
+
);
|
|
1903
|
+
runtimeRequirements.add(RuntimeGlobals.require);
|
|
1904
|
+
result.add(
|
|
1905
|
+
`\n// DEFERRED EXTERNAL MODULE: ${info.module.readableIdentifier(requestShortener)}\nvar ${info.deferredName} = ${loader};`
|
|
1906
|
+
);
|
|
1907
|
+
if (info.deferredNamespaceObjectUsed) {
|
|
1908
|
+
runtimeRequirements.add(RuntimeGlobals.makeDeferredNamespaceObject);
|
|
1909
|
+
result.add(
|
|
1910
|
+
`\nvar ${info.deferredNamespaceObjectName} = /*#__PURE__*/${
|
|
1911
|
+
RuntimeGlobals.makeDeferredNamespaceObject
|
|
1912
|
+
}(${JSON.stringify(
|
|
1913
|
+
chunkGraph.getModuleId(info.module)
|
|
1914
|
+
)}, ${getMakeDeferredNamespaceModeFromExportsType(
|
|
1915
|
+
info.module.getExportsType(moduleGraph, strictHarmonyModule)
|
|
1916
|
+
)});`
|
|
1917
|
+
);
|
|
1918
|
+
}
|
|
1919
|
+
}
|
|
1594
1920
|
}
|
|
1595
1921
|
|
|
1922
|
+
/** @type {InitFragment<ChunkRenderContext>[]} */
|
|
1596
1923
|
const chunkInitFragments = [];
|
|
1597
1924
|
|
|
1598
1925
|
// evaluate modules in order
|
|
@@ -1618,30 +1945,44 @@ ${defineGetters}`
|
|
|
1618
1945
|
break;
|
|
1619
1946
|
}
|
|
1620
1947
|
case "external": {
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1948
|
+
// deferred case is handled in the "const info of modulesWithInfo" loop above
|
|
1949
|
+
if (!info.deferred) {
|
|
1950
|
+
result.add(
|
|
1951
|
+
`\n// EXTERNAL MODULE: ${info.module.readableIdentifier(
|
|
1952
|
+
requestShortener
|
|
1953
|
+
)}\n`
|
|
1954
|
+
);
|
|
1955
|
+
runtimeRequirements.add(RuntimeGlobals.require);
|
|
1956
|
+
const { runtimeCondition } =
|
|
1957
|
+
/** @type {ExternalModuleInfo | ReferenceToModuleInfo} */
|
|
1958
|
+
(rawInfo);
|
|
1959
|
+
const condition = runtimeTemplate.runtimeConditionExpression({
|
|
1960
|
+
chunkGraph,
|
|
1961
|
+
runtimeCondition,
|
|
1962
|
+
runtime,
|
|
1963
|
+
runtimeRequirements
|
|
1964
|
+
});
|
|
1965
|
+
if (condition !== "true") {
|
|
1966
|
+
isConditional = true;
|
|
1967
|
+
result.add(`if (${condition}) {\n`);
|
|
1968
|
+
}
|
|
1969
|
+
const moduleId = JSON.stringify(
|
|
1641
1970
|
chunkGraph.getModuleId(info.module)
|
|
1642
|
-
)
|
|
1643
|
-
|
|
1644
|
-
|
|
1971
|
+
);
|
|
1972
|
+
result.add(`var ${info.name} = __webpack_require__(${moduleId});`);
|
|
1973
|
+
name = info.name;
|
|
1974
|
+
}
|
|
1975
|
+
// If a module is deferred in other places, but used as non-deferred here,
|
|
1976
|
+
// the module itself will be emitted as mod_deferred (in the case "external"),
|
|
1977
|
+
// we need to emit an extra import declaration to evaluate it in order.
|
|
1978
|
+
const { nonDeferAccess } =
|
|
1979
|
+
/** @type {ExternalModuleInfo | ReferenceToModuleInfo} */
|
|
1980
|
+
(rawInfo);
|
|
1981
|
+
if (info.deferred && nonDeferAccess) {
|
|
1982
|
+
result.add(
|
|
1983
|
+
`\n// non-deferred import to a deferred module (${info.module.readableIdentifier(requestShortener)})\nvar ${info.name} = ${info.deferredName}.a;`
|
|
1984
|
+
);
|
|
1985
|
+
}
|
|
1645
1986
|
break;
|
|
1646
1987
|
}
|
|
1647
1988
|
default:
|
|
@@ -1672,13 +2013,14 @@ ${defineGetters}`
|
|
|
1672
2013
|
}
|
|
1673
2014
|
|
|
1674
2015
|
const data = new Map();
|
|
1675
|
-
if (chunkInitFragments.length > 0)
|
|
2016
|
+
if (chunkInitFragments.length > 0) {
|
|
1676
2017
|
data.set("chunkInitFragments", chunkInitFragments);
|
|
2018
|
+
}
|
|
1677
2019
|
data.set("topLevelDeclarations", topLevelDeclarations);
|
|
1678
2020
|
|
|
1679
2021
|
/** @type {CodeGenerationResult} */
|
|
1680
2022
|
const resultEntry = {
|
|
1681
|
-
sources: new Map([[
|
|
2023
|
+
sources: new Map([[JAVASCRIPT_TYPE, new CachedSource(result)]]),
|
|
1682
2024
|
data,
|
|
1683
2025
|
runtimeRequirements
|
|
1684
2026
|
};
|
|
@@ -1687,14 +2029,16 @@ ${defineGetters}`
|
|
|
1687
2029
|
}
|
|
1688
2030
|
|
|
1689
2031
|
/**
|
|
1690
|
-
* @param {
|
|
2032
|
+
* @param {ModuleToInfoMap} modulesMap modulesMap
|
|
1691
2033
|
* @param {ModuleInfo} info info
|
|
1692
2034
|
* @param {DependencyTemplates} dependencyTemplates dependencyTemplates
|
|
1693
2035
|
* @param {RuntimeTemplate} runtimeTemplate runtimeTemplate
|
|
1694
2036
|
* @param {ModuleGraph} moduleGraph moduleGraph
|
|
1695
2037
|
* @param {ChunkGraph} chunkGraph chunkGraph
|
|
1696
2038
|
* @param {RuntimeSpec} runtime runtime
|
|
2039
|
+
* @param {RuntimeSpec[]} runtimes runtimes
|
|
1697
2040
|
* @param {CodeGenerationResults} codeGenerationResults codeGenerationResults
|
|
2041
|
+
* @param {Set<string>} usedNames used names
|
|
1698
2042
|
*/
|
|
1699
2043
|
_analyseModule(
|
|
1700
2044
|
modulesMap,
|
|
@@ -1704,13 +2048,19 @@ ${defineGetters}`
|
|
|
1704
2048
|
moduleGraph,
|
|
1705
2049
|
chunkGraph,
|
|
1706
2050
|
runtime,
|
|
1707
|
-
|
|
2051
|
+
runtimes,
|
|
2052
|
+
codeGenerationResults,
|
|
2053
|
+
usedNames
|
|
1708
2054
|
) {
|
|
1709
2055
|
if (info.type === "concatenated") {
|
|
1710
2056
|
const m = info.module;
|
|
1711
2057
|
try {
|
|
1712
2058
|
// Create a concatenation scope to track and capture information
|
|
1713
|
-
const concatenationScope = new ConcatenationScope(
|
|
2059
|
+
const concatenationScope = new ConcatenationScope(
|
|
2060
|
+
modulesMap,
|
|
2061
|
+
info,
|
|
2062
|
+
usedNames
|
|
2063
|
+
);
|
|
1714
2064
|
|
|
1715
2065
|
// TODO cache codeGeneration results
|
|
1716
2066
|
const codeGenResult = m.codeGeneration({
|
|
@@ -1719,23 +2069,34 @@ ${defineGetters}`
|
|
|
1719
2069
|
moduleGraph,
|
|
1720
2070
|
chunkGraph,
|
|
1721
2071
|
runtime,
|
|
2072
|
+
runtimes,
|
|
1722
2073
|
concatenationScope,
|
|
1723
2074
|
codeGenerationResults,
|
|
1724
|
-
sourceTypes:
|
|
2075
|
+
sourceTypes: JAVASCRIPT_TYPES
|
|
1725
2076
|
});
|
|
1726
|
-
const source =
|
|
1727
|
-
|
|
1728
|
-
|
|
2077
|
+
const source =
|
|
2078
|
+
/** @type {Source} */
|
|
2079
|
+
(codeGenResult.sources.get(JAVASCRIPT_TYPE));
|
|
1729
2080
|
const data = codeGenResult.data;
|
|
1730
2081
|
const chunkInitFragments = data && data.get("chunkInitFragments");
|
|
1731
2082
|
const code = source.source().toString();
|
|
2083
|
+
|
|
2084
|
+
/** @type {Program} */
|
|
1732
2085
|
let ast;
|
|
2086
|
+
|
|
1733
2087
|
try {
|
|
1734
|
-
ast = JavascriptParser._parse(
|
|
1735
|
-
|
|
1736
|
-
|
|
2088
|
+
({ ast } = JavascriptParser._parse(
|
|
2089
|
+
code,
|
|
2090
|
+
{
|
|
2091
|
+
sourceType: "module",
|
|
2092
|
+
ranges: true
|
|
2093
|
+
},
|
|
2094
|
+
JavascriptParser._getModuleParseFunction(this.compilation, m)
|
|
2095
|
+
));
|
|
1737
2096
|
} catch (_err) {
|
|
1738
|
-
const err =
|
|
2097
|
+
const err =
|
|
2098
|
+
/** @type {Error & { loc?: { line: number, column: number } }} */
|
|
2099
|
+
(_err);
|
|
1739
2100
|
if (
|
|
1740
2101
|
err.loc &&
|
|
1741
2102
|
typeof err.loc === "object" &&
|
|
@@ -1768,6 +2129,7 @@ ${defineGetters}`
|
|
|
1768
2129
|
info.chunkInitFragments = chunkInitFragments;
|
|
1769
2130
|
info.globalScope = globalScope;
|
|
1770
2131
|
info.moduleScope = moduleScope;
|
|
2132
|
+
info.concatenationScope = concatenationScope;
|
|
1771
2133
|
} catch (err) {
|
|
1772
2134
|
/** @type {Error} */
|
|
1773
2135
|
(err).message +=
|
|
@@ -1780,7 +2142,7 @@ ${defineGetters}`
|
|
|
1780
2142
|
/**
|
|
1781
2143
|
* @param {ModuleGraph} moduleGraph the module graph
|
|
1782
2144
|
* @param {RuntimeSpec} runtime the runtime
|
|
1783
|
-
* @returns {[ModuleInfoOrReference[],
|
|
2145
|
+
* @returns {[ModuleInfoOrReference[], ModuleToInfoMap]} module info items
|
|
1784
2146
|
*/
|
|
1785
2147
|
_getModulesWithInfo(moduleGraph, runtime) {
|
|
1786
2148
|
const orderedConcatenationList = this._createConcatenationList(
|
|
@@ -1789,7 +2151,7 @@ ${defineGetters}`
|
|
|
1789
2151
|
runtime,
|
|
1790
2152
|
moduleGraph
|
|
1791
2153
|
);
|
|
1792
|
-
/** @type {
|
|
2154
|
+
/** @type {ModuleToInfoMap} */
|
|
1793
2155
|
const map = new Map();
|
|
1794
2156
|
const list = orderedConcatenationList.map((info, index) => {
|
|
1795
2157
|
let item = map.get(info.module);
|
|
@@ -1816,7 +2178,8 @@ ${defineGetters}`
|
|
|
1816
2178
|
interopNamespaceObject2Used: false,
|
|
1817
2179
|
interopNamespaceObject2Name: undefined,
|
|
1818
2180
|
interopDefaultAccessUsed: false,
|
|
1819
|
-
interopDefaultAccessName: undefined
|
|
2181
|
+
interopDefaultAccessName: undefined,
|
|
2182
|
+
concatenationScope: undefined
|
|
1820
2183
|
};
|
|
1821
2184
|
break;
|
|
1822
2185
|
case "external":
|
|
@@ -1824,14 +2187,19 @@ ${defineGetters}`
|
|
|
1824
2187
|
type: "external",
|
|
1825
2188
|
module: info.module,
|
|
1826
2189
|
runtimeCondition: info.runtimeCondition,
|
|
2190
|
+
nonDeferAccess: info.nonDeferAccess,
|
|
1827
2191
|
index,
|
|
1828
2192
|
name: undefined,
|
|
2193
|
+
deferredName: undefined,
|
|
1829
2194
|
interopNamespaceObjectUsed: false,
|
|
1830
2195
|
interopNamespaceObjectName: undefined,
|
|
1831
2196
|
interopNamespaceObject2Used: false,
|
|
1832
2197
|
interopNamespaceObject2Name: undefined,
|
|
1833
2198
|
interopDefaultAccessUsed: false,
|
|
1834
|
-
interopDefaultAccessName: undefined
|
|
2199
|
+
interopDefaultAccessName: undefined,
|
|
2200
|
+
deferred: moduleGraph.isDeferred(info.module),
|
|
2201
|
+
deferredNamespaceObjectName: undefined,
|
|
2202
|
+
deferredNamespaceObjectUsed: false
|
|
1835
2203
|
};
|
|
1836
2204
|
break;
|
|
1837
2205
|
default:
|
|
@@ -1849,6 +2217,7 @@ ${defineGetters}`
|
|
|
1849
2217
|
const ref = {
|
|
1850
2218
|
type: "reference",
|
|
1851
2219
|
runtimeCondition: info.runtimeCondition,
|
|
2220
|
+
nonDeferAccess: info.nonDeferAccess,
|
|
1852
2221
|
target: item
|
|
1853
2222
|
};
|
|
1854
2223
|
return ref;
|