webpack 5.99.9 → 5.100.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/bin/webpack.js +8 -2
- package/hot/log.js +15 -15
- package/hot/poll.js +1 -0
- package/lib/APIPlugin.js +3 -3
- package/lib/AbstractMethodError.js +1 -0
- package/lib/AutomaticPrefetchPlugin.js +1 -0
- package/lib/BannerPlugin.js +1 -1
- package/lib/CaseSensitiveModulesWarning.js +4 -4
- package/lib/Chunk.js +6 -6
- package/lib/ChunkGraph.js +37 -31
- package/lib/ChunkGroup.js +4 -4
- package/lib/ChunkTemplate.js +1 -1
- package/lib/CleanPlugin.js +94 -17
- package/lib/CodeGenerationResults.js +1 -1
- package/lib/CompatibilityPlugin.js +5 -2
- package/lib/Compilation.js +67 -45
- package/lib/Compiler.js +46 -16
- package/lib/ConcatenationScope.js +15 -6
- package/lib/ConstPlugin.js +5 -3
- package/lib/ContextModule.js +16 -12
- package/lib/ContextModuleFactory.js +4 -3
- package/lib/ContextReplacementPlugin.js +4 -2
- package/lib/CssModule.js +2 -2
- package/lib/DefinePlugin.js +111 -3
- package/lib/DelegatedModuleFactoryPlugin.js +18 -18
- package/lib/Dependency.js +6 -1
- package/lib/DependencyTemplate.js +1 -0
- package/lib/DllEntryPlugin.js +3 -1
- package/lib/DllPlugin.js +4 -3
- package/lib/DllReferencePlugin.js +2 -2
- package/lib/DynamicEntryPlugin.js +1 -1
- package/lib/EntryOptionPlugin.js +5 -0
- package/lib/ErrorHelpers.js +4 -4
- package/lib/EvalDevToolModulePlugin.js +3 -3
- package/lib/EvalSourceMapDevToolPlugin.js +7 -7
- package/lib/ExportsInfo.js +48 -39
- package/lib/ExternalModule.js +15 -11
- package/lib/ExternalModuleFactoryPlugin.js +5 -2
- package/lib/FileSystemInfo.js +51 -36
- package/lib/FlagDependencyExportsPlugin.js +14 -7
- package/lib/FlagDependencyUsagePlugin.js +1 -1
- package/lib/Generator.js +14 -1
- package/lib/HookWebpackError.js +1 -0
- package/lib/HotModuleReplacementPlugin.js +77 -50
- package/lib/IgnorePlugin.js +1 -1
- package/lib/InvalidDependenciesModuleWarning.js +1 -1
- package/lib/JavascriptMetaInfoPlugin.js +0 -1
- package/lib/LibManifestPlugin.js +4 -2
- package/lib/LoaderOptionsPlugin.js +6 -4
- package/lib/MainTemplate.js +2 -2
- package/lib/Module.js +21 -6
- package/lib/ModuleFactory.js +1 -0
- package/lib/ModuleGraph.js +24 -2
- package/lib/ModuleGraphConnection.js +5 -5
- package/lib/ModuleInfoHeaderPlugin.js +2 -1
- package/lib/ModuleParseError.js +1 -0
- package/lib/ModuleSourceTypesConstants.js +12 -12
- package/lib/ModuleTemplate.js +1 -1
- package/lib/ModuleTypeConstants.js +21 -21
- package/lib/MultiCompiler.js +6 -6
- package/lib/NormalModule.js +31 -44
- package/lib/NormalModuleFactory.js +29 -19
- package/lib/NormalModuleReplacementPlugin.js +1 -1
- package/lib/NullFactory.js +1 -0
- package/lib/OptimizationStages.js +1 -1
- package/lib/Parser.js +1 -0
- package/lib/ProgressPlugin.js +12 -5
- package/lib/ProvidePlugin.js +5 -1
- package/lib/RecordIdsPlugin.js +3 -3
- package/lib/RuntimeGlobals.js +175 -155
- package/lib/RuntimeModule.js +1 -0
- package/lib/RuntimePlugin.js +33 -7
- package/lib/RuntimeTemplate.js +111 -11
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +15 -25
- package/lib/SourceMapDevToolPlugin.js +19 -17
- package/lib/Template.js +2 -2
- package/lib/TemplatedPathPlugin.js +1 -1
- package/lib/WarnDeprecatedOptionPlugin.js +7 -8
- package/lib/WatchIgnorePlugin.js +4 -3
- package/lib/WebpackIsIncludedPlugin.js +2 -1
- package/lib/WebpackOptionsApply.js +115 -27
- package/lib/asset/AssetGenerator.js +15 -11
- package/lib/asset/AssetModulesPlugin.js +19 -17
- package/lib/asset/AssetSourceGenerator.js +4 -4
- package/lib/asset/RawDataUrlModule.js +4 -2
- package/lib/async-modules/AwaitDependenciesInitFragment.js +1 -1
- package/lib/buildChunkGraph.js +6 -3
- package/lib/cache/AddBuildDependenciesPlugin.js +5 -6
- package/lib/cache/IdleFileCachePlugin.js +7 -4
- package/lib/cache/MemoryCachePlugin.js +1 -0
- package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
- package/lib/cache/PackFileCacheStrategy.js +26 -20
- package/lib/cache/ResolverCachePlugin.js +16 -8
- package/lib/cli.js +15 -10
- package/lib/config/browserslistTargetHandler.js +3 -3
- package/lib/config/defaults.js +25 -17
- package/lib/config/normalization.js +2 -1
- package/lib/config/target.js +6 -5
- package/lib/container/ContainerPlugin.js +1 -1
- package/lib/container/ContainerReferencePlugin.js +1 -1
- package/lib/container/FallbackModule.js +2 -1
- package/lib/container/HoistContainerReferencesPlugin.js +1 -1
- package/lib/container/ModuleFederationPlugin.js +2 -2
- package/lib/container/RemoteModule.js +1 -1
- package/lib/css/CssGenerator.js +9 -6
- package/lib/css/CssModulesPlugin.js +44 -31
- package/lib/css/CssParser.js +6 -4
- package/lib/css/walkCssTokens.js +33 -37
- package/lib/debug/ProfilingPlugin.js +6 -6
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +8 -8
- package/lib/dependencies/AMDPlugin.js +12 -8
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +28 -26
- package/lib/dependencies/CachedConstDependency.js +1 -5
- package/lib/dependencies/CommonJsExportRequireDependency.js +6 -4
- package/lib/dependencies/CommonJsExportsParserPlugin.js +22 -25
- package/lib/dependencies/CommonJsFullRequireDependency.js +1 -9
- package/lib/dependencies/CommonJsImportsParserPlugin.js +100 -114
- package/lib/dependencies/CommonJsPlugin.js +15 -16
- package/lib/dependencies/ContextDependencyHelpers.js +2 -1
- package/lib/dependencies/ContextDependencyTemplateAsId.js +1 -0
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +1 -0
- package/lib/dependencies/CssIcssExportDependency.js +1 -1
- package/lib/dependencies/CssLocalIdentifierDependency.js +2 -2
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +2 -1
- package/lib/dependencies/DynamicExports.js +9 -9
- package/lib/dependencies/ExportsInfoDependency.js +1 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +122 -101
- package/lib/dependencies/HarmonyExportExpressionDependency.js +1 -1
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +95 -19
- package/lib/dependencies/HarmonyExportInitFragment.js +1 -1
- package/lib/dependencies/HarmonyImportDependency.js +11 -5
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +238 -162
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -1
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +20 -9
- package/lib/dependencies/HarmonyModulesPlugin.js +23 -12
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -0
- package/lib/dependencies/ImportMetaContextPlugin.js +2 -1
- package/lib/dependencies/ImportMetaPlugin.js +2 -2
- package/lib/dependencies/ImportParserPlugin.js +40 -9
- package/lib/dependencies/ImportPlugin.js +3 -1
- package/lib/dependencies/LoaderPlugin.js +1 -0
- package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +1 -0
- package/lib/dependencies/RequireContextPlugin.js +3 -1
- package/lib/dependencies/RequireEnsurePlugin.js +6 -6
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +33 -34
- package/lib/dependencies/RequireIncludePlugin.js +1 -0
- package/lib/dependencies/RuntimeRequirementsDependency.js +1 -1
- package/lib/dependencies/SystemPlugin.js +1 -1
- package/lib/dependencies/URLContextDependency.js +65 -0
- package/lib/dependencies/URLPlugin.js +17 -157
- package/lib/dependencies/WorkerPlugin.js +23 -10
- package/lib/dependencies/processExportInfo.js +2 -1
- package/lib/esm/ModuleChunkFormatPlugin.js +269 -185
- package/lib/esm/ModuleChunkLoadingPlugin.js +39 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +70 -3
- package/lib/hmr/HotModuleReplacement.runtime.js +0 -1
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
- package/lib/hmr/JavascriptHotModuleReplacementHelper.js +37 -0
- package/lib/hmr/LazyCompilationPlugin.js +4 -2
- package/lib/hmr/lazyCompilationBackend.js +4 -2
- package/lib/ids/ChunkModuleIdRangePlugin.js +6 -3
- package/lib/ids/DeterministicChunkIdsPlugin.js +30 -35
- package/lib/ids/DeterministicModuleIdsPlugin.js +4 -3
- package/lib/ids/HashedModuleIdsPlugin.js +5 -4
- package/lib/ids/IdHelpers.js +21 -17
- package/lib/ids/NamedChunkIdsPlugin.js +5 -5
- package/lib/ids/NamedModuleIdsPlugin.js +4 -4
- package/lib/ids/NaturalChunkIdsPlugin.js +2 -1
- package/lib/ids/NaturalModuleIdsPlugin.js +1 -1
- package/lib/ids/OccurrenceChunkIdsPlugin.js +3 -2
- package/lib/ids/OccurrenceModuleIdsPlugin.js +1 -1
- package/lib/ids/SyncModuleIdsPlugin.js +1 -1
- package/lib/index.js +13 -3
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +113 -119
- package/lib/javascript/BasicEvaluatedExpression.js +2 -1
- package/lib/javascript/ChunkHelpers.js +1 -0
- package/lib/javascript/CommonJsChunkFormatPlugin.js +121 -136
- package/lib/javascript/EnableChunkLoadingPlugin.js +6 -3
- package/lib/javascript/JavascriptGenerator.js +14 -2
- package/lib/javascript/JavascriptModulesPlugin.js +68 -27
- package/lib/javascript/JavascriptParser.js +117 -76
- package/lib/javascript/JavascriptParserHelpers.js +41 -41
- package/lib/javascript/StartupHelpers.js +17 -17
- package/lib/json/JsonGenerator.js +4 -2
- package/lib/json/JsonModulesPlugin.js +2 -2
- package/lib/json/JsonParser.js +1 -1
- package/lib/library/AbstractLibraryPlugin.js +6 -2
- package/lib/library/AssignLibraryPlugin.js +21 -6
- package/lib/library/EnableLibraryPlugin.js +23 -3
- package/lib/library/UmdLibraryPlugin.js +15 -6
- package/lib/logging/createConsoleLogger.js +3 -3
- package/lib/logging/runtime.js +9 -9
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +4 -22
- package/lib/node/RequireChunkLoadingRuntimeModule.js +4 -22
- package/lib/node/nodeConsole.js +4 -2
- package/lib/optimize/AggressiveMergingPlugin.js +45 -46
- package/lib/optimize/AggressiveSplittingPlugin.js +13 -12
- package/lib/optimize/ConcatenatedModule.js +227 -57
- package/lib/optimize/EnsureChunkConditionsPlugin.js +58 -58
- package/lib/optimize/FlagIncludedChunksPlugin.js +3 -1
- package/lib/optimize/InnerGraph.js +115 -112
- package/lib/optimize/InnerGraphPlugin.js +2 -2
- package/lib/optimize/LimitChunkCountPlugin.js +4 -2
- package/lib/optimize/MangleExportsPlugin.js +4 -3
- package/lib/optimize/MergeDuplicateChunksPlugin.js +80 -81
- package/lib/optimize/MinChunkSizePlugin.js +6 -3
- package/lib/optimize/ModuleConcatenationPlugin.js +31 -22
- package/lib/optimize/RealContentHashPlugin.js +26 -20
- package/lib/optimize/RemoveEmptyChunksPlugin.js +2 -1
- package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
- package/lib/optimize/SideEffectsFlagPlugin.js +3 -2
- package/lib/optimize/SplitChunksPlugin.js +16 -13
- package/lib/rules/BasicEffectRulePlugin.js +4 -2
- package/lib/rules/BasicMatcherRulePlugin.js +3 -1
- package/lib/rules/ObjectMatcherRulePlugin.js +3 -1
- package/lib/rules/RuleSetCompiler.js +6 -3
- package/lib/rules/UseEffectRulePlugin.js +3 -1
- package/lib/runtime/AsyncModuleRuntimeModule.js +64 -9
- package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +1 -1
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +214 -0
- package/lib/runtime/RuntimeIdRuntimeModule.js +2 -1
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +8 -7
- package/lib/schemes/FileUriPlugin.js +1 -1
- package/lib/schemes/HttpUriPlugin.js +27 -19
- package/lib/schemes/VirtualUrlPlugin.js +222 -0
- package/lib/serialization/AggregateErrorSerializer.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +5 -4
- package/lib/serialization/FileMiddleware.js +7 -4
- package/lib/serialization/ObjectMiddleware.js +14 -8
- package/lib/serialization/Serializer.js +5 -3
- package/lib/serialization/SerializerMiddleware.js +2 -0
- package/lib/sharing/ConsumeSharedModule.js +1 -1
- package/lib/sharing/ConsumeSharedPlugin.js +3 -3
- package/lib/sharing/ConsumeSharedRuntimeModule.js +2 -2
- package/lib/sharing/ProvideSharedModule.js +1 -1
- package/lib/sharing/ProvideSharedPlugin.js +3 -2
- package/lib/sharing/SharePlugin.js +2 -1
- package/lib/sharing/ShareRuntimeModule.js +3 -5
- package/lib/sharing/utils.js +34 -34
- package/lib/stats/DefaultStatsFactoryPlugin.js +49 -46
- package/lib/stats/DefaultStatsPresetPlugin.js +4 -2
- package/lib/stats/DefaultStatsPrinterPlugin.js +15 -9
- package/lib/stats/StatsFactory.js +4 -2
- package/lib/stats/StatsPrinter.js +3 -2
- package/lib/url/URLParserPlugin.js +266 -0
- package/lib/util/ArrayQueue.js +1 -1
- package/lib/util/AsyncQueue.js +1 -1
- package/lib/util/Hash.js +2 -0
- package/lib/util/IterableHelpers.js +1 -1
- package/lib/util/LazyBucketSortedSet.js +2 -1
- package/lib/util/LazySet.js +11 -6
- package/lib/util/ParallelismFactorCalculator.js +1 -1
- package/lib/util/SetHelpers.js +3 -3
- package/lib/util/SortableSet.js +2 -2
- package/lib/util/StackedCacheMap.js +3 -1
- package/lib/util/StackedMap.js +2 -2
- package/lib/util/StringXor.js +1 -0
- package/lib/util/TupleSet.js +1 -0
- package/lib/util/URLAbsoluteSpecifier.js +1 -1
- package/lib/util/cleverMerge.js +12 -8
- package/lib/util/comparators.js +154 -127
- package/lib/util/compileBooleanMatcher.js +8 -3
- package/lib/util/concatenate.js +8 -7
- package/lib/util/conventions.js +72 -73
- package/lib/util/create-schema-validation.js +2 -1
- package/lib/util/createHash.js +10 -4
- package/lib/util/deprecation.js +69 -66
- package/lib/util/deterministicGrouping.js +4 -2
- package/lib/util/extractUrlAndGlobal.js +1 -1
- package/lib/util/findGraphRoots.js +2 -2
- package/lib/util/fs.js +30 -23
- package/lib/util/hash/md4.js +2 -2
- package/lib/util/hash/wasm-hash.js +4 -2
- package/lib/util/identifier.js +13 -12
- package/lib/util/internalSerializables.js +2 -0
- package/lib/util/magicComment.js +5 -5
- package/lib/util/processAsyncTree.js +1 -1
- package/lib/util/propertyAccess.js +1 -1
- package/lib/util/propertyName.js +1 -1
- package/lib/util/registerExternalSerializer.js +1 -2
- package/lib/util/removeBOM.js +1 -1
- package/lib/util/runtime.js +29 -21
- package/lib/util/semver.js +1 -1
- package/lib/util/serialization.js +3 -0
- package/lib/util/source.js +3 -2
- package/lib/validateSchema.js +1 -0
- package/lib/wasm/EnableWasmLoadingPlugin.js +6 -3
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -1
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +46 -49
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +2 -2
- package/lib/wasm-sync/WebAssemblyGenerator.js +2 -3
- package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +3 -2
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +3 -0
- package/lib/wasm-sync/WebAssemblyUtils.js +1 -1
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +4 -22
- package/lib/webpack.js +4 -5
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +1 -0
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +6 -24
- package/lib/webworker/WebWorkerTemplatePlugin.js +1 -0
- package/package.json +119 -113
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +17 -0
- package/schemas/plugins/schemes/VirtualUrlPlugin.check.d.ts +7 -0
- package/schemas/plugins/schemes/VirtualUrlPlugin.check.js +6 -0
- package/schemas/plugins/schemes/VirtualUrlPlugin.json +77 -0
- package/types.d.ts +1230 -360
|
@@ -22,14 +22,19 @@ const RuntimeGlobals = require("../RuntimeGlobals");
|
|
|
22
22
|
const Template = require("../Template");
|
|
23
23
|
const { DEFAULTS } = require("../config/defaults");
|
|
24
24
|
const HarmonyImportDependency = require("../dependencies/HarmonyImportDependency");
|
|
25
|
+
const HarmonyImportSideEffectDependency = require("../dependencies/HarmonyImportSideEffectDependency");
|
|
25
26
|
const JavascriptParser = require("../javascript/JavascriptParser");
|
|
27
|
+
const {
|
|
28
|
+
getMakeDeferredNamespaceModeFromExportsType,
|
|
29
|
+
getOptimizedDeferredModule
|
|
30
|
+
} = require("../runtime/MakeDeferredNamespaceObjectRuntime");
|
|
26
31
|
const { equals } = require("../util/ArrayHelpers");
|
|
27
32
|
const LazySet = require("../util/LazySet");
|
|
28
33
|
const { concatComparators } = require("../util/comparators");
|
|
29
34
|
const {
|
|
30
35
|
RESERVED_NAMES,
|
|
31
|
-
findNewName,
|
|
32
36
|
addScopeSymbols,
|
|
37
|
+
findNewName,
|
|
33
38
|
getAllReferences,
|
|
34
39
|
getPathInAst,
|
|
35
40
|
getUsedNamesInScopeInfo
|
|
@@ -154,12 +159,12 @@ if (!ReferencerClass.prototype.PropertyDefinition) {
|
|
|
154
159
|
* @property {Map<string, string> | undefined} rawExportMap
|
|
155
160
|
* @property {string=} namespaceExportSymbol
|
|
156
161
|
* @property {string | undefined} namespaceObjectName
|
|
157
|
-
* @property {boolean} interopNamespaceObjectUsed
|
|
158
|
-
* @property {string | undefined} interopNamespaceObjectName
|
|
159
|
-
* @property {boolean} interopNamespaceObject2Used
|
|
160
|
-
* @property {string | undefined} interopNamespaceObject2Name
|
|
161
|
-
* @property {boolean} interopDefaultAccessUsed
|
|
162
|
-
* @property {string | undefined} interopDefaultAccessName
|
|
162
|
+
* @property {boolean} interopNamespaceObjectUsed "default-with-named" namespace
|
|
163
|
+
* @property {string | undefined} interopNamespaceObjectName "default-with-named" namespace
|
|
164
|
+
* @property {boolean} interopNamespaceObject2Used "default-only" namespace
|
|
165
|
+
* @property {string | undefined} interopNamespaceObject2Name "default-only" namespace
|
|
166
|
+
* @property {boolean} interopDefaultAccessUsed runtime namespace object that detects "__esModule"
|
|
167
|
+
* @property {string | undefined} interopDefaultAccessName runtime namespace object that detects "__esModule"
|
|
163
168
|
*/
|
|
164
169
|
|
|
165
170
|
/**
|
|
@@ -168,13 +173,17 @@ if (!ReferencerClass.prototype.PropertyDefinition) {
|
|
|
168
173
|
* @property {Module} module
|
|
169
174
|
* @property {RuntimeSpec | boolean} runtimeCondition
|
|
170
175
|
* @property {number} index
|
|
171
|
-
* @property {string | undefined} name
|
|
172
|
-
* @property {
|
|
173
|
-
* @property {
|
|
174
|
-
* @property {boolean}
|
|
175
|
-
* @property {string | undefined}
|
|
176
|
-
* @property {boolean}
|
|
177
|
-
* @property {string | undefined}
|
|
176
|
+
* @property {string | undefined} name module.exports / harmony namespace object
|
|
177
|
+
* @property {string | undefined} deferredName deferred module.exports / harmony namespace object
|
|
178
|
+
* @property {boolean} deferred the module is deferred at least once
|
|
179
|
+
* @property {boolean} deferredNamespaceObjectUsed deferred namespace object that being used in a not-analyzable way so it must be materialized
|
|
180
|
+
* @property {string | undefined} deferredNamespaceObjectName deferred namespace object that being used in a not-analyzable way so it must be materialized
|
|
181
|
+
* @property {boolean} interopNamespaceObjectUsed "default-with-named" namespace
|
|
182
|
+
* @property {string | undefined} interopNamespaceObjectName "default-with-named" namespace
|
|
183
|
+
* @property {boolean} interopNamespaceObject2Used "default-only" namespace
|
|
184
|
+
* @property {string | undefined} interopNamespaceObject2Name "default-only" namespace
|
|
185
|
+
* @property {boolean} interopDefaultAccessUsed runtime namespace object that detects "__esModule"
|
|
186
|
+
* @property {string | undefined} interopDefaultAccessName runtime namespace object that detects "__esModule"
|
|
178
187
|
*/
|
|
179
188
|
|
|
180
189
|
/**
|
|
@@ -219,6 +228,14 @@ const compareNumbers = (a, b) => {
|
|
|
219
228
|
};
|
|
220
229
|
const bySourceOrder = createComparator("sourceOrder", compareNumbers);
|
|
221
230
|
const byRangeStart = createComparator("rangeStart", compareNumbers);
|
|
231
|
+
const moveDeferToLast = (
|
|
232
|
+
/** @type {{ defer?: boolean }} */ a,
|
|
233
|
+
/** @type {{ defer?: boolean }} */ b
|
|
234
|
+
) => {
|
|
235
|
+
if (a.defer === b.defer) return 0;
|
|
236
|
+
if (a.defer) return 1;
|
|
237
|
+
return -1;
|
|
238
|
+
};
|
|
222
239
|
|
|
223
240
|
/**
|
|
224
241
|
* @param {Iterable<string>} iterable iterable object
|
|
@@ -257,6 +274,7 @@ const joinIterableWithComma = iterable => {
|
|
|
257
274
|
* @param {RuntimeTemplate} runtimeTemplate the runtime template
|
|
258
275
|
* @param {Set<ConcatenatedModuleInfo>} neededNamespaceObjects modules for which a namespace object should be generated
|
|
259
276
|
* @param {boolean} asCall asCall
|
|
277
|
+
* @param {boolean} depDeferred the dependency is deferred
|
|
260
278
|
* @param {boolean | undefined} strictHarmonyModule strictHarmonyModule
|
|
261
279
|
* @param {boolean | undefined} asiSafe asiSafe
|
|
262
280
|
* @param {Set<ExportInfo>} alreadyVisited alreadyVisited
|
|
@@ -272,6 +290,7 @@ const getFinalBinding = (
|
|
|
272
290
|
runtimeTemplate,
|
|
273
291
|
neededNamespaceObjects,
|
|
274
292
|
asCall,
|
|
293
|
+
depDeferred,
|
|
275
294
|
strictHarmonyModule,
|
|
276
295
|
asiSafe,
|
|
277
296
|
alreadyVisited = new Set()
|
|
@@ -280,21 +299,36 @@ const getFinalBinding = (
|
|
|
280
299
|
moduleGraph,
|
|
281
300
|
strictHarmonyModule
|
|
282
301
|
);
|
|
302
|
+
const deferred =
|
|
303
|
+
depDeferred &&
|
|
304
|
+
info.type === "external" &&
|
|
305
|
+
info.deferred &&
|
|
306
|
+
!moduleGraph.isAsync(info.module);
|
|
283
307
|
if (exportName.length === 0) {
|
|
284
308
|
switch (exportsType) {
|
|
285
309
|
case "default-only":
|
|
286
|
-
info.
|
|
310
|
+
if (deferred) info.deferredNamespaceObjectUsed = true;
|
|
311
|
+
else info.interopNamespaceObject2Used = true;
|
|
287
312
|
return {
|
|
288
313
|
info,
|
|
289
|
-
rawName: /** @type {string} */ (
|
|
314
|
+
rawName: /** @type {string} */ (
|
|
315
|
+
deferred
|
|
316
|
+
? info.deferredNamespaceObjectName
|
|
317
|
+
: info.interopNamespaceObject2Name
|
|
318
|
+
),
|
|
290
319
|
ids: exportName,
|
|
291
320
|
exportName
|
|
292
321
|
};
|
|
293
322
|
case "default-with-named":
|
|
294
|
-
info.
|
|
323
|
+
if (deferred) info.deferredNamespaceObjectUsed = true;
|
|
324
|
+
else info.interopNamespaceObjectUsed = true;
|
|
295
325
|
return {
|
|
296
326
|
info,
|
|
297
|
-
rawName: /** @type {string} */ (
|
|
327
|
+
rawName: /** @type {string} */ (
|
|
328
|
+
deferred
|
|
329
|
+
? info.deferredNamespaceObjectName
|
|
330
|
+
: info.interopNamespaceObjectName
|
|
331
|
+
),
|
|
298
332
|
ids: exportName,
|
|
299
333
|
exportName
|
|
300
334
|
};
|
|
@@ -348,6 +382,14 @@ const getFinalBinding = (
|
|
|
348
382
|
switch (exportName[0]) {
|
|
349
383
|
case "default": {
|
|
350
384
|
exportName = exportName.slice(1);
|
|
385
|
+
if (deferred) {
|
|
386
|
+
return {
|
|
387
|
+
info,
|
|
388
|
+
rawName: `${info.deferredName}.a`,
|
|
389
|
+
ids: exportName,
|
|
390
|
+
exportName
|
|
391
|
+
};
|
|
392
|
+
}
|
|
351
393
|
info.interopDefaultAccessUsed = true;
|
|
352
394
|
const defaultExport = asCall
|
|
353
395
|
? `${info.interopDefaultAccessName}()`
|
|
@@ -389,6 +431,15 @@ const getFinalBinding = (
|
|
|
389
431
|
exportName
|
|
390
432
|
};
|
|
391
433
|
case "external":
|
|
434
|
+
if (deferred) {
|
|
435
|
+
info.deferredNamespaceObjectUsed = true;
|
|
436
|
+
return {
|
|
437
|
+
info,
|
|
438
|
+
rawName: /** @type {string} */ (info.deferredNamespaceObjectName),
|
|
439
|
+
ids: exportName,
|
|
440
|
+
exportName
|
|
441
|
+
};
|
|
442
|
+
}
|
|
392
443
|
return {
|
|
393
444
|
info,
|
|
394
445
|
rawName:
|
|
@@ -480,6 +531,7 @@ const getFinalBinding = (
|
|
|
480
531
|
runtimeTemplate,
|
|
481
532
|
neededNamespaceObjects,
|
|
482
533
|
asCall,
|
|
534
|
+
reexport.deferred,
|
|
483
535
|
/** @type {BuildMeta} */
|
|
484
536
|
(info.module.buildMeta).strictHarmonyModule,
|
|
485
537
|
asiSafe,
|
|
@@ -519,7 +571,15 @@ const getFinalBinding = (
|
|
|
519
571
|
const comment = equals(used, exportName)
|
|
520
572
|
? ""
|
|
521
573
|
: Template.toNormalComment(`${exportName.join(".")}`);
|
|
522
|
-
return {
|
|
574
|
+
return {
|
|
575
|
+
info,
|
|
576
|
+
rawName:
|
|
577
|
+
(deferred ? info.deferredName : info.name) +
|
|
578
|
+
(deferred ? ".a" : "") +
|
|
579
|
+
comment,
|
|
580
|
+
ids: used,
|
|
581
|
+
exportName
|
|
582
|
+
};
|
|
523
583
|
}
|
|
524
584
|
}
|
|
525
585
|
};
|
|
@@ -534,6 +594,7 @@ const getFinalBinding = (
|
|
|
534
594
|
* @param {RuntimeTemplate} runtimeTemplate the runtime template
|
|
535
595
|
* @param {Set<ConcatenatedModuleInfo>} neededNamespaceObjects modules for which a namespace object should be generated
|
|
536
596
|
* @param {boolean} asCall asCall
|
|
597
|
+
* @param {boolean} depDeferred the dependency is deferred
|
|
537
598
|
* @param {boolean | undefined} callContext callContext
|
|
538
599
|
* @param {boolean | undefined} strictHarmonyModule strictHarmonyModule
|
|
539
600
|
* @param {boolean | undefined} asiSafe asiSafe
|
|
@@ -549,6 +610,7 @@ const getFinalName = (
|
|
|
549
610
|
runtimeTemplate,
|
|
550
611
|
neededNamespaceObjects,
|
|
551
612
|
asCall,
|
|
613
|
+
depDeferred,
|
|
552
614
|
callContext,
|
|
553
615
|
strictHarmonyModule,
|
|
554
616
|
asiSafe
|
|
@@ -563,6 +625,7 @@ const getFinalName = (
|
|
|
563
625
|
runtimeTemplate,
|
|
564
626
|
neededNamespaceObjects,
|
|
565
627
|
asCall,
|
|
628
|
+
depDeferred,
|
|
566
629
|
strictHarmonyModule,
|
|
567
630
|
asiSafe
|
|
568
631
|
);
|
|
@@ -701,7 +764,7 @@ class ConcatenatedModule extends Module {
|
|
|
701
764
|
}
|
|
702
765
|
|
|
703
766
|
get modules() {
|
|
704
|
-
return
|
|
767
|
+
return [...this._modules];
|
|
705
768
|
}
|
|
706
769
|
|
|
707
770
|
/**
|
|
@@ -762,9 +825,13 @@ class ConcatenatedModule extends Module {
|
|
|
762
825
|
cacheable: true,
|
|
763
826
|
moduleArgument,
|
|
764
827
|
exportsArgument,
|
|
828
|
+
/** @type {LazySet<string>} */
|
|
765
829
|
fileDependencies: new LazySet(),
|
|
830
|
+
/** @type {LazySet<string>} */
|
|
766
831
|
contextDependencies: new LazySet(),
|
|
832
|
+
/** @type {LazySet<string>} */
|
|
767
833
|
missingDependencies: new LazySet(),
|
|
834
|
+
/** @type {Set<string>} */
|
|
768
835
|
topLevelDeclarations: new Set(),
|
|
769
836
|
assets: undefined
|
|
770
837
|
};
|
|
@@ -775,7 +842,8 @@ class ConcatenatedModule extends Module {
|
|
|
775
842
|
for (const m of this._modules) {
|
|
776
843
|
// populate cacheable
|
|
777
844
|
if (!(/** @type {BuildInfo} */ (m.buildInfo).cacheable)) {
|
|
778
|
-
|
|
845
|
+
/** @type {BuildInfo} */
|
|
846
|
+
(this.buildInfo).cacheable = false;
|
|
779
847
|
}
|
|
780
848
|
|
|
781
849
|
// populate dependencies
|
|
@@ -783,7 +851,8 @@ class ConcatenatedModule extends Module {
|
|
|
783
851
|
dep =>
|
|
784
852
|
!(dep instanceof HarmonyImportDependency) ||
|
|
785
853
|
!this._modules.has(
|
|
786
|
-
/** @type {Module} */
|
|
854
|
+
/** @type {Module} */
|
|
855
|
+
(compilation.moduleGraph.getModule(dep))
|
|
787
856
|
)
|
|
788
857
|
)) {
|
|
789
858
|
this.dependencies.push(d);
|
|
@@ -812,38 +881,37 @@ class ConcatenatedModule extends Module {
|
|
|
812
881
|
const { assets, assetsInfo, topLevelDeclarations } =
|
|
813
882
|
/** @type {BuildInfo} */ (m.buildInfo);
|
|
814
883
|
|
|
884
|
+
const buildInfo = /** @type {BuildInfo} */ (this.buildInfo);
|
|
885
|
+
|
|
815
886
|
// populate topLevelDeclarations
|
|
816
887
|
if (topLevelDeclarations) {
|
|
817
|
-
const topLevelDeclarations =
|
|
888
|
+
const topLevelDeclarations = buildInfo.topLevelDeclarations;
|
|
818
889
|
if (topLevelDeclarations !== undefined) {
|
|
819
890
|
for (const decl of topLevelDeclarations) {
|
|
820
891
|
topLevelDeclarations.add(decl);
|
|
821
892
|
}
|
|
822
893
|
}
|
|
823
894
|
} else {
|
|
824
|
-
|
|
895
|
+
buildInfo.topLevelDeclarations = undefined;
|
|
825
896
|
}
|
|
826
897
|
|
|
827
898
|
// populate assets
|
|
828
899
|
if (assets) {
|
|
829
|
-
if (
|
|
830
|
-
|
|
900
|
+
if (buildInfo.assets === undefined) {
|
|
901
|
+
buildInfo.assets = Object.create(null);
|
|
831
902
|
}
|
|
832
903
|
Object.assign(
|
|
833
904
|
/** @type {NonNullable<BuildInfo["assets"]>} */
|
|
834
|
-
(
|
|
835
|
-
/** @type {BuildInfo} */
|
|
836
|
-
(this.buildInfo).assets
|
|
837
|
-
),
|
|
905
|
+
(buildInfo.assets),
|
|
838
906
|
assets
|
|
839
907
|
);
|
|
840
908
|
}
|
|
841
909
|
if (assetsInfo) {
|
|
842
|
-
if (
|
|
843
|
-
|
|
910
|
+
if (buildInfo.assetsInfo === undefined) {
|
|
911
|
+
buildInfo.assetsInfo = new Map();
|
|
844
912
|
}
|
|
845
913
|
for (const [key, value] of assetsInfo) {
|
|
846
|
-
|
|
914
|
+
buildInfo.assetsInfo.set(key, value);
|
|
847
915
|
}
|
|
848
916
|
}
|
|
849
917
|
}
|
|
@@ -876,26 +944,28 @@ class ConcatenatedModule extends Module {
|
|
|
876
944
|
const list = [];
|
|
877
945
|
/** @type {Map<Module, RuntimeSpec | true>} */
|
|
878
946
|
const existingEntries = new Map();
|
|
947
|
+
const deferEnabled =
|
|
948
|
+
this.compilation && this.compilation.options.experiments.deferImport;
|
|
879
949
|
|
|
880
950
|
/**
|
|
881
951
|
* @param {Module} module a module
|
|
882
952
|
* @returns {Iterable<{ connection: ModuleGraphConnection, runtimeCondition: RuntimeSpec | true }>} imported modules in order
|
|
883
953
|
*/
|
|
884
954
|
const getConcatenatedImports = module => {
|
|
885
|
-
const connections =
|
|
886
|
-
moduleGraph.getOutgoingConnections(module)
|
|
887
|
-
);
|
|
955
|
+
const connections = [...moduleGraph.getOutgoingConnections(module)];
|
|
888
956
|
if (module === rootModule) {
|
|
889
|
-
for (const c of moduleGraph.getOutgoingConnections(this))
|
|
957
|
+
for (const c of moduleGraph.getOutgoingConnections(this)) {
|
|
890
958
|
connections.push(c);
|
|
959
|
+
}
|
|
891
960
|
}
|
|
892
961
|
/**
|
|
893
|
-
* @type {Array<{ connection: ModuleGraphConnection, sourceOrder: number, rangeStart: number }>}
|
|
962
|
+
* @type {Array<{ connection: ModuleGraphConnection, sourceOrder: number, rangeStart: number, defer?: boolean }>}
|
|
894
963
|
*/
|
|
895
964
|
const references = connections
|
|
896
965
|
.filter(connection => {
|
|
897
|
-
if (!(connection.dependency instanceof HarmonyImportDependency))
|
|
966
|
+
if (!(connection.dependency instanceof HarmonyImportDependency)) {
|
|
898
967
|
return false;
|
|
968
|
+
}
|
|
899
969
|
return (
|
|
900
970
|
connection &&
|
|
901
971
|
connection.resolvedOriginModule === module &&
|
|
@@ -910,7 +980,8 @@ class ConcatenatedModule extends Module {
|
|
|
910
980
|
return {
|
|
911
981
|
connection,
|
|
912
982
|
sourceOrder: dep.sourceOrder,
|
|
913
|
-
rangeStart: dep.range && dep.range[0]
|
|
983
|
+
rangeStart: dep.range && dep.range[0],
|
|
984
|
+
defer: dep.defer
|
|
914
985
|
};
|
|
915
986
|
});
|
|
916
987
|
/**
|
|
@@ -925,11 +996,16 @@ class ConcatenatedModule extends Module {
|
|
|
925
996
|
* a.a(); // first range
|
|
926
997
|
* b.b(); // second range
|
|
927
998
|
*
|
|
999
|
+
* If the import is deferred, we always move it to the last.
|
|
928
1000
|
* If there is no reexport, we have the same source.
|
|
929
1001
|
* If there is reexport, but module has side effects, this will lead to reexport module only.
|
|
930
1002
|
* If there is side-effects-free reexport, we can get simple deterministic result with range start comparison.
|
|
931
1003
|
*/
|
|
932
1004
|
references.sort(concatComparators(bySourceOrder, byRangeStart));
|
|
1005
|
+
if (deferEnabled) {
|
|
1006
|
+
// do not combine those two sorts. defer is not the same as source or range which has a comparable number, defer is only moving them.
|
|
1007
|
+
references.sort(moveDeferToLast);
|
|
1008
|
+
}
|
|
933
1009
|
/** @type {Map<Module, { connection: ModuleGraphConnection, runtimeCondition: RuntimeSpec | true }>} */
|
|
934
1010
|
const referencesMap = new Map();
|
|
935
1011
|
for (const { connection } of references) {
|
|
@@ -974,8 +1050,9 @@ class ConcatenatedModule extends Module {
|
|
|
974
1050
|
);
|
|
975
1051
|
}
|
|
976
1052
|
const imports = getConcatenatedImports(module);
|
|
977
|
-
for (const { connection, runtimeCondition } of imports)
|
|
1053
|
+
for (const { connection, runtimeCondition } of imports) {
|
|
978
1054
|
enterModule(connection, runtimeCondition);
|
|
1055
|
+
}
|
|
979
1056
|
list.push({
|
|
980
1057
|
type: "concatenated",
|
|
981
1058
|
module: connection.module,
|
|
@@ -1030,8 +1107,9 @@ class ConcatenatedModule extends Module {
|
|
|
1030
1107
|
|
|
1031
1108
|
existingEntries.set(rootModule, true);
|
|
1032
1109
|
const imports = getConcatenatedImports(rootModule);
|
|
1033
|
-
for (const { connection, runtimeCondition } of imports)
|
|
1110
|
+
for (const { connection, runtimeCondition } of imports) {
|
|
1034
1111
|
enterModule(connection, runtimeCondition);
|
|
1112
|
+
}
|
|
1035
1113
|
list.push({
|
|
1036
1114
|
type: "concatenated",
|
|
1037
1115
|
module: rootModule,
|
|
@@ -1136,6 +1214,7 @@ class ConcatenatedModule extends Module {
|
|
|
1136
1214
|
// List of all used names to avoid conflicts
|
|
1137
1215
|
const allUsedNames = new Set(RESERVED_NAMES);
|
|
1138
1216
|
// Updated Top level declarations are created by renaming
|
|
1217
|
+
/** @type {Set<string>} */
|
|
1139
1218
|
const topLevelDeclarations = new Set();
|
|
1140
1219
|
|
|
1141
1220
|
// List of additional names in scope for module references
|
|
@@ -1191,8 +1270,9 @@ class ConcatenatedModule extends Module {
|
|
|
1191
1270
|
const match = ConcatenationScope.matchModuleReference(name);
|
|
1192
1271
|
if (!match) continue;
|
|
1193
1272
|
const referencedInfo = modulesWithInfo[match.index];
|
|
1194
|
-
if (referencedInfo.type === "reference")
|
|
1273
|
+
if (referencedInfo.type === "reference") {
|
|
1195
1274
|
throw new Error("Module reference can't point to a reference");
|
|
1275
|
+
}
|
|
1196
1276
|
const binding = getFinalBinding(
|
|
1197
1277
|
moduleGraph,
|
|
1198
1278
|
referencedInfo,
|
|
@@ -1203,6 +1283,7 @@ class ConcatenatedModule extends Module {
|
|
|
1203
1283
|
runtimeTemplate,
|
|
1204
1284
|
neededNamespaceObjects,
|
|
1205
1285
|
false,
|
|
1286
|
+
match.deferredImport,
|
|
1206
1287
|
/** @type {BuildMeta} */
|
|
1207
1288
|
(info.module.buildMeta).strictHarmonyModule,
|
|
1208
1289
|
true
|
|
@@ -1277,9 +1358,10 @@ class ConcatenatedModule extends Module {
|
|
|
1277
1358
|
info.internalNames.set(name, newName);
|
|
1278
1359
|
topLevelDeclarations.add(newName);
|
|
1279
1360
|
const source = /** @type {ReplaceSource} */ (info.source);
|
|
1280
|
-
const allIdentifiers = new Set(
|
|
1281
|
-
references.map(r => r.identifier)
|
|
1282
|
-
|
|
1361
|
+
const allIdentifiers = new Set([
|
|
1362
|
+
...references.map(r => r.identifier),
|
|
1363
|
+
...variable.identifiers
|
|
1364
|
+
]);
|
|
1283
1365
|
for (const identifier of allIdentifiers) {
|
|
1284
1366
|
const r = /** @type {Range} */ (identifier.range);
|
|
1285
1367
|
const path = getPathInAst(
|
|
@@ -1326,7 +1408,10 @@ class ConcatenatedModule extends Module {
|
|
|
1326
1408
|
info.namespaceObjectName =
|
|
1327
1409
|
/** @type {string} */
|
|
1328
1410
|
(namespaceObjectName);
|
|
1329
|
-
topLevelDeclarations.add(
|
|
1411
|
+
topLevelDeclarations.add(
|
|
1412
|
+
/** @type {string} */
|
|
1413
|
+
(namespaceObjectName)
|
|
1414
|
+
);
|
|
1330
1415
|
break;
|
|
1331
1416
|
}
|
|
1332
1417
|
case "external": {
|
|
@@ -1339,6 +1424,28 @@ class ConcatenatedModule extends Module {
|
|
|
1339
1424
|
allUsedNames.add(externalName);
|
|
1340
1425
|
info.name = externalName;
|
|
1341
1426
|
topLevelDeclarations.add(externalName);
|
|
1427
|
+
|
|
1428
|
+
if (info.deferred) {
|
|
1429
|
+
const externalName = findNewName(
|
|
1430
|
+
"deferred",
|
|
1431
|
+
allUsedNames,
|
|
1432
|
+
namespaceObjectUsedNames,
|
|
1433
|
+
info.module.readableIdentifier(requestShortener)
|
|
1434
|
+
);
|
|
1435
|
+
allUsedNames.add(externalName);
|
|
1436
|
+
info.deferredName = externalName;
|
|
1437
|
+
topLevelDeclarations.add(externalName);
|
|
1438
|
+
|
|
1439
|
+
const externalNameInterop = findNewName(
|
|
1440
|
+
"deferredNamespaceObject",
|
|
1441
|
+
allUsedNames,
|
|
1442
|
+
namespaceObjectUsedNames,
|
|
1443
|
+
info.module.readableIdentifier(requestShortener)
|
|
1444
|
+
);
|
|
1445
|
+
allUsedNames.add(externalNameInterop);
|
|
1446
|
+
info.deferredNamespaceObjectName = externalNameInterop;
|
|
1447
|
+
topLevelDeclarations.add(externalNameInterop);
|
|
1448
|
+
}
|
|
1342
1449
|
break;
|
|
1343
1450
|
}
|
|
1344
1451
|
}
|
|
@@ -1356,7 +1463,8 @@ class ConcatenatedModule extends Module {
|
|
|
1356
1463
|
}
|
|
1357
1464
|
if (
|
|
1358
1465
|
buildMeta.exportsType === "default" &&
|
|
1359
|
-
buildMeta.defaultObject !== "redirect"
|
|
1466
|
+
buildMeta.defaultObject !== "redirect" &&
|
|
1467
|
+
info.interopNamespaceObject2Used
|
|
1360
1468
|
) {
|
|
1361
1469
|
const externalNameInterop = findNewName(
|
|
1362
1470
|
"namespaceObject2",
|
|
@@ -1390,8 +1498,9 @@ class ConcatenatedModule extends Module {
|
|
|
1390
1498
|
const match = ConcatenationScope.matchModuleReference(name);
|
|
1391
1499
|
if (match) {
|
|
1392
1500
|
const referencedInfo = modulesWithInfo[match.index];
|
|
1393
|
-
if (referencedInfo.type === "reference")
|
|
1501
|
+
if (referencedInfo.type === "reference") {
|
|
1394
1502
|
throw new Error("Module reference can't point to a reference");
|
|
1503
|
+
}
|
|
1395
1504
|
const finalName = getFinalName(
|
|
1396
1505
|
moduleGraph,
|
|
1397
1506
|
referencedInfo,
|
|
@@ -1402,6 +1511,7 @@ class ConcatenatedModule extends Module {
|
|
|
1402
1511
|
runtimeTemplate,
|
|
1403
1512
|
neededNamespaceObjects,
|
|
1404
1513
|
match.call,
|
|
1514
|
+
match.deferredImport,
|
|
1405
1515
|
!match.directImport,
|
|
1406
1516
|
/** @type {BuildMeta} */
|
|
1407
1517
|
(info.module.buildMeta).strictHarmonyModule,
|
|
@@ -1454,6 +1564,7 @@ class ConcatenatedModule extends Module {
|
|
|
1454
1564
|
neededNamespaceObjects,
|
|
1455
1565
|
false,
|
|
1456
1566
|
false,
|
|
1567
|
+
false,
|
|
1457
1568
|
strictHarmonyModule,
|
|
1458
1569
|
true
|
|
1459
1570
|
);
|
|
@@ -1555,6 +1666,7 @@ class ConcatenatedModule extends Module {
|
|
|
1555
1666
|
runtimeTemplate,
|
|
1556
1667
|
neededNamespaceObjects,
|
|
1557
1668
|
false,
|
|
1669
|
+
false,
|
|
1558
1670
|
undefined,
|
|
1559
1671
|
/** @type {BuildMeta} */
|
|
1560
1672
|
(info.module.buildMeta).strictHarmonyModule,
|
|
@@ -1574,8 +1686,9 @@ class ConcatenatedModule extends Module {
|
|
|
1574
1686
|
","
|
|
1575
1687
|
)}\n});\n`
|
|
1576
1688
|
: "";
|
|
1577
|
-
if (nsObj.length > 0)
|
|
1689
|
+
if (nsObj.length > 0) {
|
|
1578
1690
|
runtimeRequirements.add(RuntimeGlobals.definePropertyGetters);
|
|
1691
|
+
}
|
|
1579
1692
|
namespaceObjectSources.set(
|
|
1580
1693
|
info,
|
|
1581
1694
|
`
|
|
@@ -1596,7 +1709,10 @@ ${defineGetters}`
|
|
|
1596
1709
|
}
|
|
1597
1710
|
}
|
|
1598
1711
|
|
|
1712
|
+
/** @type {InitFragment<ChunkRenderContext>[]} */
|
|
1599
1713
|
const chunkInitFragments = [];
|
|
1714
|
+
const deferEnabled =
|
|
1715
|
+
this.compilation && this.compilation.options.experiments.deferImport;
|
|
1600
1716
|
|
|
1601
1717
|
// evaluate modules in order
|
|
1602
1718
|
for (const rawInfo of modulesWithInfo) {
|
|
@@ -1608,6 +1724,31 @@ ${defineGetters}`
|
|
|
1608
1724
|
result.add(
|
|
1609
1725
|
`\n;// ${info.module.readableIdentifier(requestShortener)}\n`
|
|
1610
1726
|
);
|
|
1727
|
+
// If a module is deferred in other places, but used as non-deferred here,
|
|
1728
|
+
// the module itself will be emitted as mod_deferred (in the case "external"),
|
|
1729
|
+
// we need to emit an extra import declaration to evaluate it in order.
|
|
1730
|
+
if (deferEnabled) {
|
|
1731
|
+
for (const dep of info.module.dependencies) {
|
|
1732
|
+
if (
|
|
1733
|
+
!dep.defer &&
|
|
1734
|
+
dep instanceof HarmonyImportSideEffectDependency
|
|
1735
|
+
) {
|
|
1736
|
+
const referredModule = moduleGraph.getModule(dep);
|
|
1737
|
+
if (!referredModule) continue;
|
|
1738
|
+
if (moduleGraph.isDeferred(referredModule)) {
|
|
1739
|
+
const deferredModuleInfo = /** @type {ExternalModuleInfo} */ (
|
|
1740
|
+
modulesWithInfo.find(
|
|
1741
|
+
i => i.type === "external" && i.module === referredModule
|
|
1742
|
+
)
|
|
1743
|
+
);
|
|
1744
|
+
if (!deferredModuleInfo) continue;
|
|
1745
|
+
result.add(
|
|
1746
|
+
`\n// non-deferred import to a deferred module (${referredModule.readableIdentifier(requestShortener)})\nvar ${deferredModuleInfo.name} = ${deferredModuleInfo.deferredName}.a;`
|
|
1747
|
+
);
|
|
1748
|
+
}
|
|
1749
|
+
}
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1611
1752
|
result.add(/** @type {ReplaceSource} */ (info.source));
|
|
1612
1753
|
if (info.chunkInitFragments) {
|
|
1613
1754
|
for (const f of info.chunkInitFragments) chunkInitFragments.push(f);
|
|
@@ -1640,11 +1781,23 @@ ${defineGetters}`
|
|
|
1640
1781
|
isConditional = true;
|
|
1641
1782
|
result.add(`if (${condition}) {\n`);
|
|
1642
1783
|
}
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1784
|
+
const moduleId = JSON.stringify(chunkGraph.getModuleId(info.module));
|
|
1785
|
+
if (info.deferred) {
|
|
1786
|
+
const loader = getOptimizedDeferredModule(
|
|
1787
|
+
runtimeTemplate,
|
|
1788
|
+
info.module.getExportsType(
|
|
1789
|
+
moduleGraph,
|
|
1790
|
+
this.rootModule.buildMeta &&
|
|
1791
|
+
this.rootModule.buildMeta.strictHarmonyModule
|
|
1792
|
+
),
|
|
1793
|
+
moduleId,
|
|
1794
|
+
// an async module will opt-out of the concat module optimization.
|
|
1795
|
+
[]
|
|
1796
|
+
);
|
|
1797
|
+
result.add(`var ${info.deferredName} = ${loader};`);
|
|
1798
|
+
} else {
|
|
1799
|
+
result.add(`var ${info.name} = __webpack_require__(${moduleId});`);
|
|
1800
|
+
}
|
|
1648
1801
|
name = info.name;
|
|
1649
1802
|
break;
|
|
1650
1803
|
}
|
|
@@ -1652,6 +1805,18 @@ ${defineGetters}`
|
|
|
1652
1805
|
// @ts-expect-error never is expected here
|
|
1653
1806
|
throw new Error(`Unsupported concatenation entry type ${info.type}`);
|
|
1654
1807
|
}
|
|
1808
|
+
if (info.type === "external" && info.deferredNamespaceObjectUsed) {
|
|
1809
|
+
runtimeRequirements.add(RuntimeGlobals.makeDeferredNamespaceObject);
|
|
1810
|
+
result.add(
|
|
1811
|
+
`\nvar ${info.deferredNamespaceObjectName} = /*#__PURE__*/${
|
|
1812
|
+
RuntimeGlobals.makeDeferredNamespaceObject
|
|
1813
|
+
}(${JSON.stringify(
|
|
1814
|
+
chunkGraph.getModuleId(info.module)
|
|
1815
|
+
)}, ${getMakeDeferredNamespaceModeFromExportsType(
|
|
1816
|
+
info.module.getExportsType(moduleGraph, strictHarmonyModule)
|
|
1817
|
+
)});`
|
|
1818
|
+
);
|
|
1819
|
+
}
|
|
1655
1820
|
if (info.interopNamespaceObjectUsed) {
|
|
1656
1821
|
runtimeRequirements.add(RuntimeGlobals.createFakeNamespaceObject);
|
|
1657
1822
|
result.add(
|
|
@@ -1676,8 +1841,9 @@ ${defineGetters}`
|
|
|
1676
1841
|
}
|
|
1677
1842
|
|
|
1678
1843
|
const data = new Map();
|
|
1679
|
-
if (chunkInitFragments.length > 0)
|
|
1844
|
+
if (chunkInitFragments.length > 0) {
|
|
1680
1845
|
data.set("chunkInitFragments", chunkInitFragments);
|
|
1846
|
+
}
|
|
1681
1847
|
data.set("topLevelDeclarations", topLevelDeclarations);
|
|
1682
1848
|
|
|
1683
1849
|
/** @type {CodeGenerationResult} */
|
|
@@ -1832,12 +1998,16 @@ ${defineGetters}`
|
|
|
1832
1998
|
runtimeCondition: info.runtimeCondition,
|
|
1833
1999
|
index,
|
|
1834
2000
|
name: undefined,
|
|
2001
|
+
deferredName: undefined,
|
|
1835
2002
|
interopNamespaceObjectUsed: false,
|
|
1836
2003
|
interopNamespaceObjectName: undefined,
|
|
1837
2004
|
interopNamespaceObject2Used: false,
|
|
1838
2005
|
interopNamespaceObject2Name: undefined,
|
|
1839
2006
|
interopDefaultAccessUsed: false,
|
|
1840
|
-
interopDefaultAccessName: undefined
|
|
2007
|
+
interopDefaultAccessName: undefined,
|
|
2008
|
+
deferred: moduleGraph.isDeferred(info.module),
|
|
2009
|
+
deferredNamespaceObjectName: undefined,
|
|
2010
|
+
deferredNamespaceObjectUsed: false
|
|
1841
2011
|
};
|
|
1842
2012
|
break;
|
|
1843
2013
|
default:
|