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
package/lib/RuntimeTemplate.js
CHANGED
|
@@ -12,6 +12,7 @@ const {
|
|
|
12
12
|
getOutgoingAsyncModules
|
|
13
13
|
} = require("./async-modules/AsyncModuleHelpers");
|
|
14
14
|
const { ImportPhaseUtils } = require("./dependencies/ImportPhase");
|
|
15
|
+
const { InlinedUsedName } = require("./optimize/InlineExports");
|
|
15
16
|
const {
|
|
16
17
|
getMakeDeferredNamespaceModeFromExportsType,
|
|
17
18
|
getOptimizedDeferredModule
|
|
@@ -19,7 +20,7 @@ const {
|
|
|
19
20
|
const { equals } = require("./util/ArrayHelpers");
|
|
20
21
|
const compileBooleanMatcher = require("./util/compileBooleanMatcher");
|
|
21
22
|
const memoize = require("./util/memoize");
|
|
22
|
-
const { propertyAccess } = require("./util/property");
|
|
23
|
+
const { propertyAccess, propertyName } = require("./util/property");
|
|
23
24
|
const { forEachRuntime, subtractRuntime } = require("./util/runtime");
|
|
24
25
|
|
|
25
26
|
const getHarmonyImportDependency = memoize(() =>
|
|
@@ -64,9 +65,9 @@ It's in these chunks: ${
|
|
|
64
65
|
Module has these incoming connections: ${Array.from(
|
|
65
66
|
chunkGraph.moduleGraph.getIncomingConnections(module),
|
|
66
67
|
(connection) =>
|
|
67
|
-
`\n - ${
|
|
68
|
-
connection.
|
|
69
|
-
} ${
|
|
68
|
+
`\n - ${connection.originModule && connection.originModule.identifier()} ${
|
|
69
|
+
connection.dependency && connection.dependency.type
|
|
70
|
+
} ${
|
|
70
71
|
(connection.explanations && [...connection.explanations].join(", ")) || ""
|
|
71
72
|
}`
|
|
72
73
|
).join("")}`;
|
|
@@ -102,12 +103,16 @@ class RuntimeTemplate {
|
|
|
102
103
|
* @param {RequestShortener} requestShortener the request shortener
|
|
103
104
|
*/
|
|
104
105
|
constructor(compilation, outputOptions, requestShortener) {
|
|
106
|
+
/** @type {Compilation} */
|
|
105
107
|
this.compilation = compilation;
|
|
106
108
|
this.outputOptions = /** @type {OutputOptions} */ (outputOptions || {});
|
|
109
|
+
/** @type {RequestShortener} */
|
|
107
110
|
this.requestShortener = requestShortener;
|
|
111
|
+
/** @type {string} */
|
|
108
112
|
this.globalObject =
|
|
109
113
|
/** @type {string} */
|
|
110
114
|
(getGlobalObject(outputOptions.globalObject));
|
|
115
|
+
/** @type {string} */
|
|
111
116
|
this.contentHashReplacement = "X".repeat(outputOptions.hashDigestLength);
|
|
112
117
|
}
|
|
113
118
|
|
|
@@ -126,14 +131,59 @@ class RuntimeTemplate {
|
|
|
126
131
|
);
|
|
127
132
|
}
|
|
128
133
|
|
|
134
|
+
/**
|
|
135
|
+
* Whether the bundle targets node and web at once (universal `["node", "web"]` + `output.module`), like `isUniversalTarget` in `WebpackOptionsApply`.
|
|
136
|
+
* @returns {boolean} true for a universal target
|
|
137
|
+
*/
|
|
138
|
+
isUniversalTarget() {
|
|
139
|
+
const { platform } = this.compilation.compiler;
|
|
140
|
+
return (
|
|
141
|
+
Boolean(this.outputOptions.module) &&
|
|
142
|
+
platform.node === null &&
|
|
143
|
+
platform.web === null
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Runtime expression that is truthy in browser-like environments (a DOM
|
|
149
|
+
* `document` or a worker `self`) and falsy in Node.js. Single source of
|
|
150
|
+
* truth for branching a universal ("node-or-web") target at runtime.
|
|
151
|
+
* @returns {string} runtime condition expression
|
|
152
|
+
*/
|
|
153
|
+
isWebLikePlatformExpression() {
|
|
154
|
+
return "typeof document !== 'undefined' || typeof self !== 'undefined'";
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Expression for the global registry that collects CSS server-side when there
|
|
159
|
+
* is no DOM (SSR). An SSR host reads it from `globalThis`; it is keyed by the
|
|
160
|
+
* style/chunk identifier and namespaced by `output.uniqueName`.
|
|
161
|
+
* @returns {string} runtime expression evaluating to the registry object
|
|
162
|
+
*/
|
|
163
|
+
cssServerStyleRegistry() {
|
|
164
|
+
const name = this.outputOptions.uniqueName;
|
|
165
|
+
const key = JSON.stringify(
|
|
166
|
+
name ? `__webpack_css__${name}` : "__webpack_css__"
|
|
167
|
+
);
|
|
168
|
+
return `(${this.assignOr(`globalThis[${key}]`, "{}")})`;
|
|
169
|
+
}
|
|
170
|
+
|
|
129
171
|
supportsConst() {
|
|
130
172
|
return this.outputOptions.environment.const;
|
|
131
173
|
}
|
|
132
174
|
|
|
175
|
+
supportsLet() {
|
|
176
|
+
return this.outputOptions.environment.let;
|
|
177
|
+
}
|
|
178
|
+
|
|
133
179
|
supportsMethodShorthand() {
|
|
134
180
|
return this.outputOptions.environment.methodShorthand;
|
|
135
181
|
}
|
|
136
182
|
|
|
183
|
+
supportsLogicalAssignment() {
|
|
184
|
+
return this.outputOptions.environment.logicalAssignment;
|
|
185
|
+
}
|
|
186
|
+
|
|
137
187
|
supportsArrowFunction() {
|
|
138
188
|
return this.outputOptions.environment.arrowFunction;
|
|
139
189
|
}
|
|
@@ -146,6 +196,18 @@ class RuntimeTemplate {
|
|
|
146
196
|
return this.outputOptions.environment.optionalChaining;
|
|
147
197
|
}
|
|
148
198
|
|
|
199
|
+
supportsSpread() {
|
|
200
|
+
return this.outputOptions.environment.spread;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
supportsObjectHasOwn() {
|
|
204
|
+
return this.outputOptions.environment.hasOwn;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
supportsSymbol() {
|
|
208
|
+
return this.outputOptions.environment.symbol;
|
|
209
|
+
}
|
|
210
|
+
|
|
149
211
|
supportsForOf() {
|
|
150
212
|
return this.outputOptions.environment.forOf;
|
|
151
213
|
}
|
|
@@ -186,11 +248,19 @@ class RuntimeTemplate {
|
|
|
186
248
|
}
|
|
187
249
|
|
|
188
250
|
/**
|
|
189
|
-
* Renders return const when it is supported, otherwise var.
|
|
190
|
-
* @returns {"const" | "var"} return `const` when it is supported, otherwise `var`
|
|
251
|
+
* Renders return const when it is supported, otherwise let when supported, otherwise var.
|
|
252
|
+
* @returns {"const" | "let" | "var"} return `const` when it is supported, otherwise `let` when supported, otherwise `var`
|
|
191
253
|
*/
|
|
192
254
|
renderConst() {
|
|
193
|
-
return this.supportsConst() ? "const" : "var";
|
|
255
|
+
return this.supportsConst() ? "const" : this.supportsLet() ? "let" : "var";
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Renders return let when it is supported, otherwise var.
|
|
260
|
+
* @returns {"let" | "var"} return `let` when it is supported, otherwise `var`
|
|
261
|
+
*/
|
|
262
|
+
renderLet() {
|
|
263
|
+
return this.supportsLet() ? "let" : "var";
|
|
194
264
|
}
|
|
195
265
|
|
|
196
266
|
/**
|
|
@@ -305,6 +375,80 @@ class RuntimeTemplate {
|
|
|
305
375
|
return this.supportsArrowFunction() ? "x => {}" : "function() {}";
|
|
306
376
|
}
|
|
307
377
|
|
|
378
|
+
/**
|
|
379
|
+
* Guards an access/call on `object` with optional chaining when supported,
|
|
380
|
+
* otherwise an equivalent `&&` short-circuit. `object` is evaluated twice in
|
|
381
|
+
* the fallback, so it must be side-effect free.
|
|
382
|
+
* @param {string} object base expression (side-effect free)
|
|
383
|
+
* @param {string} access continuation after the optional point, e.g. `()`, `prop`, `method(arg)` or `[key]`
|
|
384
|
+
* @returns {string} guarded access expression
|
|
385
|
+
*/
|
|
386
|
+
optionalChaining(object, access) {
|
|
387
|
+
if (this.supportsOptionalChaining()) {
|
|
388
|
+
return `${object}?.${access}`;
|
|
389
|
+
}
|
|
390
|
+
const sep = access[0] === "(" || access[0] === "[" ? "" : ".";
|
|
391
|
+
return `${object} && ${object}${sep}${access}`;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* Reads a node builtin via `process.getBuiltinModule()`, guarded to stay falsy off node so universal `["node", "web"]` bundles don't crash (also falsy on node <22.3).
|
|
396
|
+
* @param {string} request builtin module request as a JS string expression, e.g. from `renderNodePrefixForCoreModule`
|
|
397
|
+
* @param {string=} access member/call chain appended to the module, e.g. `.Worker` or `.createRequire(url)`
|
|
398
|
+
* @returns {string} guarded expression
|
|
399
|
+
*/
|
|
400
|
+
getBuiltinModule(request, access = "") {
|
|
401
|
+
const getter = `process.getBuiltinModule(${request})${access}`;
|
|
402
|
+
if (this.outputOptions.environment.nodeBuiltinModuleGetter) {
|
|
403
|
+
return `typeof process !== "undefined" && ${getter}`;
|
|
404
|
+
}
|
|
405
|
+
return `typeof process !== "undefined" && typeof process.getBuiltinModule === "function" && ${getter}`;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* Renders an object-literal method, using method shorthand when supported
|
|
410
|
+
* and falling back to a `prop: function/arrow` property otherwise.
|
|
411
|
+
* @param {string} prop property name (or computed key like `[x]`)
|
|
412
|
+
* @param {string} args arguments
|
|
413
|
+
* @param {string | string[]} body body
|
|
414
|
+
* @returns {string} method code
|
|
415
|
+
*/
|
|
416
|
+
method(prop, args, body) {
|
|
417
|
+
return this.supportsMethodShorthand()
|
|
418
|
+
? `${prop}(${args}) {\n${Template.indent(body)}\n}`
|
|
419
|
+
: `${prop}: ${this.basicFunction(args, body)}`;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Returns an own-property check, using `Object.hasOwn` when supported and
|
|
424
|
+
* falling back to `Object.prototype.hasOwnProperty.call` otherwise.
|
|
425
|
+
* @param {string} object object expression
|
|
426
|
+
* @param {string} property property expression
|
|
427
|
+
* @returns {string} own-property check expression
|
|
428
|
+
*/
|
|
429
|
+
objectHasOwn(object, property) {
|
|
430
|
+
return this.supportsObjectHasOwn()
|
|
431
|
+
? `Object.hasOwn(${object}, ${property})`
|
|
432
|
+
: `Object.prototype.hasOwnProperty.call(${object}, ${property})`;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* Returns a self-defaulting assignment, using the `||=` logical assignment
|
|
437
|
+
* operator when supported and falling back to `target = target || value`
|
|
438
|
+
* otherwise. `target` is evaluated twice in the fallback, so it must be
|
|
439
|
+
* side-effect free. The expression evaluates to the resulting value.
|
|
440
|
+
* Models `||` only, so `target` must never hold a legitimate falsy value
|
|
441
|
+
* (`0`, `""`, `false`) — it would be overwritten; use it for object/array defaults.
|
|
442
|
+
* @param {string} target assignment target (side-effect free)
|
|
443
|
+
* @param {string} value default value expression
|
|
444
|
+
* @returns {string} assignment expression
|
|
445
|
+
*/
|
|
446
|
+
assignOr(target, value) {
|
|
447
|
+
return this.supportsLogicalAssignment()
|
|
448
|
+
? `${target} ||= ${value}`
|
|
449
|
+
: `${target} = ${target} || ${value}`;
|
|
450
|
+
}
|
|
451
|
+
|
|
308
452
|
/**
|
|
309
453
|
* Returns destructure array code.
|
|
310
454
|
* @param {string[]} items items
|
|
@@ -312,10 +456,11 @@ class RuntimeTemplate {
|
|
|
312
456
|
* @returns {string} destructure array code
|
|
313
457
|
*/
|
|
314
458
|
destructureArray(items, value) {
|
|
459
|
+
const decl = this.renderLet();
|
|
315
460
|
return this.supportsDestructuring()
|
|
316
|
-
?
|
|
461
|
+
? `${decl} [${items.join(", ")}] = ${value};`
|
|
317
462
|
: Template.asString(
|
|
318
|
-
items.map((item, i) =>
|
|
463
|
+
items.map((item, i) => `${decl} ${item} = ${value}[${i}];`)
|
|
319
464
|
);
|
|
320
465
|
}
|
|
321
466
|
|
|
@@ -326,11 +471,12 @@ class RuntimeTemplate {
|
|
|
326
471
|
* @returns {string} destructure object code
|
|
327
472
|
*/
|
|
328
473
|
destructureObject(items, value) {
|
|
474
|
+
const decl = this.renderLet();
|
|
329
475
|
return this.supportsDestructuring()
|
|
330
|
-
?
|
|
476
|
+
? `${decl} {${items.join(", ")}} = ${value};`
|
|
331
477
|
: Template.asString(
|
|
332
478
|
items.map(
|
|
333
|
-
(item) =>
|
|
479
|
+
(item) => `${decl} ${item} = ${value}${propertyAccess([item])};`
|
|
334
480
|
)
|
|
335
481
|
);
|
|
336
482
|
}
|
|
@@ -399,7 +545,7 @@ class RuntimeTemplate {
|
|
|
399
545
|
*/
|
|
400
546
|
throwMissingModuleErrorBlock({ request }) {
|
|
401
547
|
const err = `Cannot find module '${request}'`;
|
|
402
|
-
return
|
|
548
|
+
return `${this.renderConst()} e = new Error(${JSON.stringify(
|
|
403
549
|
err
|
|
404
550
|
)}); e.code = 'MODULE_NOT_FOUND'; throw e;`;
|
|
405
551
|
}
|
|
@@ -469,9 +615,7 @@ class RuntimeTemplate {
|
|
|
469
615
|
`Module '${moduleId}' is not available (weak dependency)`
|
|
470
616
|
);
|
|
471
617
|
const comment = request ? `${Template.toNormalComment(request)} ` : "";
|
|
472
|
-
const errorStatements =
|
|
473
|
-
comment
|
|
474
|
-
}e.code = 'MODULE_NOT_FOUND'; throw e;`;
|
|
618
|
+
const errorStatements = `${this.renderConst()} e = new Error(${errorMessage}); ${comment}e.code = 'MODULE_NOT_FOUND'; throw e;`;
|
|
475
619
|
switch (type) {
|
|
476
620
|
case "statements":
|
|
477
621
|
return errorStatements;
|
|
@@ -715,7 +859,7 @@ class RuntimeTemplate {
|
|
|
715
859
|
if (weak) {
|
|
716
860
|
if (idExpr.length > 8) {
|
|
717
861
|
// 'var x="nnnnnn";x,"+x+",x' vs '"nnnnnn",nnnnnn,"nnnnnn"'
|
|
718
|
-
header +=
|
|
862
|
+
header += `${this.renderConst()} id = ${idExpr}; `;
|
|
719
863
|
idExpr = "id";
|
|
720
864
|
}
|
|
721
865
|
runtimeRequirements.add(RuntimeGlobals.moduleFactories);
|
|
@@ -751,11 +895,17 @@ class RuntimeTemplate {
|
|
|
751
895
|
if (header) {
|
|
752
896
|
appending = `.then(${this.basicFunction(
|
|
753
897
|
"",
|
|
754
|
-
`${header}return ${
|
|
898
|
+
`${header}return ${
|
|
899
|
+
RuntimeGlobals.deferredModuleAsyncTransitiveDependencies
|
|
900
|
+
}(${JSON.stringify(asyncDeps)});`
|
|
755
901
|
)})`;
|
|
756
902
|
} else {
|
|
757
903
|
runtimeRequirements.add(RuntimeGlobals.require);
|
|
758
|
-
appending = `.then(${this.returningFunction(
|
|
904
|
+
appending = `.then(${this.returningFunction(
|
|
905
|
+
`${
|
|
906
|
+
RuntimeGlobals.deferredModuleAsyncTransitiveDependencies
|
|
907
|
+
}(${JSON.stringify(asyncDeps)})`
|
|
908
|
+
)})`;
|
|
759
909
|
}
|
|
760
910
|
appending += `.then(${RuntimeGlobals.makeDeferredNamespaceObject}.bind(${RuntimeGlobals.require}, ${comment}${idExpr}, ${mode}))`;
|
|
761
911
|
} else if (header) {
|
|
@@ -943,6 +1093,10 @@ class RuntimeTemplate {
|
|
|
943
1093
|
request,
|
|
944
1094
|
weak
|
|
945
1095
|
});
|
|
1096
|
+
// Harmony imports may be wrapped in runtime-condition `if` blocks
|
|
1097
|
+
// but referenced outside those blocks (e.g. by harmony reexport),
|
|
1098
|
+
// so they must remain function-scoped (`var`) rather than
|
|
1099
|
+
// block-scoped (`let`/`const`).
|
|
946
1100
|
const optDeclaration = update ? "" : "var ";
|
|
947
1101
|
|
|
948
1102
|
const exportsType = module.getExportsType(
|
|
@@ -1005,6 +1159,7 @@ class RuntimeTemplate {
|
|
|
1005
1159
|
* @param {RuntimeSpec} options.runtime runtime for which this code will be generated
|
|
1006
1160
|
* @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
|
|
1007
1161
|
* @param {ModuleDependency} options.dependency module dependency
|
|
1162
|
+
* @param {boolean=} options.mangleableNamespace true, when a whole-namespace value may use a decoupled namespace object that keeps the original export names
|
|
1008
1163
|
* @returns {string} expression
|
|
1009
1164
|
*/
|
|
1010
1165
|
exportFromImport({
|
|
@@ -1022,7 +1177,8 @@ class RuntimeTemplate {
|
|
|
1022
1177
|
initFragments,
|
|
1023
1178
|
runtime,
|
|
1024
1179
|
runtimeRequirements,
|
|
1025
|
-
dependency
|
|
1180
|
+
dependency,
|
|
1181
|
+
mangleableNamespace = false
|
|
1026
1182
|
}) {
|
|
1027
1183
|
if (!module) {
|
|
1028
1184
|
return this.missingModule({
|
|
@@ -1057,6 +1213,11 @@ class RuntimeTemplate {
|
|
|
1057
1213
|
);
|
|
1058
1214
|
return `${comment} undefined`;
|
|
1059
1215
|
}
|
|
1216
|
+
if (used instanceof InlinedUsedName) {
|
|
1217
|
+
throw new Error(
|
|
1218
|
+
"Can't inline the exports of defer imported module"
|
|
1219
|
+
);
|
|
1220
|
+
}
|
|
1060
1221
|
const access = `${importVar}.a${propertyAccess(used)}`;
|
|
1061
1222
|
if (isCall || asiSafe === undefined) {
|
|
1062
1223
|
return access;
|
|
@@ -1115,7 +1276,7 @@ class RuntimeTemplate {
|
|
|
1115
1276
|
runtimeRequirements.add(RuntimeGlobals.createFakeNamespaceObject);
|
|
1116
1277
|
initFragments.push(
|
|
1117
1278
|
new InitFragment(
|
|
1118
|
-
|
|
1279
|
+
`${this.renderLet()} ${importVar}_namespace_cache;\n`,
|
|
1119
1280
|
InitFragment.STAGE_CONSTANTS,
|
|
1120
1281
|
-1,
|
|
1121
1282
|
`${importVar}_namespace_cache`
|
|
@@ -1140,6 +1301,13 @@ class RuntimeTemplate {
|
|
|
1140
1301
|
);
|
|
1141
1302
|
return `${comment} undefined`;
|
|
1142
1303
|
}
|
|
1304
|
+
if (used instanceof InlinedUsedName) {
|
|
1305
|
+
return used.render(
|
|
1306
|
+
Template.toNormalComment(
|
|
1307
|
+
`inlined export ${propertyAccess(exportName)}`
|
|
1308
|
+
)
|
|
1309
|
+
);
|
|
1310
|
+
}
|
|
1143
1311
|
const comment = equals(used, exportName)
|
|
1144
1312
|
? ""
|
|
1145
1313
|
: `${Template.toNormalComment(propertyAccess(exportName))} `;
|
|
@@ -1158,7 +1326,7 @@ class RuntimeTemplate {
|
|
|
1158
1326
|
if (isModuleDeferred) {
|
|
1159
1327
|
initFragments.push(
|
|
1160
1328
|
new InitFragment(
|
|
1161
|
-
|
|
1329
|
+
`${this.renderLet()} ${importVar}_deferred_namespace_cache;\n`,
|
|
1162
1330
|
InitFragment.STAGE_CONSTANTS,
|
|
1163
1331
|
-1,
|
|
1164
1332
|
`${importVar}_deferred_namespace_cache`
|
|
@@ -1176,12 +1344,101 @@ class RuntimeTemplate {
|
|
|
1176
1344
|
asiSafe ? "" : asiSafe === false ? ";" : "Object"
|
|
1177
1345
|
}(${importVar}_deferred_namespace_cache || (${importVar}_deferred_namespace_cache = ${init}))`;
|
|
1178
1346
|
}
|
|
1347
|
+
// The whole namespace object is used as a value. If the module's exports
|
|
1348
|
+
// were mangled, importVar's keys are the mangled names, so we materialize
|
|
1349
|
+
// a decoupled namespace object that exposes the original names.
|
|
1350
|
+
if (
|
|
1351
|
+
exportsType === "namespace" &&
|
|
1352
|
+
mangleableNamespace &&
|
|
1353
|
+
this.compilation &&
|
|
1354
|
+
this.compilation.options.optimization.mangleExports
|
|
1355
|
+
) {
|
|
1356
|
+
const materialized = this._materializedNamespaceObject({
|
|
1357
|
+
moduleGraph,
|
|
1358
|
+
module,
|
|
1359
|
+
importVar,
|
|
1360
|
+
initFragments,
|
|
1361
|
+
runtime,
|
|
1362
|
+
runtimeRequirements
|
|
1363
|
+
});
|
|
1364
|
+
if (materialized !== undefined) return materialized;
|
|
1365
|
+
}
|
|
1179
1366
|
// if we hit here, the importVar is either
|
|
1180
1367
|
// - already a ES module namespace object
|
|
1181
1368
|
// - or imported by a way that does not need interop.
|
|
1182
1369
|
return importVar;
|
|
1183
1370
|
}
|
|
1184
1371
|
|
|
1372
|
+
/**
|
|
1373
|
+
* Materializes a namespace object that keeps the original export names while
|
|
1374
|
+
* the module's own exports are mangled. Returns undefined when no export was
|
|
1375
|
+
* mangled (then the raw namespace object can be used as-is).
|
|
1376
|
+
* @template GenerateContext
|
|
1377
|
+
* @param {object} options options
|
|
1378
|
+
* @param {ModuleGraph} options.moduleGraph the module graph
|
|
1379
|
+
* @param {Module} options.module the imported module
|
|
1380
|
+
* @param {string} options.importVar the import variable referencing the module
|
|
1381
|
+
* @param {InitFragment<GenerateContext>[]} options.initFragments target array for init fragments
|
|
1382
|
+
* @param {RuntimeSpec} options.runtime the runtime
|
|
1383
|
+
* @param {RuntimeRequirements} options.runtimeRequirements runtime requirements
|
|
1384
|
+
* @returns {string | undefined} expression of the materialized namespace object, or undefined
|
|
1385
|
+
*/
|
|
1386
|
+
_materializedNamespaceObject({
|
|
1387
|
+
moduleGraph,
|
|
1388
|
+
module,
|
|
1389
|
+
importVar,
|
|
1390
|
+
initFragments,
|
|
1391
|
+
runtime,
|
|
1392
|
+
runtimeRequirements
|
|
1393
|
+
}) {
|
|
1394
|
+
const exportsInfo = moduleGraph.getExportsInfo(module);
|
|
1395
|
+
/** @type {string[]} */
|
|
1396
|
+
const definitions = [];
|
|
1397
|
+
let mangled = false;
|
|
1398
|
+
for (const exportInfo of exportsInfo.orderedExports) {
|
|
1399
|
+
if (exportInfo.provided === false) continue;
|
|
1400
|
+
const used = exportsInfo.getUsedName([exportInfo.name], runtime);
|
|
1401
|
+
if (!used) continue;
|
|
1402
|
+
if (used instanceof InlinedUsedName) {
|
|
1403
|
+
// An inlined export isn't reachable by name on the raw exports object,
|
|
1404
|
+
// so the decoupled object must expose the inlined value directly.
|
|
1405
|
+
mangled = true;
|
|
1406
|
+
definitions.push(
|
|
1407
|
+
`${propertyName(exportInfo.name)}: ${this.returningFunction(
|
|
1408
|
+
used.render(
|
|
1409
|
+
Template.toNormalComment(
|
|
1410
|
+
`inlined export ${propertyAccess([exportInfo.name])}`
|
|
1411
|
+
)
|
|
1412
|
+
)
|
|
1413
|
+
)}`
|
|
1414
|
+
);
|
|
1415
|
+
continue;
|
|
1416
|
+
}
|
|
1417
|
+
if (used[used.length - 1] !== exportInfo.name) mangled = true;
|
|
1418
|
+
definitions.push(
|
|
1419
|
+
`${propertyName(exportInfo.name)}: ${this.returningFunction(
|
|
1420
|
+
`${importVar}${propertyAccess(used)}`
|
|
1421
|
+
)}`
|
|
1422
|
+
);
|
|
1423
|
+
}
|
|
1424
|
+
if (!mangled) return;
|
|
1425
|
+
const name = `${importVar}_namespace_object`;
|
|
1426
|
+
runtimeRequirements.add(RuntimeGlobals.exports);
|
|
1427
|
+
runtimeRequirements.add(RuntimeGlobals.makeNamespaceObject);
|
|
1428
|
+
runtimeRequirements.add(RuntimeGlobals.definePropertyGetters);
|
|
1429
|
+
initFragments.push(
|
|
1430
|
+
new InitFragment(
|
|
1431
|
+
`var ${name} = {};\n${RuntimeGlobals.makeNamespaceObject}(${name});\n${
|
|
1432
|
+
RuntimeGlobals.definePropertyGetters
|
|
1433
|
+
}(${name}, {\n\t${definitions.join(",\n\t")}\n});\n`,
|
|
1434
|
+
InitFragment.STAGE_PROVIDES,
|
|
1435
|
+
0,
|
|
1436
|
+
name
|
|
1437
|
+
)
|
|
1438
|
+
);
|
|
1439
|
+
return name;
|
|
1440
|
+
}
|
|
1441
|
+
|
|
1185
1442
|
/**
|
|
1186
1443
|
* Returns expression.
|
|
1187
1444
|
* @param {object} options options
|
package/lib/SelfModuleFactory.js
CHANGED
|
@@ -11,6 +11,7 @@ const Compilation = require("./Compilation");
|
|
|
11
11
|
const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
|
|
12
12
|
const ProgressPlugin = require("./ProgressPlugin");
|
|
13
13
|
const SourceMapDevToolModuleOptionsPlugin = require("./SourceMapDevToolModuleOptionsPlugin");
|
|
14
|
+
const { getPresentKinds } = require("./TemplatedPathPlugin");
|
|
14
15
|
const createHash = require("./util/createHash");
|
|
15
16
|
const { dirname, relative } = require("./util/fs");
|
|
16
17
|
const generateDebugId = require("./util/generateDebugId");
|
|
@@ -46,7 +47,6 @@ const { makePathsAbsolute } = require("./util/identifier");
|
|
|
46
47
|
*/
|
|
47
48
|
|
|
48
49
|
const METACHARACTERS_REGEXP = /[-[\]\\/{}()*+?.^$|]/g;
|
|
49
|
-
const CONTENT_HASH_DETECT_REGEXP = /\[contenthash(?::\w+)?\]/;
|
|
50
50
|
const CSS_AND_JS_MODULE_EXTENSIONS_REGEXP = /\.((c|m)?js|css)($|\?)/i;
|
|
51
51
|
const CSS_EXTENSION_DETECT_REGEXP = /\.css(?:$|\?)/i;
|
|
52
52
|
const MAP_URL_COMMENT_REGEXP = /\[map\]/g;
|
|
@@ -681,10 +681,8 @@ class SourceMapDevToolPlugin {
|
|
|
681
681
|
}
|
|
682
682
|
|
|
683
683
|
const usesContentHash =
|
|
684
|
-
sourceMapFilename &&
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
resetRegexpState(CONTENT_HASH_DETECT_REGEXP);
|
|
684
|
+
typeof sourceMapFilename === "string" &&
|
|
685
|
+
getPresentKinds(sourceMapFilename).has("contenthash");
|
|
688
686
|
|
|
689
687
|
let outputFile = file;
|
|
690
688
|
// If SourceMap and asset uses contenthash, avoid a circular dependency by hiding hash in `file`
|
package/lib/Stats.js
CHANGED
package/lib/Template.js
CHANGED
|
@@ -34,6 +34,10 @@ const NUMBER_OF_IDENTIFIER_START_CHARS = DELTA_A_TO_Z * 2 + 2; // a-z A-Z _ $
|
|
|
34
34
|
const NUMBER_OF_IDENTIFIER_CONTINUATION_CHARS =
|
|
35
35
|
NUMBER_OF_IDENTIFIER_START_CHARS + 10; // a-z A-Z _ $ 0-9
|
|
36
36
|
const FUNCTION_CONTENT_REGEX = /^function\s?\(\)\s?\{\r?\n?|\r?\n?\}$/g;
|
|
37
|
+
// JSDoc type annotations exist only to type the runtime template; strip them so
|
|
38
|
+
// they are never emitted into the bundle. Whole-line blocks drop the line too.
|
|
39
|
+
const JSDOC_LINE_REGEX = /^[ \t]*\/\*\*(?:[^*]|\*(?!\/))*\*\/[ \t]*\r?\n/gm;
|
|
40
|
+
const JSDOC_INLINE_REGEX = /\/\*\*(?:[^*]|\*(?!\/))*\*\/[ \t]*/g;
|
|
37
41
|
const INDENT_MULTILINE_REGEX = /^\t/gm;
|
|
38
42
|
const LINE_SEPARATOR_REGEX = /\r?\n/g;
|
|
39
43
|
const IDENTIFIER_NAME_REPLACE_REGEX = /^([^a-z$_])/i;
|
|
@@ -102,6 +106,8 @@ class Template {
|
|
|
102
106
|
static getFunctionContent(fn) {
|
|
103
107
|
return fn
|
|
104
108
|
.toString()
|
|
109
|
+
.replace(JSDOC_LINE_REGEX, "")
|
|
110
|
+
.replace(JSDOC_INLINE_REGEX, "")
|
|
105
111
|
.replace(FUNCTION_CONTENT_REGEX, "")
|
|
106
112
|
.replace(INDENT_MULTILINE_REGEX, "")
|
|
107
113
|
.replace(LINE_SEPARATOR_REGEX, "\n");
|
|
@@ -126,7 +132,7 @@ class Template {
|
|
|
126
132
|
*/
|
|
127
133
|
static toComment(str) {
|
|
128
134
|
if (!str) return "";
|
|
129
|
-
return `/*! ${str.replace(COMMENT_END_REGEX, "* /")} */`;
|
|
135
|
+
return `/*! ${str.includes("*/") ? str.replace(COMMENT_END_REGEX, "* /") : str} */`;
|
|
130
136
|
}
|
|
131
137
|
|
|
132
138
|
/**
|
|
@@ -136,7 +142,7 @@ class Template {
|
|
|
136
142
|
*/
|
|
137
143
|
static toNormalComment(str) {
|
|
138
144
|
if (!str) return "";
|
|
139
|
-
return `/* ${str.replace(COMMENT_END_REGEX, "* /")} */`;
|
|
145
|
+
return `/* ${str.includes("*/") ? str.replace(COMMENT_END_REGEX, "* /") : str} */`;
|
|
140
146
|
}
|
|
141
147
|
|
|
142
148
|
/**
|