@depup/webpack 5.109.2-depup.0 → 5.110.1-depup.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/changes.json +7 -7
- package/lib/APIPlugin.js +123 -17
- package/lib/AsyncDependenciesBlock.js +10 -7
- package/lib/AutomaticPrefetchPlugin.js +1 -1
- package/lib/BannerPlugin.js +10 -6
- package/lib/CacheFacade.js +6 -6
- package/lib/Chunk.js +14 -11
- package/lib/ChunkGraph.js +26 -17
- package/lib/ChunkGroup.js +7 -7
- package/lib/ChunkTemplate.js +35 -44
- package/lib/CircularModulesPlugin.js +205 -28
- package/lib/CleanPlugin.js +4 -7
- package/lib/CodeGenerationResults.js +11 -8
- package/lib/CompatibilityPlugin.js +7 -7
- package/lib/Compilation.js +688 -409
- package/lib/Compiler.js +53 -38
- package/lib/ConcatenationScope.js +117 -8
- package/lib/ConditionalInitFragment.js +3 -3
- package/lib/ConstPlugin.js +13 -11
- package/lib/ContextExclusionPlugin.js +1 -1
- package/lib/ContextModule.js +146 -54
- package/lib/ContextModuleFactory.js +46 -14
- package/lib/ContextReplacementPlugin.js +12 -14
- package/lib/DefinePlugin.js +121 -37
- package/lib/DependenciesBlock.js +9 -6
- package/lib/Dependency.js +36 -16
- package/lib/DependencyTemplate.js +11 -12
- package/lib/DependencyTemplates.js +3 -3
- package/lib/DotenvPlugin.js +50 -13
- package/lib/DynamicEntryPlugin.js +8 -4
- package/lib/EntryOptionPlugin.js +8 -4
- package/lib/EntryPlugin.js +2 -2
- package/lib/Entrypoint.js +6 -2
- package/lib/EnvironmentPlugin.js +2 -2
- package/lib/EvalDevToolModulePlugin.js +8 -4
- package/lib/EvalSourceMapDevToolPlugin.js +15 -8
- package/lib/ExportsInfo.js +101 -14
- package/lib/ExportsInfoApiPlugin.js +2 -4
- package/lib/ExternalModule.js +232 -77
- package/lib/ExternalModuleFactoryPlugin.js +97 -38
- package/lib/ExternalsPlugin.js +10 -6
- package/lib/FileSystemInfo.js +44 -70
- package/lib/FlagAllModulesAsUsedPlugin.js +2 -3
- package/lib/FlagDependencyExportsPlugin.js +76 -19
- package/lib/FlagDependencyUsagePlugin.js +32 -47
- package/lib/FlagEntryExportAsUsedPlugin.js +1 -1
- package/lib/Generator.js +36 -15
- package/lib/HotModuleReplacementPlugin.js +16 -44
- package/lib/IgnorePlugin.js +8 -4
- package/lib/IgnoreWarningsPlugin.js +2 -2
- package/lib/InitFragment.js +8 -4
- package/lib/JavascriptMetaInfoPlugin.js +35 -4
- package/lib/LazyBarrel.js +3 -4
- package/lib/LibraryTemplatePlugin.js +10 -6
- package/lib/LoaderOptionsPlugin.js +7 -3
- package/lib/LoaderTargetPlugin.js +1 -1
- package/lib/MainTemplate.js +49 -42
- package/lib/ManifestPlugin.js +12 -11
- package/lib/Module.js +62 -33
- package/lib/ModuleFactory.js +3 -3
- package/lib/ModuleFilenameHelpers.js +9 -4
- package/lib/ModuleGraph.js +195 -21
- package/lib/ModuleGraphConnection.js +6 -13
- package/lib/ModuleInfoHeaderPlugin.js +8 -10
- package/lib/ModuleTemplate.js +62 -63
- package/lib/MultiCompiler.js +130 -64
- package/lib/MultiStats.js +40 -9
- package/lib/MultiWatching.js +3 -3
- package/lib/NoEmitOnErrorsPlugin.js +1 -1
- package/lib/NodeStuffPlugin.js +29 -19
- package/lib/NormalModule.js +141 -85
- package/lib/NormalModuleFactory.js +555 -110
- package/lib/NormalModuleReplacementPlugin.js +5 -8
- package/lib/NullFactory.js +6 -2
- package/lib/OptionsApply.js +7 -3
- package/lib/Parser.js +7 -3
- package/lib/PlatformPlugin.js +2 -2
- package/lib/PrefetchPlugin.js +1 -1
- package/lib/ProgressPlugin.js +16 -13
- package/lib/ProvidePlugin.js +3 -5
- package/lib/RawModule.js +25 -17
- package/lib/RecordIdsPlugin.js +3 -3
- package/lib/RequestShortener.js +1 -1
- package/lib/ResolverFactory.js +2 -2
- package/lib/RuntimeGlobals.js +22 -10
- package/lib/RuntimeModule.js +29 -19
- package/lib/RuntimePlugin.js +332 -169
- package/lib/RuntimeTemplate.js +2792 -352
- package/lib/SelfModuleFactory.js +7 -3
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +6 -2
- package/lib/SourceMapDevToolPlugin.js +30 -20
- package/lib/Stats.js +3 -4
- package/lib/Template.js +32 -22
- package/lib/TemplatedPathPlugin.js +96 -14
- package/lib/UseStrictPlugin.js +4 -6
- package/lib/WarnCaseSensitiveModulesPlugin.js +4 -4
- package/lib/WarnDeprecatedOptionPlugin.js +1 -1
- package/lib/WarnNoModeSetPlugin.js +1 -1
- package/lib/WatchIgnorePlugin.js +8 -6
- package/lib/Watching.js +8 -8
- package/lib/WebpackIsIncludedPlugin.js +2 -4
- package/lib/WebpackOptionsApply.js +308 -18
- package/lib/WebpackOptionsDefaulter.js +6 -2
- package/lib/asset/AssetBytesGenerator.js +12 -10
- package/lib/asset/AssetBytesParser.js +2 -4
- package/lib/asset/AssetGenerator.js +188 -95
- package/lib/asset/AssetModule.js +7 -3
- package/lib/asset/AssetModulesPlugin.js +110 -38
- package/lib/asset/AssetParser.js +9 -7
- package/lib/asset/AssetSourceGenerator.js +60 -13
- package/lib/asset/AssetSourceParser.js +2 -4
- package/lib/asset/RawDataUrlModule.js +24 -16
- package/lib/asset/WebManifestGenerator.js +8 -10
- package/lib/asset/WebManifestParser.js +24 -10
- package/lib/async-modules/AsyncModuleHelpers.js +2 -2
- package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
- package/lib/async-modules/InferAsyncModulesPlugin.js +2 -2
- package/lib/async-modules/isGeneratorLowered.js +4 -4
- package/lib/buildChunkGraph.js +36 -27
- package/lib/bun/BunTargetPlugin.js +1 -1
- package/lib/cache/AddBuildDependenciesPlugin.js +1 -1
- package/lib/cache/AddManagedPathsPlugin.js +1 -1
- package/lib/cache/IdleFileCachePlugin.js +2 -2
- package/lib/cache/MemoryCachePlugin.js +18 -10
- package/lib/cache/MemoryWithGcCachePlugin.js +34 -22
- package/lib/cache/PackFileCacheStrategy.js +30 -23
- package/lib/cache/ResolverCachePlugin.js +38 -18
- package/lib/cache/getLazyHashedEtag.js +1 -2
- package/lib/cache/mergeEtags.js +1 -1
- package/lib/cli.js +1 -3
- package/lib/config/browserslistTargetHandler.js +41 -5
- package/lib/config/defaults.js +261 -79
- package/lib/config/defineConfig.js +10 -2
- package/lib/config/getClaimedAssetTypes.js +65 -0
- package/lib/config/normalization.js +36 -16
- package/lib/config/target.js +46 -3
- package/lib/container/ContainerEntryDependency.js +1 -1
- package/lib/container/ContainerEntryModule.js +24 -15
- package/lib/container/ContainerEntryModuleFactory.js +7 -3
- package/lib/container/ContainerPlugin.js +9 -10
- package/lib/container/ContainerReferencePlugin.js +6 -2
- package/lib/container/FallbackDependency.js +1 -1
- package/lib/container/FallbackModule.js +24 -17
- package/lib/container/FallbackModuleFactory.js +7 -3
- package/lib/container/HoistContainerReferencesPlugin.js +6 -11
- package/lib/container/ModuleFederationPlugin.js +7 -24
- package/lib/container/RemoteModule.js +27 -19
- package/lib/container/RemoteRuntimeModule.js +10 -8
- package/lib/container/moduleFederationHooks.js +32 -0
- package/lib/css/CssGenerator.js +171 -43
- package/lib/css/CssInjectStyleRuntimeModule.js +7 -5
- package/lib/css/CssLoadingRuntimeModule.js +57 -24
- package/lib/css/CssModule.js +10 -7
- package/lib/css/CssModulesPlugin.js +168 -88
- package/lib/css/CssParser.js +1113 -568
- package/lib/css/CssServerStylesRuntimeModule.js +54 -0
- package/lib/css/cssMinify.js +168 -0
- package/lib/css/data.js +5324 -0
- package/lib/css/syntax.js +9579 -232
- package/lib/debug/ProfilingPlugin.js +14 -9
- package/lib/deno/DenoTargetPlugin.js +1 -1
- package/lib/dependencies/AMDDefineDependency.js +112 -87
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +30 -17
- package/lib/dependencies/AMDPlugin.js +9 -7
- package/lib/dependencies/AMDRequireArrayDependency.js +5 -5
- package/lib/dependencies/AMDRequireContextDependency.js +2 -2
- package/lib/dependencies/AMDRequireDependenciesBlock.js +1 -1
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +25 -14
- package/lib/dependencies/AMDRequireDependency.js +8 -7
- package/lib/dependencies/AMDRequireItemDependency.js +1 -1
- package/lib/dependencies/AMDRuntimeModules.js +21 -1
- package/lib/dependencies/BuildTimeConstDependency.js +102 -0
- package/lib/dependencies/CachedConstDependency.js +11 -8
- package/lib/dependencies/CommonJsDependencyHelpers.js +67 -46
- package/lib/dependencies/CommonJsExportRequireDependency.js +121 -45
- package/lib/dependencies/CommonJsExportsDependency.js +53 -49
- package/lib/dependencies/CommonJsExportsParserPlugin.js +207 -25
- package/lib/dependencies/CommonJsFullRequireDependency.js +119 -34
- package/lib/dependencies/CommonJsImportsParserPlugin.js +100 -50
- package/lib/dependencies/CommonJsObjectExportDependency.js +188 -0
- package/lib/dependencies/CommonJsPlugin.js +35 -6
- package/lib/dependencies/CommonJsRequireContextDependency.js +5 -6
- package/lib/dependencies/CommonJsRequireDependency.js +156 -27
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +63 -38
- package/lib/dependencies/ConstDependency.js +8 -9
- package/lib/dependencies/ContextDependency.js +12 -8
- package/lib/dependencies/ContextDependencyHelpers.js +14 -9
- package/lib/dependencies/ContextDependencyTemplateAsId.js +4 -4
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +4 -4
- package/lib/dependencies/ContextElementDependency.js +31 -12
- package/lib/dependencies/CreateRequireParserPlugin.js +12 -7
- package/lib/dependencies/CreateScriptUrlDependency.js +4 -4
- package/lib/dependencies/CssIcssExportDependency.js +56 -28
- package/lib/dependencies/CssIcssImportDependency.js +17 -13
- package/lib/dependencies/CssIcssSymbolDependency.js +9 -10
- package/lib/dependencies/CssImportDependency.js +18 -9
- package/lib/dependencies/CssUrlDependency.js +17 -13
- package/lib/dependencies/DllEntryDependency.js +1 -1
- package/lib/dependencies/DynamicExports.js +2 -2
- package/lib/dependencies/ExportBindingInitFragment.js +36 -9
- package/lib/dependencies/ExportsInfoDependency.js +7 -8
- package/lib/dependencies/ExternalModuleDependency.js +9 -5
- package/lib/dependencies/ExternalModuleInitFragment.js +2 -2
- package/lib/dependencies/ExternalModuleInitFragmentDependency.js +8 -5
- package/lib/dependencies/HarmonyAcceptDependency.js +5 -5
- package/lib/dependencies/HarmonyCompatibilityDependency.js +52 -17
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +11 -7
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +13 -10
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +78 -12
- package/lib/dependencies/HarmonyExportExpressionDependency.js +23 -18
- package/lib/dependencies/HarmonyExportHeaderDependency.js +7 -7
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +143 -63
- package/lib/dependencies/HarmonyExportInitFragment.js +18 -6
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +51 -14
- package/lib/dependencies/HarmonyExports.js +7 -4
- package/lib/dependencies/HarmonyImportDependency.js +27 -19
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +31 -24
- package/lib/dependencies/HarmonyImportGuard.js +20 -30
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +38 -9
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +97 -49
- package/lib/dependencies/HarmonyModulesPlugin.js +7 -3
- package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +1 -3
- package/lib/dependencies/HtmlEntryDependency.js +37 -29
- package/lib/dependencies/HtmlInlineHtmlDependency.js +7 -8
- package/lib/dependencies/HtmlInlineScriptDependency.js +11 -8
- package/lib/dependencies/HtmlInlineStyleDependency.js +7 -10
- package/lib/dependencies/HtmlSourceDependency.js +22 -14
- package/lib/dependencies/ImportContextDependency.js +2 -2
- package/lib/dependencies/ImportDependency.js +24 -20
- package/lib/dependencies/ImportEagerDependency.js +6 -9
- package/lib/dependencies/ImportMetaContextDependency.js +2 -2
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +14 -13
- package/lib/dependencies/ImportMetaContextPlugin.js +7 -3
- package/lib/dependencies/ImportMetaGlobDependency.js +2 -2
- package/lib/dependencies/ImportMetaGlobDependencyParserPlugin.js +2 -3
- package/lib/dependencies/ImportMetaGlobHelpers.js +19 -22
- package/lib/dependencies/ImportMetaHotAcceptDependency.js +1 -1
- package/lib/dependencies/ImportMetaHotDeclineDependency.js +1 -1
- package/lib/dependencies/ImportMetaPlugin.js +154 -71
- package/lib/dependencies/ImportMetaResolveDependency.js +3 -4
- package/lib/dependencies/ImportParserPlugin.js +49 -35
- package/lib/dependencies/ImportPhase.js +12 -5
- package/lib/dependencies/ImportPlugin.js +7 -3
- package/lib/dependencies/ImportWeakDependency.js +6 -9
- package/lib/dependencies/JsonExportsDependency.js +11 -7
- package/lib/dependencies/LoaderDependency.js +2 -2
- package/lib/dependencies/LoaderImportDependency.js +2 -2
- package/lib/dependencies/LoaderPlugin.js +11 -7
- package/lib/dependencies/LocalModuleDependency.js +5 -5
- package/lib/dependencies/LocalModulesHelpers.js +1 -1
- package/lib/dependencies/ModuleDecoratorDependency.js +6 -7
- package/lib/dependencies/ModuleDependency.js +9 -6
- package/lib/dependencies/ModuleDependencyTemplateAsId.js +4 -4
- package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +3 -3
- package/lib/dependencies/ModuleHotAcceptDependency.js +1 -1
- package/lib/dependencies/ModuleHotDeclineDependency.js +1 -1
- package/lib/dependencies/ModuleInitFragmentDependency.js +24 -10
- package/lib/dependencies/NullDependency.js +3 -3
- package/lib/dependencies/ProvidedDependency.js +14 -10
- package/lib/dependencies/PureExpressionDependency.js +9 -10
- package/lib/dependencies/RequireContextDependency.js +2 -2
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +2 -4
- package/lib/dependencies/RequireContextPlugin.js +8 -4
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +2 -2
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +5 -8
- package/lib/dependencies/RequireEnsureDependency.js +8 -7
- package/lib/dependencies/RequireEnsurePlugin.js +7 -3
- package/lib/dependencies/RequireHeaderDependency.js +51 -12
- package/lib/dependencies/RequireIncludeDependency.js +6 -6
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +2 -3
- package/lib/dependencies/RequireIncludePlugin.js +7 -3
- package/lib/dependencies/RequireJsStuffPlugin.js +7 -3
- package/lib/dependencies/RequireResolveContextDependency.js +2 -2
- package/lib/dependencies/RequireResolveDependency.js +4 -4
- package/lib/dependencies/RequireResolveHeaderDependency.js +4 -4
- package/lib/dependencies/RuntimeRequirementsDependency.js +5 -6
- package/lib/dependencies/StaticExportsDependency.js +2 -2
- package/lib/dependencies/SystemPlugin.js +10 -6
- package/lib/dependencies/SystemRuntimeModule.js +10 -0
- package/lib/dependencies/TopLevelAwaitDependency.js +11 -7
- package/lib/dependencies/URLContextDependency.js +2 -2
- package/lib/dependencies/URLDependency.js +110 -64
- package/lib/dependencies/URLPlugin.js +7 -3
- package/lib/dependencies/UnsupportedDependency.js +4 -4
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +3 -4
- package/lib/dependencies/WebAssemblyImportDependency.js +5 -5
- package/lib/dependencies/WebpackIsIncludedDependency.js +6 -6
- package/lib/dependencies/WorkerAndWorkletPlugin.js +46 -28
- package/lib/dependencies/WorkerDependency.js +28 -22
- package/lib/dependencies/WorkletDependency.js +15 -14
- package/lib/dependencies/getFunctionExpression.js +8 -4
- package/lib/dependencies/processExportInfo.js +5 -5
- package/lib/dll/DelegatedModule.js +34 -22
- package/lib/dll/DelegatedModuleFactoryPlugin.js +15 -7
- package/lib/dll/DelegatedPlugin.js +2 -2
- package/lib/dll/DllEntryPlugin.js +2 -2
- package/lib/dll/DllModule.js +22 -15
- package/lib/dll/DllModuleFactory.js +7 -3
- package/lib/dll/DllPlugin.js +7 -5
- package/lib/dll/DllReferencePlugin.js +10 -7
- package/lib/dll/LibManifestPlugin.js +5 -5
- package/lib/electron/ElectronTargetPlugin.js +53 -49
- package/lib/errors/AsyncChunkWaterfallWarning.js +36 -0
- package/lib/errors/AsyncDependencyToInitialChunkError.js +2 -2
- package/lib/errors/BroadContextsWarning.js +43 -0
- package/lib/errors/BuildCycleError.js +1 -1
- package/lib/errors/CacheEffectivenessWarning.js +55 -0
- package/lib/errors/ChunkRenderError.js +1 -1
- package/lib/errors/CircularDependenciesWarning.js +38 -0
- package/lib/errors/CodeGenerationError.js +1 -1
- package/lib/errors/CommentCompilationWarning.js +1 -1
- package/lib/errors/ConflictingResourceHintsWarning.js +35 -0
- package/lib/errors/DuplicateModulesWarning.js +45 -0
- package/lib/errors/DynamicExportsWarning.js +30 -0
- package/lib/errors/EmbeddedSourceMapsWarning.js +25 -0
- package/lib/errors/EntrypointOverlapWarning.js +45 -0
- package/lib/errors/EnvironmentNotSupportAsyncWarning.js +2 -2
- package/lib/errors/EvalUsageWarning.js +28 -0
- package/lib/errors/HookWebpackError.js +5 -5
- package/lib/errors/HotspotsWarning.js +57 -0
- package/lib/errors/IgnoreErrorModuleFactory.js +7 -3
- package/lib/errors/InlinedAssetsWarning.js +36 -0
- package/lib/errors/InvalidDependenciesModuleWarning.js +1 -1
- package/lib/errors/LargeModulesWarning.js +45 -0
- package/lib/errors/LegacyJavascriptWarning.js +48 -0
- package/lib/errors/MissingSideEffectsWarning.js +36 -0
- package/lib/errors/MixedExportsWarning.js +41 -0
- package/lib/errors/ModuleDependencyError.js +13 -16
- package/lib/errors/ModuleDependencyWarning.js +5 -15
- package/lib/errors/ModuleHashingError.js +1 -1
- package/lib/errors/ModuleNotFoundError.js +2 -2
- package/lib/errors/ModuleParseError.js +1 -2
- package/lib/errors/ModuleRestoreError.js +1 -1
- package/lib/errors/ModuleStoreError.js +1 -1
- package/lib/errors/NodeStuffInWebError.js +1 -1
- package/lib/errors/OsDependentRuleWarning.js +31 -0
- package/lib/errors/PureAnnotationsWarning.js +36 -0
- package/lib/errors/RedundantDynamicImportWarning.js +31 -0
- package/lib/errors/ScopeHoistingBailoutsWarning.js +41 -0
- package/lib/errors/SplitChunksCappedWarning.js +41 -0
- package/lib/errors/TinyChunksWarning.js +40 -0
- package/lib/errors/TopLevelThisWarning.js +34 -0
- package/lib/errors/UnsplitVendorsWarning.js +42 -0
- package/lib/errors/UnsupportedFeatureWarning.js +1 -1
- package/lib/errors/UnusedAliasesWarning.js +29 -0
- package/lib/errors/UnusedDefinesWarning.js +29 -0
- package/lib/errors/UnusedExternalsWarning.js +29 -0
- package/lib/errors/UnusedReexportsWarning.js +42 -0
- package/lib/errors/UnusedRuleWarning.js +29 -0
- package/lib/errors/WebpackError.js +9 -5
- package/lib/errors/deriveStackFromNestedError.js +90 -0
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +2 -0
- package/lib/esm/ModuleChunkFormatPlugin.js +37 -19
- package/lib/esm/ModuleChunkLoadingPlugin.js +89 -51
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +155 -62
- package/lib/hmr/HotModuleReplacement.runtime.js +24 -5
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
- package/lib/hmr/LazyCompilationPlugin.js +45 -24
- package/lib/hmr/lazyCompilationBackend.js +9 -6
- package/lib/hmr/parserHooks.js +56 -0
- package/lib/html/HtmlGenerator.js +277 -77
- package/lib/html/HtmlModule.js +7 -3
- package/lib/html/HtmlModulesPlugin.js +282 -162
- package/lib/html/HtmlParser.js +31 -86
- package/lib/html/data.js +1928 -0
- package/lib/html/htmlMinify.js +288 -0
- package/lib/html/syntax.js +5557 -1155
- package/lib/ids/ChunkModuleIdRangePlugin.js +3 -3
- package/lib/ids/DeterministicChunkIdsPlugin.js +1 -1
- package/lib/ids/DeterministicModuleIdsPlugin.js +2 -2
- package/lib/ids/HashedModuleIdsPlugin.js +6 -2
- package/lib/ids/IdHelpers.js +7 -8
- package/lib/ids/NamedChunkIdsPlugin.js +1 -1
- package/lib/ids/NamedModuleIdsPlugin.js +1 -1
- package/lib/ids/NaturalChunkIdsPlugin.js +2 -2
- package/lib/ids/NaturalModuleIdsPlugin.js +1 -1
- package/lib/ids/OccurrenceChunkIdsPlugin.js +7 -3
- package/lib/ids/OccurrenceModuleIdsPlugin.js +7 -3
- package/lib/ids/SyncModuleIdsPlugin.js +4 -4
- package/lib/index.js +10 -0
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +3 -3
- package/lib/javascript/BasicEvaluatedExpression.js +18 -14
- package/lib/javascript/ChunkFormatHelpers.js +6 -6
- package/lib/javascript/ChunkHelpers.js +1 -1
- package/lib/javascript/CommonJsChunkFormatPlugin.js +11 -5
- package/lib/javascript/EnableChunkLoadingPlugin.js +2 -2
- package/lib/javascript/JavascriptGenerator.js +65 -165
- package/lib/javascript/JavascriptModule.js +9 -3
- package/lib/javascript/JavascriptModulesPlugin.js +98 -113
- package/lib/javascript/JavascriptParser.js +242 -99
- package/lib/javascript/JavascriptParserHelpers.js +10 -7
- package/lib/javascript/ScopeAnalyzer.js +1094 -0
- package/lib/javascript/StartupHelpers.js +55 -9
- package/lib/javascript/syntax.js +2678 -232
- package/lib/json/JsonData.js +8 -4
- package/lib/json/JsonGenerator.js +38 -16
- package/lib/json/JsonModule.js +7 -3
- package/lib/json/JsonModulesPlugin.js +1 -1
- package/lib/json/JsonParser.js +5 -6
- package/lib/library/AbstractLibraryPlugin.js +20 -14
- package/lib/library/AmdLibraryPlugin.js +11 -7
- package/lib/library/AssignLibraryPlugin.js +19 -13
- package/lib/library/EnableLibraryPlugin.js +2 -2
- package/lib/library/ExportPropertyLibraryPlugin.js +15 -8
- package/lib/library/JsonpLibraryPlugin.js +11 -7
- package/lib/library/ModuleLibraryPlugin.js +256 -64
- package/lib/library/SystemLibraryPlugin.js +12 -8
- package/lib/library/UmdLibraryPlugin.js +62 -25
- package/lib/loaders/LoaderRunner.js +14 -1
- package/lib/loaders/loadLoader.js +8 -4
- package/lib/logging/createConsoleLogger.js +7 -4
- package/lib/node/CommonJsChunkLoadingPlugin.js +36 -22
- package/lib/node/NodeEnvironmentPlugin.js +17 -3
- package/lib/node/NodeSourcePlugin.js +1 -1
- package/lib/node/NodeTargetPlugin.js +4 -3
- package/lib/node/NodeTemplatePlugin.js +1 -1
- package/lib/node/NodeWatchFileSystem.js +70 -9
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +35 -38
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +72 -19
- package/lib/node/ReadFileCompileWasmPlugin.js +28 -16
- package/lib/node/RequireChunkLoadingRuntimeModule.js +35 -38
- package/lib/node/nodeConsole.js +7 -3
- package/lib/optimize/AggressiveMergingPlugin.js +2 -2
- package/lib/optimize/AggressiveSplittingPlugin.js +9 -6
- package/lib/optimize/ConcatenatedModule.js +985 -470
- package/lib/optimize/ConstExportsPlugin.js +11 -7
- package/lib/optimize/EnsureChunkConditionsPlugin.js +3 -3
- package/lib/optimize/FlagIncludedChunksPlugin.js +3 -4
- package/lib/optimize/InlineExports.js +9 -5
- package/lib/optimize/InnerGraph.js +28 -12
- package/lib/optimize/InnerGraphPlugin.js +23 -18
- package/lib/optimize/LimitChunkCountPlugin.js +7 -3
- package/lib/optimize/MangleExportsPlugin.js +7 -8
- package/lib/optimize/MergeDuplicateChunksPlugin.js +7 -3
- package/lib/optimize/MinChunkSizePlugin.js +7 -3
- package/lib/optimize/ModuleConcatenationPlugin.js +51 -35
- package/lib/optimize/RealContentHashPlugin.js +10 -6
- package/lib/optimize/RemoveEmptyChunksPlugin.js +2 -2
- package/lib/optimize/RemoveParentModulesPlugin.js +4 -4
- package/lib/optimize/RuntimeChunkPlugin.js +2 -2
- package/lib/optimize/SideEffectsFlagPlugin.js +262 -39
- package/lib/optimize/SplitChunksPlugin.js +86 -24
- package/lib/performance/AssetsOverSizeLimitWarning.js +10 -2
- package/lib/performance/AsyncChunkWaterfallsPlugin.js +136 -0
- package/lib/performance/BroadContextsPlugin.js +142 -0
- package/lib/performance/CacheEffectivenessPlugin.js +125 -0
- package/lib/performance/ConflictingResourceHintsPlugin.js +99 -0
- package/lib/performance/DuplicateModulesPlugin.js +93 -0
- package/lib/performance/DuplicatePackagesPlugin.js +119 -0
- package/lib/performance/DuplicatePackagesWarning.js +84 -0
- package/lib/performance/DynamicExportsPlugin.js +120 -0
- package/lib/performance/EmbeddedSourceMapsPlugin.js +71 -0
- package/lib/performance/EntrypointOverlapPlugin.js +122 -0
- package/lib/performance/EntrypointsOverSizeLimitWarning.js +1 -1
- package/lib/performance/EvalUsagePlugin.js +115 -0
- package/lib/performance/HotspotsPlugin.js +296 -0
- package/lib/performance/InlinedAssetsPlugin.js +99 -0
- package/lib/performance/LargeModulesPlugin.js +126 -0
- package/lib/performance/LegacyJavascriptPlugin.js +139 -0
- package/lib/performance/MissingSideEffectsPlugin.js +138 -0
- package/lib/performance/MixedExportsPlugin.js +136 -0
- package/lib/performance/OsDependentRuleWarningPlugin.js +178 -0
- package/lib/performance/PureAnnotationsPlugin.js +219 -0
- package/lib/performance/RedundantDynamicImportsPlugin.js +225 -0
- package/lib/performance/RuntimeInLargeChunkWarning.js +27 -0
- package/lib/performance/ScopeHoistingBailoutsPlugin.js +164 -0
- package/lib/performance/SizeLimitsPlugin.js +139 -7
- package/lib/performance/SplitChunksCappedPlugin.js +99 -0
- package/lib/performance/TinyChunksPlugin.js +128 -0
- package/lib/performance/TopLevelThisPlugin.js +208 -0
- package/lib/performance/UnsplitVendorsPlugin.js +112 -0
- package/lib/performance/UnusedAliasesPlugin.js +253 -0
- package/lib/performance/UnusedDefinesPlugin.js +87 -0
- package/lib/performance/UnusedExternalsPlugin.js +110 -0
- package/lib/performance/UnusedReexportsPlugin.js +159 -0
- package/lib/performance/UnusedRuleWarningPlugin.js +105 -0
- package/lib/performance/getModuleSize.js +22 -0
- package/lib/performance/getSourceModules.js +22 -0
- package/lib/performance/hasOnlyUnusedExports.js +40 -0
- package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +24 -10
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +63 -46
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +2 -3
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +2 -2
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +2 -2
- package/lib/prefetch/ResourceHintPlugin.js +295 -78
- package/lib/prefetch/ResourceHintRuntimeModule.js +1 -21
- package/lib/prefetch/StartupAssetHintRuntimeModule.js +10 -133
- package/lib/prefetch/parseResourceHintOptions.js +31 -4
- package/lib/rules/BasicEffectRulePlugin.js +2 -2
- package/lib/rules/BasicMatcherRulePlugin.js +8 -4
- package/lib/rules/GlobMatcherRulePlugin.js +68 -0
- package/lib/rules/ObjectMatcherRulePlugin.js +12 -5
- package/lib/rules/RuleSetCompiler.js +146 -12
- package/lib/rules/UseEffectRulePlugin.js +18 -11
- package/lib/runtime/AsyncModuleGeneratorRuntimeModule.js +11 -1
- package/lib/runtime/AsyncModuleRuntimeModule.js +1 -1
- package/lib/runtime/AutoPublicPathRuntimeModule.js +15 -20
- package/lib/runtime/BaseUriRuntimeModule.js +33 -7
- package/lib/runtime/ChunkNameRuntimeModule.js +10 -0
- package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +11 -1
- package/lib/runtime/CompatRuntimeModule.js +5 -3
- package/lib/runtime/ConcatenationWrapRuntimeModule.js +90 -0
- package/lib/runtime/ConstructRequireRuntimeModule.js +52 -0
- package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +8 -6
- package/lib/runtime/CreateScriptRuntimeModule.js +11 -1
- package/lib/runtime/CreateScriptUrlRuntimeModule.js +11 -1
- package/lib/runtime/DefinePropertyGettersRuntimeModule.js +56 -38
- package/lib/runtime/EnsureChunkRuntimeModule.js +18 -2
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +62 -37
- package/lib/runtime/GetFullHashRuntimeModule.js +12 -2
- package/lib/runtime/GetMainFilenameRuntimeModule.js +12 -2
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +2 -2
- package/lib/runtime/GetWorkletBootstrapRuntimeModule.js +16 -3
- package/lib/runtime/GlobalRuntimeModule.js +18 -0
- package/lib/runtime/HasOwnPropertyRuntimeModule.js +12 -2
- package/lib/runtime/LoadScriptRuntimeModule.js +2 -2
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +23 -6
- package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +22 -6
- package/lib/runtime/NonceRuntimeModule.js +10 -0
- package/lib/runtime/OnChunksLoadedRuntimeModule.js +5 -3
- package/lib/runtime/PublicPathRuntimeModule.js +12 -2
- package/lib/runtime/RelativeUrlRuntimeModule.js +11 -1
- package/lib/runtime/RuntimeIdRuntimeModule.js +12 -2
- package/lib/runtime/SetAnonymousDefaultNameRuntimeModule.js +11 -1
- package/lib/runtime/StartupChunkDependenciesPlugin.js +18 -9
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +3 -3
- package/lib/runtime/StartupEntrypointRuntimeModule.js +21 -4
- package/lib/runtime/SystemContextRuntimeModule.js +10 -0
- package/lib/runtime/ToBinaryRuntimeModule.js +1 -1
- package/lib/runtime/WorkerRuntimeModule.js +11 -1
- package/lib/runtime/baseUri.js +63 -0
- package/lib/schemes/DataUriPlugin.js +1 -1
- package/lib/schemes/FileUriPlugin.js +1 -1
- package/lib/schemes/HttpUriPlugin.js +24 -15
- package/lib/schemes/VirtualUrlPlugin.js +13 -7
- package/lib/serialization/AggregateErrorSerializer.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +4 -4
- package/lib/serialization/ErrorObjectSerializer.js +1 -1
- package/lib/serialization/FileMiddleware.js +7 -7
- package/lib/serialization/ObjectMiddleware.js +139 -114
- package/lib/serialization/PlainObjectSerializer.js +19 -16
- package/lib/sharing/ConsumeSharedModule.js +30 -21
- package/lib/sharing/ConsumeSharedPlugin.js +18 -10
- package/lib/sharing/ConsumeSharedRuntimeModule.js +6 -9
- package/lib/sharing/ProvideSharedModule.js +25 -16
- package/lib/sharing/ProvideSharedModuleFactory.js +7 -3
- package/lib/sharing/ProvideSharedPlugin.js +8 -4
- package/lib/sharing/SharePlugin.js +17 -5
- package/lib/sharing/ShareRuntimeModule.js +4 -4
- package/lib/sharing/resolveMatchedConfigs.js +9 -6
- package/lib/sharing/utils.js +1 -3
- package/lib/stats/DefaultStatsFactoryPlugin.js +50 -29
- package/lib/stats/DefaultStatsPresetPlugin.js +17 -8
- package/lib/stats/DefaultStatsPrinterPlugin.js +36 -26
- package/lib/stats/StatsFactory.js +25 -26
- package/lib/stats/StatsPrinter.js +16 -12
- package/lib/typescript/TypeScriptPlugin.js +12 -14
- package/lib/url/URLParserPlugin.js +26 -13
- package/lib/util/AsyncQueue.js +4 -3
- package/lib/util/Hash.js +5 -1
- package/lib/util/LazySet.js +35 -22
- package/lib/util/LocConverter.js +36 -13
- package/lib/util/SourceProcessor.js +1050 -24
- package/lib/util/StringXor.js +1 -1
- package/lib/util/chainedImports.js +9 -5
- package/lib/util/cleverMerge.js +1 -1
- package/lib/util/comparators.js +45 -14
- package/lib/util/concatenate.js +203 -77
- package/lib/util/conventions.js +5 -1
- package/lib/util/createHash.js +2 -2
- package/lib/util/createHooksRegistry.js +8 -10
- package/lib/util/dataURL.js +225 -1
- package/lib/util/extractSourceMap.js +4 -3
- package/lib/util/findCaseMismatch.js +139 -0
- package/lib/util/formatLocation.js +1 -2
- package/lib/util/fs.js +22 -5
- package/lib/util/globUtils.js +298 -24
- package/lib/util/hash/BatchedHash.js +5 -1
- package/lib/util/hash/BulkUpdateHash.js +5 -1
- package/lib/util/hash/DebugHash.js +5 -1
- package/lib/util/hash/hash-digest.js +6 -2
- package/lib/util/identifier.js +4 -0
- package/lib/util/implicitTypeLoaderFallback.js +1 -1
- package/lib/util/internalSerializables.js +6 -0
- package/lib/util/lazyModule.js +56 -0
- package/lib/util/makeSerializable.js +7 -3
- package/lib/util/matchAlias.js +25 -0
- package/lib/util/mimeTypes.js +11 -5
- package/lib/util/nonNumericOnlyHash.js +4 -3
- package/lib/util/parseJson.js +5 -3
- package/lib/util/preloadModuleType.js +32 -0
- package/lib/util/registerExternalSerializer.js +7 -5
- package/lib/util/runtime.js +2 -2
- package/lib/util/semver.js +1 -1
- package/lib/util/serialization.js +28 -28
- package/lib/util/source.js +2 -2
- package/lib/util/traverseDestructuringAssignmentProperties.js +6 -2
- package/lib/wasm/EnableWasmLoadingPlugin.js +10 -8
- package/lib/wasm/wasmModuleFilename.js +54 -0
- package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +41 -21
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +43 -21
- package/lib/wasm-async/AsyncWasmModule.js +3 -3
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +4 -5
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +57 -17
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +34 -18
- package/lib/wasm-async/AsyncWebAssemblyParser.js +9 -8
- package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +34 -8
- package/lib/wasm-sync/SyncWasmModule.js +2 -2
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +18 -13
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +4 -5
- package/lib/wasm-sync/WebAssemblyGenerator.js +18 -17
- package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +4 -4
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +7 -7
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +24 -11
- package/lib/wasm-sync/WebAssemblyParser.js +4 -6
- package/lib/wasm-sync/WebAssemblyUtils.js +2 -2
- package/lib/web/FetchCompileAsyncWasmPlugin.js +101 -19
- package/lib/web/FetchCompileWasmPlugin.js +46 -16
- package/lib/web/JsonpChunkLoadingPlugin.js +47 -23
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +50 -20
- package/lib/web/JsonpTemplatePlugin.js +2 -2
- package/lib/webpack.js +22 -11
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +60 -26
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +30 -32
- package/lib/webworker/WebWorkerTemplatePlugin.js +1 -1
- package/module.d.ts +1 -0
- package/package.json +32 -25
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +670 -36
- package/schemas/plugins/HtmlParserOptions.check.js +1 -1
- package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerPlugin.json +10 -0
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.json +10 -0
- package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssParserOptions.check.js +1 -1
- package/types.d.ts +3144 -454
- package/lib/runtime/CommonJsWrapRuntimeModule.js +0 -37
|
@@ -5,8 +5,6 @@
|
|
|
5
5
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
|
-
const eslintScope = require("eslint-scope");
|
|
9
|
-
const Referencer = require("eslint-scope/lib/referencer");
|
|
10
8
|
const { SyncBailHook } = require("tapable");
|
|
11
9
|
const {
|
|
12
10
|
CachedSource,
|
|
@@ -16,18 +14,23 @@ const {
|
|
|
16
14
|
const ConcatenationScope = require("../ConcatenationScope");
|
|
17
15
|
const Dependency = require("../Dependency");
|
|
18
16
|
const { UsageState } = require("../ExportsInfo");
|
|
17
|
+
const ExternalModule = require("../ExternalModule");
|
|
19
18
|
const Module = require("../Module");
|
|
20
19
|
const {
|
|
21
20
|
JAVASCRIPT_TYPE,
|
|
22
21
|
JAVASCRIPT_TYPES
|
|
23
22
|
} = require("../ModuleSourceTypeConstants");
|
|
24
23
|
const { JAVASCRIPT_MODULE_TYPE_ESM } = require("../ModuleTypeConstants");
|
|
24
|
+
const NormalModule = require("../NormalModule");
|
|
25
25
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
|
26
26
|
const Template = require("../Template");
|
|
27
27
|
const { DEFAULTS } = require("../config/defaults");
|
|
28
|
+
const CommonJsExportRequireDependency = require("../dependencies/CommonJsExportRequireDependency");
|
|
29
|
+
const CommonJsFullRequireDependency = require("../dependencies/CommonJsFullRequireDependency");
|
|
30
|
+
const CommonJsRequireDependency = require("../dependencies/CommonJsRequireDependency");
|
|
28
31
|
const { ImportPhaseUtils } = require("../dependencies/ImportPhase");
|
|
29
|
-
const { isCommonJsWrapped } = require("../javascript/JavascriptGenerator");
|
|
30
32
|
const JavascriptParser = require("../javascript/JavascriptParser");
|
|
33
|
+
const analyzeScope = require("../javascript/ScopeAnalyzer");
|
|
31
34
|
const {
|
|
32
35
|
getDeferredCycleModuleIds,
|
|
33
36
|
getDeferredCycleModules,
|
|
@@ -36,14 +39,18 @@ const {
|
|
|
36
39
|
} = require("../runtime/MakeDeferredNamespaceObjectRuntime");
|
|
37
40
|
const { equals } = require("../util/ArrayHelpers");
|
|
38
41
|
const LazySet = require("../util/LazySet");
|
|
39
|
-
const {
|
|
42
|
+
const {
|
|
43
|
+
compareModulesByFullName,
|
|
44
|
+
concatComparators
|
|
45
|
+
} = require("../util/comparators");
|
|
40
46
|
const {
|
|
41
47
|
RESERVED_NAMES,
|
|
42
48
|
addScopeSymbols,
|
|
43
49
|
findNewName,
|
|
44
50
|
getAllReferences,
|
|
45
51
|
getPathInAst,
|
|
46
|
-
getUsedNamesInScopeInfo
|
|
52
|
+
getUsedNamesInScopeInfo,
|
|
53
|
+
isCommonJsConcatenationEnabled
|
|
47
54
|
} = require("../util/concatenate");
|
|
48
55
|
const createHash = require("../util/createHash");
|
|
49
56
|
const createHooksRegistry = require("../util/createHooksRegistry");
|
|
@@ -60,54 +67,71 @@ const {
|
|
|
60
67
|
} = require("../util/runtime");
|
|
61
68
|
const { InlinedUsedName } = require("./InlineExports");
|
|
62
69
|
|
|
63
|
-
/** @
|
|
64
|
-
/**
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
/** @
|
|
70
|
-
/** @
|
|
71
|
-
/** @
|
|
72
|
-
/** @
|
|
73
|
-
/** @
|
|
74
|
-
/** @
|
|
75
|
-
/** @
|
|
76
|
-
/**
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
/** @
|
|
94
|
-
/**
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
/** @
|
|
100
|
-
/** @
|
|
101
|
-
/** @
|
|
102
|
-
/**
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
|
|
110
|
-
|
|
70
|
+
/** @import { Source } from "webpack-sources" */
|
|
71
|
+
/**
|
|
72
|
+
* @import {
|
|
73
|
+
* WebpackOptionsNormalizedWithDefaults as WebpackOptions
|
|
74
|
+
* } from "../config/defaults"
|
|
75
|
+
*/
|
|
76
|
+
/** @import ChunkGraph from "../ChunkGraph" */
|
|
77
|
+
/** @import CodeGenerationResults from "../CodeGenerationResults" */
|
|
78
|
+
/** @import Compilation, { FileSystemDependencies } from "../Compilation" */
|
|
79
|
+
/** @import { UpdateHashContext } from "../Dependency" */
|
|
80
|
+
/** @import HarmonyImportDependency from "../dependencies/HarmonyImportDependency" */
|
|
81
|
+
/** @import DependencyTemplates from "../DependencyTemplates" */
|
|
82
|
+
/** @import { ExportInfo } from "../ExportsInfo" */
|
|
83
|
+
/**
|
|
84
|
+
* @import {
|
|
85
|
+
* BuildCallback,
|
|
86
|
+
* BuildInfo,
|
|
87
|
+
* BuildMeta,
|
|
88
|
+
* ExportsType,
|
|
89
|
+
* CodeGenerationContext,
|
|
90
|
+
* CodeGenerationResultData,
|
|
91
|
+
* CodeGenerationResult,
|
|
92
|
+
* LibIdentOptions,
|
|
93
|
+
* LibIdent,
|
|
94
|
+
* NameForCondition,
|
|
95
|
+
* ReadOnlyRuntimeRequirements,
|
|
96
|
+
* RuntimeRequirements,
|
|
97
|
+
* SourceTypes
|
|
98
|
+
* } from "../Module"
|
|
99
|
+
*/
|
|
100
|
+
/** @import ModuleGraph from "../ModuleGraph" */
|
|
101
|
+
/**
|
|
102
|
+
* @import ModuleGraphConnection, {
|
|
103
|
+
* ConnectionState
|
|
104
|
+
* } from "../ModuleGraphConnection"
|
|
105
|
+
*/
|
|
106
|
+
/** @import RequestShortener from "../RequestShortener" */
|
|
107
|
+
/** @import { ResolverWithOptions } from "../ResolverFactory" */
|
|
108
|
+
/** @import RuntimeTemplate from "../RuntimeTemplate" */
|
|
109
|
+
/**
|
|
110
|
+
* @import {
|
|
111
|
+
* JavascriptModuleBuildInfo,
|
|
112
|
+
* JavascriptModuleBuildMeta
|
|
113
|
+
* } from "../javascript/JavascriptModule"
|
|
114
|
+
*/
|
|
115
|
+
/**
|
|
116
|
+
* @import {
|
|
117
|
+
* ChunkRenderContext,
|
|
118
|
+
* Scope,
|
|
119
|
+
* Reference,
|
|
120
|
+
* Variable
|
|
121
|
+
* } from "../javascript/JavascriptModulesPlugin"
|
|
122
|
+
*/
|
|
123
|
+
/** @import { Range } from "../javascript/JavascriptParser" */
|
|
124
|
+
/** @import { Identifier, Program } from "estree" */
|
|
125
|
+
/**
|
|
126
|
+
* @import {
|
|
127
|
+
* ObjectDeserializerContext
|
|
128
|
+
* } from "../serialization/ObjectMiddleware"
|
|
129
|
+
*/
|
|
130
|
+
/** @import Hash, { HashFunction } from "../util/Hash" */
|
|
131
|
+
/** @import { UsedNames, UsedNamesInScopeInfo } from "../util/concatenate" */
|
|
132
|
+
/** @import { InputFileSystem } from "../util/fs" */
|
|
133
|
+
/** @import { AssociatedObjectForCache } from "../util/identifier" */
|
|
134
|
+
/** @import { RuntimeSpec } from "../util/runtime" */
|
|
111
135
|
/**
|
|
112
136
|
* @template T
|
|
113
137
|
* @typedef {import("../InitFragment")<T>} InitFragment
|
|
@@ -118,13 +142,33 @@ const { InlinedUsedName } = require("./InlineExports");
|
|
|
118
142
|
* @typedef {import("../util/comparators").Comparator<T>} Comparator
|
|
119
143
|
*/
|
|
120
144
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
145
|
+
const IDENTIFIER_SCAN_REGEXP = /[$A-Za-z_][\w$]*/g;
|
|
146
|
+
const IDENTIFIER_SCAN_WHITESPACE = new Set([" ", "\t", "\n", "\r"]);
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Finds every identifier a generated source could resolve against the enclosing
|
|
150
|
+
* concatenation scope. Property names are skipped; string and comment contents
|
|
151
|
+
* are not, which only over-reserves.
|
|
152
|
+
* @param {Source} source generated source
|
|
153
|
+
* @returns {ReadonlySet<string>} identifier names
|
|
154
|
+
*/
|
|
155
|
+
const findIdentifiers = (source) => {
|
|
156
|
+
const code = source.source().toString();
|
|
157
|
+
/** @type {Set<string>} */
|
|
158
|
+
const result = new Set();
|
|
159
|
+
IDENTIFIER_SCAN_REGEXP.lastIndex = 0;
|
|
160
|
+
let match = IDENTIFIER_SCAN_REGEXP.exec(code);
|
|
161
|
+
while (match !== null) {
|
|
162
|
+
let i = match.index - 1;
|
|
163
|
+
while (i >= 0 && IDENTIFIER_SCAN_WHITESPACE.has(code[i])) i--;
|
|
164
|
+
// `a.b` can't bind to the outer scope, but the `b` of `...b` can
|
|
165
|
+
if (!(i >= 0 && code[i] === "." && code[i - 1] !== ".")) {
|
|
166
|
+
result.add(match[0]);
|
|
167
|
+
}
|
|
168
|
+
match = IDENTIFIER_SCAN_REGEXP.exec(code);
|
|
169
|
+
}
|
|
170
|
+
return result;
|
|
171
|
+
};
|
|
128
172
|
|
|
129
173
|
/** @typedef {RawBinding | SymbolBinding} Binding */
|
|
130
174
|
|
|
@@ -156,20 +200,23 @@ if (!ReferencerClass.prototype.PropertyDefinition) {
|
|
|
156
200
|
/**
|
|
157
201
|
* @typedef {object} ConcatenatedModuleInfo
|
|
158
202
|
* @property {"concatenated"} type
|
|
203
|
+
* @property {boolean} wrapped the body renders inside the lazy CJS wrapper with real module/exports instead of being scope-hoisted into the shared scope
|
|
204
|
+
* @property {boolean} eager a wrapped body reached by an eager import edge, so its accessor is called at its own slot in evaluation order
|
|
159
205
|
* @property {Module} module
|
|
160
206
|
* @property {number} index
|
|
161
|
-
* @property {boolean=} cjsWrapped a "weird" CommonJS module executed via the CJS wrapper runtime helper with real module/exports objects
|
|
162
207
|
* @property {Program | undefined} ast
|
|
163
208
|
* @property {Source | undefined} internalSource
|
|
164
209
|
* @property {ReplaceSource | undefined} source
|
|
165
210
|
* @property {InitFragment<ChunkRenderContext>[]=} chunkInitFragments
|
|
166
211
|
* @property {ReadOnlyRuntimeRequirements | undefined} runtimeRequirements
|
|
167
212
|
* @property {Scope | undefined} globalScope
|
|
213
|
+
* @property {Reference[] | undefined} unresolvedReferences the module's free references
|
|
168
214
|
* @property {Scope | undefined} moduleScope
|
|
169
215
|
* @property {Map<string, string>} internalNames
|
|
170
216
|
* @property {ExportMap | undefined} exportMap
|
|
171
217
|
* @property {ExportMap | undefined} rawExportMap
|
|
172
218
|
* @property {string=} namespaceExportSymbol
|
|
219
|
+
* @property {string | undefined} namespaceFnName name of the lazy wrapper accessor function (calling it evaluates the module and returns its exports)
|
|
173
220
|
* @property {string | undefined} namespaceObjectName
|
|
174
221
|
* @property {string | undefined} escapeNamespaceObjectName decoupled namespace object that keeps original export names when the exports are mangled
|
|
175
222
|
* @property {ConcatenationScope | undefined} concatenationScope
|
|
@@ -186,11 +233,14 @@ if (!ReferencerClass.prototype.PropertyDefinition) {
|
|
|
186
233
|
/**
|
|
187
234
|
* @typedef {object} ExternalModuleInfo
|
|
188
235
|
* @property {"external"} type
|
|
236
|
+
* @property {boolean} wrapped the module's `require()` call is deferred behind an accessor instead of running at its own slot; unlike a wrapped concatenated member there is no body and no CJS wrapper, so any external may be wrapped
|
|
237
|
+
* @property {boolean} eager a wrapped module reached by an eager import edge, so its accessor is called at its own slot in evaluation order
|
|
189
238
|
* @property {Module} module
|
|
190
239
|
* @property {RuntimeSpec | boolean} runtimeCondition
|
|
191
240
|
* @property {NonDeferAccess} nonDeferAccess
|
|
192
241
|
* @property {number} index
|
|
193
242
|
* @property {string | undefined} name module.exports / harmony namespace object
|
|
243
|
+
* @property {string | undefined} namespaceFnName lazy module accessor
|
|
194
244
|
* @property {string | undefined} escapeNamespaceObjectName decoupled namespace object that keeps original export names when the exports are mangled
|
|
195
245
|
* @property {string | undefined} deferredName deferred module.exports / harmony namespace object
|
|
196
246
|
* @property {boolean} deferred the module is deferred at least once
|
|
@@ -290,11 +340,36 @@ const subtractNonDeferAccess = (a, b) => a && !b;
|
|
|
290
340
|
/**
|
|
291
341
|
* @typedef {object} ConcatenationEntry
|
|
292
342
|
* @property {"concatenated" | "external"} type
|
|
343
|
+
* @property {boolean} wrapped evaluation is deferred behind an accessor: a "concatenated" entry renders its body inside the lazy CJS wrapper instead of being scope-hoisted, an "external" entry only defers its `require()` call
|
|
293
344
|
* @property {Module} module
|
|
294
345
|
* @property {RuntimeSpec | boolean} runtimeCondition
|
|
295
346
|
* @property {NonDeferAccess} nonDeferAccess
|
|
296
347
|
*/
|
|
297
348
|
|
|
349
|
+
/**
|
|
350
|
+
* Whether a member runs inside the lazy CJS wrapper or is scope-hoisted. Only a
|
|
351
|
+
* NormalModule can carry a CJS body; an ESM member starts out hoisted and is
|
|
352
|
+
* downgraded by {@link ConcatenatedModule._createConcatenationList}.
|
|
353
|
+
* @param {Module} module a module taking part in the concatenation
|
|
354
|
+
* @returns {boolean} true, when the module renders wrapped
|
|
355
|
+
*/
|
|
356
|
+
const needWrapped = (module) =>
|
|
357
|
+
module instanceof NormalModule &&
|
|
358
|
+
module.type.startsWith("javascript/") &&
|
|
359
|
+
module.buildMeta !== undefined &&
|
|
360
|
+
module.buildMeta.exportsType !== "namespace";
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Whether a hoisted member can move into the lazy wrapper instead.
|
|
364
|
+
* @param {ConcatenationEntry} entry a member of the concatenation
|
|
365
|
+
* @returns {boolean} true, when it may be wrapped
|
|
366
|
+
*/
|
|
367
|
+
const entryCanBeWrapped = (entry) =>
|
|
368
|
+
(entry.module instanceof NormalModule &&
|
|
369
|
+
!entry.module.type.startsWith("css/")) ||
|
|
370
|
+
(entry.module instanceof ExternalModule &&
|
|
371
|
+
entry.module.canBeWrappedInConcatenation());
|
|
372
|
+
|
|
298
373
|
/** @typedef {Set<ConcatenatedModuleInfo>} NeededNamespaceObjects */
|
|
299
374
|
|
|
300
375
|
/** @typedef {Map<Module, ModuleInfo>} ModuleToInfoMap */
|
|
@@ -320,6 +395,40 @@ const getExportsType = (moduleGraph, info, strict) => {
|
|
|
320
395
|
return info.exportsTypeNonStrict;
|
|
321
396
|
};
|
|
322
397
|
|
|
398
|
+
/**
|
|
399
|
+
* @param {ExternalModuleInfo} info module info
|
|
400
|
+
* @returns {string} module exports expression
|
|
401
|
+
*/
|
|
402
|
+
const getExternalModuleExpr = (info) =>
|
|
403
|
+
info.wrapped
|
|
404
|
+
? `${
|
|
405
|
+
/** @type {NonNullable<ExternalModuleInfo["namespaceFnName"]>} */
|
|
406
|
+
(info.namespaceFnName)
|
|
407
|
+
}()`
|
|
408
|
+
: /** @type {NonNullable<ExternalModuleInfo["name"]>} */ (info.name);
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* A wrapped module's interop object is declared as a lazy accessor, so reading
|
|
412
|
+
* it is a call. See `declareInterop`.
|
|
413
|
+
* @param {ModuleInfo} info module info
|
|
414
|
+
* @param {string | undefined} interopName interop variable name
|
|
415
|
+
* @returns {string} interop object expression
|
|
416
|
+
*/
|
|
417
|
+
const getInteropExpr = (info, interopName) =>
|
|
418
|
+
info.wrapped ? `${interopName}()` : /** @type {string} */ (interopName);
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Expression for an export that is not used. A hoisted body runs at its own
|
|
422
|
+
* slot, but a wrapped one only runs when its accessor is called, so dropping
|
|
423
|
+
* the reference would drop the module's side effects with it.
|
|
424
|
+
* @param {ConcatenatedModuleInfo} info module info
|
|
425
|
+
* @returns {string} expression evaluating to undefined
|
|
426
|
+
*/
|
|
427
|
+
const getUnusedExportExpr = (info) =>
|
|
428
|
+
info.wrapped
|
|
429
|
+
? `/* unused export */ (${info.namespaceObjectName}, undefined)`
|
|
430
|
+
: "/* unused export */ undefined";
|
|
431
|
+
|
|
323
432
|
/**
|
|
324
433
|
* @param {ModuleGraph} moduleGraph the module graph
|
|
325
434
|
* @param {ModuleInfo} info module info
|
|
@@ -333,7 +442,8 @@ const getExportsType = (moduleGraph, info, strict) => {
|
|
|
333
442
|
* @param {boolean} depDeferred the dependency is deferred
|
|
334
443
|
* @param {boolean | undefined} strictHarmonyModule strictHarmonyModule
|
|
335
444
|
* @param {boolean | undefined} asiSafe asiSafe
|
|
336
|
-
* @param {
|
|
445
|
+
* @param {boolean=} moduleExportsAccess resolve to the module's own exports value with plain property access, skipping ESM interop
|
|
446
|
+
* @param {Set<InstanceType<ExportInfo>>=} alreadyVisited alreadyVisited
|
|
337
447
|
* @returns {Binding} the final variable
|
|
338
448
|
*/
|
|
339
449
|
const getFinalBinding = (
|
|
@@ -349,6 +459,7 @@ const getFinalBinding = (
|
|
|
349
459
|
depDeferred,
|
|
350
460
|
strictHarmonyModule,
|
|
351
461
|
asiSafe,
|
|
462
|
+
moduleExportsAccess,
|
|
352
463
|
alreadyVisited
|
|
353
464
|
) => {
|
|
354
465
|
const exportsType = getExportsType(moduleGraph, info, strictHarmonyModule);
|
|
@@ -357,35 +468,57 @@ const getFinalBinding = (
|
|
|
357
468
|
info.deferred &&
|
|
358
469
|
!(/** @type {BuildMeta} */ (info.module.buildMeta).async);
|
|
359
470
|
const deferred = depDeferred && moduleDeferred;
|
|
471
|
+
|
|
472
|
+
if (moduleExportsAccess && info.type === "concatenated") {
|
|
473
|
+
neededNamespaceObjects.add(info);
|
|
474
|
+
// ids arrive as declared names and the rendered exports object is keyed by
|
|
475
|
+
// used ones, so resolve here — the same way `case "external"` does below.
|
|
476
|
+
// Resolving in the caller instead would mangle twice.
|
|
477
|
+
const usedName =
|
|
478
|
+
exportName.length === 0
|
|
479
|
+
? exportName
|
|
480
|
+
: moduleGraph
|
|
481
|
+
.getExportsInfo(info.module)
|
|
482
|
+
.getUsedName(exportName, runtime);
|
|
483
|
+
if (!usedName) {
|
|
484
|
+
return {
|
|
485
|
+
info,
|
|
486
|
+
rawName: getUnusedExportExpr(info),
|
|
487
|
+
ids: [],
|
|
488
|
+
exportName
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
return {
|
|
492
|
+
info,
|
|
493
|
+
rawName:
|
|
494
|
+
/** @type {NonNullable<ConcatenatedModuleInfo["namespaceObjectName"]>} */
|
|
495
|
+
(info.namespaceObjectName),
|
|
496
|
+
ids: /** @type {ExportName} */ (usedName),
|
|
497
|
+
exportName
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
|
|
360
501
|
if (exportName.length === 0) {
|
|
361
502
|
switch (exportsType) {
|
|
362
503
|
case "default-only":
|
|
363
|
-
// a concatenated CommonJS module has no runtime exports object;
|
|
364
|
-
// its fake namespace is built over the generated namespace object
|
|
365
|
-
if (info.type === "concatenated") neededNamespaceObjects.add(info);
|
|
366
504
|
if (deferred) info.deferredNamespaceObjectUsed = true;
|
|
367
505
|
else info.interopNamespaceObject2Used = true;
|
|
368
506
|
return {
|
|
369
507
|
info,
|
|
370
|
-
rawName:
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
: info.interopNamespaceObject2Name
|
|
374
|
-
),
|
|
508
|
+
rawName: deferred
|
|
509
|
+
? /** @type {string} */ (info.deferredNamespaceObjectName)
|
|
510
|
+
: getInteropExpr(info, info.interopNamespaceObject2Name),
|
|
375
511
|
ids: exportName,
|
|
376
512
|
exportName
|
|
377
513
|
};
|
|
378
514
|
case "default-with-named":
|
|
379
|
-
if (info.type === "concatenated") neededNamespaceObjects.add(info);
|
|
380
515
|
if (deferred) info.deferredNamespaceObjectUsed = true;
|
|
381
516
|
else info.interopNamespaceObjectUsed = true;
|
|
382
517
|
return {
|
|
383
518
|
info,
|
|
384
|
-
rawName:
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
: info.interopNamespaceObjectName
|
|
388
|
-
),
|
|
519
|
+
rawName: deferred
|
|
520
|
+
? /** @type {string} */ (info.deferredNamespaceObjectName)
|
|
521
|
+
: getInteropExpr(info, info.interopNamespaceObjectName),
|
|
389
522
|
ids: exportName,
|
|
390
523
|
exportName
|
|
391
524
|
};
|
|
@@ -476,19 +609,23 @@ const getFinalBinding = (
|
|
|
476
609
|
if (moduleDeferred) {
|
|
477
610
|
return {
|
|
478
611
|
info,
|
|
479
|
-
rawName:
|
|
612
|
+
rawName: getExternalModuleExpr(info),
|
|
480
613
|
ids: exportName,
|
|
481
614
|
exportName
|
|
482
615
|
};
|
|
483
616
|
}
|
|
484
617
|
info.interopDefaultAccessUsed = true;
|
|
618
|
+
const accessor = getInteropExpr(
|
|
619
|
+
info,
|
|
620
|
+
info.interopDefaultAccessName
|
|
621
|
+
);
|
|
485
622
|
const defaultExport = asCall
|
|
486
|
-
? `${
|
|
623
|
+
? `${accessor}()`
|
|
487
624
|
: asiSafe
|
|
488
|
-
? `(${
|
|
625
|
+
? `(${accessor}())`
|
|
489
626
|
: asiSafe === false
|
|
490
|
-
? `;(${
|
|
491
|
-
: `${
|
|
627
|
+
? `;(${accessor}())`
|
|
628
|
+
: `${accessor}.a`;
|
|
492
629
|
return {
|
|
493
630
|
info,
|
|
494
631
|
rawName: defaultExport,
|
|
@@ -509,6 +646,7 @@ const getFinalBinding = (
|
|
|
509
646
|
throw new Error(`Unexpected exportsType ${exportsType}`);
|
|
510
647
|
}
|
|
511
648
|
}
|
|
649
|
+
|
|
512
650
|
if (exportName.length === 0) {
|
|
513
651
|
switch (info.type) {
|
|
514
652
|
case "concatenated":
|
|
@@ -533,9 +671,7 @@ const getFinalBinding = (
|
|
|
533
671
|
}
|
|
534
672
|
return {
|
|
535
673
|
info,
|
|
536
|
-
rawName:
|
|
537
|
-
/** @type {NonNullable<ExternalModuleInfo["name"]>} */
|
|
538
|
-
(info.name),
|
|
674
|
+
rawName: getExternalModuleExpr(info),
|
|
539
675
|
ids: exportName,
|
|
540
676
|
exportName
|
|
541
677
|
};
|
|
@@ -664,19 +800,41 @@ const getFinalBinding = (
|
|
|
664
800
|
/** @type {BuildMeta} */
|
|
665
801
|
(info.module.buildMeta).strictHarmonyModule,
|
|
666
802
|
asiSafe,
|
|
803
|
+
false,
|
|
667
804
|
alreadyVisited
|
|
668
805
|
);
|
|
669
806
|
}
|
|
670
807
|
// A wrapped module resolves every export through its live exports
|
|
671
808
|
// alias (namespaceObjectName), same as namespaceExportSymbol modules.
|
|
672
|
-
if (info.namespaceExportSymbol || info.
|
|
673
|
-
const usedName =
|
|
674
|
-
|
|
675
|
-
|
|
809
|
+
if (info.namespaceExportSymbol || info.wrapped) {
|
|
810
|
+
const usedName = exportsInfo.getUsedName(exportName, runtime);
|
|
811
|
+
if (!usedName) {
|
|
812
|
+
return {
|
|
813
|
+
info,
|
|
814
|
+
rawName: "/* unused export */ undefined",
|
|
815
|
+
ids: exportName.slice(1),
|
|
816
|
+
exportName
|
|
817
|
+
};
|
|
818
|
+
}
|
|
819
|
+
// an inlined export never reaches the exports object, so render the
|
|
820
|
+
// literal instead of reading the namespace
|
|
821
|
+
if (usedName instanceof InlinedUsedName) {
|
|
822
|
+
return {
|
|
823
|
+
info,
|
|
824
|
+
// Literal only; suffix is appended once via `ids` (see directExport branch).
|
|
825
|
+
rawName: usedName.render(
|
|
826
|
+
Template.toNormalComment(
|
|
827
|
+
`inlined export ${propertyAccess(exportName)}`
|
|
828
|
+
)
|
|
829
|
+
),
|
|
830
|
+
ids: usedName.suffix,
|
|
831
|
+
exportName
|
|
832
|
+
};
|
|
833
|
+
}
|
|
676
834
|
return {
|
|
677
835
|
info,
|
|
678
836
|
rawName: /** @type {string} */ (info.namespaceObjectName),
|
|
679
|
-
ids: usedName,
|
|
837
|
+
ids: /** @type {ExportName} */ (usedName),
|
|
680
838
|
exportName
|
|
681
839
|
};
|
|
682
840
|
}
|
|
@@ -717,8 +875,7 @@ const getFinalBinding = (
|
|
|
717
875
|
return {
|
|
718
876
|
info,
|
|
719
877
|
rawName:
|
|
720
|
-
(deferred ? info.deferredName : info
|
|
721
|
-
(deferred ? ".a" : "") +
|
|
878
|
+
(deferred ? `${info.deferredName}.a` : getExternalModuleExpr(info)) +
|
|
722
879
|
comment,
|
|
723
880
|
ids: usedName,
|
|
724
881
|
exportName
|
|
@@ -741,6 +898,7 @@ const getFinalBinding = (
|
|
|
741
898
|
* @param {boolean | undefined} callContext callContext
|
|
742
899
|
* @param {boolean | undefined} strictHarmonyModule strictHarmonyModule
|
|
743
900
|
* @param {boolean | undefined} asiSafe asiSafe
|
|
901
|
+
* @param {boolean=} moduleExportsAccess resolve to the module's own exports value with plain property access, skipping ESM interop
|
|
744
902
|
* @returns {string} the final name
|
|
745
903
|
*/
|
|
746
904
|
const getFinalName = (
|
|
@@ -756,7 +914,8 @@ const getFinalName = (
|
|
|
756
914
|
depDeferred,
|
|
757
915
|
callContext,
|
|
758
916
|
strictHarmonyModule,
|
|
759
|
-
asiSafe
|
|
917
|
+
asiSafe,
|
|
918
|
+
moduleExportsAccess
|
|
760
919
|
) => {
|
|
761
920
|
const binding = getFinalBinding(
|
|
762
921
|
moduleGraph,
|
|
@@ -770,7 +929,8 @@ const getFinalName = (
|
|
|
770
929
|
asCall,
|
|
771
930
|
depDeferred,
|
|
772
931
|
strictHarmonyModule,
|
|
773
|
-
asiSafe
|
|
932
|
+
asiSafe,
|
|
933
|
+
moduleExportsAccess
|
|
774
934
|
);
|
|
775
935
|
{
|
|
776
936
|
const { ids, comment } = binding;
|
|
@@ -799,13 +959,19 @@ const getFinalName = (
|
|
|
799
959
|
reference = `${name}${comment || ""}${propertyAccess(ids)}`;
|
|
800
960
|
isPropertyAccess = ids.length > 1;
|
|
801
961
|
}
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
?
|
|
807
|
-
:
|
|
962
|
+
|
|
963
|
+
if (isPropertyAccess) {
|
|
964
|
+
if (asCall && callContext === false) {
|
|
965
|
+
return asiSafe
|
|
966
|
+
? `(0,${reference})`
|
|
967
|
+
: asiSafe === false
|
|
968
|
+
? `;(0,${reference})`
|
|
969
|
+
: `/*#__PURE__*/Object(${reference})`;
|
|
970
|
+
} else if (binding.info.wrapped) {
|
|
971
|
+
return asiSafe === false ? `;(${reference})` : `(${reference})`;
|
|
972
|
+
}
|
|
808
973
|
}
|
|
974
|
+
|
|
809
975
|
return reference;
|
|
810
976
|
}
|
|
811
977
|
};
|
|
@@ -973,6 +1139,9 @@ class ConcatenatedModule extends Module {
|
|
|
973
1139
|
*/
|
|
974
1140
|
build(options, compilation, resolver, fs, callback) {
|
|
975
1141
|
const { rootModule } = this;
|
|
1142
|
+
const concatenateCommonJsModules = isCommonJsConcatenationEnabled(
|
|
1143
|
+
options.optimization.concatenateModules
|
|
1144
|
+
);
|
|
976
1145
|
const { moduleArgument, exportsArgument } =
|
|
977
1146
|
/** @type {BuildInfo} */
|
|
978
1147
|
(rootModule.buildInfo);
|
|
@@ -1015,7 +1184,7 @@ class ConcatenatedModule extends Module {
|
|
|
1015
1184
|
// populate dependencies — keep only deps that leave the concat set
|
|
1016
1185
|
for (const d of m.dependencies) {
|
|
1017
1186
|
if (
|
|
1018
|
-
!Dependency.canConcatenate(d) ||
|
|
1187
|
+
!Dependency.canConcatenate(d, concatenateCommonJsModules) ||
|
|
1019
1188
|
!this._modules.has(
|
|
1020
1189
|
/** @type {Module} */
|
|
1021
1190
|
(compilation.moduleGraph.getModule(d))
|
|
@@ -1127,11 +1296,19 @@ class ConcatenatedModule extends Module {
|
|
|
1127
1296
|
* @returns {ConcatenationEntry[]} concatenation list
|
|
1128
1297
|
*/
|
|
1129
1298
|
_createConcatenationList(rootModule, modulesSet, runtime, moduleGraph) {
|
|
1299
|
+
const concatenateCommonJsModules = isCommonJsConcatenationEnabled(
|
|
1300
|
+
this.compilation.options.optimization.concatenateModules
|
|
1301
|
+
);
|
|
1130
1302
|
/** @type {ConcatenationEntry[]} */
|
|
1131
1303
|
const list = [];
|
|
1132
1304
|
/** @type {Map<Module, { runtimeCondition: RuntimeSpec | true, nonDeferAccess: NonDeferAccess }>} */
|
|
1133
1305
|
const existingEntries = new Map();
|
|
1134
1306
|
|
|
1307
|
+
/** @type {Map<Module, Module[]>} */
|
|
1308
|
+
const importConnections = new Map();
|
|
1309
|
+
/** @type {Set<Module>} */
|
|
1310
|
+
const wrappedModules = new Set();
|
|
1311
|
+
|
|
1135
1312
|
/**
|
|
1136
1313
|
* @param {Module} module a module
|
|
1137
1314
|
* @returns {Iterable<{ connection: ModuleGraphConnection, runtimeCondition: RuntimeSpec | true, nonDeferAccess: NonDeferAccess }>} imported modules in order
|
|
@@ -1150,7 +1327,10 @@ class ConcatenatedModule extends Module {
|
|
|
1150
1327
|
.filter((connection) => {
|
|
1151
1328
|
if (
|
|
1152
1329
|
!connection.dependency ||
|
|
1153
|
-
!Dependency.canConcatenate(
|
|
1330
|
+
!Dependency.canConcatenate(
|
|
1331
|
+
connection.dependency,
|
|
1332
|
+
concatenateCommonJsModules
|
|
1333
|
+
)
|
|
1154
1334
|
) {
|
|
1155
1335
|
return false;
|
|
1156
1336
|
}
|
|
@@ -1172,7 +1352,12 @@ class ConcatenatedModule extends Module {
|
|
|
1172
1352
|
(connection.dependency);
|
|
1173
1353
|
return {
|
|
1174
1354
|
connection,
|
|
1175
|
-
|
|
1355
|
+
// A require() edge carries no sourceOrder; Infinity sorts it last,
|
|
1356
|
+
// matching the low-priority sentinel. NaN must not be used here:
|
|
1357
|
+
// compareNumbers returns 0 against every number, which makes the
|
|
1358
|
+
// comparator non-transitive and the order depend on insertion order.
|
|
1359
|
+
sourceOrder:
|
|
1360
|
+
typeof dep.sourceOrder === "number" ? dep.sourceOrder : Infinity,
|
|
1176
1361
|
rangeStart: dep.range && dep.range[0],
|
|
1177
1362
|
defer: ImportPhaseUtils.isDefer(dep.phase)
|
|
1178
1363
|
};
|
|
@@ -1196,6 +1381,8 @@ class ConcatenatedModule extends Module {
|
|
|
1196
1381
|
references.sort(concatComparators(bySourceOrder, byRangeStart));
|
|
1197
1382
|
/** @type {Map<Module, { connection: ModuleGraphConnection, runtimeCondition: RuntimeSpec | true, nonDeferAccess: NonDeferAccess }>} */
|
|
1198
1383
|
const referencesMap = new Map();
|
|
1384
|
+
/** @type {Module[] | undefined} */
|
|
1385
|
+
let targets;
|
|
1199
1386
|
for (const { connection, defer } of references) {
|
|
1200
1387
|
const runtimeCondition = filterRuntime(runtime, (r) =>
|
|
1201
1388
|
connection.isTargetActive(r)
|
|
@@ -1203,6 +1390,17 @@ class ConcatenatedModule extends Module {
|
|
|
1203
1390
|
if (runtimeCondition === false) continue;
|
|
1204
1391
|
const nonDeferAccess = !defer;
|
|
1205
1392
|
const module = connection.module;
|
|
1393
|
+
if (targets === undefined) targets = [module];
|
|
1394
|
+
else if (!targets.includes(module)) targets.push(module);
|
|
1395
|
+
if (
|
|
1396
|
+
[
|
|
1397
|
+
CommonJsRequireDependency,
|
|
1398
|
+
CommonJsFullRequireDependency,
|
|
1399
|
+
CommonJsExportRequireDependency
|
|
1400
|
+
].some((Dep) => connection.dependency instanceof Dep)
|
|
1401
|
+
) {
|
|
1402
|
+
wrappedModules.add(module);
|
|
1403
|
+
}
|
|
1206
1404
|
const entry = referencesMap.get(module);
|
|
1207
1405
|
if (entry === undefined) {
|
|
1208
1406
|
referencesMap.set(module, {
|
|
@@ -1222,6 +1420,7 @@ class ConcatenatedModule extends Module {
|
|
|
1222
1420
|
nonDeferAccess
|
|
1223
1421
|
);
|
|
1224
1422
|
}
|
|
1423
|
+
if (targets !== undefined) importConnections.set(module, targets);
|
|
1225
1424
|
return referencesMap.values();
|
|
1226
1425
|
};
|
|
1227
1426
|
|
|
@@ -1269,6 +1468,7 @@ class ConcatenatedModule extends Module {
|
|
|
1269
1468
|
}
|
|
1270
1469
|
list.push({
|
|
1271
1470
|
type: "concatenated",
|
|
1471
|
+
wrapped: needWrapped(module),
|
|
1272
1472
|
module: connection.module,
|
|
1273
1473
|
runtimeCondition,
|
|
1274
1474
|
nonDeferAccess
|
|
@@ -1335,6 +1535,7 @@ class ConcatenatedModule extends Module {
|
|
|
1335
1535
|
}
|
|
1336
1536
|
list.push({
|
|
1337
1537
|
type: "external",
|
|
1538
|
+
wrapped: wrappedModules.has(connection.module),
|
|
1338
1539
|
get module() {
|
|
1339
1540
|
// We need to use a getter here, because the module in the dependency
|
|
1340
1541
|
// could be replaced by some other process (i. e. also replaced with a
|
|
@@ -1357,11 +1558,39 @@ class ConcatenatedModule extends Module {
|
|
|
1357
1558
|
}
|
|
1358
1559
|
list.push({
|
|
1359
1560
|
type: "concatenated",
|
|
1561
|
+
wrapped: needWrapped(rootModule),
|
|
1360
1562
|
module: rootModule,
|
|
1361
1563
|
runtimeCondition: true,
|
|
1362
1564
|
nonDeferAccess: true
|
|
1363
1565
|
});
|
|
1364
1566
|
|
|
1567
|
+
// A lazily evaluated member may only depend on lazily evaluated members,
|
|
1568
|
+
// so wrapping propagates forward from every `require()` target along all
|
|
1569
|
+
// import edges, ESM included.
|
|
1570
|
+
/** @type {Set<Module>} */
|
|
1571
|
+
const modules = new Set(wrappedModules);
|
|
1572
|
+
for (const entry of list) {
|
|
1573
|
+
if (entry.wrapped) modules.add(entry.module);
|
|
1574
|
+
}
|
|
1575
|
+
const queue = [...modules];
|
|
1576
|
+
for (let i = 0; i < queue.length; i++) {
|
|
1577
|
+
const targets = importConnections.get(queue[i]);
|
|
1578
|
+
if (targets === undefined) continue;
|
|
1579
|
+
for (const target of targets) {
|
|
1580
|
+
if (modules.has(target)) continue;
|
|
1581
|
+
modules.add(target);
|
|
1582
|
+
queue.push(target);
|
|
1583
|
+
}
|
|
1584
|
+
}
|
|
1585
|
+
for (const entry of list) {
|
|
1586
|
+
if (
|
|
1587
|
+
!entry.wrapped &&
|
|
1588
|
+
modules.has(entry.module) &&
|
|
1589
|
+
entryCanBeWrapped(entry)
|
|
1590
|
+
) {
|
|
1591
|
+
entry.wrapped = true;
|
|
1592
|
+
}
|
|
1593
|
+
}
|
|
1365
1594
|
return list;
|
|
1366
1595
|
}
|
|
1367
1596
|
|
|
@@ -1416,6 +1645,40 @@ class ConcatenatedModule extends Module {
|
|
|
1416
1645
|
}
|
|
1417
1646
|
}
|
|
1418
1647
|
|
|
1648
|
+
/*
|
|
1649
|
+
* How the inner modules become one flat source. Stages [1]-[5] only mutate the
|
|
1650
|
+
* per-module info records (names, ReplaceSource patches); stages [6]-[9] append
|
|
1651
|
+
* to the single output ConcatSource, in exactly the order shown.
|
|
1652
|
+
*
|
|
1653
|
+
* _getModulesWithInfo() — ordered concatenation list + one info per module
|
|
1654
|
+
* | (concatenated [+wrapped] | external | reference)
|
|
1655
|
+
* v
|
|
1656
|
+
* [1] ANALYSE — inner codeGeneration() per module, into a ConcatenationScope
|
|
1657
|
+
* | plain -> ReplaceSource + ast + scope analysis
|
|
1658
|
+
* | wrapped -> ReplaceSource only, body kept verbatim
|
|
1659
|
+
* | external -> nothing yet, rendered as a require() below
|
|
1660
|
+
* [2] RESERVE — free globals of the analysed bodies enter allUsedNames, so
|
|
1661
|
+
* | renaming in [3] can't shadow them (a wrapped body is not analysed;
|
|
1662
|
+
* | the reserved `__webpack_` prefix protects it)
|
|
1663
|
+
* [3] RENAME — module-scope variables renamed inside the ReplaceSource, then
|
|
1664
|
+
* | the generated names allocated: wrapper accessor, namespace object,
|
|
1665
|
+
* | interop helpers, external import variable
|
|
1666
|
+
* [4] LINK — __WEBPACK_MODULE_REFERENCE__ tokens replaced by their final
|
|
1667
|
+
* | binding; through the ast for analysed bodies, textually for wrapped
|
|
1668
|
+
* [5] COLLECT EXPORTS — root exports split into used / unused / inlined
|
|
1669
|
+
* v
|
|
1670
|
+
* ---- from here on everything is appended to the result ConcatSource ----
|
|
1671
|
+
* |
|
|
1672
|
+
* [6] EMIT EXPORTS — __esModule flag + exports getters, UNUSED/INLINED lists
|
|
1673
|
+
* [7] BUILD NS — namespace object sources built as strings (not emitted yet)
|
|
1674
|
+
* [8] DEFINE — everything that must exist before any body runs: namespace
|
|
1675
|
+
* | objects, wrapper accessors (wrapped modules and wrapped externals),
|
|
1676
|
+
* | deferred external loaders
|
|
1677
|
+
* [9] EVALUATE — bodies in concatenation order: plain bodies inline, externals
|
|
1678
|
+
* | as require(); a wrapped body stays behind its accessor
|
|
1679
|
+
* v
|
|
1680
|
+
* [10] RESULT — CodeGenerationResult { sources, data, runtimeRequirements }
|
|
1681
|
+
*/
|
|
1419
1682
|
/**
|
|
1420
1683
|
* Generates code and runtime requirements for this module.
|
|
1421
1684
|
* @param {CodeGenerationContext} context context for code generation
|
|
@@ -1439,12 +1702,39 @@ class ConcatenatedModule extends Module {
|
|
|
1439
1702
|
const runtime = intersectRuntime(generationRuntime, this._runtime);
|
|
1440
1703
|
|
|
1441
1704
|
const requestShortener = runtimeTemplate.requestShortener;
|
|
1442
|
-
// Meta info for each module
|
|
1705
|
+
// Meta info for each module, in evaluation order (repeats become references)
|
|
1443
1706
|
const [modulesWithInfo, moduleToInfoMap] = this._getModulesWithInfo(
|
|
1444
1707
|
moduleGraph,
|
|
1445
1708
|
runtime
|
|
1446
1709
|
);
|
|
1447
1710
|
|
|
1711
|
+
// This module's body is the root's body, so a wrapped root still evaluates
|
|
1712
|
+
// at its slot. No import edge inside the concatenation expresses that.
|
|
1713
|
+
const rootModuleInfo = moduleToInfoMap.get(this.rootModule);
|
|
1714
|
+
if (rootModuleInfo !== undefined) rootModuleInfo.eager = true;
|
|
1715
|
+
|
|
1716
|
+
// State shared by all stages below, in the order they are filled
|
|
1717
|
+
|
|
1718
|
+
// List of all used names to avoid conflicts
|
|
1719
|
+
const allUsedNames = new Set(RESERVED_NAMES);
|
|
1720
|
+
|
|
1721
|
+
// Updated Top level declarations are created by renaming
|
|
1722
|
+
/** @type {TopLevelDeclarations} */
|
|
1723
|
+
const topLevelDeclarations = new Set();
|
|
1724
|
+
|
|
1725
|
+
// Free names remaining in the rendered source (runtime globals are
|
|
1726
|
+
// tracked by runtimeRequirements instead)
|
|
1727
|
+
/** @type {Set<string>} */
|
|
1728
|
+
const freeNames = new Set();
|
|
1729
|
+
|
|
1730
|
+
// List of additional names in scope for module references
|
|
1731
|
+
/** @type {UsedNamesInScopeInfo} */
|
|
1732
|
+
const usedNamesInScopeInfo = new Map();
|
|
1733
|
+
|
|
1734
|
+
// Set of already checked scopes
|
|
1735
|
+
/** @type {Set<Scope>} */
|
|
1736
|
+
const ignoredScopes = new Set();
|
|
1737
|
+
|
|
1448
1738
|
// Set with modules that need a generated namespace object
|
|
1449
1739
|
/** @type {NeededNamespaceObjects} */
|
|
1450
1740
|
const neededNamespaceObjects = new Set();
|
|
@@ -1454,11 +1744,8 @@ class ConcatenatedModule extends Module {
|
|
|
1454
1744
|
/** @type {Set<ConcatenatedModuleInfo | ExternalModuleInfo>} */
|
|
1455
1745
|
const neededEscapeNamespaceObjects = new Set();
|
|
1456
1746
|
|
|
1457
|
-
//
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
// Generate source code and analyse scopes
|
|
1461
|
-
// Prepare a ReplaceSource for the final source
|
|
1747
|
+
// #region [1] ANALYSE: run each inner module's own codeGeneration; a
|
|
1748
|
+
// non-wrapped body is parsed and scope-analysed so [3] can rename its locals
|
|
1462
1749
|
for (const info of moduleToInfoMap.values()) {
|
|
1463
1750
|
this._analyseModule(
|
|
1464
1751
|
moduleToInfoMap,
|
|
@@ -1474,23 +1761,7 @@ class ConcatenatedModule extends Module {
|
|
|
1474
1761
|
allUsedNames
|
|
1475
1762
|
);
|
|
1476
1763
|
}
|
|
1477
|
-
|
|
1478
|
-
// Updated Top level declarations are created by renaming
|
|
1479
|
-
/** @type {TopLevelDeclarations} */
|
|
1480
|
-
const topLevelDeclarations = new Set();
|
|
1481
|
-
|
|
1482
|
-
// Free names remaining in the rendered source (runtime globals are
|
|
1483
|
-
// tracked by runtimeRequirements instead)
|
|
1484
|
-
/** @type {Set<string>} */
|
|
1485
|
-
const freeNames = new Set();
|
|
1486
|
-
|
|
1487
|
-
// List of additional names in scope for module references
|
|
1488
|
-
/** @type {UsedNamesInScopeInfo} */
|
|
1489
|
-
const usedNamesInScopeInfo = new Map();
|
|
1490
|
-
|
|
1491
|
-
// Set of already checked scopes
|
|
1492
|
-
/** @type {Set<Scope>} */
|
|
1493
|
-
const ignoredScopes = new Set();
|
|
1764
|
+
// #endregion
|
|
1494
1765
|
|
|
1495
1766
|
/**
|
|
1496
1767
|
* Lazily allocates a decoupled namespace object for a concatenated module
|
|
@@ -1501,12 +1772,22 @@ class ConcatenatedModule extends Module {
|
|
|
1501
1772
|
* @returns {string | undefined} the escape namespace object name
|
|
1502
1773
|
*/
|
|
1503
1774
|
const getEscapeNamespaceObjectName = (info) => {
|
|
1504
|
-
|
|
1775
|
+
// Only a hoisted member's namespaceExportSymbol is a real variable
|
|
1776
|
+
// holding the original names; a wrapped one reuses the field for its
|
|
1777
|
+
// `X_namespaceFn()` call, which exposes the mangled keys
|
|
1778
|
+
if (
|
|
1779
|
+
info.type === "concatenated" &&
|
|
1780
|
+
!info.wrapped &&
|
|
1781
|
+
info.namespaceExportSymbol
|
|
1782
|
+
) {
|
|
1505
1783
|
return undefined;
|
|
1506
1784
|
}
|
|
1785
|
+
|
|
1507
1786
|
// Deferred external modules keep their special deferred namespace object
|
|
1508
1787
|
// and are rendered through a different path that wouldn't emit ours.
|
|
1509
|
-
if (info.type === "external" && info.deferred)
|
|
1788
|
+
if (info.type === "external" && info.deferred) {
|
|
1789
|
+
return undefined;
|
|
1790
|
+
}
|
|
1510
1791
|
// Only real ES module namespaces are decoupled; non-harmony modules use
|
|
1511
1792
|
// their interop/fake namespace object as before.
|
|
1512
1793
|
const buildMeta = /** @type {BuildMeta} */ (info.module.buildMeta);
|
|
@@ -1539,118 +1820,129 @@ class ConcatenatedModule extends Module {
|
|
|
1539
1820
|
return name;
|
|
1540
1821
|
};
|
|
1541
1822
|
|
|
1542
|
-
//
|
|
1823
|
+
// #region [2] RESERVE: the free globals of every analysed body. Claiming
|
|
1824
|
+
// them up front is what lets [3] rename without shadowing any of them
|
|
1543
1825
|
for (const info of modulesWithInfo) {
|
|
1544
|
-
if (info.type === "concatenated"
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1826
|
+
if (info.type === "concatenated") {
|
|
1827
|
+
if (info.wrapped) {
|
|
1828
|
+
// The body is emitted verbatim and never renamed, so every identifier
|
|
1829
|
+
// in it is claimed: its declarations must not shadow a name [3]
|
|
1830
|
+
// generates, and its free globals must not be captured by one.
|
|
1831
|
+
for (const name of findIdentifiers(
|
|
1832
|
+
/** @type {Source} */ (info.internalSource)
|
|
1833
|
+
)) {
|
|
1834
|
+
allUsedNames.add(name);
|
|
1835
|
+
}
|
|
1836
|
+
// A wrapped body has no scope analysis, so its references are found
|
|
1837
|
+
// textually. They still have to be resolved here: binding one is what
|
|
1838
|
+
// flags the interop objects it needs, and [3] allocates their names.
|
|
1839
|
+
/** @type {Set<string>} */
|
|
1840
|
+
const visitedReferences = new Set();
|
|
1841
|
+
for (const reference of ConcatenationScope.findModuleReferences(
|
|
1842
|
+
/** @type {Source} */ (info.internalSource)
|
|
1843
|
+
)) {
|
|
1844
|
+
if (visitedReferences.has(reference.name)) continue;
|
|
1845
|
+
visitedReferences.add(reference.name);
|
|
1846
|
+
const match = ConcatenationScope.matchModuleReference(
|
|
1847
|
+
reference.name
|
|
1848
|
+
);
|
|
1849
|
+
if (!match) continue;
|
|
1850
|
+
const referencedInfo = modulesWithInfo[match.index];
|
|
1851
|
+
if (referencedInfo.type === "reference") {
|
|
1852
|
+
throw new Error("Module reference can't point to a reference");
|
|
1853
|
+
}
|
|
1568
1854
|
if (
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1855
|
+
match.mangleableNamespace &&
|
|
1856
|
+
match.ids.length === 0 &&
|
|
1857
|
+
getEscapeNamespaceObjectName(referencedInfo) !== undefined
|
|
1572
1858
|
) {
|
|
1573
|
-
|
|
1574
|
-
range: /** @type {Range} */ (block.superClass.range),
|
|
1575
|
-
variables: childScope.variables
|
|
1576
|
-
});
|
|
1859
|
+
continue;
|
|
1577
1860
|
}
|
|
1861
|
+
getFinalBinding(
|
|
1862
|
+
moduleGraph,
|
|
1863
|
+
referencedInfo,
|
|
1864
|
+
match.ids,
|
|
1865
|
+
moduleToInfoMap,
|
|
1866
|
+
runtime,
|
|
1867
|
+
requestShortener,
|
|
1868
|
+
runtimeTemplate,
|
|
1869
|
+
neededNamespaceObjects,
|
|
1870
|
+
match.call,
|
|
1871
|
+
match.deferredImport,
|
|
1872
|
+
/** @type {BuildMeta} */
|
|
1873
|
+
(info.module.buildMeta).strictHarmonyModule,
|
|
1874
|
+
match.asiSafe,
|
|
1875
|
+
match.moduleExportsAccess
|
|
1876
|
+
);
|
|
1877
|
+
}
|
|
1878
|
+
} else {
|
|
1879
|
+
// ignore symbols from moduleScope
|
|
1880
|
+
if (info.moduleScope) {
|
|
1881
|
+
ignoredScopes.add(info.moduleScope);
|
|
1578
1882
|
}
|
|
1579
|
-
superClassCache.set(scope, superClassExpressions);
|
|
1580
|
-
return superClassExpressions;
|
|
1581
|
-
};
|
|
1582
1883
|
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
match.ids.length === 0 &&
|
|
1600
|
-
(referencedInfo.type === "concatenated" ||
|
|
1601
|
-
referencedInfo.type === "external") &&
|
|
1602
|
-
getEscapeNamespaceObjectName(referencedInfo) !== undefined
|
|
1603
|
-
) {
|
|
1604
|
-
continue;
|
|
1605
|
-
}
|
|
1606
|
-
const binding = getFinalBinding(
|
|
1607
|
-
moduleGraph,
|
|
1608
|
-
referencedInfo,
|
|
1609
|
-
match.ids,
|
|
1610
|
-
moduleToInfoMap,
|
|
1611
|
-
runtime,
|
|
1612
|
-
requestShortener,
|
|
1613
|
-
runtimeTemplate,
|
|
1614
|
-
neededNamespaceObjects,
|
|
1615
|
-
false,
|
|
1616
|
-
match.deferredImport,
|
|
1617
|
-
/** @type {BuildMeta} */
|
|
1618
|
-
(info.module.buildMeta).strictHarmonyModule,
|
|
1619
|
-
true
|
|
1620
|
-
);
|
|
1621
|
-
if (!binding.ids) continue;
|
|
1622
|
-
const { usedNames, alreadyCheckedScopes } =
|
|
1623
|
-
getUsedNamesInScopeInfo(
|
|
1624
|
-
usedNamesInScopeInfo,
|
|
1625
|
-
binding.info.module.identifier(),
|
|
1626
|
-
"name" in binding ? binding.name : ""
|
|
1627
|
-
);
|
|
1628
|
-
for (const expr of getSuperClassExpressions(reference.from)) {
|
|
1884
|
+
// add global symbols
|
|
1885
|
+
if (info.unresolvedReferences) {
|
|
1886
|
+
for (const reference of info.unresolvedReferences) {
|
|
1887
|
+
const name = reference.identifier.name;
|
|
1888
|
+
if (ConcatenationScope.isModuleReference(name)) {
|
|
1889
|
+
const match = ConcatenationScope.matchModuleReference(name);
|
|
1890
|
+
if (!match) continue;
|
|
1891
|
+
const referencedInfo = modulesWithInfo[match.index];
|
|
1892
|
+
if (referencedInfo.type === "reference") {
|
|
1893
|
+
throw new Error(
|
|
1894
|
+
"Module reference can't point to a reference"
|
|
1895
|
+
);
|
|
1896
|
+
}
|
|
1897
|
+
// An escaping mangled namespace resolves to its own decoupled
|
|
1898
|
+
// namespace object (a unique top-level name), so it neither needs
|
|
1899
|
+
// the regular namespace object nor super-class scope handling.
|
|
1629
1900
|
if (
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
/** @type {Range} */ (reference.identifier.range)[1]
|
|
1901
|
+
match.mangleableNamespace &&
|
|
1902
|
+
match.ids.length === 0 &&
|
|
1903
|
+
getEscapeNamespaceObjectName(referencedInfo) !== undefined
|
|
1634
1904
|
) {
|
|
1635
|
-
|
|
1636
|
-
usedNames.add(variable.name);
|
|
1637
|
-
}
|
|
1905
|
+
continue;
|
|
1638
1906
|
}
|
|
1907
|
+
const binding = getFinalBinding(
|
|
1908
|
+
moduleGraph,
|
|
1909
|
+
referencedInfo,
|
|
1910
|
+
match.ids,
|
|
1911
|
+
moduleToInfoMap,
|
|
1912
|
+
runtime,
|
|
1913
|
+
requestShortener,
|
|
1914
|
+
runtimeTemplate,
|
|
1915
|
+
neededNamespaceObjects,
|
|
1916
|
+
false,
|
|
1917
|
+
match.deferredImport,
|
|
1918
|
+
/** @type {BuildMeta} */
|
|
1919
|
+
(info.module.buildMeta).strictHarmonyModule,
|
|
1920
|
+
true,
|
|
1921
|
+
match.moduleExportsAccess
|
|
1922
|
+
);
|
|
1923
|
+
if (!binding.ids) continue;
|
|
1924
|
+
const { usedNames, alreadyCheckedScopes } =
|
|
1925
|
+
getUsedNamesInScopeInfo(
|
|
1926
|
+
usedNamesInScopeInfo,
|
|
1927
|
+
binding.info.module.identifier(),
|
|
1928
|
+
"name" in binding ? binding.name : ""
|
|
1929
|
+
);
|
|
1930
|
+
addScopeSymbols(
|
|
1931
|
+
reference.from,
|
|
1932
|
+
usedNames,
|
|
1933
|
+
alreadyCheckedScopes,
|
|
1934
|
+
ignoredScopes
|
|
1935
|
+
);
|
|
1936
|
+
} else {
|
|
1937
|
+
allUsedNames.add(name);
|
|
1938
|
+
freeNames.add(name);
|
|
1639
1939
|
}
|
|
1640
|
-
addScopeSymbols(
|
|
1641
|
-
reference.from,
|
|
1642
|
-
usedNames,
|
|
1643
|
-
alreadyCheckedScopes,
|
|
1644
|
-
ignoredScopes
|
|
1645
|
-
);
|
|
1646
|
-
} else {
|
|
1647
|
-
allUsedNames.add(name);
|
|
1648
|
-
freeNames.add(name);
|
|
1649
1940
|
}
|
|
1650
1941
|
}
|
|
1651
1942
|
}
|
|
1652
1943
|
}
|
|
1653
1944
|
}
|
|
1945
|
+
// #endregion
|
|
1654
1946
|
|
|
1655
1947
|
/**
|
|
1656
1948
|
* @param {string} name the name to find a new name for
|
|
@@ -1722,7 +2014,9 @@ class ConcatenatedModule extends Module {
|
|
|
1722
2014
|
}
|
|
1723
2015
|
};
|
|
1724
2016
|
|
|
1725
|
-
//
|
|
2017
|
+
// #region [3] RENAME: rename every module-scope variable inside its
|
|
2018
|
+
// ReplaceSource, then allocate the generated names (wrapper accessor,
|
|
2019
|
+
// namespace object, interop helpers, external import variable)
|
|
1726
2020
|
for (const info of moduleToInfoMap.values()) {
|
|
1727
2021
|
const { usedNames: namespaceObjectUsedNames } = getUsedNamesInScopeInfo(
|
|
1728
2022
|
usedNamesInScopeInfo,
|
|
@@ -1731,82 +2025,85 @@ class ConcatenatedModule extends Module {
|
|
|
1731
2025
|
);
|
|
1732
2026
|
switch (info.type) {
|
|
1733
2027
|
case "concatenated": {
|
|
1734
|
-
if (info.
|
|
1735
|
-
//
|
|
1736
|
-
//
|
|
1737
|
-
|
|
1738
|
-
|
|
2028
|
+
if (info.wrapped) {
|
|
2029
|
+
// A wrapped module declares exactly one shared-scope name: the
|
|
2030
|
+
// lazy wrapper accessor holding its body. [2] claimed every
|
|
2031
|
+
// identifier of that body, so findNewName avoids the ones that
|
|
2032
|
+
// would shadow the accessor from inside it.
|
|
2033
|
+
const namespaceFnName = findNewName(
|
|
2034
|
+
"namespaceFn",
|
|
1739
2035
|
allUsedNames,
|
|
1740
2036
|
namespaceObjectUsedNames,
|
|
1741
2037
|
info.module.readableIdentifier(requestShortener)
|
|
1742
2038
|
);
|
|
1743
|
-
allUsedNames.add(
|
|
1744
|
-
topLevelDeclarations.add(
|
|
1745
|
-
info.
|
|
1746
|
-
//
|
|
1747
|
-
//
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
}
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
2039
|
+
allUsedNames.add(namespaceFnName);
|
|
2040
|
+
topLevelDeclarations.add(namespaceFnName);
|
|
2041
|
+
info.namespaceFnName = namespaceFnName;
|
|
2042
|
+
// Every reference — `require()` and ESM import alike — reads the
|
|
2043
|
+
// live exports object through the accessor, so the namespace is
|
|
2044
|
+
// the call itself, not a variable. Not a declared name.
|
|
2045
|
+
info.namespaceObjectName = `${namespaceFnName}()`;
|
|
2046
|
+
} else {
|
|
2047
|
+
const variables = /** @type {Scope} */ (info.moduleScope).variables;
|
|
2048
|
+
for (const variable of variables) {
|
|
2049
|
+
const name = variable.name;
|
|
2050
|
+
const references = getAllReferences(variable);
|
|
2051
|
+
const newName = _findNewName(name, info, references);
|
|
2052
|
+
if (newName) {
|
|
2053
|
+
const source = /** @type {ReplaceSource} */ (info.source);
|
|
2054
|
+
/** @type {Set<Identifier>} */
|
|
2055
|
+
const allIdentifiers = new Set();
|
|
2056
|
+
for (const r of references) allIdentifiers.add(r.identifier);
|
|
2057
|
+
for (const identifier of variable.identifiers) {
|
|
2058
|
+
allIdentifiers.add(identifier);
|
|
2059
|
+
}
|
|
2060
|
+
for (const identifier of allIdentifiers) {
|
|
2061
|
+
const r = /** @type {Range} */ (identifier.range);
|
|
2062
|
+
const path = getPathInAst(
|
|
2063
|
+
/** @type {NonNullable<ConcatenatedModuleInfo["ast"]>} */
|
|
2064
|
+
(info.ast),
|
|
2065
|
+
identifier
|
|
2066
|
+
);
|
|
2067
|
+
if (path && path.length > 1) {
|
|
2068
|
+
const maybeProperty =
|
|
2069
|
+
path[1].type === "AssignmentPattern" &&
|
|
2070
|
+
path[1].left === path[0]
|
|
2071
|
+
? path[2]
|
|
2072
|
+
: path[1];
|
|
2073
|
+
if (
|
|
2074
|
+
maybeProperty.type === "Property" &&
|
|
2075
|
+
maybeProperty.shorthand
|
|
2076
|
+
) {
|
|
2077
|
+
source.insert(r[1], `: ${newName}`);
|
|
2078
|
+
continue;
|
|
2079
|
+
}
|
|
1783
2080
|
}
|
|
2081
|
+
source.replace(r[0], r[1] - 1, newName);
|
|
1784
2082
|
}
|
|
1785
|
-
|
|
2083
|
+
} else {
|
|
2084
|
+
allUsedNames.add(name);
|
|
2085
|
+
info.internalNames.set(name, name);
|
|
2086
|
+
topLevelDeclarations.add(name);
|
|
1786
2087
|
}
|
|
2088
|
+
}
|
|
2089
|
+
/** @type {string} */
|
|
2090
|
+
let namespaceObjectName;
|
|
2091
|
+
if (info.namespaceExportSymbol) {
|
|
2092
|
+
namespaceObjectName =
|
|
2093
|
+
/** @type {string} */
|
|
2094
|
+
(info.internalNames.get(info.namespaceExportSymbol));
|
|
1787
2095
|
} else {
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
2096
|
+
namespaceObjectName = findNewName(
|
|
2097
|
+
"namespaceObject",
|
|
2098
|
+
allUsedNames,
|
|
2099
|
+
namespaceObjectUsedNames,
|
|
2100
|
+
info.module.readableIdentifier(requestShortener)
|
|
2101
|
+
);
|
|
2102
|
+
allUsedNames.add(namespaceObjectName);
|
|
1791
2103
|
}
|
|
2104
|
+
info.namespaceObjectName = namespaceObjectName;
|
|
2105
|
+
topLevelDeclarations.add(namespaceObjectName);
|
|
1792
2106
|
}
|
|
1793
|
-
/** @type {string} */
|
|
1794
|
-
let namespaceObjectName;
|
|
1795
|
-
if (info.namespaceExportSymbol) {
|
|
1796
|
-
namespaceObjectName =
|
|
1797
|
-
/** @type {string} */
|
|
1798
|
-
(info.internalNames.get(info.namespaceExportSymbol));
|
|
1799
|
-
} else {
|
|
1800
|
-
namespaceObjectName = findNewName(
|
|
1801
|
-
"namespaceObject",
|
|
1802
|
-
allUsedNames,
|
|
1803
|
-
namespaceObjectUsedNames,
|
|
1804
|
-
info.module.readableIdentifier(requestShortener)
|
|
1805
|
-
);
|
|
1806
|
-
allUsedNames.add(namespaceObjectName);
|
|
1807
|
-
}
|
|
1808
|
-
info.namespaceObjectName = namespaceObjectName;
|
|
1809
|
-
topLevelDeclarations.add(namespaceObjectName);
|
|
1810
2107
|
break;
|
|
1811
2108
|
}
|
|
1812
2109
|
case "external": {
|
|
@@ -1820,6 +2117,18 @@ class ConcatenatedModule extends Module {
|
|
|
1820
2117
|
info.name = externalName;
|
|
1821
2118
|
topLevelDeclarations.add(externalName);
|
|
1822
2119
|
|
|
2120
|
+
if (info.wrapped) {
|
|
2121
|
+
const namespaceFnName = findNewName(
|
|
2122
|
+
"namespaceFn",
|
|
2123
|
+
allUsedNames,
|
|
2124
|
+
namespaceObjectUsedNames,
|
|
2125
|
+
info.module.readableIdentifier(requestShortener)
|
|
2126
|
+
);
|
|
2127
|
+
allUsedNames.add(namespaceFnName);
|
|
2128
|
+
info.namespaceFnName = namespaceFnName;
|
|
2129
|
+
topLevelDeclarations.add(namespaceFnName);
|
|
2130
|
+
}
|
|
2131
|
+
|
|
1823
2132
|
if (info.deferred) {
|
|
1824
2133
|
const externalName = findNewName(
|
|
1825
2134
|
"deferred",
|
|
@@ -1883,15 +2192,20 @@ class ConcatenatedModule extends Module {
|
|
|
1883
2192
|
topLevelDeclarations.add(externalNameInterop);
|
|
1884
2193
|
}
|
|
1885
2194
|
}
|
|
2195
|
+
// #endregion
|
|
1886
2196
|
|
|
1887
|
-
//
|
|
2197
|
+
// #region [4] LINK: resolve each cross-module reference token to the final
|
|
2198
|
+
// name picked in [3] and patch it in. Must run after [3] — a reference can
|
|
2199
|
+
// only be resolved once its target has been named
|
|
1888
2200
|
for (const info of moduleToInfoMap.values()) {
|
|
1889
|
-
if (info.type
|
|
1890
|
-
|
|
2201
|
+
if (info.type !== "concatenated") continue;
|
|
2202
|
+
if (!info.wrapped) {
|
|
1891
2203
|
// group references by name
|
|
1892
2204
|
/** @type {Map<string, Reference[]>} */
|
|
1893
2205
|
const referencesByName = new Map();
|
|
1894
|
-
for (const reference of
|
|
2206
|
+
for (const reference of /** @type {Reference[]} */ (
|
|
2207
|
+
info.unresolvedReferences
|
|
2208
|
+
)) {
|
|
1895
2209
|
const name = reference.identifier.name;
|
|
1896
2210
|
let references = referencesByName.get(name);
|
|
1897
2211
|
if (references === undefined) {
|
|
@@ -1936,10 +2250,7 @@ class ConcatenatedModule extends Module {
|
|
|
1936
2250
|
// are mangled, point it at a decoupled namespace object that keeps
|
|
1937
2251
|
// the original names so untracked access keeps working.
|
|
1938
2252
|
const escapeName =
|
|
1939
|
-
match.mangleableNamespace &&
|
|
1940
|
-
match.ids.length === 0 &&
|
|
1941
|
-
(referencedInfo.type === "concatenated" ||
|
|
1942
|
-
referencedInfo.type === "external")
|
|
2253
|
+
match.mangleableNamespace && match.ids.length === 0
|
|
1943
2254
|
? getEscapeNamespaceObjectName(referencedInfo)
|
|
1944
2255
|
: undefined;
|
|
1945
2256
|
const finalName =
|
|
@@ -1959,7 +2270,8 @@ class ConcatenatedModule extends Module {
|
|
|
1959
2270
|
!match.directImport,
|
|
1960
2271
|
/** @type {BuildMeta} */
|
|
1961
2272
|
(info.module.buildMeta).strictHarmonyModule,
|
|
1962
|
-
match.asiSafe
|
|
2273
|
+
match.asiSafe,
|
|
2274
|
+
match.moduleExportsAccess
|
|
1963
2275
|
);
|
|
1964
2276
|
|
|
1965
2277
|
for (const reference of references) {
|
|
@@ -1970,9 +2282,64 @@ class ConcatenatedModule extends Module {
|
|
|
1970
2282
|
}
|
|
1971
2283
|
}
|
|
1972
2284
|
}
|
|
2285
|
+
} else {
|
|
2286
|
+
// Wrapped bodies are not re-parsed: find their reference tokens
|
|
2287
|
+
// textually. [2] scanned the same source, so this reuses its result.
|
|
2288
|
+
/** @type {Map<string, string>} */
|
|
2289
|
+
const finalNames = new Map();
|
|
2290
|
+
const source = /** @type {ReplaceSource} */ (info.source);
|
|
2291
|
+
for (const reference of ConcatenationScope.findModuleReferences(
|
|
2292
|
+
/** @type {Source} */ (info.internalSource)
|
|
2293
|
+
)) {
|
|
2294
|
+
let finalName = finalNames.get(reference.name);
|
|
2295
|
+
if (finalName === undefined) {
|
|
2296
|
+
const match = ConcatenationScope.matchModuleReference(
|
|
2297
|
+
reference.name
|
|
2298
|
+
);
|
|
2299
|
+
if (!match) continue;
|
|
2300
|
+
const referencedInfo = modulesWithInfo[match.index];
|
|
2301
|
+
if (referencedInfo.type === "reference") {
|
|
2302
|
+
throw new Error("Module reference can't point to a reference");
|
|
2303
|
+
}
|
|
2304
|
+
// Same escaping whole-namespace rule as the hoisted branch above: a
|
|
2305
|
+
// wrapped target resolves to its `X_namespaceFn()` exports object,
|
|
2306
|
+
// whose keys are the mangled ones.
|
|
2307
|
+
const escapeName =
|
|
2308
|
+
match.mangleableNamespace && match.ids.length === 0
|
|
2309
|
+
? getEscapeNamespaceObjectName(referencedInfo)
|
|
2310
|
+
: undefined;
|
|
2311
|
+
finalName =
|
|
2312
|
+
escapeName !== undefined
|
|
2313
|
+
? escapeName
|
|
2314
|
+
: getFinalName(
|
|
2315
|
+
moduleGraph,
|
|
2316
|
+
referencedInfo,
|
|
2317
|
+
match.ids,
|
|
2318
|
+
moduleToInfoMap,
|
|
2319
|
+
runtime,
|
|
2320
|
+
requestShortener,
|
|
2321
|
+
runtimeTemplate,
|
|
2322
|
+
neededNamespaceObjects,
|
|
2323
|
+
match.call,
|
|
2324
|
+
match.deferredImport,
|
|
2325
|
+
!match.directImport,
|
|
2326
|
+
/** @type {BuildMeta} */
|
|
2327
|
+
(info.module.buildMeta).strictHarmonyModule,
|
|
2328
|
+
match.asiSafe,
|
|
2329
|
+
match.moduleExportsAccess
|
|
2330
|
+
);
|
|
2331
|
+
finalNames.set(reference.name, finalName);
|
|
2332
|
+
}
|
|
2333
|
+
// token end is extended by 2 chars to cover the appended "._"
|
|
2334
|
+
source.replace(reference.start, reference.end + 1, finalName);
|
|
2335
|
+
}
|
|
1973
2336
|
}
|
|
1974
2337
|
}
|
|
2338
|
+
// #endregion
|
|
1975
2339
|
|
|
2340
|
+
// #region [5] COLLECT EXPORTS: split the root module's exports into used /
|
|
2341
|
+
// unused / inlined. Used ones stay thunks — resolving one can still
|
|
2342
|
+
// register a namespace object, which [7] must see
|
|
1976
2343
|
// Map with all root exposed used exports
|
|
1977
2344
|
/** @type {Map<string, (requestShortener: RequestShortener) => string>} */
|
|
1978
2345
|
const exportsMap = new Map();
|
|
@@ -2034,7 +2401,10 @@ class ConcatenatedModule extends Module {
|
|
|
2034
2401
|
}
|
|
2035
2402
|
});
|
|
2036
2403
|
}
|
|
2404
|
+
// #endregion
|
|
2037
2405
|
|
|
2406
|
+
// #region [6] EMIT EXPORTS: first thing in the output — the exports getters
|
|
2407
|
+
// must exist before any body runs, so circular importers see them
|
|
2038
2408
|
const result = new ConcatSource();
|
|
2039
2409
|
|
|
2040
2410
|
// add harmony compatibility flag (must be first because of possible circular dependencies)
|
|
@@ -2063,15 +2433,14 @@ class ConcatenatedModule extends Module {
|
|
|
2063
2433
|
runtimeRequirements.add(RuntimeGlobals.exports);
|
|
2064
2434
|
runtimeRequirements.add(RuntimeGlobals.definePropertyGetters);
|
|
2065
2435
|
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2436
|
+
// Goes with the definitions below: whoever takes those over emits both,
|
|
2437
|
+
// and the marker has to stay in front of them.
|
|
2438
|
+
const harmonyFlagSource = shouldAddHarmonyFlag
|
|
2439
|
+
? `// ESM COMPAT FLAG\n${runtimeTemplate.defineEsModuleFlagStatement({
|
|
2070
2440
|
exportsArgument: this.exportsArgument,
|
|
2071
2441
|
runtimeRequirements
|
|
2072
|
-
})
|
|
2073
|
-
|
|
2074
|
-
}
|
|
2442
|
+
})}`
|
|
2443
|
+
: "";
|
|
2075
2444
|
|
|
2076
2445
|
const exportsSource =
|
|
2077
2446
|
"\n// EXPORTS\n" +
|
|
@@ -2086,10 +2455,11 @@ class ConcatenatedModule extends Module {
|
|
|
2086
2455
|
!onDemandExportsGeneration.call(
|
|
2087
2456
|
this,
|
|
2088
2457
|
runtimes,
|
|
2089
|
-
exportsSource
|
|
2458
|
+
`${harmonyFlagSource}${exportsSource}`,
|
|
2090
2459
|
exportsFinalName
|
|
2091
2460
|
)
|
|
2092
2461
|
) {
|
|
2462
|
+
result.add(harmonyFlagSource);
|
|
2093
2463
|
result.add(exportsSource);
|
|
2094
2464
|
}
|
|
2095
2465
|
}
|
|
@@ -2107,7 +2477,12 @@ class ConcatenatedModule extends Module {
|
|
|
2107
2477
|
`\n// INLINED EXPORTS: ${joinIterableWithComma(inlinedExports)}\n`
|
|
2108
2478
|
);
|
|
2109
2479
|
}
|
|
2480
|
+
// #endregion
|
|
2110
2481
|
|
|
2482
|
+
// #region [7] BUILD NS: namespace object sources are built as strings here
|
|
2483
|
+
// and emitted by [8]; an external's is emitted next to its import variable
|
|
2484
|
+
// or accessor instead, which is defined later.
|
|
2485
|
+
//
|
|
2111
2486
|
// generate decoupled namespace objects for escaping mangled namespaces:
|
|
2112
2487
|
// same getters as the regular namespace object, but keyed by the original
|
|
2113
2488
|
// export names so untracked access by name keeps working. Done before the
|
|
@@ -2139,9 +2514,7 @@ class ConcatenatedModule extends Module {
|
|
|
2139
2514
|
// import variable; concatenated ones resolve to an internal binding.
|
|
2140
2515
|
const finalName =
|
|
2141
2516
|
info.type === "external"
|
|
2142
|
-
? `${
|
|
2143
|
-
usedName
|
|
2144
|
-
])}`
|
|
2517
|
+
? `${getExternalModuleExpr(info)}${propertyAccess([usedName])}`
|
|
2145
2518
|
: getFinalName(
|
|
2146
2519
|
moduleGraph,
|
|
2147
2520
|
info,
|
|
@@ -2192,50 +2565,41 @@ ${defineGetters}`
|
|
|
2192
2565
|
/** @type {Map<ConcatenatedModuleInfo, string>} */
|
|
2193
2566
|
const namespaceObjectSources = new Map();
|
|
2194
2567
|
for (const info of neededNamespaceObjects) {
|
|
2195
|
-
if (
|
|
2568
|
+
if (
|
|
2569
|
+
info.namespaceExportSymbol ||
|
|
2570
|
+
// Skip constructing namespace object generated for wrapped module
|
|
2571
|
+
info.wrapped
|
|
2572
|
+
) {
|
|
2573
|
+
continue;
|
|
2574
|
+
}
|
|
2196
2575
|
/** @type {string[]} */
|
|
2197
2576
|
const nsObj = [];
|
|
2198
2577
|
const exportsInfo = moduleGraph.getExportsInfo(info.module);
|
|
2199
2578
|
for (const exportInfo of exportsInfo.orderedExports) {
|
|
2200
2579
|
if (exportInfo.provided === false) continue;
|
|
2201
2580
|
const usedName = exportInfo.getUsedName(undefined, runtime);
|
|
2202
|
-
if (usedName) {
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
runtimeTemplate,
|
|
2225
|
-
neededNamespaceObjects,
|
|
2226
|
-
false,
|
|
2227
|
-
false,
|
|
2228
|
-
undefined,
|
|
2229
|
-
/** @type {BuildMeta} */
|
|
2230
|
-
(info.module.buildMeta).strictHarmonyModule,
|
|
2231
|
-
true
|
|
2232
|
-
);
|
|
2233
|
-
nsObj.push(
|
|
2234
|
-
`\n ${propertyName(
|
|
2235
|
-
usedName
|
|
2236
|
-
)}: ${runtimeTemplate.returningFunction(finalName)}`
|
|
2237
|
-
);
|
|
2238
|
-
}
|
|
2581
|
+
if (usedName && !(usedName instanceof InlinedUsedName)) {
|
|
2582
|
+
const finalName = getFinalName(
|
|
2583
|
+
moduleGraph,
|
|
2584
|
+
info,
|
|
2585
|
+
[exportInfo.name],
|
|
2586
|
+
moduleToInfoMap,
|
|
2587
|
+
runtime,
|
|
2588
|
+
requestShortener,
|
|
2589
|
+
runtimeTemplate,
|
|
2590
|
+
neededNamespaceObjects,
|
|
2591
|
+
false,
|
|
2592
|
+
false,
|
|
2593
|
+
undefined,
|
|
2594
|
+
/** @type {BuildMeta} */
|
|
2595
|
+
(info.module.buildMeta).strictHarmonyModule,
|
|
2596
|
+
true
|
|
2597
|
+
);
|
|
2598
|
+
nsObj.push(
|
|
2599
|
+
`\n ${propertyName(
|
|
2600
|
+
usedName
|
|
2601
|
+
)}: ${runtimeTemplate.returningFunction(finalName)}`
|
|
2602
|
+
);
|
|
2239
2603
|
}
|
|
2240
2604
|
}
|
|
2241
2605
|
const name = info.namespaceObjectName;
|
|
@@ -2258,20 +2622,92 @@ ${defineGetters}`
|
|
|
2258
2622
|
);
|
|
2259
2623
|
runtimeRequirements.add(RuntimeGlobals.makeNamespaceObject);
|
|
2260
2624
|
}
|
|
2625
|
+
// #endregion
|
|
2626
|
+
|
|
2627
|
+
// #region [8] DEFINE: define required namespace objects and wrapper
|
|
2628
|
+
// (must be before evaluation modules — a cycle member calls another's
|
|
2629
|
+
// accessor before that module's own position in the order)
|
|
2261
2630
|
|
|
2262
|
-
//
|
|
2631
|
+
// wrapper accessors are only called later, so their definitions may be
|
|
2632
|
+
// emitted in a stable order of their own instead of concatenation order
|
|
2633
|
+
/** @type {(ConcatenatedModuleInfo | ExternalModuleInfo)[]} */
|
|
2634
|
+
const wrappedInfos = [];
|
|
2263
2635
|
for (const info of modulesWithInfo) {
|
|
2636
|
+
if (
|
|
2637
|
+
(info.type === "concatenated" || info.type === "external") &&
|
|
2638
|
+
info.wrapped
|
|
2639
|
+
) {
|
|
2640
|
+
wrappedInfos.push(info);
|
|
2641
|
+
}
|
|
2642
|
+
}
|
|
2643
|
+
const compareWrappedModules = compareModulesByFullName(
|
|
2644
|
+
runtimeTemplate.compilation.compiler
|
|
2645
|
+
);
|
|
2646
|
+
wrappedInfos.sort((a, b) => compareWrappedModules(a.module, b.module));
|
|
2647
|
+
|
|
2648
|
+
for (const info of wrappedInfos) {
|
|
2264
2649
|
if (info.type === "concatenated") {
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2650
|
+
runtimeRequirements.add(RuntimeGlobals.concatenationWrap);
|
|
2651
|
+
result.add(
|
|
2652
|
+
`\n// MODULE: ${info.module.readableIdentifier(
|
|
2653
|
+
requestShortener
|
|
2654
|
+
)}\nvar ${info.namespaceFnName} = /*#__PURE__*/${
|
|
2655
|
+
RuntimeGlobals.concatenationWrap
|
|
2656
|
+
}(function(${info.module.moduleArgument}, ${
|
|
2657
|
+
info.module.exportsArgument
|
|
2658
|
+
}) {\n`
|
|
2659
|
+
);
|
|
2660
|
+
result.add(/** @type {ReplaceSource} */ (info.source));
|
|
2661
|
+
// A generated body (json, asset, html) binds its value to a local
|
|
2662
|
+
// instead of writing exports; hand that local to the accessor. The
|
|
2663
|
+
// name is verbatim: a wrapped body is not scope-analysed, so it keeps
|
|
2664
|
+
// the reserved symbol the generator registered.
|
|
2665
|
+
result.add(
|
|
2666
|
+
info.namespaceExportSymbol
|
|
2667
|
+
? `\n${info.module.moduleArgument}.exports = ${info.namespaceExportSymbol};\n});\n`
|
|
2668
|
+
: "\n});\n"
|
|
2669
|
+
);
|
|
2670
|
+
// its getters call the accessor lazily, so this may sit right after it
|
|
2671
|
+
const escapeSource = escapeNamespaceObjectSources.get(info);
|
|
2672
|
+
if (escapeSource) result.add(escapeSource);
|
|
2673
|
+
} else if (info.type === "external") {
|
|
2674
|
+
runtimeRequirements.add(RuntimeGlobals.require);
|
|
2675
|
+
const { runtimeCondition } = info;
|
|
2676
|
+
const condition = runtimeTemplate.runtimeConditionExpression({
|
|
2677
|
+
chunkGraph,
|
|
2678
|
+
runtimeCondition,
|
|
2679
|
+
runtime,
|
|
2680
|
+
runtimeRequirements
|
|
2681
|
+
});
|
|
2682
|
+
const moduleId = JSON.stringify(chunkGraph.getModuleId(info.module));
|
|
2683
|
+
const body =
|
|
2684
|
+
condition === "true"
|
|
2685
|
+
? `return ${RuntimeGlobals.require}(${moduleId});`
|
|
2686
|
+
: `if (${condition}) return ${RuntimeGlobals.require}(${moduleId});`;
|
|
2687
|
+
result.add(
|
|
2688
|
+
`\n// EXTERNAL MODULE: ${info.module.readableIdentifier(
|
|
2689
|
+
requestShortener
|
|
2690
|
+
)}\nvar ${info.namespaceFnName} = ${runtimeTemplate.basicFunction(
|
|
2691
|
+
"",
|
|
2692
|
+
body
|
|
2693
|
+
)};\n`
|
|
2269
2694
|
);
|
|
2695
|
+
const escapeSource = escapeNamespaceObjectSources.get(info);
|
|
2270
2696
|
if (escapeSource) result.add(escapeSource);
|
|
2271
|
-
if (!source && !escapeSource) continue;
|
|
2272
2697
|
}
|
|
2698
|
+
}
|
|
2273
2699
|
|
|
2274
|
-
|
|
2700
|
+
for (const info of modulesWithInfo) {
|
|
2701
|
+
if (info.type === "concatenated") {
|
|
2702
|
+
if (!info.wrapped) {
|
|
2703
|
+
const source = namespaceObjectSources.get(info);
|
|
2704
|
+
if (source) result.add(source);
|
|
2705
|
+
const escapeSource = escapeNamespaceObjectSources.get(
|
|
2706
|
+
/** @type {ConcatenatedModuleInfo} */ (info)
|
|
2707
|
+
);
|
|
2708
|
+
if (escapeSource) result.add(escapeSource);
|
|
2709
|
+
}
|
|
2710
|
+
} else if (info.type === "external" && info.deferred) {
|
|
2275
2711
|
const moduleId = JSON.stringify(chunkGraph.getModuleId(info.module));
|
|
2276
2712
|
const loader = getOptimizedDeferredModule(
|
|
2277
2713
|
moduleId,
|
|
@@ -2316,10 +2752,13 @@ ${defineGetters}`
|
|
|
2316
2752
|
}
|
|
2317
2753
|
}
|
|
2318
2754
|
|
|
2755
|
+
// #endregion
|
|
2756
|
+
|
|
2757
|
+
// #region [9] EVALUATE: emit the bodies in concatenation order and collect
|
|
2758
|
+
// what they need — runtime requirements, chunk init fragments, interop
|
|
2319
2759
|
/** @type {InitFragment<ChunkRenderContext>[]} */
|
|
2320
2760
|
const chunkInitFragments = [];
|
|
2321
2761
|
|
|
2322
|
-
// evaluate modules in order
|
|
2323
2762
|
for (const rawInfo of modulesWithInfo) {
|
|
2324
2763
|
/** @type {undefined | string} */
|
|
2325
2764
|
let name;
|
|
@@ -2327,35 +2766,47 @@ ${defineGetters}`
|
|
|
2327
2766
|
const info = rawInfo.type === "reference" ? rawInfo.target : rawInfo;
|
|
2328
2767
|
switch (info.type) {
|
|
2329
2768
|
case "concatenated": {
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
)
|
|
2333
|
-
|
|
2334
|
-
//
|
|
2335
|
-
// body with this = exports and returns the final module.exports.
|
|
2336
|
-
runtimeRequirements.add(RuntimeGlobals.commonJsWrap);
|
|
2769
|
+
name = info.namespaceObjectName;
|
|
2770
|
+
// wrapped bodies are emitted above, evaluated at their call sites
|
|
2771
|
+
if (info.wrapped && info.eager) {
|
|
2772
|
+
// This slot is the module's place in evaluation order; calling from
|
|
2773
|
+
// the importing body would run it too late.
|
|
2337
2774
|
result.add(
|
|
2338
|
-
|
|
2775
|
+
`\n;// ${info.module.readableIdentifier(
|
|
2776
|
+
requestShortener
|
|
2777
|
+
)}\n${info.namespaceFnName}();\n`
|
|
2778
|
+
);
|
|
2779
|
+
} else if (!info.wrapped) {
|
|
2780
|
+
result.add(
|
|
2781
|
+
`\n;// ${info.module.readableIdentifier(requestShortener)}\n`
|
|
2339
2782
|
);
|
|
2340
|
-
result.add(/** @type {ReplaceSource} */ (info.source));
|
|
2341
|
-
result.add("\n});\n");
|
|
2342
|
-
} else {
|
|
2343
2783
|
result.add(/** @type {ReplaceSource} */ (info.source));
|
|
2344
2784
|
}
|
|
2785
|
+
|
|
2345
2786
|
if (info.chunkInitFragments) {
|
|
2346
2787
|
for (const f of info.chunkInitFragments) chunkInitFragments.push(f);
|
|
2347
2788
|
}
|
|
2348
2789
|
if (info.runtimeRequirements) {
|
|
2349
2790
|
for (const r of info.runtimeRequirements) {
|
|
2791
|
+
// Wrapped module supplies module/exports/this itself
|
|
2792
|
+
if (
|
|
2793
|
+
info.wrapped &&
|
|
2794
|
+
(r === RuntimeGlobals.module ||
|
|
2795
|
+
r === RuntimeGlobals.exports ||
|
|
2796
|
+
r === RuntimeGlobals.thisAsExports)
|
|
2797
|
+
) {
|
|
2798
|
+
continue;
|
|
2799
|
+
}
|
|
2350
2800
|
runtimeRequirements.add(r);
|
|
2351
2801
|
}
|
|
2352
2802
|
}
|
|
2353
|
-
|
|
2803
|
+
|
|
2354
2804
|
break;
|
|
2355
2805
|
}
|
|
2356
2806
|
case "external": {
|
|
2357
|
-
|
|
2358
|
-
|
|
2807
|
+
name = getExternalModuleExpr(info);
|
|
2808
|
+
// deferred and wrapped cases are handled in the "const info of modulesWithInfo" loop above
|
|
2809
|
+
if (!info.deferred && !info.wrapped) {
|
|
2359
2810
|
result.add(
|
|
2360
2811
|
`\n// EXTERNAL MODULE: ${info.module.readableIdentifier(
|
|
2361
2812
|
requestShortener
|
|
@@ -2382,11 +2833,17 @@ ${defineGetters}`
|
|
|
2382
2833
|
// runtime-condition `if` blocks but referenced outside,
|
|
2383
2834
|
// so they must remain function-scoped (`var`).
|
|
2384
2835
|
result.add(`var ${info.name} = __webpack_require__(${moduleId});`);
|
|
2385
|
-
|
|
2836
|
+
|
|
2386
2837
|
// Decoupled namespace object for an escaping mangled external
|
|
2387
2838
|
// module must come after its import variable is defined.
|
|
2388
2839
|
const escapeSource = escapeNamespaceObjectSources.get(info);
|
|
2389
2840
|
if (escapeSource) result.add(escapeSource);
|
|
2841
|
+
} else if (info.wrapped && info.eager) {
|
|
2842
|
+
result.add(
|
|
2843
|
+
`\n;// EXTERNAL MODULE: ${info.module.readableIdentifier(
|
|
2844
|
+
requestShortener
|
|
2845
|
+
)}\n${info.namespaceFnName}();\n`
|
|
2846
|
+
);
|
|
2390
2847
|
}
|
|
2391
2848
|
// If a module is deferred in other places, but used as non-deferred here,
|
|
2392
2849
|
// the module itself will be emitted as mod_deferred (in the case "external"),
|
|
@@ -2394,7 +2851,7 @@ ${defineGetters}`
|
|
|
2394
2851
|
const { nonDeferAccess } =
|
|
2395
2852
|
/** @type {ExternalModuleInfo | ReferenceToModuleInfo} */
|
|
2396
2853
|
(rawInfo);
|
|
2397
|
-
if (info.deferred && nonDeferAccess) {
|
|
2854
|
+
if (info.deferred && nonDeferAccess && !info.wrapped) {
|
|
2398
2855
|
result.add(
|
|
2399
2856
|
`\n// non-deferred import to a deferred module (${info.module.readableIdentifier(
|
|
2400
2857
|
requestShortener
|
|
@@ -2407,29 +2864,54 @@ ${defineGetters}`
|
|
|
2407
2864
|
// @ts-expect-error never is expected here
|
|
2408
2865
|
throw new Error(`Unsupported concatenation entry type ${info.type}`);
|
|
2409
2866
|
}
|
|
2867
|
+
// Building a wrapped module's interop object here would evaluate its body
|
|
2868
|
+
// at the top level and break require() cycles, so defer it behind a
|
|
2869
|
+
// hoisted function. The memo lives on the function object: it keeps the
|
|
2870
|
+
// identity stable without claiming a second top-level name.
|
|
2871
|
+
/**
|
|
2872
|
+
* @param {string} interopName interop variable name
|
|
2873
|
+
* @param {string} expr interop object expression
|
|
2874
|
+
* @returns {string} the declaration
|
|
2875
|
+
*/
|
|
2876
|
+
const declareInterop = (interopName, expr) =>
|
|
2877
|
+
info.wrapped
|
|
2878
|
+
? `\nfunction ${interopName}() { return ${interopName}.c || (${interopName}.c = ${expr}); }`
|
|
2879
|
+
: `\nvar ${interopName} = /*#__PURE__*/${expr};`;
|
|
2410
2880
|
if (info.interopNamespaceObjectUsed) {
|
|
2411
2881
|
runtimeRequirements.add(RuntimeGlobals.createFakeNamespaceObject);
|
|
2412
2882
|
result.add(
|
|
2413
|
-
|
|
2883
|
+
declareInterop(
|
|
2884
|
+
/** @type {string} */ (info.interopNamespaceObjectName),
|
|
2885
|
+
`${RuntimeGlobals.createFakeNamespaceObject}(${name}, 2)`
|
|
2886
|
+
)
|
|
2414
2887
|
);
|
|
2415
2888
|
}
|
|
2416
2889
|
if (info.interopNamespaceObject2Used) {
|
|
2417
2890
|
runtimeRequirements.add(RuntimeGlobals.createFakeNamespaceObject);
|
|
2418
2891
|
result.add(
|
|
2419
|
-
|
|
2892
|
+
declareInterop(
|
|
2893
|
+
/** @type {string} */ (info.interopNamespaceObject2Name),
|
|
2894
|
+
`${RuntimeGlobals.createFakeNamespaceObject}(${name})`
|
|
2895
|
+
)
|
|
2420
2896
|
);
|
|
2421
2897
|
}
|
|
2422
2898
|
if (info.interopDefaultAccessUsed) {
|
|
2423
2899
|
runtimeRequirements.add(RuntimeGlobals.compatGetDefaultExport);
|
|
2424
2900
|
result.add(
|
|
2425
|
-
|
|
2901
|
+
declareInterop(
|
|
2902
|
+
/** @type {string} */ (info.interopDefaultAccessName),
|
|
2903
|
+
`${RuntimeGlobals.compatGetDefaultExport}(${name})`
|
|
2904
|
+
)
|
|
2426
2905
|
);
|
|
2427
2906
|
}
|
|
2428
2907
|
if (isConditional) {
|
|
2429
2908
|
result.add("\n}");
|
|
2430
2909
|
}
|
|
2431
2910
|
}
|
|
2911
|
+
// #endregion
|
|
2432
2912
|
|
|
2913
|
+
// #region [10] RESULT: topLevelDeclarations and freeNames let consumers
|
|
2914
|
+
// (mangling, an outer concatenation) reason about this source unparsed
|
|
2433
2915
|
/** @type {CodeGenerationResultData} */
|
|
2434
2916
|
const data = new Map();
|
|
2435
2917
|
if (chunkInitFragments.length > 0) {
|
|
@@ -2444,6 +2926,7 @@ ${defineGetters}`
|
|
|
2444
2926
|
data,
|
|
2445
2927
|
runtimeRequirements
|
|
2446
2928
|
};
|
|
2929
|
+
// #endregion
|
|
2447
2930
|
|
|
2448
2931
|
return resultEntry;
|
|
2449
2932
|
}
|
|
@@ -2474,43 +2957,17 @@ ${defineGetters}`
|
|
|
2474
2957
|
) {
|
|
2475
2958
|
if (info.type === "concatenated") {
|
|
2476
2959
|
const m = info.module;
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
// analysis — the wrapper isolates its top-level declarations.
|
|
2483
|
-
const codeGenResult = m.codeGeneration({
|
|
2484
|
-
dependencyTemplates,
|
|
2485
|
-
runtimeTemplate,
|
|
2486
|
-
moduleGraph,
|
|
2487
|
-
chunkGraph,
|
|
2488
|
-
runtime,
|
|
2489
|
-
runtimes,
|
|
2490
|
-
codeGenerationResults,
|
|
2491
|
-
sourceTypes: JAVASCRIPT_TYPES
|
|
2492
|
-
});
|
|
2493
|
-
const source =
|
|
2494
|
-
/** @type {Source} */
|
|
2495
|
-
(codeGenResult.sources.get(JAVASCRIPT_TYPE));
|
|
2496
|
-
const data = codeGenResult.data;
|
|
2497
|
-
info.runtimeRequirements =
|
|
2498
|
-
/** @type {ReadOnlyRuntimeRequirements} */
|
|
2499
|
-
(codeGenResult.runtimeRequirements);
|
|
2500
|
-
info.internalSource = source;
|
|
2501
|
-
info.source = new ReplaceSource(source);
|
|
2502
|
-
info.chunkInitFragments = data && data.get("chunkInitFragments");
|
|
2503
|
-
return;
|
|
2504
|
-
}
|
|
2505
|
-
// Create a concatenation scope to track and capture information
|
|
2960
|
+
if (info.wrapped) {
|
|
2961
|
+
// the wrapper isolates the body's top-level declarations, so no
|
|
2962
|
+
// renaming is needed -- only a concatenation scope, to rewrite in-scope
|
|
2963
|
+
// `require()` targets to accessor references. [2] claims its identifiers
|
|
2964
|
+
// textually in place of the scope analysis skipped here.
|
|
2506
2965
|
const concatenationScope = new ConcatenationScope(
|
|
2507
2966
|
modulesMap,
|
|
2508
2967
|
info,
|
|
2509
2968
|
usedNames
|
|
2510
2969
|
);
|
|
2511
|
-
|
|
2512
|
-
// Not cached: Compilation memoizes the outer codeGeneration per
|
|
2513
|
-
// (module, runtime), so inner generation never recomputes usefully.
|
|
2970
|
+
info.concatenationScope = concatenationScope;
|
|
2514
2971
|
const codeGenResult = m.codeGeneration({
|
|
2515
2972
|
dependencyTemplates,
|
|
2516
2973
|
runtimeTemplate,
|
|
@@ -2526,69 +2983,95 @@ ${defineGetters}`
|
|
|
2526
2983
|
/** @type {Source} */
|
|
2527
2984
|
(codeGenResult.sources.get(JAVASCRIPT_TYPE));
|
|
2528
2985
|
const data = codeGenResult.data;
|
|
2529
|
-
const chunkInitFragments = data && data.get("chunkInitFragments");
|
|
2530
|
-
const code = source.source().toString();
|
|
2531
|
-
|
|
2532
|
-
/** @type {Program} */
|
|
2533
|
-
let ast;
|
|
2534
|
-
|
|
2535
|
-
try {
|
|
2536
|
-
const { experiments } = this.compilation.options;
|
|
2537
|
-
|
|
2538
|
-
({ ast } = JavascriptParser._parse(
|
|
2539
|
-
code,
|
|
2540
|
-
{
|
|
2541
|
-
sourceType: "module",
|
|
2542
|
-
ranges: true,
|
|
2543
|
-
// generated code contains phase imports when the experiments are on
|
|
2544
|
-
importPhases: Boolean(
|
|
2545
|
-
experiments.deferImport || experiments.sourceImport
|
|
2546
|
-
)
|
|
2547
|
-
},
|
|
2548
|
-
JavascriptParser._getModuleParseFunction(this.compilation, m)
|
|
2549
|
-
));
|
|
2550
|
-
} catch (_err) {
|
|
2551
|
-
const err =
|
|
2552
|
-
/** @type {Error & { loc?: { line: number, column: number } }} */
|
|
2553
|
-
(_err);
|
|
2554
|
-
if (
|
|
2555
|
-
err.loc &&
|
|
2556
|
-
typeof err.loc === "object" &&
|
|
2557
|
-
typeof err.loc.line === "number"
|
|
2558
|
-
) {
|
|
2559
|
-
const lineNumber = err.loc.line;
|
|
2560
|
-
const lines = code.split("\n");
|
|
2561
|
-
err.message += `\n| ${lines
|
|
2562
|
-
.slice(Math.max(0, lineNumber - 3), lineNumber + 2)
|
|
2563
|
-
.join("\n| ")}`;
|
|
2564
|
-
}
|
|
2565
|
-
throw err;
|
|
2566
|
-
}
|
|
2567
|
-
const scopeManager = eslintScope.analyze(ast, {
|
|
2568
|
-
ecmaVersion: 6,
|
|
2569
|
-
sourceType: "module",
|
|
2570
|
-
optimistic: true,
|
|
2571
|
-
ignoreEval: true,
|
|
2572
|
-
impliedStrict: true
|
|
2573
|
-
});
|
|
2574
|
-
const globalScope = /** @type {Scope} */ (scopeManager.acquire(ast));
|
|
2575
|
-
const moduleScope = globalScope.childScopes[0];
|
|
2576
|
-
const resultSource = new ReplaceSource(source);
|
|
2577
2986
|
info.runtimeRequirements =
|
|
2578
2987
|
/** @type {ReadOnlyRuntimeRequirements} */
|
|
2579
2988
|
(codeGenResult.runtimeRequirements);
|
|
2580
|
-
info.ast = ast;
|
|
2581
2989
|
info.internalSource = source;
|
|
2582
|
-
info.source =
|
|
2583
|
-
info.chunkInitFragments = chunkInitFragments;
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2990
|
+
info.source = new ReplaceSource(source);
|
|
2991
|
+
info.chunkInitFragments = data && data.get("chunkInitFragments");
|
|
2992
|
+
} else {
|
|
2993
|
+
try {
|
|
2994
|
+
// Create a concatenation scope to track and capture information
|
|
2995
|
+
const concatenationScope = new ConcatenationScope(
|
|
2996
|
+
modulesMap,
|
|
2997
|
+
info,
|
|
2998
|
+
usedNames
|
|
2999
|
+
);
|
|
3000
|
+
|
|
3001
|
+
// Not cached: Compilation memoizes the outer codeGeneration per
|
|
3002
|
+
// (module, runtime), so inner generation never recomputes usefully.
|
|
3003
|
+
const codeGenResult = m.codeGeneration({
|
|
3004
|
+
dependencyTemplates,
|
|
3005
|
+
runtimeTemplate,
|
|
3006
|
+
moduleGraph,
|
|
3007
|
+
chunkGraph,
|
|
3008
|
+
runtime,
|
|
3009
|
+
runtimes,
|
|
3010
|
+
concatenationScope,
|
|
3011
|
+
codeGenerationResults,
|
|
3012
|
+
sourceTypes: JAVASCRIPT_TYPES
|
|
3013
|
+
});
|
|
3014
|
+
const source =
|
|
3015
|
+
/** @type {Source} */
|
|
3016
|
+
(codeGenResult.sources.get(JAVASCRIPT_TYPE));
|
|
3017
|
+
const data = codeGenResult.data;
|
|
3018
|
+
const chunkInitFragments = data && data.get("chunkInitFragments");
|
|
3019
|
+
const code = source.source().toString();
|
|
3020
|
+
|
|
3021
|
+
/** @type {Program} */
|
|
3022
|
+
let ast;
|
|
3023
|
+
|
|
3024
|
+
try {
|
|
3025
|
+
const { experiments } = this.compilation.options;
|
|
3026
|
+
|
|
3027
|
+
({ ast } = JavascriptParser._parse(
|
|
3028
|
+
code,
|
|
3029
|
+
{
|
|
3030
|
+
sourceType: "module",
|
|
3031
|
+
ranges: true,
|
|
3032
|
+
// generated code contains phase imports when the experiments are on
|
|
3033
|
+
importPhases: Boolean(
|
|
3034
|
+
experiments.deferImport || experiments.sourceImport
|
|
3035
|
+
)
|
|
3036
|
+
},
|
|
3037
|
+
JavascriptParser._getModuleParseFunction(this.compilation, m)
|
|
3038
|
+
));
|
|
3039
|
+
} catch (_err) {
|
|
3040
|
+
const err =
|
|
3041
|
+
/** @type {Error & { loc?: { line: number, column: number } }} */
|
|
3042
|
+
(_err);
|
|
3043
|
+
if (
|
|
3044
|
+
err.loc &&
|
|
3045
|
+
typeof err.loc === "object" &&
|
|
3046
|
+
typeof err.loc.line === "number"
|
|
3047
|
+
) {
|
|
3048
|
+
const lineNumber = err.loc.line;
|
|
3049
|
+
const lines = code.split("\n");
|
|
3050
|
+
err.message += `\n| ${lines
|
|
3051
|
+
.slice(Math.max(0, lineNumber - 3), lineNumber + 2)
|
|
3052
|
+
.join("\n| ")}`;
|
|
3053
|
+
}
|
|
3054
|
+
throw err;
|
|
3055
|
+
}
|
|
3056
|
+
const analysis = analyzeScope(ast);
|
|
3057
|
+
const resultSource = new ReplaceSource(source);
|
|
3058
|
+
info.runtimeRequirements =
|
|
3059
|
+
/** @type {ReadOnlyRuntimeRequirements} */
|
|
3060
|
+
(codeGenResult.runtimeRequirements);
|
|
3061
|
+
info.ast = ast;
|
|
3062
|
+
info.internalSource = source;
|
|
3063
|
+
info.source = resultSource;
|
|
3064
|
+
info.chunkInitFragments = chunkInitFragments;
|
|
3065
|
+
info.globalScope = analysis.globalScope;
|
|
3066
|
+
info.moduleScope = analysis.moduleScope;
|
|
3067
|
+
info.unresolvedReferences = analysis.unresolvedReferences;
|
|
3068
|
+
info.concatenationScope = concatenationScope;
|
|
3069
|
+
} catch (err) {
|
|
3070
|
+
/** @type {Error} */
|
|
3071
|
+
(err).message +=
|
|
3072
|
+
`\nwhile analyzing module ${m.identifier()} for concatenation`;
|
|
3073
|
+
throw err;
|
|
3074
|
+
}
|
|
2592
3075
|
}
|
|
2593
3076
|
}
|
|
2594
3077
|
}
|
|
@@ -2614,17 +3097,18 @@ ${defineGetters}`
|
|
|
2614
3097
|
case "concatenated":
|
|
2615
3098
|
item = {
|
|
2616
3099
|
type: "concatenated",
|
|
3100
|
+
wrapped: info.wrapped,
|
|
3101
|
+
eager: false,
|
|
2617
3102
|
module: info.module,
|
|
2618
3103
|
index,
|
|
2619
|
-
|
|
2620
|
-
/** @type {NormalModule} */ (info.module)
|
|
2621
|
-
),
|
|
3104
|
+
namespaceFnName: undefined,
|
|
2622
3105
|
ast: undefined,
|
|
2623
3106
|
chunkInitFragments: undefined,
|
|
2624
3107
|
internalSource: undefined,
|
|
2625
3108
|
runtimeRequirements: undefined,
|
|
2626
3109
|
source: undefined,
|
|
2627
3110
|
globalScope: undefined,
|
|
3111
|
+
unresolvedReferences: undefined,
|
|
2628
3112
|
moduleScope: undefined,
|
|
2629
3113
|
internalNames: new Map(),
|
|
2630
3114
|
exportMap: undefined,
|
|
@@ -2646,11 +3130,14 @@ ${defineGetters}`
|
|
|
2646
3130
|
case "external":
|
|
2647
3131
|
item = {
|
|
2648
3132
|
type: "external",
|
|
3133
|
+
wrapped: info.wrapped,
|
|
3134
|
+
eager: false,
|
|
2649
3135
|
module: info.module,
|
|
2650
3136
|
runtimeCondition: info.runtimeCondition,
|
|
2651
3137
|
nonDeferAccess: info.nonDeferAccess,
|
|
2652
3138
|
index,
|
|
2653
3139
|
name: undefined,
|
|
3140
|
+
namespaceFnName: undefined,
|
|
2654
3141
|
escapeNamespaceObjectName: undefined,
|
|
2655
3142
|
deferredName: undefined,
|
|
2656
3143
|
interopNamespaceObjectUsed: false,
|
|
@@ -2761,4 +3248,32 @@ ConcatenatedModule.getCompilationHooks = createHooksRegistry(
|
|
|
2761
3248
|
|
|
2762
3249
|
makeSerializable(ConcatenatedModule, "webpack/lib/optimize/ConcatenatedModule");
|
|
2763
3250
|
|
|
3251
|
+
/** @type {WeakMap<Compilation, WeakMap<Module, ConcatenatedModule>>} */
|
|
3252
|
+
const absorbedBy = new WeakMap();
|
|
3253
|
+
|
|
3254
|
+
/**
|
|
3255
|
+
* The module the chunk graph holds for `module`: concatenation replaces every module
|
|
3256
|
+
* it absorbs with one `ConcatenatedModule`, so an absorbed module is itself in no
|
|
3257
|
+
* chunk and no runtime, and asking the chunk graph about it answers about nothing.
|
|
3258
|
+
* @param {Compilation} compilation the compilation
|
|
3259
|
+
* @param {Module} module a module, possibly absorbed by concatenation
|
|
3260
|
+
* @returns {Module} the module the chunk graph holds, or `module` itself
|
|
3261
|
+
*/
|
|
3262
|
+
ConcatenatedModule.getChunkGraphModule = (compilation, module) => {
|
|
3263
|
+
let map = absorbedBy.get(compilation);
|
|
3264
|
+
if (map === undefined) {
|
|
3265
|
+
map = new WeakMap();
|
|
3266
|
+
for (const candidate of compilation.modules) {
|
|
3267
|
+
if (candidate instanceof ConcatenatedModule) {
|
|
3268
|
+
for (const inner of candidate._modules) {
|
|
3269
|
+
map.set(inner, candidate);
|
|
3270
|
+
}
|
|
3271
|
+
}
|
|
3272
|
+
}
|
|
3273
|
+
absorbedBy.set(compilation, map);
|
|
3274
|
+
}
|
|
3275
|
+
const outer = map.get(module);
|
|
3276
|
+
return outer === undefined ? module : outer;
|
|
3277
|
+
};
|
|
3278
|
+
|
|
2764
3279
|
module.exports = ConcatenatedModule;
|