@depup/webpack 5.110.1-depup.0 → 5.111.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 +7 -8
- package/changes.json +7 -11
- package/lib/APIPlugin.js +26 -11
- package/lib/AutomaticPrefetchPlugin.js +1 -1
- package/lib/Cache.js +8 -3
- package/lib/CacheFacade.js +1 -1
- package/lib/ChunkGraph.js +20 -18
- package/lib/CircularModulesPlugin.js +157 -55
- package/lib/CleanPlugin.js +2 -2
- package/lib/CompatibilityPlugin.js +3 -4
- package/lib/Compilation.js +337 -338
- package/lib/Compiler.js +213 -51
- package/lib/ConcatenationScope.js +25 -35
- package/lib/ConstPlugin.js +16 -132
- package/lib/CopyPlugin.js +1054 -0
- package/lib/DefinePlugin.js +24 -8
- package/lib/DependencyTemplate.js +2 -1
- package/lib/DotenvPlugin.js +64 -40
- package/lib/ErrorHelpers.js +113 -0
- package/lib/ExportsInfo.js +30 -16
- package/lib/ExternalModule.js +47 -22
- package/lib/FileSystemInfo.js +17 -14
- package/lib/FlagDependencyExportsPlugin.js +53 -34
- package/lib/FlagDependencyUsagePlugin.js +17 -15
- package/lib/Generator.js +24 -2
- package/lib/HotModuleReplacementPlugin.js +55 -7
- package/lib/IgnorePlugin.js +1 -1
- package/lib/JavascriptMetaInfoPlugin.js +5 -3
- package/lib/LoaderOptionsPlugin.js +1 -1
- package/lib/MainTemplate.js +5 -1
- package/lib/Module.js +19 -10
- package/lib/ModuleGraph.js +6 -9
- package/lib/MultiCompiler.js +7 -17
- package/lib/MultiWatching.js +1 -1
- package/lib/NormalModule.js +148 -70
- package/lib/NormalModuleFactory.js +1 -1
- package/lib/RuntimeGlobals.js +21 -7
- package/lib/RuntimeModule.js +28 -12
- package/lib/RuntimePlugin.js +33 -3
- package/lib/RuntimeTemplate.js +1147 -847
- package/lib/SourceMapDevToolPlugin.js +54 -104
- package/lib/TemplatedPathPlugin.js +16 -59
- package/lib/Watching.js +9 -0
- package/lib/WebpackOptionsApply.js +84 -91
- package/lib/asset/AssetBytesGenerator.js +7 -1
- package/lib/asset/AssetGenerator.js +50 -24
- package/lib/asset/AssetModule.js +3 -0
- package/lib/asset/AssetSourceGenerator.js +7 -1
- package/lib/asset/WebManifestParser.js +7 -5
- package/lib/async-modules/AsyncModuleHelpers.js +10 -4
- package/lib/buildChunkGraph.js +11 -15
- package/lib/cache/AddBuildDependenciesPlugin.js +33 -4
- package/lib/cache/IdleFileCachePlugin.js +2 -2
- package/lib/cache/MemoryCachePlugin.js +4 -4
- package/lib/cache/MemoryWithGcCachePlugin.js +7 -8
- package/lib/cache/PackFileCacheStrategy.js +17 -19
- package/lib/cache/getLazyHashedEtag.js +3 -5
- package/lib/config/browserslistTargetHandler.js +17 -4
- package/lib/config/defaults.js +162 -142
- package/lib/config/getClaimedAssetTypes.js +10 -11
- package/lib/config/normalization.js +100 -20
- package/lib/config/target.js +13 -4
- package/lib/container/ContainerReferencePlugin.js +6 -0
- package/lib/container/RemoteRuntimeModule.js +9 -0
- package/lib/container/declaredRemotes.js +39 -0
- package/lib/{ContextExclusionPlugin.js → context/ContextExclusionPlugin.js} +1 -1
- package/lib/{ContextModule.js → context/ContextModule.js} +54 -115
- package/lib/{ContextModuleFactory.js → context/ContextModuleFactory.js} +19 -21
- package/lib/{ContextReplacementPlugin.js → context/ContextReplacementPlugin.js} +4 -4
- package/lib/css/CssGenerator.js +27 -11
- package/lib/css/CssInjectStyleRuntimeModule.js +9 -0
- package/lib/css/CssLoadingRuntimeModule.js +92 -15
- package/lib/css/CssModule.js +1 -1
- package/lib/css/CssModulesPlugin.js +3 -10
- package/lib/css/CssParser.js +162 -31
- package/lib/css/CssServerStylesRuntimeModule.js +9 -0
- package/lib/css/cssMinify.js +43 -32
- package/lib/css/data.js +3526 -871
- package/lib/css/syntax.js +6455 -1237
- package/lib/debug/ProfilingPlugin.js +7 -4
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -3
- package/lib/dependencies/AMDRuntimeModules.js +18 -0
- package/lib/dependencies/CommonJsExportRequireDependency.js +13 -12
- package/lib/dependencies/CommonJsExportsParserPlugin.js +12 -13
- package/lib/dependencies/CommonJsImportsParserPlugin.js +5 -5
- package/lib/dependencies/CommonJsPlugin.js +19 -3
- package/lib/dependencies/CommonJsRequireDependency.js +32 -9
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +2 -4
- package/lib/dependencies/ContextDependency.js +1 -1
- package/lib/dependencies/ContextDependencyHelpers.js +3 -9
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +20 -7
- package/lib/dependencies/ContextElementDependency.js +1 -1
- package/lib/dependencies/CssIcssExportDependency.js +13 -9
- package/lib/dependencies/CssIcssImportDependency.js +3 -6
- package/lib/dependencies/CssUrlDependency.js +3 -5
- package/lib/dependencies/HarmonyCompatibilityDependency.js +67 -22
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +3 -4
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +10 -4
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +12 -7
- package/lib/dependencies/HarmonyExportExpressionDependency.js +47 -33
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +217 -34
- package/lib/dependencies/HarmonyExportInitFragment.js +110 -23
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +25 -58
- package/lib/dependencies/HarmonyImportBareSideEffectDependency.js +59 -0
- package/lib/dependencies/HarmonyImportDependency.js +99 -41
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +198 -25
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +117 -4
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +40 -3
- package/lib/dependencies/HarmonyModulesPlugin.js +20 -0
- package/lib/dependencies/HtmlEntryDependency.js +136 -104
- package/lib/dependencies/HtmlInlineScriptDependency.js +3 -4
- package/lib/dependencies/HtmlInlineStyleDependency.js +3 -4
- package/lib/dependencies/ImportContextDependency.js +43 -3
- package/lib/dependencies/ImportDependency.js +8 -29
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -1
- package/lib/dependencies/ImportMetaGlobHelpers.js +1 -1
- package/lib/dependencies/ImportMetaMainDependency.js +104 -0
- package/lib/dependencies/ImportMetaPlugin.js +67 -25
- package/lib/dependencies/ImportParserPlugin.js +25 -15
- package/lib/dependencies/LoaderPlugin.js +26 -1
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -1
- package/lib/dependencies/RequireHeaderDependency.js +20 -21
- package/lib/dependencies/SystemRuntimeModule.js +9 -0
- package/lib/dependencies/URLContextDependency.js +1 -1
- package/lib/dependencies/URLDependency.js +6 -5
- package/lib/dependencies/WorkerAndWorkletPlugin.js +16 -21
- package/lib/dependencies/WorkerDependency.js +12 -18
- package/lib/dependencies/WorkletDependency.js +12 -20
- package/lib/dependencies/importOptionsCheck.js +47 -0
- package/lib/dll/DelegatedModule.js +18 -1
- package/lib/dll/DllReferencePlugin.js +11 -8
- package/lib/dll/LibManifestPlugin.js +1 -1
- package/lib/errors/AnalyzableBailoutsWarning.js +41 -0
- package/lib/errors/DotenvFileError.js +29 -0
- package/lib/errors/DuplicateModulesWarning.js +12 -7
- package/lib/errors/EmptyCopyPatternWarning.js +26 -0
- package/lib/errors/ExternalStarReexportError.js +44 -0
- package/lib/errors/HookWebpackError.js +3 -2
- package/lib/errors/ImportedBindingAssignmentError.js +30 -0
- package/lib/errors/MissingSourceMapsWarning.js +36 -0
- package/lib/errors/ModuleParseError.js +2 -1
- package/lib/errors/UnusedAssetsWarning.js +36 -0
- package/lib/errors/UnusedFederationWarning.js +35 -0
- package/lib/errors/UnusedModulesWarning.js +38 -0
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +9 -0
- package/lib/esm/ModuleChunkFormatPlugin.js +28 -3
- package/lib/esm/ModuleChunkLoadingPlugin.js +21 -5
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +91 -53
- package/lib/hmr/HotModuleReplacement.runtime.js +8 -2
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +9 -0
- package/lib/hmr/LazyCompilationPlugin.js +3 -5
- package/lib/html/HtmlGenerator.js +72 -87
- package/lib/html/HtmlModulesPlugin.js +479 -215
- package/lib/html/HtmlParser.js +110 -147
- package/lib/html/builtinEmbeddedRenderer.js +107 -0
- package/lib/html/data.js +142 -7
- package/lib/html/htmlMinify.js +92 -122
- package/lib/html/syntax.js +2031 -1556
- package/lib/ids/HashedModuleIdsPlugin.js +2 -1
- package/lib/index.js +49 -3
- package/lib/javascript/ChunkFormatHelpers.js +4 -3
- package/lib/javascript/JavascriptGenerator.js +8 -1
- package/lib/javascript/JavascriptModule.js +1 -0
- package/lib/javascript/JavascriptModulesPlugin.js +76 -80
- package/lib/javascript/JavascriptParser.js +1970 -900
- package/lib/javascript/StartupHelpers.js +27 -3
- package/lib/javascript/data.js +172 -0
- package/lib/javascript/grammar.js +5546 -0
- package/lib/javascript/parser.js +1500 -0
- package/lib/javascript/regexp.js +1762 -0
- package/lib/javascript/regexpData.js +51 -0
- package/lib/javascript/syntax.js +9061 -5262
- package/lib/json/JsonGenerator.js +7 -1
- package/lib/library/ModuleLibraryPlugin.js +171 -132
- package/lib/loaders/LoaderRunner.js +170 -14
- package/lib/node/NodeWatchFileSystem.js +3 -9
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +22 -0
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +8 -15
- package/lib/node/RequireChunkLoadingRuntimeModule.js +22 -0
- package/lib/optimize/AggressiveMergingPlugin.js +3 -5
- package/lib/optimize/ConcatenatedModule.js +222 -125
- package/lib/optimize/ConstExportsPlugin.js +50 -34
- package/lib/optimize/FlagIncludedChunksPlugin.js +3 -11
- package/lib/optimize/InlineExports.js +20 -2
- package/lib/optimize/InnerGraphPlugin.js +7 -13
- package/lib/optimize/LimitChunkCountPlugin.js +5 -8
- package/lib/optimize/MangleExportsPlugin.js +13 -4
- package/lib/optimize/ModuleConcatenationPlugin.js +27 -5
- package/lib/optimize/RealContentHashPlugin.js +179 -44
- package/lib/optimize/SideEffectsFlagPlugin.js +24 -28
- package/lib/optimize/SplitChunksPlugin.js +2 -4
- package/lib/performance/AnalyzableBailoutsPlugin.js +115 -0
- package/lib/performance/BroadContextsPlugin.js +1 -1
- package/lib/performance/CacheEffectivenessPlugin.js +7 -7
- package/lib/performance/DuplicateModulesPlugin.js +57 -13
- package/lib/performance/EvalUsagePlugin.js +5 -2
- package/lib/performance/MissingSourceMapsPlugin.js +115 -0
- package/lib/performance/PureAnnotationsPlugin.js +6 -3
- package/lib/performance/SizeLimitsPlugin.js +2 -4
- package/lib/performance/TopLevelThisPlugin.js +5 -4
- package/lib/performance/UnusedAssetsPlugin.js +109 -0
- package/lib/performance/UnusedFederationPlugin.js +147 -0
- package/lib/performance/UnusedModulesPlugin.js +141 -0
- package/lib/performance/UnusedReexportsPlugin.js +1 -55
- package/lib/performance/isOnlyReexported.js +65 -0
- package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +25 -5
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +8 -8
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +9 -0
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +9 -0
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +9 -0
- package/lib/prefetch/ResourceHintPlugin.js +29 -35
- package/lib/prefetch/ResourceHintRuntimeModule.js +9 -0
- package/lib/prefetch/StartupAssetHintRuntimeModule.js +16 -10
- package/lib/rules/RuleSetCompiler.js +211 -4
- package/lib/runtime/AsyncModuleRuntimeModule.js +103 -67
- package/lib/runtime/AutoPublicPathRuntimeModule.js +9 -0
- package/lib/runtime/BaseUriRuntimeModule.js +9 -0
- package/lib/runtime/ChunkNameRuntimeModule.js +9 -0
- package/lib/runtime/EnsureChunkRuntimeModule.js +35 -16
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +12 -4
- package/lib/runtime/GetFullHashRuntimeModule.js +9 -0
- package/lib/runtime/GetMainFilenameRuntimeModule.js +9 -0
- package/lib/runtime/GetWorkletBootstrapRuntimeModule.js +9 -0
- package/lib/runtime/GlobalRuntimeModule.js +11 -4
- package/lib/runtime/HasOwnPropertyRuntimeModule.js +9 -0
- package/lib/runtime/HelperRuntimeModule.js +10 -0
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +313 -222
- package/lib/runtime/NonceRuntimeModule.js +9 -0
- package/lib/runtime/OnChunksLoadedRuntimeModule.js +67 -20
- package/lib/runtime/PublicPathRuntimeModule.js +9 -0
- package/lib/runtime/RuntimeIdRuntimeModule.js +9 -0
- package/lib/runtime/SpecNamespaceObjectRuntimeModule.js +90 -0
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +9 -0
- package/lib/runtime/StartupEntrypointRuntimeModule.js +9 -0
- package/lib/runtime/SystemContextRuntimeModule.js +9 -0
- package/lib/runtime/ToBinaryRuntimeModule.js +9 -0
- package/lib/schemes/DataUriPlugin.js +3 -6
- package/lib/schemes/HttpUriPlugin.js +22 -5
- package/lib/schemes/VirtualUrlPlugin.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +9 -9
- package/lib/serialization/FileMiddleware.js +31 -18
- package/lib/serialization/ObjectMiddleware.js +168 -139
- package/lib/sharing/ConsumeSharedPlugin.js +12 -0
- package/lib/sharing/ConsumeSharedRuntimeModule.js +11 -0
- package/lib/sharing/ShareRuntimeModule.js +9 -0
- package/lib/sharing/declaredShared.js +47 -0
- package/lib/stats/DefaultStatsFactoryPlugin.js +6 -5
- package/lib/stats/DefaultStatsPrinterPlugin.js +3 -0
- package/lib/typescript/TypeScriptPlugin.js +10 -13
- package/lib/url/URLParserPlugin.js +6 -8
- package/lib/util/ArrayQueue.js +3 -3
- package/lib/util/LocConverter.js +4 -7
- package/lib/util/SourceProcessor.js +115 -99
- package/lib/util/URLAbsoluteSpecifier.js +3 -1
- package/lib/util/async.js +292 -0
- package/lib/util/buildDiagnostics.js +69 -0
- package/lib/util/chainedImports.js +3 -4
- package/lib/util/concatenate.js +4 -4
- package/lib/util/conventions.js +5 -1
- package/lib/util/createHooksRegistry.js +1 -2
- package/lib/util/createMappings.js +25 -3
- package/lib/util/dataURL.js +2 -3
- package/lib/util/deterministicGrouping.js +8 -13
- package/lib/util/findGraphRoots.js +6 -13
- package/lib/util/fs.js +27 -1
- package/lib/util/globUtils.js +1 -1
- package/lib/util/handlerKeys.js +40 -0
- package/lib/util/hash/wasm-hash.js +3 -4
- package/lib/util/identifier.js +20 -0
- package/lib/util/internalSerializables.js +7 -1
- package/lib/util/registerExternalSerializer.js +6 -45
- package/lib/util/removeBOM.js +82 -1
- package/lib/util/semver.js +5 -3
- package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +14 -3
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +14 -3
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +6 -1
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -1
- package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +7 -12
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +12 -4
- package/lib/wasm-sync/WebAssemblyGenerator.js +6 -1
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +5 -1
- package/lib/wasm-sync/WebAssemblyUtils.js +2 -4
- package/lib/web/FetchCompileAsyncWasmPlugin.js +10 -6
- package/lib/web/FetchCompileWasmPlugin.js +4 -2
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +36 -0
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +19 -0
- package/package.json +55 -46
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +388 -76
- package/schemas/plugins/LoaderOptionsPlugin.check.js +1 -1
- package/schemas/plugins/ManifestPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
- package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
- package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/debug/ProfilingPlugin.check.js +1 -1
- package/schemas/plugins/dll/DllReferencePlugin.check.js +1 -1
- package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +1 -1
- package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
- package/types.d.ts +1795 -608
- package/lib/dependencies/ExportBindingInitFragment.js +0 -191
- package/lib/errors/EntrypointOverlapWarning.js +0 -45
- package/lib/performance/EntrypointOverlapPlugin.js +0 -122
|
@@ -34,11 +34,13 @@ const analyzeScope = require("../javascript/ScopeAnalyzer");
|
|
|
34
34
|
const {
|
|
35
35
|
getDeferredCycleModuleIds,
|
|
36
36
|
getDeferredCycleModules,
|
|
37
|
+
getKnownExportNames,
|
|
37
38
|
getMakeDeferredNamespaceModeFromExportsType,
|
|
38
39
|
getOptimizedDeferredModule
|
|
39
40
|
} = require("../runtime/MakeDeferredNamespaceObjectRuntime");
|
|
40
41
|
const { equals } = require("../util/ArrayHelpers");
|
|
41
42
|
const LazySet = require("../util/LazySet");
|
|
43
|
+
const { getBuildDiagnostics } = require("../util/buildDiagnostics");
|
|
42
44
|
const {
|
|
43
45
|
compareModulesByFullName,
|
|
44
46
|
concatComparators
|
|
@@ -116,8 +118,7 @@ const { InlinedUsedName } = require("./InlineExports");
|
|
|
116
118
|
* @import {
|
|
117
119
|
* ChunkRenderContext,
|
|
118
120
|
* Scope,
|
|
119
|
-
* Reference
|
|
120
|
-
* Variable
|
|
121
|
+
* Reference
|
|
121
122
|
* } from "../javascript/JavascriptModulesPlugin"
|
|
122
123
|
*/
|
|
123
124
|
/** @import { Range } from "../javascript/JavascriptParser" */
|
|
@@ -181,6 +182,7 @@ const findIdentifiers = (source) => {
|
|
|
181
182
|
* @property {string=} comment
|
|
182
183
|
* @property {ExportName} ids
|
|
183
184
|
* @property {ExportName} exportName
|
|
185
|
+
* @property {boolean=} accessorCall the raw name is the wrapper accessor call itself, so it binds looser than the identifier it replaces
|
|
184
186
|
*/
|
|
185
187
|
|
|
186
188
|
/**
|
|
@@ -246,6 +248,7 @@ const findIdentifiers = (source) => {
|
|
|
246
248
|
* @property {boolean} deferred the module is deferred at least once
|
|
247
249
|
* @property {boolean} deferredNamespaceObjectUsed deferred namespace object that being used in a not-analyzable way so it must be materialized
|
|
248
250
|
* @property {string | undefined} deferredNamespaceObjectName deferred namespace object that being used in a not-analyzable way so it must be materialized
|
|
251
|
+
* @property {boolean} specNamespaceObjectUsed an import reads the spec namespace object the module hands out
|
|
249
252
|
* @property {boolean} interopNamespaceObjectUsed "default-with-named" namespace
|
|
250
253
|
* @property {string | undefined} interopNamespaceObjectName "default-with-named" namespace
|
|
251
254
|
* @property {boolean} interopNamespaceObject2Used "default-only" namespace
|
|
@@ -422,13 +425,26 @@ const getInteropExpr = (info, interopName) =>
|
|
|
422
425
|
* slot, but a wrapped one only runs when its accessor is called, so dropping
|
|
423
426
|
* the reference would drop the module's side effects with it.
|
|
424
427
|
* @param {ConcatenatedModuleInfo} info module info
|
|
428
|
+
* @param {boolean | undefined} asiSafe asiSafe
|
|
425
429
|
* @returns {string} expression evaluating to undefined
|
|
426
430
|
*/
|
|
427
|
-
const getUnusedExportExpr = (info) =>
|
|
431
|
+
const getUnusedExportExpr = (info, asiSafe) =>
|
|
428
432
|
info.wrapped
|
|
429
|
-
?
|
|
433
|
+
? `${asiSafe === false ? ";" : ""}/* unused export */ (${info.namespaceObjectName}, undefined)`
|
|
430
434
|
: "/* unused export */ undefined";
|
|
431
435
|
|
|
436
|
+
/**
|
|
437
|
+
* Parenthesizes a reference that may already carry an ASI guard of its own,
|
|
438
|
+
* keeping that guard outside the new parentheses — nested it would not parse.
|
|
439
|
+
* @param {string} reference the reference
|
|
440
|
+
* @param {boolean | undefined} asiSafe asiSafe
|
|
441
|
+
* @returns {string} the parenthesized reference
|
|
442
|
+
*/
|
|
443
|
+
const parenthesizeReference = (reference, asiSafe) =>
|
|
444
|
+
asiSafe === false
|
|
445
|
+
? `;(${reference.startsWith(";") ? reference.slice(1) : reference})`
|
|
446
|
+
: `(${reference})`;
|
|
447
|
+
|
|
432
448
|
/**
|
|
433
449
|
* @param {ModuleGraph} moduleGraph the module graph
|
|
434
450
|
* @param {ModuleInfo} info module info
|
|
@@ -483,7 +499,7 @@ const getFinalBinding = (
|
|
|
483
499
|
if (!usedName) {
|
|
484
500
|
return {
|
|
485
501
|
info,
|
|
486
|
-
rawName: getUnusedExportExpr(info),
|
|
502
|
+
rawName: getUnusedExportExpr(info, asiSafe),
|
|
487
503
|
ids: [],
|
|
488
504
|
exportName
|
|
489
505
|
};
|
|
@@ -494,11 +510,14 @@ const getFinalBinding = (
|
|
|
494
510
|
/** @type {NonNullable<ConcatenatedModuleInfo["namespaceObjectName"]>} */
|
|
495
511
|
(info.namespaceObjectName),
|
|
496
512
|
ids: /** @type {ExportName} */ (usedName),
|
|
497
|
-
exportName
|
|
513
|
+
exportName,
|
|
514
|
+
accessorCall: info.wrapped
|
|
498
515
|
};
|
|
499
516
|
}
|
|
500
517
|
|
|
501
|
-
if (
|
|
518
|
+
if (moduleExportsAccess) {
|
|
519
|
+
// Skip ESM interop when require() targets a module outside the concatenation
|
|
520
|
+
} else if (exportName.length === 0) {
|
|
502
521
|
switch (exportsType) {
|
|
503
522
|
case "default-only":
|
|
504
523
|
if (deferred) info.deferredNamespaceObjectUsed = true;
|
|
@@ -509,7 +528,8 @@ const getFinalBinding = (
|
|
|
509
528
|
? /** @type {string} */ (info.deferredNamespaceObjectName)
|
|
510
529
|
: getInteropExpr(info, info.interopNamespaceObject2Name),
|
|
511
530
|
ids: exportName,
|
|
512
|
-
exportName
|
|
531
|
+
exportName,
|
|
532
|
+
accessorCall: !deferred && info.wrapped
|
|
513
533
|
};
|
|
514
534
|
case "default-with-named":
|
|
515
535
|
if (deferred) info.deferredNamespaceObjectUsed = true;
|
|
@@ -520,7 +540,8 @@ const getFinalBinding = (
|
|
|
520
540
|
? /** @type {string} */ (info.deferredNamespaceObjectName)
|
|
521
541
|
: getInteropExpr(info, info.interopNamespaceObjectName),
|
|
522
542
|
ids: exportName,
|
|
523
|
-
exportName
|
|
543
|
+
exportName,
|
|
544
|
+
accessorCall: !deferred && info.wrapped
|
|
524
545
|
};
|
|
525
546
|
case "namespace":
|
|
526
547
|
case "dynamic":
|
|
@@ -537,12 +558,13 @@ const getFinalBinding = (
|
|
|
537
558
|
case "default":
|
|
538
559
|
exportName = exportName.slice(1);
|
|
539
560
|
if (deferred) {
|
|
540
|
-
// `ns.default` for a deferred default-with-named external
|
|
541
|
-
// module must read through the optimized `.a` getter
|
|
542
|
-
//
|
|
543
|
-
//
|
|
544
|
-
// `typeof ns.default`
|
|
545
|
-
// observe the proxy
|
|
561
|
+
// WHY: `ns.default` for a deferred default-with-named external
|
|
562
|
+
// module must read through the optimized `.a` getter, which
|
|
563
|
+
// evaluates the
|
|
564
|
+
// module lazily and returns its exports, rather than through the
|
|
565
|
+
// proxy namespace — otherwise `typeof ns.default` and
|
|
566
|
+
// `ns.default instanceof X` observe the proxy, not the actual
|
|
567
|
+
// default.
|
|
546
568
|
return {
|
|
547
569
|
info,
|
|
548
570
|
rawName: `${info.deferredName}.a`,
|
|
@@ -581,10 +603,9 @@ const getFinalBinding = (
|
|
|
581
603
|
};
|
|
582
604
|
}
|
|
583
605
|
if (deferred) {
|
|
584
|
-
// As with default-with-named above,
|
|
585
|
-
//
|
|
586
|
-
//
|
|
587
|
-
// observe the actual default value rather than the proxy.
|
|
606
|
+
// As with default-with-named above, a deferred default-only
|
|
607
|
+
// external reads through the `.a` getter, so `typeof` and
|
|
608
|
+
// `instanceof` see the value rather than the proxy.
|
|
588
609
|
return {
|
|
589
610
|
info,
|
|
590
611
|
rawName: `${info.deferredName}.a`,
|
|
@@ -611,7 +632,8 @@ const getFinalBinding = (
|
|
|
611
632
|
info,
|
|
612
633
|
rawName: getExternalModuleExpr(info),
|
|
613
634
|
ids: exportName,
|
|
614
|
-
exportName
|
|
635
|
+
exportName,
|
|
636
|
+
accessorCall: info.wrapped
|
|
615
637
|
};
|
|
616
638
|
}
|
|
617
639
|
info.interopDefaultAccessUsed = true;
|
|
@@ -657,9 +679,10 @@ const getFinalBinding = (
|
|
|
657
679
|
/** @type {NonNullable<ConcatenatedModuleInfo["namespaceObjectName"]>} */
|
|
658
680
|
(info.namespaceObjectName),
|
|
659
681
|
ids: exportName,
|
|
660
|
-
exportName
|
|
682
|
+
exportName,
|
|
683
|
+
accessorCall: info.wrapped
|
|
661
684
|
};
|
|
662
|
-
case "external":
|
|
685
|
+
case "external": {
|
|
663
686
|
if (deferred) {
|
|
664
687
|
info.deferredNamespaceObjectUsed = true;
|
|
665
688
|
return {
|
|
@@ -669,12 +692,30 @@ const getFinalBinding = (
|
|
|
669
692
|
exportName
|
|
670
693
|
};
|
|
671
694
|
}
|
|
695
|
+
|
|
696
|
+
// `require()` reads the exports object rather than a namespace, so
|
|
697
|
+
// only an import gets the spec object and interop keeps working.
|
|
698
|
+
const spec =
|
|
699
|
+
!moduleExportsAccess &&
|
|
700
|
+
exportsType === "namespace" &&
|
|
701
|
+
Boolean(
|
|
702
|
+
/** @type {BuildInfo} */
|
|
703
|
+
(info.module.buildInfo).specNamespaceObject
|
|
704
|
+
);
|
|
705
|
+
const rawName = getExternalModuleExpr(info);
|
|
706
|
+
|
|
707
|
+
if (spec) info.specNamespaceObjectUsed = true;
|
|
708
|
+
|
|
672
709
|
return {
|
|
673
710
|
info,
|
|
674
|
-
rawName:
|
|
711
|
+
rawName: spec
|
|
712
|
+
? `${RuntimeGlobals.specNamespaceObject}(${rawName})`
|
|
713
|
+
: rawName,
|
|
675
714
|
ids: exportName,
|
|
676
|
-
exportName
|
|
715
|
+
exportName,
|
|
716
|
+
accessorCall: spec || info.wrapped
|
|
677
717
|
};
|
|
718
|
+
}
|
|
678
719
|
}
|
|
679
720
|
}
|
|
680
721
|
const exportsInfo = moduleGraph.getExportsInfo(info.module);
|
|
@@ -718,10 +759,9 @@ const getFinalBinding = (
|
|
|
718
759
|
if (usedName instanceof InlinedUsedName) {
|
|
719
760
|
return {
|
|
720
761
|
info,
|
|
721
|
-
// Render the inlined literal only
|
|
722
|
-
//
|
|
723
|
-
//
|
|
724
|
-
// duplicating the access (e.g. `"str".a.a`).
|
|
762
|
+
// Render the inlined literal only, not its property suffix: that
|
|
763
|
+
// comes back in `ids` and getFinalName appends it once, so emitting
|
|
764
|
+
// it here too would duplicate the access.
|
|
725
765
|
rawName: usedName.render(
|
|
726
766
|
Template.toNormalComment(
|
|
727
767
|
`inlined export ${propertyAccess(exportName)}`
|
|
@@ -938,9 +978,13 @@ const getFinalName = (
|
|
|
938
978
|
let reference;
|
|
939
979
|
/** @type {boolean} */
|
|
940
980
|
let isPropertyAccess;
|
|
981
|
+
// the raw name is the wrapper accessor call itself, so the reference binds
|
|
982
|
+
// looser than the identifier it stands in for
|
|
983
|
+
let accessorCall = false;
|
|
941
984
|
if ("rawName" in binding) {
|
|
942
985
|
reference = `${binding.rawName}${comment || ""}${propertyAccess(ids)}`;
|
|
943
986
|
isPropertyAccess = ids.length > 0;
|
|
987
|
+
accessorCall = binding.accessorCall === true;
|
|
944
988
|
} else {
|
|
945
989
|
const { info, name: exportId } = binding;
|
|
946
990
|
const name = info.internalNames.get(exportId);
|
|
@@ -968,8 +1012,12 @@ const getFinalName = (
|
|
|
968
1012
|
? `;(0,${reference})`
|
|
969
1013
|
: `/*#__PURE__*/Object(${reference})`;
|
|
970
1014
|
} else if (binding.info.wrapped) {
|
|
971
|
-
return
|
|
1015
|
+
return parenthesizeReference(reference, asiSafe);
|
|
972
1016
|
}
|
|
1017
|
+
} else if (accessorCall && !asCall) {
|
|
1018
|
+
// without parentheses `new X()` would construct the accessor rather
|
|
1019
|
+
// than what it returns
|
|
1020
|
+
return parenthesizeReference(reference, asiSafe);
|
|
973
1021
|
}
|
|
974
1022
|
|
|
975
1023
|
return reference;
|
|
@@ -978,7 +1026,6 @@ const getFinalName = (
|
|
|
978
1026
|
|
|
979
1027
|
/**
|
|
980
1028
|
* @typedef {object} ConcatenateModuleHooks
|
|
981
|
-
* @property {SyncBailHook<[ConcatenatedModule, RuntimeSpec[], string, Record<string, string>], boolean>} onDemandExportsGeneration
|
|
982
1029
|
* @property {SyncBailHook<[Partial<ConcatenatedModuleInfo>, ConcatenatedModuleInfo], boolean | void>} concatenatedModuleInfo
|
|
983
1030
|
*/
|
|
984
1031
|
|
|
@@ -1166,15 +1213,17 @@ class ConcatenatedModule extends Module {
|
|
|
1166
1213
|
|
|
1167
1214
|
for (const m of this._modules) {
|
|
1168
1215
|
// populate cacheable
|
|
1169
|
-
const { cacheable,
|
|
1170
|
-
m.buildInfo
|
|
1171
|
-
);
|
|
1216
|
+
const { cacheable, diagnostics } = /** @type {BuildInfo} */ (m.buildInfo);
|
|
1172
1217
|
if (!cacheable) {
|
|
1173
1218
|
this.buildInfo.cacheable = false;
|
|
1219
|
+
const notCacheableReasons =
|
|
1220
|
+
diagnostics === undefined
|
|
1221
|
+
? undefined
|
|
1222
|
+
: diagnostics.notCacheableReasons;
|
|
1174
1223
|
if (notCacheableReasons) {
|
|
1224
|
+
const own = getBuildDiagnostics(this.buildInfo);
|
|
1175
1225
|
const reasons =
|
|
1176
|
-
|
|
1177
|
-
(this.buildInfo.notCacheableReasons = []);
|
|
1226
|
+
own.notCacheableReasons || (own.notCacheableReasons = []);
|
|
1178
1227
|
for (const reason of notCacheableReasons) {
|
|
1179
1228
|
if (!reasons.includes(reason)) reasons.push(reason);
|
|
1180
1229
|
}
|
|
@@ -1193,10 +1242,9 @@ class ConcatenatedModule extends Module {
|
|
|
1193
1242
|
this.dependencies.push(d);
|
|
1194
1243
|
}
|
|
1195
1244
|
}
|
|
1196
|
-
// populate codeGenerationDependencies
|
|
1197
|
-
//
|
|
1198
|
-
//
|
|
1199
|
-
// Skip references that point back into the concat set itself.
|
|
1245
|
+
// populate codeGenerationDependencies: the inner templates are applied
|
|
1246
|
+
// during this module's own codeGeneration, so what they reference must be
|
|
1247
|
+
// generated by then. References back into the concat set are skipped.
|
|
1200
1248
|
if (m.codeGenerationDependencies !== undefined) {
|
|
1201
1249
|
for (const d of m.codeGenerationDependencies) {
|
|
1202
1250
|
const referenced =
|
|
@@ -1352,10 +1400,9 @@ class ConcatenatedModule extends Module {
|
|
|
1352
1400
|
(connection.dependency);
|
|
1353
1401
|
return {
|
|
1354
1402
|
connection,
|
|
1355
|
-
// A require() edge carries no sourceOrder
|
|
1356
|
-
//
|
|
1357
|
-
//
|
|
1358
|
-
// comparator non-transitive and the order depend on insertion order.
|
|
1403
|
+
// A require() edge carries no sourceOrder, and Infinity sorts it
|
|
1404
|
+
// last. Not NaN: `compareNumbers` returns 0 against every number,
|
|
1405
|
+
// which makes the comparator non-transitive.
|
|
1359
1406
|
sourceOrder:
|
|
1360
1407
|
typeof dep.sourceOrder === "number" ? dep.sourceOrder : Infinity,
|
|
1361
1408
|
rangeStart: dep.range && dep.range[0],
|
|
@@ -1415,10 +1462,18 @@ class ConcatenatedModule extends Module {
|
|
|
1415
1462
|
runtimeCondition,
|
|
1416
1463
|
runtime
|
|
1417
1464
|
);
|
|
1465
|
+
const wasDeferredOnly = !entry.nonDeferAccess;
|
|
1418
1466
|
entry.nonDeferAccess = mergeNonDeferAccess(
|
|
1419
1467
|
entry.nonDeferAccess,
|
|
1420
1468
|
nonDeferAccess
|
|
1421
1469
|
);
|
|
1470
|
+
// A deferred import does not evaluate, so the first eager reference
|
|
1471
|
+
// fixes the position; insertion order is emit order.
|
|
1472
|
+
if (wasDeferredOnly && nonDeferAccess) {
|
|
1473
|
+
entry.connection = connection;
|
|
1474
|
+
referencesMap.delete(module);
|
|
1475
|
+
referencesMap.set(module, entry);
|
|
1476
|
+
}
|
|
1422
1477
|
}
|
|
1423
1478
|
if (targets !== undefined) importConnections.set(module, targets);
|
|
1424
1479
|
return referencesMap.values();
|
|
@@ -1645,40 +1700,38 @@ class ConcatenatedModule extends Module {
|
|
|
1645
1700
|
}
|
|
1646
1701
|
}
|
|
1647
1702
|
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
* [10] RESULT — CodeGenerationResult { sources, data, runtimeRequirements }
|
|
1681
|
-
*/
|
|
1703
|
+
// WHY: how the inner modules become one flat source. Stages [1]-[5] only mutate
|
|
1704
|
+
// the per-module info records (names, ReplaceSource patches); stages [6]-[9]
|
|
1705
|
+
// append to the single output ConcatSource, in exactly the order shown.
|
|
1706
|
+
//
|
|
1707
|
+
// _getModulesWithInfo() — ordered concatenation list + one info per module
|
|
1708
|
+
// | (concatenated [+wrapped] | external | reference)
|
|
1709
|
+
// v
|
|
1710
|
+
// [1] ANALYSE — inner codeGeneration() per module, into a ConcatenationScope
|
|
1711
|
+
// | plain -> ReplaceSource + ast + scope analysis
|
|
1712
|
+
// | wrapped -> ReplaceSource only, body kept verbatim
|
|
1713
|
+
// | external -> nothing yet, rendered as a require() below
|
|
1714
|
+
// [2] RESERVE — free globals of the analysed bodies enter allUsedNames, so
|
|
1715
|
+
// | renaming in [3] can't shadow them (a wrapped body is not analysed;
|
|
1716
|
+
// | the reserved `__webpack_` prefix protects it)
|
|
1717
|
+
// [3] RENAME — module-scope variables renamed inside the ReplaceSource, then
|
|
1718
|
+
// | the generated names allocated: wrapper accessor, namespace object,
|
|
1719
|
+
// | interop helpers, external import variable
|
|
1720
|
+
// [4] LINK — __WEBPACK_MODULE_REFERENCE__ tokens replaced by their final
|
|
1721
|
+
// | binding; through the ast for analysed bodies, textually for wrapped
|
|
1722
|
+
// [5] COLLECT EXPORTS — root exports split into used / unused / inlined
|
|
1723
|
+
// v
|
|
1724
|
+
// ---- from here on everything is appended to the result ConcatSource ----
|
|
1725
|
+
// |
|
|
1726
|
+
// [6] EMIT EXPORTS — __esModule flag + exports getters, UNUSED/INLINED lists
|
|
1727
|
+
// [7] BUILD NS — namespace object sources built as strings (not emitted yet)
|
|
1728
|
+
// [8] DEFINE — everything that must exist before any body runs: namespace
|
|
1729
|
+
// | objects, wrapper accessors (wrapped modules and wrapped externals),
|
|
1730
|
+
// | deferred external loaders
|
|
1731
|
+
// [9] EVALUATE — bodies in concatenation order: plain bodies inline, externals
|
|
1732
|
+
// | as require(); a wrapped body stays behind its accessor
|
|
1733
|
+
// v
|
|
1734
|
+
// [10] RESULT — CodeGenerationResult { sources, data, runtimeRequirements }
|
|
1682
1735
|
/**
|
|
1683
1736
|
* Generates code and runtime requirements for this module.
|
|
1684
1737
|
* @param {CodeGenerationContext} context context for code generation
|
|
@@ -1796,6 +1849,15 @@ class ConcatenatedModule extends Module {
|
|
|
1796
1849
|
return info.escapeNamespaceObjectName;
|
|
1797
1850
|
}
|
|
1798
1851
|
const exportsInfo = moduleGraph.getExportsInfo(info.module);
|
|
1852
|
+
// Its names are not mangled, and the wrapped binding is already the
|
|
1853
|
+
// namespace, so a decoupled object would only shadow it.
|
|
1854
|
+
if (
|
|
1855
|
+
/** @type {BuildInfo} */
|
|
1856
|
+
(info.module.buildInfo).specNamespaceObject
|
|
1857
|
+
) {
|
|
1858
|
+
return undefined;
|
|
1859
|
+
}
|
|
1860
|
+
|
|
1799
1861
|
let mangled = false;
|
|
1800
1862
|
for (const exportInfo of exportsInfo.orderedExports) {
|
|
1801
1863
|
if (exportInfo.provided === false) continue;
|
|
@@ -1841,6 +1903,13 @@ class ConcatenatedModule extends Module {
|
|
|
1841
1903
|
for (const reference of ConcatenationScope.findModuleReferences(
|
|
1842
1904
|
/** @type {Source} */ (info.internalSource)
|
|
1843
1905
|
)) {
|
|
1906
|
+
if (reference.leaked) {
|
|
1907
|
+
throw new Error(
|
|
1908
|
+
`Unsubstituted module reference "${reference.name}" in ${info.module.readableIdentifier(
|
|
1909
|
+
requestShortener
|
|
1910
|
+
)}`
|
|
1911
|
+
);
|
|
1912
|
+
}
|
|
1844
1913
|
if (visitedReferences.has(reference.name)) continue;
|
|
1845
1914
|
visitedReferences.add(reference.name);
|
|
1846
1915
|
const match = ConcatenationScope.matchModuleReference(
|
|
@@ -1934,6 +2003,13 @@ class ConcatenatedModule extends Module {
|
|
|
1934
2003
|
ignoredScopes
|
|
1935
2004
|
);
|
|
1936
2005
|
} else {
|
|
2006
|
+
if (ConcatenationScope.isLeakedModuleReference(name)) {
|
|
2007
|
+
throw new Error(
|
|
2008
|
+
`Unsubstituted module reference "${name}" in ${info.module.readableIdentifier(
|
|
2009
|
+
requestShortener
|
|
2010
|
+
)}`
|
|
2011
|
+
);
|
|
2012
|
+
}
|
|
1937
2013
|
allUsedNames.add(name);
|
|
1938
2014
|
freeNames.add(name);
|
|
1939
2015
|
}
|
|
@@ -2026,10 +2102,9 @@ class ConcatenatedModule extends Module {
|
|
|
2026
2102
|
switch (info.type) {
|
|
2027
2103
|
case "concatenated": {
|
|
2028
2104
|
if (info.wrapped) {
|
|
2029
|
-
// A wrapped module declares
|
|
2030
|
-
//
|
|
2031
|
-
//
|
|
2032
|
-
// would shadow the accessor from inside it.
|
|
2105
|
+
// A wrapped module declares one shared-scope name, the lazy accessor
|
|
2106
|
+
// holding its body. Stage 2 claimed that body's identifiers, so
|
|
2107
|
+
// findNewName avoids the ones that would shadow it from inside.
|
|
2033
2108
|
const namespaceFnName = findNewName(
|
|
2034
2109
|
"namespaceFn",
|
|
2035
2110
|
allUsedNames,
|
|
@@ -2337,10 +2412,9 @@ class ConcatenatedModule extends Module {
|
|
|
2337
2412
|
}
|
|
2338
2413
|
// #endregion
|
|
2339
2414
|
|
|
2340
|
-
// #region [5] COLLECT EXPORTS: split the root module's exports into used
|
|
2341
|
-
// unused
|
|
2342
|
-
// register a namespace object
|
|
2343
|
-
// Map with all root exposed used exports
|
|
2415
|
+
// #region [5] COLLECT EXPORTS: split the root module's exports into used,
|
|
2416
|
+
// unused and inlined. Used ones stay thunks, since resolving one can still
|
|
2417
|
+
// register a namespace object that stage 7 must see.
|
|
2344
2418
|
/** @type {Map<string, (requestShortener: RequestShortener) => string>} */
|
|
2345
2419
|
const exportsMap = new Map();
|
|
2346
2420
|
|
|
@@ -2418,6 +2492,8 @@ class ConcatenatedModule extends Module {
|
|
|
2418
2492
|
shouldAddHarmonyFlag = true;
|
|
2419
2493
|
}
|
|
2420
2494
|
|
|
2495
|
+
/** @type {string | undefined} */
|
|
2496
|
+
let onDemandExportsSource;
|
|
2421
2497
|
// define exports
|
|
2422
2498
|
if (exportsMap.size > 0) {
|
|
2423
2499
|
/** @type {string[]} */
|
|
@@ -2448,17 +2524,10 @@ class ConcatenatedModule extends Module {
|
|
|
2448
2524
|
this.exportsArgument
|
|
2449
2525
|
}, {${definitions.join(",")}\n});\n`;
|
|
2450
2526
|
|
|
2451
|
-
const
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
!onDemandExportsGeneration.call(
|
|
2456
|
-
this,
|
|
2457
|
-
runtimes,
|
|
2458
|
-
`${harmonyFlagSource}${exportsSource}`,
|
|
2459
|
-
exportsFinalName
|
|
2460
|
-
)
|
|
2461
|
-
) {
|
|
2527
|
+
const meta = moduleGraph.getMetaIfExisting(this);
|
|
2528
|
+
if (meta !== undefined && meta.onDemandExports === true) {
|
|
2529
|
+
onDemandExportsSource = `${harmonyFlagSource}${exportsSource}`;
|
|
2530
|
+
} else {
|
|
2462
2531
|
result.add(harmonyFlagSource);
|
|
2463
2532
|
result.add(exportsSource);
|
|
2464
2533
|
}
|
|
@@ -2480,13 +2549,12 @@ class ConcatenatedModule extends Module {
|
|
|
2480
2549
|
// #endregion
|
|
2481
2550
|
|
|
2482
2551
|
// #region [7] BUILD NS: namespace object sources are built as strings here
|
|
2483
|
-
// and emitted by
|
|
2484
|
-
//
|
|
2485
|
-
|
|
2486
|
-
//
|
|
2487
|
-
//
|
|
2488
|
-
//
|
|
2489
|
-
// regular namespace objects so any nested namespace they pull in is built.
|
|
2552
|
+
// and emitted by stage 8; an external's goes next to its import variable or
|
|
2553
|
+
// accessor instead, defined later.
|
|
2554
|
+
|
|
2555
|
+
// Decoupled namespace objects for escaping mangled namespaces carry the same
|
|
2556
|
+
// getters keyed by the original export names, so untracked access by name
|
|
2557
|
+
// keeps working. Built first, so any nested namespace they pull in exists.
|
|
2490
2558
|
/** @type {Map<ConcatenatedModuleInfo | ExternalModuleInfo, string>} */
|
|
2491
2559
|
const escapeNamespaceObjectSources = new Map();
|
|
2492
2560
|
for (const info of neededEscapeNamespaceObjects) {
|
|
@@ -2658,10 +2726,9 @@ ${defineGetters}`
|
|
|
2658
2726
|
}) {\n`
|
|
2659
2727
|
);
|
|
2660
2728
|
result.add(/** @type {ReplaceSource} */ (info.source));
|
|
2661
|
-
// A generated body
|
|
2662
|
-
//
|
|
2663
|
-
//
|
|
2664
|
-
// the reserved symbol the generator registered.
|
|
2729
|
+
// A generated body binds its value to a local rather than writing
|
|
2730
|
+
// exports, so hand that local to the accessor. The name is verbatim: a
|
|
2731
|
+
// wrapped body is not scope-analysed and keeps the reserved symbol.
|
|
2665
2732
|
result.add(
|
|
2666
2733
|
info.namespaceExportSymbol
|
|
2667
2734
|
? `\n${info.module.moduleArgument}.exports = ${info.namespaceExportSymbol};\n});\n`
|
|
@@ -2680,10 +2747,18 @@ ${defineGetters}`
|
|
|
2680
2747
|
runtimeRequirements
|
|
2681
2748
|
});
|
|
2682
2749
|
const moduleId = JSON.stringify(chunkGraph.getModuleId(info.module));
|
|
2750
|
+
const required = `${RuntimeGlobals.require}(${moduleId})`;
|
|
2751
|
+
|
|
2752
|
+
// The wrapping happens per reference, so only the helper has to be
|
|
2753
|
+
// declared here.
|
|
2754
|
+
if (info.specNamespaceObjectUsed) {
|
|
2755
|
+
runtimeRequirements.add(RuntimeGlobals.specNamespaceObject);
|
|
2756
|
+
}
|
|
2757
|
+
|
|
2683
2758
|
const body =
|
|
2684
2759
|
condition === "true"
|
|
2685
|
-
? `return ${
|
|
2686
|
-
: `if (${condition}) return ${
|
|
2760
|
+
? `return ${required};`
|
|
2761
|
+
: `if (${condition}) return ${required};`;
|
|
2687
2762
|
result.add(
|
|
2688
2763
|
`\n// EXTERNAL MODULE: ${info.module.readableIdentifier(
|
|
2689
2764
|
requestShortener
|
|
@@ -2739,14 +2814,31 @@ ${defineGetters}`
|
|
|
2739
2814
|
);
|
|
2740
2815
|
if (info.deferredNamespaceObjectUsed) {
|
|
2741
2816
|
runtimeRequirements.add(RuntimeGlobals.makeDeferredNamespaceObject);
|
|
2817
|
+
// Every call site for a module must agree on the shape, since the
|
|
2818
|
+
// runtime caches one namespace object per module and mode.
|
|
2819
|
+
const deferredExportsType = getExportsType(
|
|
2820
|
+
moduleGraph,
|
|
2821
|
+
info,
|
|
2822
|
+
strictHarmonyModule
|
|
2823
|
+
);
|
|
2824
|
+
const names = getKnownExportNames(
|
|
2825
|
+
moduleGraph,
|
|
2826
|
+
info.module,
|
|
2827
|
+
deferredExportsType
|
|
2828
|
+
);
|
|
2829
|
+
runtimeRequirements.add(
|
|
2830
|
+
names
|
|
2831
|
+
? RuntimeGlobals.hasSealedDeferredNamespace
|
|
2832
|
+
: RuntimeGlobals.hasSynthesizedDeferredNamespace
|
|
2833
|
+
);
|
|
2742
2834
|
result.add(
|
|
2743
2835
|
`\nvar ${info.deferredNamespaceObjectName} = /*#__PURE__*/${
|
|
2744
2836
|
RuntimeGlobals.makeDeferredNamespaceObject
|
|
2745
2837
|
}(${JSON.stringify(
|
|
2746
2838
|
chunkGraph.getModuleId(info.module)
|
|
2747
2839
|
)}, ${getMakeDeferredNamespaceModeFromExportsType(
|
|
2748
|
-
|
|
2749
|
-
)});`
|
|
2840
|
+
deferredExportsType
|
|
2841
|
+
)}${names ? `, ${JSON.stringify(names)}` : ""});`
|
|
2750
2842
|
);
|
|
2751
2843
|
}
|
|
2752
2844
|
}
|
|
@@ -2832,7 +2924,15 @@ ${defineGetters}`
|
|
|
2832
2924
|
// External module bindings may be wrapped in
|
|
2833
2925
|
// runtime-condition `if` blocks but referenced outside,
|
|
2834
2926
|
// so they must remain function-scoped (`var`).
|
|
2835
|
-
|
|
2927
|
+
const required = `__webpack_require__(${moduleId})`;
|
|
2928
|
+
|
|
2929
|
+
// The wrapping happens per reference, so only the helper has
|
|
2930
|
+
// to be declared here.
|
|
2931
|
+
if (info.specNamespaceObjectUsed) {
|
|
2932
|
+
runtimeRequirements.add(RuntimeGlobals.specNamespaceObject);
|
|
2933
|
+
}
|
|
2934
|
+
|
|
2935
|
+
result.add(`var ${info.name} = ${required};`);
|
|
2836
2936
|
|
|
2837
2937
|
// Decoupled namespace object for an escaping mangled external
|
|
2838
2938
|
// module must come after its import variable is defined.
|
|
@@ -2865,9 +2965,8 @@ ${defineGetters}`
|
|
|
2865
2965
|
throw new Error(`Unsupported concatenation entry type ${info.type}`);
|
|
2866
2966
|
}
|
|
2867
2967
|
// Building a wrapped module's interop object here would evaluate its body
|
|
2868
|
-
// at the top level and break require() cycles, so
|
|
2869
|
-
// hoisted function
|
|
2870
|
-
// identity stable without claiming a second top-level name.
|
|
2968
|
+
// at the top level and break require() cycles, so it is deferred behind a
|
|
2969
|
+
// hoisted function, memoized on the function object itself.
|
|
2871
2970
|
/**
|
|
2872
2971
|
* @param {string} interopName interop variable name
|
|
2873
2972
|
* @param {string} expr interop object expression
|
|
@@ -2919,6 +3018,10 @@ ${defineGetters}`
|
|
|
2919
3018
|
}
|
|
2920
3019
|
data.set("topLevelDeclarations", topLevelDeclarations);
|
|
2921
3020
|
data.set("freeNames", freeNames);
|
|
3021
|
+
if (onDemandExportsSource !== undefined) {
|
|
3022
|
+
data.set("exportsSource", onDemandExportsSource);
|
|
3023
|
+
data.set("exportsFinalName", exportsFinalName);
|
|
3024
|
+
}
|
|
2922
3025
|
|
|
2923
3026
|
/** @type {CodeGenerationResult} */
|
|
2924
3027
|
const resultEntry = {
|
|
@@ -2958,10 +3061,9 @@ ${defineGetters}`
|
|
|
2958
3061
|
if (info.type === "concatenated") {
|
|
2959
3062
|
const m = info.module;
|
|
2960
3063
|
if (info.wrapped) {
|
|
2961
|
-
// the wrapper isolates the body's top-level declarations, so
|
|
2962
|
-
//
|
|
2963
|
-
//
|
|
2964
|
-
// textually in place of the scope analysis skipped here.
|
|
3064
|
+
// the wrapper isolates the body's top-level declarations, so only a
|
|
3065
|
+
// concatenation scope is needed, rewriting in-scope `require()` targets.
|
|
3066
|
+
// Stage 2 claims its identifiers textually, in place of that analysis.
|
|
2965
3067
|
const concatenationScope = new ConcatenationScope(
|
|
2966
3068
|
modulesMap,
|
|
2967
3069
|
info,
|
|
@@ -3140,6 +3242,7 @@ ${defineGetters}`
|
|
|
3140
3242
|
namespaceFnName: undefined,
|
|
3141
3243
|
escapeNamespaceObjectName: undefined,
|
|
3142
3244
|
deferredName: undefined,
|
|
3245
|
+
specNamespaceObjectUsed: false,
|
|
3143
3246
|
interopNamespaceObjectUsed: false,
|
|
3144
3247
|
interopNamespaceObjectName: undefined,
|
|
3145
3248
|
interopNamespaceObject2Used: false,
|
|
@@ -3233,12 +3336,6 @@ ${defineGetters}`
|
|
|
3233
3336
|
ConcatenatedModule.getCompilationHooks = createHooksRegistry(
|
|
3234
3337
|
() =>
|
|
3235
3338
|
/** @type {ConcatenateModuleHooks} */ ({
|
|
3236
|
-
onDemandExportsGeneration: new SyncBailHook([
|
|
3237
|
-
"module",
|
|
3238
|
-
"runtimes",
|
|
3239
|
-
"exportsFinalName",
|
|
3240
|
-
"exportsSource"
|
|
3241
|
-
]),
|
|
3242
3339
|
concatenatedModuleInfo: new SyncBailHook([
|
|
3243
3340
|
"updatedInfo",
|
|
3244
3341
|
"concatenatedModuleInfo"
|