webpack 5.107.2 → 5.108.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/hot/dev-server.js +2 -0
- package/lib/APIPlugin.js +8 -4
- package/lib/CacheFacade.js +7 -0
- package/lib/Chunk.js +4 -0
- package/lib/ChunkGraph.js +30 -9
- package/lib/CircularModulesPlugin.js +190 -0
- package/lib/CleanPlugin.js +2 -1
- package/lib/Compilation.js +396 -65
- package/lib/Compiler.js +25 -11
- package/lib/ConcatenationScope.js +10 -3
- package/lib/ContextExclusionPlugin.js +1 -0
- package/lib/ContextModule.js +92 -47
- package/lib/ContextReplacementPlugin.js +4 -0
- package/lib/DefinePlugin.js +89 -15
- package/lib/Dependency.js +111 -7
- package/lib/EntryOptionPlugin.js +39 -2
- package/lib/EntryPlugin.js +2 -0
- package/lib/ExportsInfo.js +314 -73
- package/lib/ExternalModule.js +82 -34
- package/lib/ExternalModuleFactoryPlugin.js +1 -0
- package/lib/ExternalsPlugin.js +1 -0
- package/lib/FileSystemInfo.js +173 -23
- package/lib/FlagAllModulesAsUsedPlugin.js +1 -5
- package/lib/FlagDependencyExportsPlugin.js +23 -0
- package/lib/FlagDependencyUsagePlugin.js +87 -5
- package/lib/FlagEntryExportAsUsedPlugin.js +2 -0
- package/lib/Generator.js +8 -0
- package/lib/HotModuleReplacementPlugin.js +65 -28
- package/lib/IgnorePlugin.js +1 -0
- package/lib/InitFragment.js +5 -0
- package/lib/JavascriptMetaInfoPlugin.js +7 -5
- package/lib/LazyBarrel.js +361 -0
- package/lib/LoaderTargetPlugin.js +1 -0
- package/lib/Module.js +21 -42
- package/lib/ModuleGraph.js +3 -2
- package/lib/ModuleProfile.js +27 -1
- package/lib/ModuleTemplate.js +2 -0
- package/lib/MultiCompiler.js +2 -0
- package/lib/MultiStats.js +1 -0
- package/lib/MultiWatching.js +2 -0
- package/lib/NodeStuffPlugin.js +22 -17
- package/lib/NormalModule.js +142 -80
- package/lib/NormalModuleReplacementPlugin.js +2 -0
- package/lib/PrefetchPlugin.js +2 -0
- package/lib/ProgressPlugin.js +8 -0
- package/lib/ProvidePlugin.js +1 -0
- package/lib/RawModule.js +20 -16
- package/lib/RecordIdsPlugin.js +1 -0
- package/lib/RuntimeGlobals.js +5 -0
- package/lib/RuntimePlugin.js +58 -26
- package/lib/RuntimeTemplate.js +278 -21
- package/lib/SelfModuleFactory.js +1 -0
- package/lib/SourceMapDevToolPlugin.js +3 -5
- package/lib/Stats.js +1 -0
- package/lib/Template.js +8 -2
- package/lib/TemplatedPathPlugin.js +473 -131
- package/lib/WarnCaseSensitiveModulesPlugin.js +1 -0
- package/lib/WarnDeprecatedOptionPlugin.js +4 -0
- package/lib/WarnNoModeSetPlugin.js +1 -0
- package/lib/WatchIgnorePlugin.js +1 -0
- package/lib/Watching.js +9 -0
- package/lib/WebpackOptionsApply.js +50 -5
- package/lib/asset/AssetBytesGenerator.js +11 -3
- package/lib/asset/AssetGenerator.js +47 -22
- package/lib/asset/AssetModule.js +47 -0
- package/lib/asset/AssetModulesPlugin.js +14 -14
- package/lib/asset/AssetParser.js +2 -2
- package/lib/asset/AssetSourceGenerator.js +8 -0
- package/lib/asset/RawDataUrlModule.js +12 -13
- package/lib/buildChunkGraph.js +64 -7
- package/lib/bun/BunTargetPlugin.js +48 -0
- package/lib/cache/AddBuildDependenciesPlugin.js +1 -0
- package/lib/cache/AddManagedPathsPlugin.js +3 -0
- package/lib/cache/IdleFileCachePlugin.js +4 -0
- package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
- package/lib/cache/PackFileCacheStrategy.js +1 -0
- package/lib/cache/ResolverCachePlugin.js +2 -0
- package/lib/cache/mergeEtags.js +2 -0
- package/lib/cli.js +109 -19
- package/lib/config/browserslistTargetHandler.js +99 -0
- package/lib/config/defaults.js +147 -7
- package/lib/config/defineConfig.js +31 -0
- package/lib/config/normalization.js +5 -0
- package/lib/config/target.js +181 -2
- package/lib/container/ContainerEntryModule.js +15 -14
- package/lib/container/ContainerExposedDependency.js +2 -2
- package/lib/container/ContainerReferencePlugin.js +1 -1
- package/lib/container/FallbackDependency.js +5 -7
- package/lib/container/FallbackModule.js +10 -9
- package/lib/container/RemoteModule.js +20 -10
- package/lib/container/RemoteRuntimeModule.js +14 -12
- package/lib/css/CssGenerator.js +353 -327
- package/lib/css/CssInjectStyleRuntimeModule.js +36 -8
- package/lib/css/CssLoadingRuntimeModule.js +118 -47
- package/lib/css/CssModule.js +52 -23
- package/lib/css/CssModulesPlugin.js +107 -124
- package/lib/css/CssParser.js +2759 -2205
- package/lib/css/syntax.js +2859 -0
- package/lib/debug/ProfilingPlugin.js +2 -0
- package/lib/deno/DenoTargetPlugin.js +47 -0
- package/lib/dependencies/AMDDefineDependency.js +22 -17
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +1 -0
- package/lib/dependencies/AMDRequireArrayDependency.js +7 -11
- package/lib/dependencies/AMDRequireContextDependency.js +7 -11
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +1 -0
- package/lib/dependencies/AMDRequireDependency.js +24 -20
- package/lib/dependencies/CachedConstDependency.js +3 -0
- package/lib/dependencies/CommonJsDependencyHelpers.js +1 -0
- package/lib/dependencies/CommonJsExportRequireDependency.js +79 -31
- package/lib/dependencies/CommonJsExportsDependency.js +21 -16
- package/lib/dependencies/CommonJsExportsParserPlugin.js +230 -7
- package/lib/dependencies/CommonJsFullRequireDependency.js +27 -19
- package/lib/dependencies/CommonJsImportsParserPlugin.js +51 -16
- package/lib/dependencies/CommonJsPlugin.js +1 -1
- package/lib/dependencies/CommonJsRequireContextDependency.js +10 -13
- package/lib/dependencies/CommonJsRequireDependency.js +42 -11
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +22 -14
- package/lib/dependencies/ConstDependency.js +16 -11
- package/lib/dependencies/ContextDependency.js +4 -0
- package/lib/dependencies/ContextDependencyTemplateAsId.js +1 -1
- package/lib/dependencies/ContextElementDependency.js +23 -14
- package/lib/dependencies/CreateRequireParserPlugin.js +1 -0
- package/lib/dependencies/CreateScriptUrlDependency.js +5 -7
- package/lib/dependencies/CriticalDependencyWarning.js +1 -0
- package/lib/dependencies/CssIcssExportDependency.js +512 -574
- package/lib/dependencies/CssIcssImportDependency.js +9 -9
- package/lib/dependencies/CssIcssSymbolDependency.js +22 -15
- package/lib/dependencies/CssImportDependency.js +25 -1
- package/lib/dependencies/CssUrlDependency.js +23 -14
- package/lib/dependencies/DllEntryDependency.js +9 -13
- package/lib/dependencies/ExportBindingInitFragment.js +164 -0
- package/lib/dependencies/ExportsInfoDependency.js +12 -12
- package/lib/dependencies/ExternalModuleDependency.js +8 -5
- package/lib/dependencies/ExternalModuleInitFragment.js +7 -5
- package/lib/dependencies/ExternalModuleInitFragmentDependency.js +13 -10
- package/lib/dependencies/HarmonyAcceptDependency.js +11 -11
- package/lib/dependencies/HarmonyAcceptImportDependency.js +1 -0
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +47 -22
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +28 -2
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +46 -22
- package/lib/dependencies/HarmonyExportExpressionDependency.js +107 -30
- package/lib/dependencies/HarmonyExportHeaderDependency.js +7 -9
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +109 -31
- package/lib/dependencies/HarmonyExportInitFragment.js +18 -15
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +83 -18
- package/lib/dependencies/HarmonyExports.js +4 -1
- package/lib/dependencies/HarmonyImportDependency.js +24 -0
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +110 -74
- package/lib/dependencies/HarmonyImportGuard.js +254 -0
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +18 -1
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +118 -14
- package/lib/dependencies/HarmonyLinkingError.js +1 -0
- package/lib/dependencies/HarmonyModulesPlugin.js +1 -0
- package/lib/dependencies/{HtmlScriptSrcDependency.js → HtmlEntryDependency.js} +261 -109
- package/lib/dependencies/HtmlInlineHtmlDependency.js +107 -0
- package/lib/dependencies/HtmlInlineScriptDependency.js +17 -13
- package/lib/dependencies/HtmlInlineStyleDependency.js +45 -11
- package/lib/dependencies/ImportContextDependency.js +5 -9
- package/lib/dependencies/ImportDependency.js +44 -2
- package/lib/dependencies/ImportMetaHotAcceptDependency.js +1 -0
- package/lib/dependencies/ImportMetaHotDeclineDependency.js +1 -0
- package/lib/dependencies/ImportMetaPlugin.js +74 -30
- package/lib/dependencies/ImportParserPlugin.js +19 -0
- package/lib/dependencies/ImportWeakDependency.js +1 -0
- package/lib/dependencies/JsonExportsDependency.js +9 -9
- package/lib/dependencies/LoaderImportDependency.js +1 -0
- package/lib/dependencies/LocalModule.js +11 -12
- package/lib/dependencies/LocalModuleDependency.js +11 -13
- package/lib/dependencies/ModuleDecoratorDependency.js +9 -9
- package/lib/dependencies/ModuleDependency.js +7 -0
- package/lib/dependencies/ModuleHotAcceptDependency.js +1 -0
- package/lib/dependencies/ModuleHotDeclineDependency.js +1 -0
- package/lib/dependencies/ModuleInitFragmentDependency.js +15 -11
- package/lib/dependencies/ProvidedDependency.js +31 -27
- package/lib/dependencies/PureExpressionDependency.js +7 -9
- package/lib/dependencies/RequireEnsureDependency.js +12 -13
- package/lib/dependencies/RequireHeaderDependency.js +3 -4
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +3 -0
- package/lib/dependencies/RequireResolveContextDependency.js +7 -11
- package/lib/dependencies/RequireResolveDependency.js +1 -0
- package/lib/dependencies/RequireResolveHeaderDependency.js +3 -5
- package/lib/dependencies/RuntimeRequirementsDependency.js +6 -7
- package/lib/dependencies/StaticExportsDependency.js +10 -10
- package/lib/dependencies/SystemPlugin.js +2 -0
- package/lib/dependencies/URLContextDependency.js +5 -7
- package/lib/dependencies/URLDependency.js +14 -16
- package/lib/dependencies/UnsupportedDependency.js +8 -13
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +11 -16
- package/lib/dependencies/WebAssemblyImportDependency.js +14 -16
- package/lib/dependencies/WebpackIsIncludedDependency.js +1 -0
- package/lib/dependencies/WorkerDependency.js +19 -8
- package/lib/dependencies/WorkerPlugin.js +22 -6
- package/lib/dependencies/processExportInfo.js +13 -11
- package/lib/dll/DelegatedModule.js +29 -15
- package/lib/dll/DelegatedModuleFactoryPlugin.js +1 -0
- package/lib/dll/DelegatedPlugin.js +1 -0
- package/lib/dll/DllEntryPlugin.js +3 -0
- package/lib/dll/DllModule.js +3 -2
- package/lib/dll/DllPlugin.js +16 -0
- package/lib/dll/DllReferencePlugin.js +3 -0
- package/lib/dll/LibManifestPlugin.js +1 -0
- package/lib/electron/ElectronTargetPlugin.js +22 -4
- package/lib/errors/ConcurrentCompilationError.js +1 -0
- package/lib/errors/HookWebpackError.js +11 -13
- package/lib/errors/IgnoreErrorModuleFactory.js +1 -0
- package/lib/errors/InvalidDependenciesModuleWarning.js +2 -0
- package/lib/errors/JSONParseError.js +9 -8
- package/lib/errors/ModuleBuildError.js +16 -13
- package/lib/errors/ModuleDependencyError.js +8 -1
- package/lib/errors/ModuleDependencyWarning.js +8 -1
- package/lib/errors/ModuleError.js +5 -11
- package/lib/errors/ModuleHashingError.js +4 -0
- package/lib/errors/ModuleNotFoundError.js +3 -0
- package/lib/errors/ModuleParseError.js +5 -11
- package/lib/errors/ModuleRestoreError.js +2 -0
- package/lib/errors/ModuleStoreError.js +3 -0
- package/lib/errors/ModuleWarning.js +7 -11
- package/lib/errors/NodeStuffInWebError.js +1 -0
- package/lib/errors/NonErrorEmittedError.js +2 -0
- package/lib/errors/UnhandledSchemeError.js +1 -0
- package/lib/esm/ModuleChunkLoadingPlugin.js +0 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +28 -23
- package/lib/hmr/HotModuleReplacement.runtime.js +175 -30
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +7 -0
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +173 -26
- package/lib/hmr/LazyCompilationPlugin.js +30 -6
- package/lib/html/HtmlGenerator.js +217 -23
- package/lib/html/HtmlModule.js +40 -0
- package/lib/html/HtmlModulesPlugin.js +219 -55
- package/lib/html/HtmlParser.js +1108 -1099
- package/lib/html/{walkHtmlTokens.js → syntax.js} +4701 -212
- package/lib/ids/IdHelpers.js +4 -2
- package/lib/index.js +19 -0
- package/lib/javascript/BasicEvaluatedExpression.js +1 -0
- package/lib/javascript/EnableChunkLoadingPlugin.js +1 -0
- package/lib/javascript/JavascriptGenerator.js +6 -2
- package/lib/javascript/JavascriptModule.js +54 -0
- package/lib/javascript/JavascriptModulesPlugin.js +257 -102
- package/lib/javascript/JavascriptParser.js +285 -158
- package/lib/json/JsonModule.js +40 -0
- package/lib/json/JsonModulesPlugin.js +7 -0
- package/lib/json/JsonParser.js +4 -2
- package/lib/library/AssignLibraryPlugin.js +5 -3
- package/lib/library/ExportPropertyLibraryPlugin.js +1 -0
- package/lib/library/FalseIIFEUmdWarning.js +1 -0
- package/lib/library/ModuleLibraryPlugin.js +24 -5
- package/lib/library/SystemLibraryPlugin.js +3 -3
- package/lib/node/NodeTargetPlugin.js +1 -0
- package/lib/node/NodeWatchFileSystem.js +1 -0
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +10 -9
- package/lib/node/RequireChunkLoadingRuntimeModule.js +18 -16
- package/lib/optimize/ConcatenatedModule.js +395 -77
- package/lib/optimize/ConstExportsPlugin.js +211 -0
- package/lib/optimize/InlineExports.js +178 -0
- package/lib/optimize/InnerGraph.js +372 -275
- package/lib/optimize/InnerGraphPlugin.js +196 -99
- package/lib/optimize/ModuleConcatenationPlugin.js +56 -25
- package/lib/optimize/RealContentHashPlugin.js +14 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +234 -64
- package/lib/runtime/AsyncModuleRuntimeModule.js +32 -30
- package/lib/runtime/AutoPublicPathRuntimeModule.js +11 -5
- package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +1 -1
- package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +6 -4
- package/lib/runtime/DefinePropertyGettersRuntimeModule.js +33 -4
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +82 -3
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -1
- package/lib/runtime/HasOwnPropertyRuntimeModule.js +1 -1
- package/lib/runtime/LoadScriptRuntimeModule.js +18 -13
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +39 -26
- package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +1 -1
- package/lib/runtime/OnChunksLoadedRuntimeModule.js +4 -4
- package/lib/runtime/RelativeUrlRuntimeModule.js +3 -2
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -1
- package/lib/runtime/StartupEntrypointRuntimeModule.js +4 -3
- package/lib/runtime/WorkerRuntimeModule.js +33 -0
- package/lib/schemes/HttpUriPlugin.js +3 -2
- package/lib/serialization/AggregateErrorSerializer.js +7 -6
- package/lib/serialization/ArraySerializer.js +4 -8
- package/lib/serialization/BinaryMiddleware.js +538 -468
- package/lib/serialization/DateObjectSerializer.js +2 -2
- package/lib/serialization/ErrorObjectSerializer.js +7 -6
- package/lib/serialization/MapObjectSerializer.js +5 -9
- package/lib/serialization/NullPrototypeObjectSerializer.js +7 -9
- package/lib/serialization/ObjectMiddleware.js +50 -13
- package/lib/serialization/PlainObjectSerializer.js +9 -8
- package/lib/serialization/RegExpObjectSerializer.js +2 -2
- package/lib/serialization/Serializer.js +1 -0
- package/lib/serialization/SetObjectSerializer.js +4 -8
- package/lib/sharing/ConsumeSharedModule.js +6 -7
- package/lib/sharing/ConsumeSharedPlugin.js +1 -0
- package/lib/sharing/ConsumeSharedRuntimeModule.js +46 -41
- package/lib/sharing/ProvideSharedDependency.js +30 -15
- package/lib/sharing/ProvideSharedModule.js +30 -11
- package/lib/sharing/ProvideSharedPlugin.js +4 -2
- package/lib/sharing/SharePlugin.js +3 -0
- package/lib/sharing/ShareRuntimeModule.js +18 -16
- package/lib/sharing/resolveMatchedConfigs.js +2 -1
- package/lib/sharing/utils.js +1 -1
- package/lib/stats/DefaultStatsFactoryPlugin.js +4 -6
- package/lib/stats/DefaultStatsPrinterPlugin.js +14 -14
- package/lib/stats/StatsFactory.js +11 -9
- package/lib/stats/StatsPrinter.js +9 -2
- package/lib/url/URLParserPlugin.js +5 -2
- package/lib/util/AsyncQueue.js +10 -0
- package/lib/util/LazyBucketSortedSet.js +5 -0
- package/lib/util/LazySet.js +6 -4
- package/lib/util/LocConverter.js +11 -1
- package/lib/util/Semaphore.js +1 -0
- package/lib/util/SourceProcessor.js +106 -0
- package/lib/util/TupleSet.js +1 -0
- package/lib/util/WeakTupleMap.js +27 -1
- package/lib/util/chainedImports.js +3 -3
- package/lib/util/comparators.js +2 -2
- package/lib/util/concatenate.js +31 -7
- package/lib/util/createHash.js +0 -1
- package/lib/util/deterministicGrouping.js +19 -12
- package/lib/util/extractSourceMap.js +1 -1
- package/lib/util/findGraphRoots.js +2 -0
- package/lib/util/fs.js +10 -5
- package/lib/util/hash/DebugHash.js +1 -0
- package/lib/util/hash/hash-digest.js +24 -15
- package/lib/util/identifier.js +7 -0
- package/lib/util/internalSerializables.js +11 -2
- package/lib/util/magicComment.js +42 -0
- package/lib/util/makeSerializable.js +1 -0
- package/lib/util/nonNumericOnlyHash.js +30 -1
- package/lib/util/property.js +7 -1
- package/lib/util/publicPathPlaceholder.js +64 -0
- package/lib/util/registerExternalSerializer.js +4 -4
- package/lib/wasm-async/AsyncWasmModule.js +77 -0
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +1 -1
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +1 -96
- package/lib/wasm-async/AsyncWebAssemblyParser.js +1 -1
- package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +1 -1
- package/lib/wasm-sync/SyncWasmModule.js +39 -0
- package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +1 -0
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +6 -3
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +2 -1
- package/lib/wasm-sync/WebAssemblyGenerator.js +1 -0
- package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +2 -0
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +10 -0
- package/lib/wasm-sync/WebAssemblyParser.js +7 -3
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +45 -39
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +11 -10
- package/package.json +35 -27
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +212 -3
- package/schemas/plugins/HtmlGeneratorOptions.check.js +1 -1
- package/schemas/plugins/HtmlParserOptions.check.d.ts +7 -0
- package/schemas/plugins/HtmlParserOptions.check.js +6 -0
- package/schemas/plugins/HtmlParserOptions.json +3 -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 +1456 -290
- package/lib/css/walkCssTokens.js +0 -2020
- package/lib/util/AppendOnlyStackedSet.js +0 -93
|
@@ -42,10 +42,11 @@ const {
|
|
|
42
42
|
getUsedNamesInScopeInfo
|
|
43
43
|
} = require("../util/concatenate");
|
|
44
44
|
const createHash = require("../util/createHash");
|
|
45
|
-
const
|
|
45
|
+
const { digestNonNumericOnlyWithFull } = require("../util/nonNumericOnlyHash");
|
|
46
46
|
const removeBOM = require("../util/removeBOM");
|
|
47
47
|
const { intersectRuntime } = require("../util/runtime");
|
|
48
48
|
const JavascriptGenerator = require("./JavascriptGenerator");
|
|
49
|
+
const JavascriptModule = require("./JavascriptModule");
|
|
49
50
|
const JavascriptParser = require("./JavascriptParser");
|
|
50
51
|
|
|
51
52
|
/** @typedef {import("estree").Program} Program */
|
|
@@ -347,6 +348,75 @@ const printGeneratedCodeForStack = (module, code) => {
|
|
|
347
348
|
/** @type {WeakMap<Compilation, CompilationHooks>} */
|
|
348
349
|
const compilationHooksMap = new WeakMap();
|
|
349
350
|
|
|
351
|
+
/**
|
|
352
|
+
* Renames an inlined module's top-level declaration (and all its references) when
|
|
353
|
+
* its name is already taken in the shared startup scope, recording the chosen name
|
|
354
|
+
* in `allUsedNames`. Lets inlined modules be emitted without a per-entry/per-chunk
|
|
355
|
+
* IIFE by resolving name collisions instead of isolating each module.
|
|
356
|
+
* @param {InstanceType<typeof import("webpack-sources").ReplaceSource>} source the module source to edit
|
|
357
|
+
* @param {Program} ast the parsed module AST
|
|
358
|
+
* @param {Variable} variable the top-level variable to check/rename
|
|
359
|
+
* @param {string} moduleIdentifier the module identifier (for scope caching)
|
|
360
|
+
* @param {string} readableIdentifier the readable module identifier (for new names)
|
|
361
|
+
* @param {Set<string>} allUsedNames names already used in the shared scope (mutated)
|
|
362
|
+
* @returns {void}
|
|
363
|
+
*/
|
|
364
|
+
const renameInlinedModuleVariable = (
|
|
365
|
+
source,
|
|
366
|
+
ast,
|
|
367
|
+
variable,
|
|
368
|
+
moduleIdentifier,
|
|
369
|
+
readableIdentifier,
|
|
370
|
+
allUsedNames
|
|
371
|
+
) => {
|
|
372
|
+
/** @type {UsedNamesInScopeInfo} */
|
|
373
|
+
const usedNamesInScopeInfo = new Map();
|
|
374
|
+
/** @type {ScopeSet} */
|
|
375
|
+
const ignoredScopes = new Set();
|
|
376
|
+
|
|
377
|
+
const name = variable.name;
|
|
378
|
+
const { usedNames, alreadyCheckedScopes } = getUsedNamesInScopeInfo(
|
|
379
|
+
usedNamesInScopeInfo,
|
|
380
|
+
moduleIdentifier,
|
|
381
|
+
name
|
|
382
|
+
);
|
|
383
|
+
|
|
384
|
+
if (allUsedNames.has(name) || usedNames.has(name)) {
|
|
385
|
+
const references = getAllReferences(variable);
|
|
386
|
+
const allIdentifiers = new Set([
|
|
387
|
+
...references.map((r) => r.identifier),
|
|
388
|
+
...variable.identifiers
|
|
389
|
+
]);
|
|
390
|
+
for (const ref of references) {
|
|
391
|
+
addScopeSymbols(ref.from, usedNames, alreadyCheckedScopes, ignoredScopes);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
const newName = findNewName(
|
|
395
|
+
name,
|
|
396
|
+
allUsedNames,
|
|
397
|
+
usedNames,
|
|
398
|
+
readableIdentifier
|
|
399
|
+
);
|
|
400
|
+
allUsedNames.add(newName);
|
|
401
|
+
for (const identifier of allIdentifiers) {
|
|
402
|
+
const r = /** @type {Range} */ (identifier.range);
|
|
403
|
+
const path = getPathInAst(ast, identifier);
|
|
404
|
+
if (path && path.length > 1) {
|
|
405
|
+
const maybeProperty =
|
|
406
|
+
path[1].type === "AssignmentPattern" && path[1].left === path[0]
|
|
407
|
+
? path[2]
|
|
408
|
+
: path[1];
|
|
409
|
+
if (maybeProperty.type === "Property" && maybeProperty.shorthand) {
|
|
410
|
+
source.insert(r[1], `: ${newName}`);
|
|
411
|
+
continue;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
source.replace(r[0], r[1] - 1, newName);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
allUsedNames.add(name);
|
|
418
|
+
};
|
|
419
|
+
|
|
350
420
|
const PLUGIN_NAME = "JavascriptModulesPlugin";
|
|
351
421
|
|
|
352
422
|
/** @typedef {{ header: string[], beforeStartup: string[], startup: string[], afterStartup: string[], allowInlineStartup: boolean }} Bootstrap */
|
|
@@ -424,6 +494,12 @@ class JavascriptModulesPlugin {
|
|
|
424
494
|
JAVASCRIPT_MODULE_TYPE_DYNAMIC,
|
|
425
495
|
JAVASCRIPT_MODULE_TYPE_ESM
|
|
426
496
|
]) {
|
|
497
|
+
normalModuleFactory.hooks.createModuleClass
|
|
498
|
+
.for(type)
|
|
499
|
+
.tap(
|
|
500
|
+
PLUGIN_NAME,
|
|
501
|
+
(createData, _resolveData) => new JavascriptModule(createData)
|
|
502
|
+
);
|
|
427
503
|
normalModuleFactory.hooks.createParser
|
|
428
504
|
.for(type)
|
|
429
505
|
.tap(PLUGIN_NAME, (options) => {
|
|
@@ -641,11 +717,8 @@ class JavascriptModulesPlugin {
|
|
|
641
717
|
}
|
|
642
718
|
xor.updateHash(hash);
|
|
643
719
|
}
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
digest,
|
|
647
|
-
hashDigestLength
|
|
648
|
-
);
|
|
720
|
+
[chunk.contentHash.javascript, chunk.contentHashFull.javascript] =
|
|
721
|
+
digestNonNumericOnlyWithFull(hash, hashDigest, hashDigestLength);
|
|
649
722
|
});
|
|
650
723
|
compilation.hooks.additionalTreeRuntimeRequirements.tap(
|
|
651
724
|
PLUGIN_NAME,
|
|
@@ -739,6 +812,12 @@ class JavascriptModulesPlugin {
|
|
|
739
812
|
return chunk.filenameTemplate;
|
|
740
813
|
} else if (chunk instanceof HotUpdateChunk) {
|
|
741
814
|
return outputOptions.hotUpdateChunkFilename;
|
|
815
|
+
}
|
|
816
|
+
const entryOptions = chunk.getEntryOptions();
|
|
817
|
+
// A worker entry (`new Worker` or `entry.worker`) uses workerChunkFilename;
|
|
818
|
+
// chunks it loads internally keep `chunkFilename`
|
|
819
|
+
if (entryOptions !== undefined && entryOptions.worker) {
|
|
820
|
+
return outputOptions.workerChunkFilename;
|
|
742
821
|
} else if (chunk.canBeInitial()) {
|
|
743
822
|
return outputOptions.filename;
|
|
744
823
|
}
|
|
@@ -1143,10 +1222,8 @@ class JavascriptModulesPlugin {
|
|
|
1143
1222
|
|
|
1144
1223
|
const iife = innerStrict
|
|
1145
1224
|
? "it needs to be in strict mode."
|
|
1146
|
-
: inlinedModules.size > 1
|
|
1147
|
-
?
|
|
1148
|
-
// to make a better decision
|
|
1149
|
-
"it needs to be isolated against other entry modules."
|
|
1225
|
+
: inlinedModules.size > 1 && !renamedInlinedModule
|
|
1226
|
+
? "it needs to be isolated against other entry modules."
|
|
1150
1227
|
: chunkModules && !renamedInlinedModule
|
|
1151
1228
|
? "it needs to be isolated against other modules in the chunk."
|
|
1152
1229
|
: exports && !webpackExports
|
|
@@ -1190,10 +1267,12 @@ class JavascriptModulesPlugin {
|
|
|
1190
1267
|
}
|
|
1191
1268
|
if (exports) {
|
|
1192
1269
|
if (m !== lastInlinedModule) {
|
|
1193
|
-
startupSource.add(
|
|
1270
|
+
startupSource.add(
|
|
1271
|
+
`${runtimeTemplate.renderLet()} ${m.exportsArgument} = {};\n`
|
|
1272
|
+
);
|
|
1194
1273
|
} else if (m.exportsArgument !== RuntimeGlobals.exports) {
|
|
1195
1274
|
startupSource.add(
|
|
1196
|
-
|
|
1275
|
+
`${runtimeTemplate.renderLet()} ${m.exportsArgument} = ${RuntimeGlobals.exports};\n`
|
|
1197
1276
|
);
|
|
1198
1277
|
}
|
|
1199
1278
|
}
|
|
@@ -1236,7 +1315,7 @@ class JavascriptModulesPlugin {
|
|
|
1236
1315
|
}
|
|
1237
1316
|
if (startupRenderContext.needExportsDeclaration) {
|
|
1238
1317
|
renderedStartup = new ConcatSource(
|
|
1239
|
-
|
|
1318
|
+
`${runtimeTemplate.renderLet()} ${RuntimeGlobals.exports} = {};\n`,
|
|
1240
1319
|
renderedStartup
|
|
1241
1320
|
);
|
|
1242
1321
|
}
|
|
@@ -1414,9 +1493,10 @@ class JavascriptModulesPlugin {
|
|
|
1414
1493
|
result.allowInlineStartup = false;
|
|
1415
1494
|
}
|
|
1416
1495
|
|
|
1496
|
+
const bootstrapCst = runtimeTemplate.renderConst();
|
|
1417
1497
|
if (useRequire || moduleCache) {
|
|
1418
1498
|
buf.push("// The module cache");
|
|
1419
|
-
buf.push(
|
|
1499
|
+
buf.push(`${bootstrapCst} __webpack_module_cache__ = {};`);
|
|
1420
1500
|
buf.push("");
|
|
1421
1501
|
}
|
|
1422
1502
|
|
|
@@ -1426,14 +1506,16 @@ class JavascriptModulesPlugin {
|
|
|
1426
1506
|
// This requires all deferred imports to a module can get the module export object before the module
|
|
1427
1507
|
// is evaluated.
|
|
1428
1508
|
buf.push("// The deferred module cache");
|
|
1429
|
-
buf.push(
|
|
1509
|
+
buf.push(`${bootstrapCst} __webpack_module_deferred_exports__ = {};`);
|
|
1430
1510
|
// Per the TC39 import-defer spec, every defer-import call site for
|
|
1431
1511
|
// the same module must yield the same Deferred Module Namespace
|
|
1432
1512
|
// Exotic Object (and a distinct one from any eager namespace).
|
|
1433
1513
|
// Cache the deferred namespace proxy here so calls from different
|
|
1434
1514
|
// files share identity.
|
|
1435
1515
|
buf.push("// The deferred namespace cache");
|
|
1436
|
-
buf.push(
|
|
1516
|
+
buf.push(
|
|
1517
|
+
`${bootstrapCst} __webpack_module_deferred_namespace_cache__ = {};`
|
|
1518
|
+
);
|
|
1437
1519
|
buf.push("");
|
|
1438
1520
|
}
|
|
1439
1521
|
|
|
@@ -1445,7 +1527,7 @@ class JavascriptModulesPlugin {
|
|
|
1445
1527
|
buf.push("");
|
|
1446
1528
|
} else if (runtimeRequirements.has(RuntimeGlobals.requireScope)) {
|
|
1447
1529
|
buf.push("// The require scope");
|
|
1448
|
-
buf.push(
|
|
1530
|
+
buf.push(`${bootstrapCst} ${RuntimeGlobals.require} = {};`);
|
|
1449
1531
|
buf.push("");
|
|
1450
1532
|
}
|
|
1451
1533
|
|
|
@@ -1581,9 +1663,17 @@ class JavascriptModulesPlugin {
|
|
|
1581
1663
|
result.allowInlineStartup = false;
|
|
1582
1664
|
}
|
|
1583
1665
|
|
|
1666
|
+
// `__webpack_exports__` may be reassigned later — by the
|
|
1667
|
+
// `onChunksLoaded` wrapper below, by an inlined entry
|
|
1668
|
+
// module that uses top-level `await` (the emitted
|
|
1669
|
+
// bridge reassigns `__webpack_exports__` to the awaited
|
|
1670
|
+
// value), or by other downstream codegen. Always declare
|
|
1671
|
+
// with `let` (or `var` if `let` is unsupported) so
|
|
1672
|
+
// reassignment is allowed.
|
|
1673
|
+
const exportsDecl = runtimeTemplate.renderLet();
|
|
1584
1674
|
if (chunks.length > 0) {
|
|
1585
1675
|
buf2.push(
|
|
1586
|
-
`${i === 0 ?
|
|
1676
|
+
`${i === 0 ? `${exportsDecl} ${RuntimeGlobals.exports} = ` : ""}${
|
|
1587
1677
|
RuntimeGlobals.onChunksLoaded
|
|
1588
1678
|
}(undefined, ${JSON.stringify(
|
|
1589
1679
|
chunks.map((c) => c.id)
|
|
@@ -1593,12 +1683,14 @@ class JavascriptModulesPlugin {
|
|
|
1593
1683
|
);
|
|
1594
1684
|
} else if (useRequire) {
|
|
1595
1685
|
buf2.push(
|
|
1596
|
-
`${i === 0 ?
|
|
1686
|
+
`${i === 0 ? `${exportsDecl} ${RuntimeGlobals.exports} = ` : ""}${
|
|
1597
1687
|
RuntimeGlobals.require
|
|
1598
1688
|
}(${moduleIdExpr});`
|
|
1599
1689
|
);
|
|
1600
1690
|
} else {
|
|
1601
|
-
if (i === 0)
|
|
1691
|
+
if (i === 0) {
|
|
1692
|
+
buf2.push(`${exportsDecl} ${RuntimeGlobals.exports} = {};`);
|
|
1693
|
+
}
|
|
1602
1694
|
const needThisAsExports = entryRuntimeRequirements.has(
|
|
1603
1695
|
RuntimeGlobals.thisAsExports
|
|
1604
1696
|
);
|
|
@@ -1711,11 +1803,10 @@ class JavascriptModulesPlugin {
|
|
|
1711
1803
|
* @returns {string} the generated source of the require function
|
|
1712
1804
|
*/
|
|
1713
1805
|
renderRequire(renderContext, hooks) {
|
|
1714
|
-
const {
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
} = renderContext;
|
|
1806
|
+
const { chunk, chunkGraph, runtimeTemplate } = renderContext;
|
|
1807
|
+
const { outputOptions } = runtimeTemplate;
|
|
1808
|
+
const cst = runtimeTemplate.renderConst();
|
|
1809
|
+
const lt = runtimeTemplate.renderLet();
|
|
1719
1810
|
const runtimeRequirements = chunkGraph.getTreeRuntimeRequirements(chunk);
|
|
1720
1811
|
|
|
1721
1812
|
/**
|
|
@@ -1724,12 +1815,12 @@ class JavascriptModulesPlugin {
|
|
|
1724
1815
|
* @returns {string[]} source
|
|
1725
1816
|
*/
|
|
1726
1817
|
const renderMissingModuleError = (condition) =>
|
|
1727
|
-
outputOptions.
|
|
1818
|
+
outputOptions.strictModuleResolution
|
|
1728
1819
|
? [
|
|
1729
1820
|
`if (${condition}) {`,
|
|
1730
1821
|
Template.indent([
|
|
1731
1822
|
"delete __webpack_module_cache__[moduleId];",
|
|
1732
|
-
|
|
1823
|
+
`${cst} e = new Error("Cannot find module '" + moduleId + "'");`,
|
|
1733
1824
|
"e.code = 'MODULE_NOT_FOUND';",
|
|
1734
1825
|
"throw e;"
|
|
1735
1826
|
]),
|
|
@@ -1741,7 +1832,7 @@ class JavascriptModulesPlugin {
|
|
|
1741
1832
|
RuntimeGlobals.interceptModuleExecution
|
|
1742
1833
|
)
|
|
1743
1834
|
? Template.asString([
|
|
1744
|
-
|
|
1835
|
+
`${cst} execOptions = { id: moduleId, module: module, factory: __webpack_modules__[moduleId], require: ${RuntimeGlobals.require} };`,
|
|
1745
1836
|
`${RuntimeGlobals.interceptModuleExecution}.forEach(function(handler) { handler(execOptions); });`,
|
|
1746
1837
|
...renderMissingModuleError("!execOptions.factory"),
|
|
1747
1838
|
"module = execOptions.module;",
|
|
@@ -1763,9 +1854,15 @@ class JavascriptModulesPlugin {
|
|
|
1763
1854
|
const needModuleDefer = runtimeRequirements.has(
|
|
1764
1855
|
RuntimeGlobals.makeDeferredNamespaceObject
|
|
1765
1856
|
);
|
|
1857
|
+
// `module` is reassigned by the interceptModuleExecution path; use `let`.
|
|
1858
|
+
const moduleDecl = runtimeRequirements.has(
|
|
1859
|
+
RuntimeGlobals.interceptModuleExecution
|
|
1860
|
+
)
|
|
1861
|
+
? lt
|
|
1862
|
+
: cst;
|
|
1766
1863
|
const content = Template.asString([
|
|
1767
1864
|
"// Check if module is in cache",
|
|
1768
|
-
|
|
1865
|
+
`${cst} cachedModule = __webpack_module_cache__[moduleId];`,
|
|
1769
1866
|
"if (cachedModule !== undefined) {",
|
|
1770
1867
|
outputOptions.strictModuleErrorHandling
|
|
1771
1868
|
? Template.indent([
|
|
@@ -1775,7 +1872,7 @@ class JavascriptModulesPlugin {
|
|
|
1775
1872
|
: Template.indent("return cachedModule.exports;"),
|
|
1776
1873
|
"}",
|
|
1777
1874
|
"// Create a new module (and put it into the cache)",
|
|
1778
|
-
|
|
1875
|
+
`${moduleDecl} module = __webpack_module_cache__[moduleId] = {`,
|
|
1779
1876
|
Template.indent([
|
|
1780
1877
|
needModuleId ? "id: moduleId," : "// no module.id needed",
|
|
1781
1878
|
needModuleLoaded ? "loaded: false," : "// no module.loaded needed",
|
|
@@ -1788,7 +1885,7 @@ class JavascriptModulesPlugin {
|
|
|
1788
1885
|
outputOptions.strictModuleExceptionHandling
|
|
1789
1886
|
? Template.asString([
|
|
1790
1887
|
"// Execute the module function",
|
|
1791
|
-
|
|
1888
|
+
`${lt} threw = true;`,
|
|
1792
1889
|
"try {",
|
|
1793
1890
|
Template.indent([
|
|
1794
1891
|
moduleExecution,
|
|
@@ -1870,11 +1967,11 @@ class JavascriptModulesPlugin {
|
|
|
1870
1967
|
allModules.every((m) => /** @type {BuildInfo} */ (m.buildInfo).strict);
|
|
1871
1968
|
const isMultipleEntries = inlinedModules.size > 1;
|
|
1872
1969
|
const singleEntryWithModules = inlinedModules.size === 1 && hasChunkModules;
|
|
1873
|
-
//
|
|
1874
|
-
//
|
|
1875
|
-
//
|
|
1876
|
-
//
|
|
1877
|
-
if (
|
|
1970
|
+
// This step is before the IIFE reason calculation; it only runs for the
|
|
1971
|
+
// cases whose IIFE reason it can remove: multiple inlined entry modules, or a
|
|
1972
|
+
// single inlined entry alongside other chunk modules. The remaining reason
|
|
1973
|
+
// ('it uses a non-standard name for the exports') is not handled here.
|
|
1974
|
+
if (innerStrict || (!isMultipleEntries && !singleEntryWithModules)) {
|
|
1878
1975
|
return false;
|
|
1879
1976
|
}
|
|
1880
1977
|
|
|
@@ -1887,6 +1984,8 @@ class JavascriptModulesPlugin {
|
|
|
1887
1984
|
const inlinedModulesToInfo = new Map();
|
|
1888
1985
|
/** @type {Set<string>} */
|
|
1889
1986
|
const nonInlinedModuleThroughIdentifiers = new Set();
|
|
1987
|
+
/** @type {Map<Module, Source>} */
|
|
1988
|
+
const inlinedModuleSources = new Map();
|
|
1890
1989
|
|
|
1891
1990
|
for (const m of allModules) {
|
|
1892
1991
|
const isInlinedModule = inlinedModules && inlinedModules.has(m);
|
|
@@ -1901,6 +2000,12 @@ class JavascriptModulesPlugin {
|
|
|
1901
2000
|
);
|
|
1902
2001
|
|
|
1903
2002
|
if (!moduleSource) continue;
|
|
2003
|
+
if (isInlinedModule) {
|
|
2004
|
+
// Parsing the inlined entry (often the whole concatenated app) is
|
|
2005
|
+
// expensive; defer it until we know renaming is actually needed.
|
|
2006
|
+
inlinedModuleSources.set(m, moduleSource);
|
|
2007
|
+
continue;
|
|
2008
|
+
}
|
|
1904
2009
|
const code = /** @type {string} */ (moduleSource.source());
|
|
1905
2010
|
|
|
1906
2011
|
const { ast } = JavascriptParser._parse(
|
|
@@ -1920,22 +2025,88 @@ class JavascriptModulesPlugin {
|
|
|
1920
2025
|
});
|
|
1921
2026
|
|
|
1922
2027
|
const globalScope = /** @type {Scope} */ (scopeManager.acquire(ast));
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
}
|
|
1935
|
-
|
|
1936
|
-
|
|
2028
|
+
for (const ref of globalScope.through) {
|
|
2029
|
+
nonInlinedModuleThroughIdentifiers.add(ref.identifier.name);
|
|
2030
|
+
}
|
|
2031
|
+
}
|
|
2032
|
+
|
|
2033
|
+
// Fast path: codegen reports each inlined entry's rendered top-level
|
|
2034
|
+
// declarations and free names (post-concatenation), so when no declaration
|
|
2035
|
+
// collides with a free name of any other module, another entry's
|
|
2036
|
+
// declarations, or a reserved name, no renaming is needed and the entries
|
|
2037
|
+
// don't have to be parsed at all.
|
|
2038
|
+
fastPath: {
|
|
2039
|
+
const { codeGenerationResults, chunk } = renderContext;
|
|
2040
|
+
/** @type {Set<string>} */
|
|
2041
|
+
const usedNames = new Set(nonInlinedModuleThroughIdentifiers);
|
|
2042
|
+
for (const name of RESERVED_NAMES) usedNames.add(name);
|
|
2043
|
+
/** @type {Set<string>[]} */
|
|
2044
|
+
const declarationsList = [];
|
|
2045
|
+
for (const m of inlinedModuleSources.keys()) {
|
|
2046
|
+
if (!codeGenerationResults.has(m, chunk.runtime)) break fastPath;
|
|
2047
|
+
const result = codeGenerationResults.get(m, chunk.runtime);
|
|
2048
|
+
const data = result.data;
|
|
2049
|
+
if (!data) break fastPath;
|
|
2050
|
+
const declarations = data.get("topLevelDeclarations");
|
|
2051
|
+
if (!declarations) break fastPath;
|
|
2052
|
+
declarationsList.push(declarations);
|
|
2053
|
+
if (!isMultipleEntries) continue;
|
|
2054
|
+
// Entries share the startup scope: an entry's free names and runtime
|
|
2055
|
+
// globals must not be shadowed by another entry's declarations.
|
|
2056
|
+
const freeNames = data.get("freeNames");
|
|
2057
|
+
if (!freeNames) break fastPath;
|
|
2058
|
+
for (const name of freeNames) usedNames.add(name);
|
|
2059
|
+
if (result.runtimeRequirements) {
|
|
2060
|
+
for (const req of result.runtimeRequirements) {
|
|
2061
|
+
const dot = req.indexOf(".");
|
|
2062
|
+
usedNames.add(dot === -1 ? req : req.slice(0, dot));
|
|
2063
|
+
}
|
|
2064
|
+
}
|
|
2065
|
+
}
|
|
2066
|
+
for (const declarations of declarationsList) {
|
|
2067
|
+
for (const name of declarations) {
|
|
2068
|
+
if (usedNames.has(name)) break fastPath;
|
|
1937
2069
|
}
|
|
2070
|
+
// earlier entries' declarations join the used set so later entries
|
|
2071
|
+
// are checked against them
|
|
2072
|
+
for (const name of declarations) usedNames.add(name);
|
|
1938
2073
|
}
|
|
2074
|
+
for (const [m, moduleSource] of inlinedModuleSources) {
|
|
2075
|
+
renamedInlinedModules.set(m, moduleSource);
|
|
2076
|
+
}
|
|
2077
|
+
return renamedInlinedModules;
|
|
2078
|
+
}
|
|
2079
|
+
|
|
2080
|
+
for (const [m, moduleSource] of inlinedModuleSources) {
|
|
2081
|
+
const code = /** @type {string} */ (moduleSource.source());
|
|
2082
|
+
|
|
2083
|
+
const { ast } = JavascriptParser._parse(
|
|
2084
|
+
code,
|
|
2085
|
+
{
|
|
2086
|
+
sourceType: "auto",
|
|
2087
|
+
ranges: true
|
|
2088
|
+
},
|
|
2089
|
+
JavascriptParser._getModuleParseFunction(compilation, m)
|
|
2090
|
+
);
|
|
2091
|
+
|
|
2092
|
+
const scopeManager = eslintScope.analyze(ast, {
|
|
2093
|
+
ecmaVersion: 6,
|
|
2094
|
+
sourceType: "module",
|
|
2095
|
+
optimistic: true,
|
|
2096
|
+
ignoreEval: true
|
|
2097
|
+
});
|
|
2098
|
+
|
|
2099
|
+
const globalScope = /** @type {Scope} */ (scopeManager.acquire(ast));
|
|
2100
|
+
const moduleScope = globalScope.childScopes[0];
|
|
2101
|
+
inlinedModulesToInfo.set(m, {
|
|
2102
|
+
source: moduleSource,
|
|
2103
|
+
ast,
|
|
2104
|
+
module: m,
|
|
2105
|
+
variables: new Set(moduleScope.variables),
|
|
2106
|
+
through: new Set(moduleScope.through),
|
|
2107
|
+
usedInNonInlined: new Set(),
|
|
2108
|
+
moduleScope
|
|
2109
|
+
});
|
|
1939
2110
|
}
|
|
1940
2111
|
|
|
1941
2112
|
for (const [, { variables, usedInNonInlined }] of inlinedModulesToInfo) {
|
|
@@ -1949,6 +2120,36 @@ class JavascriptModulesPlugin {
|
|
|
1949
2120
|
}
|
|
1950
2121
|
}
|
|
1951
2122
|
|
|
2123
|
+
// Multiple inlined entry modules share the chunk's startup scope. Rename any
|
|
2124
|
+
// top-level declaration that would collide with another inlined module's
|
|
2125
|
+
// declaration, with any inlined or non-inlined module's free (global)
|
|
2126
|
+
// reference, or with a reserved name, so the modules can be emitted without a
|
|
2127
|
+
// per-entry IIFE.
|
|
2128
|
+
if (isMultipleEntries) {
|
|
2129
|
+
/** @type {Set<string>} */
|
|
2130
|
+
const allUsedNames = new Set(nonInlinedModuleThroughIdentifiers);
|
|
2131
|
+
for (const name of RESERVED_NAMES) allUsedNames.add(name);
|
|
2132
|
+
for (const { through } of inlinedModulesToInfo.values()) {
|
|
2133
|
+
for (const ref of through) allUsedNames.add(ref.identifier.name);
|
|
2134
|
+
}
|
|
2135
|
+
for (const [m, moduleInfo] of inlinedModulesToInfo) {
|
|
2136
|
+
const { ast, source: _source } = moduleInfo;
|
|
2137
|
+
const source = new ReplaceSource(_source);
|
|
2138
|
+
for (const variable of moduleInfo.variables) {
|
|
2139
|
+
renameInlinedModuleVariable(
|
|
2140
|
+
source,
|
|
2141
|
+
ast,
|
|
2142
|
+
variable,
|
|
2143
|
+
moduleInfo.module.identifier(),
|
|
2144
|
+
m.readableIdentifier(runtimeTemplate.requestShortener),
|
|
2145
|
+
allUsedNames
|
|
2146
|
+
);
|
|
2147
|
+
}
|
|
2148
|
+
renamedInlinedModules.set(m, source);
|
|
2149
|
+
}
|
|
2150
|
+
return renamedInlinedModules;
|
|
2151
|
+
}
|
|
2152
|
+
|
|
1952
2153
|
for (const [m, moduleInfo] of inlinedModulesToInfo) {
|
|
1953
2154
|
const { ast, source: _source, usedInNonInlined } = moduleInfo;
|
|
1954
2155
|
const source = new ReplaceSource(_source);
|
|
@@ -1967,60 +2168,14 @@ class JavascriptModulesPlugin {
|
|
|
1967
2168
|
}
|
|
1968
2169
|
|
|
1969
2170
|
for (const variable of info.variables) {
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
const name = variable.name;
|
|
1976
|
-
const { usedNames, alreadyCheckedScopes } = getUsedNamesInScopeInfo(
|
|
1977
|
-
usedNamesInScopeInfo,
|
|
2171
|
+
renameInlinedModuleVariable(
|
|
2172
|
+
source,
|
|
2173
|
+
ast,
|
|
2174
|
+
variable,
|
|
1978
2175
|
info.module.identifier(),
|
|
1979
|
-
|
|
2176
|
+
m.readableIdentifier(runtimeTemplate.requestShortener),
|
|
2177
|
+
allUsedNames
|
|
1980
2178
|
);
|
|
1981
|
-
|
|
1982
|
-
if (allUsedNames.has(name) || usedNames.has(name)) {
|
|
1983
|
-
const references = getAllReferences(variable);
|
|
1984
|
-
const allIdentifiers = new Set([
|
|
1985
|
-
...references.map((r) => r.identifier),
|
|
1986
|
-
...variable.identifiers
|
|
1987
|
-
]);
|
|
1988
|
-
for (const ref of references) {
|
|
1989
|
-
addScopeSymbols(
|
|
1990
|
-
ref.from,
|
|
1991
|
-
usedNames,
|
|
1992
|
-
alreadyCheckedScopes,
|
|
1993
|
-
ignoredScopes
|
|
1994
|
-
);
|
|
1995
|
-
}
|
|
1996
|
-
|
|
1997
|
-
const newName = findNewName(
|
|
1998
|
-
variable.name,
|
|
1999
|
-
allUsedNames,
|
|
2000
|
-
usedNames,
|
|
2001
|
-
m.readableIdentifier(runtimeTemplate.requestShortener)
|
|
2002
|
-
);
|
|
2003
|
-
allUsedNames.add(newName);
|
|
2004
|
-
for (const identifier of allIdentifiers) {
|
|
2005
|
-
const r = /** @type {Range} */ (identifier.range);
|
|
2006
|
-
const path = getPathInAst(ast, identifier);
|
|
2007
|
-
if (path && path.length > 1) {
|
|
2008
|
-
const maybeProperty =
|
|
2009
|
-
path[1].type === "AssignmentPattern" && path[1].left === path[0]
|
|
2010
|
-
? path[2]
|
|
2011
|
-
: path[1];
|
|
2012
|
-
if (
|
|
2013
|
-
maybeProperty.type === "Property" &&
|
|
2014
|
-
maybeProperty.shorthand
|
|
2015
|
-
) {
|
|
2016
|
-
source.insert(r[1], `: ${newName}`);
|
|
2017
|
-
continue;
|
|
2018
|
-
}
|
|
2019
|
-
}
|
|
2020
|
-
source.replace(r[0], r[1] - 1, newName);
|
|
2021
|
-
}
|
|
2022
|
-
}
|
|
2023
|
-
allUsedNames.add(name);
|
|
2024
2179
|
}
|
|
2025
2180
|
|
|
2026
2181
|
renamedInlinedModules.set(m, source);
|