webpack 5.102.1 → 5.104.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 +121 -134
- package/hot/dev-server.js +18 -3
- package/hot/emitter-event-target.js +7 -0
- package/hot/lazy-compilation-node.js +45 -29
- package/hot/lazy-compilation-universal.js +18 -0
- package/hot/lazy-compilation-web.js +15 -5
- package/hot/load-http.js +7 -0
- package/hot/only-dev-server.js +19 -4
- package/lib/APIPlugin.js +6 -0
- package/lib/Chunk.js +1 -1
- package/lib/ChunkGraph.js +9 -7
- package/lib/ChunkGroup.js +8 -5
- package/lib/CleanPlugin.js +6 -3
- package/lib/CodeGenerationResults.js +2 -1
- package/lib/CompatibilityPlugin.js +28 -2
- package/lib/Compilation.js +58 -21
- package/lib/Compiler.js +3 -3
- package/lib/ConcatenationScope.js +0 -15
- package/lib/ContextModule.js +6 -3
- package/lib/ContextModuleFactory.js +6 -4
- package/lib/CssModule.js +6 -1
- package/lib/DefinePlugin.js +45 -14
- package/lib/DelegatedModule.js +7 -4
- package/lib/Dependency.js +8 -1
- package/lib/DependencyTemplate.js +1 -0
- package/lib/DllModule.js +6 -3
- package/lib/DotenvPlugin.js +462 -0
- package/lib/EnvironmentPlugin.js +19 -16
- package/lib/EvalSourceMapDevToolPlugin.js +16 -0
- package/lib/ExportsInfo.js +6 -2
- package/lib/ExternalModule.js +28 -35
- package/lib/ExternalModuleFactoryPlugin.js +11 -9
- package/lib/ExternalsPlugin.js +2 -1
- package/lib/FileSystemInfo.js +1 -1
- package/lib/Generator.js +10 -7
- package/lib/HookWebpackError.js +33 -4
- package/lib/HotModuleReplacementPlugin.js +22 -0
- package/lib/ManifestPlugin.js +235 -0
- package/lib/Module.js +27 -15
- package/lib/ModuleBuildError.js +1 -1
- package/lib/ModuleError.js +1 -1
- package/lib/ModuleFilenameHelpers.js +1 -1
- package/lib/ModuleGraph.js +29 -13
- package/lib/ModuleGraphConnection.js +2 -2
- package/lib/ModuleSourceTypeConstants.js +189 -0
- package/lib/ModuleTypeConstants.js +1 -4
- package/lib/ModuleWarning.js +1 -1
- package/lib/MultiCompiler.js +1 -1
- package/lib/NodeStuffPlugin.js +424 -116
- package/lib/NormalModule.js +23 -20
- package/lib/NormalModuleFactory.js +7 -10
- package/lib/Parser.js +1 -1
- package/lib/RawModule.js +7 -4
- package/lib/RuntimeGlobals.js +22 -4
- package/lib/RuntimeModule.js +1 -1
- package/lib/RuntimePlugin.js +27 -6
- package/lib/RuntimeTemplate.js +120 -57
- package/lib/SourceMapDevToolPlugin.js +26 -1
- package/lib/Template.js +17 -6
- package/lib/TemplatedPathPlugin.js +5 -6
- package/lib/WebpackError.js +0 -1
- package/lib/WebpackOptionsApply.js +67 -15
- package/lib/asset/AssetBytesGenerator.js +16 -12
- package/lib/asset/AssetGenerator.js +31 -26
- package/lib/asset/AssetSourceGenerator.js +16 -12
- package/lib/asset/RawDataUrlModule.js +6 -3
- package/lib/buildChunkGraph.js +4 -2
- package/lib/cache/PackFileCacheStrategy.js +6 -5
- package/lib/cli.js +2 -43
- package/lib/config/browserslistTargetHandler.js +24 -0
- package/lib/config/defaults.js +226 -61
- package/lib/config/normalization.js +4 -3
- package/lib/config/target.js +11 -0
- package/lib/container/ContainerEntryModule.js +6 -3
- package/lib/container/FallbackModule.js +6 -3
- package/lib/container/RemoteModule.js +1 -3
- package/lib/css/CssGenerator.js +304 -76
- package/lib/css/CssLoadingRuntimeModule.js +14 -4
- package/lib/css/CssMergeStyleSheetsRuntimeModule.js +56 -0
- package/lib/css/CssModulesPlugin.js +72 -67
- package/lib/css/CssParser.js +1726 -732
- package/lib/css/walkCssTokens.js +128 -11
- package/lib/dependencies/CachedConstDependency.js +24 -10
- package/lib/dependencies/CommonJsImportsParserPlugin.js +0 -9
- package/lib/dependencies/CommonJsPlugin.js +12 -0
- package/lib/dependencies/CommonJsRequireContextDependency.js +1 -1
- package/lib/dependencies/ContextDependencyHelpers.js +2 -2
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +3 -1
- package/lib/dependencies/CssIcssExportDependency.js +389 -12
- package/lib/dependencies/CssIcssImportDependency.js +114 -51
- package/lib/dependencies/CssIcssSymbolDependency.js +31 -33
- package/lib/dependencies/CssImportDependency.js +17 -6
- package/lib/dependencies/CssUrlDependency.js +3 -2
- package/lib/dependencies/DynamicExports.js +7 -7
- package/lib/dependencies/ExternalModuleDependency.js +7 -4
- package/lib/dependencies/ExternalModuleInitFragment.js +3 -2
- package/lib/dependencies/ExternalModuleInitFragmentDependency.js +96 -0
- package/lib/dependencies/HarmonyAcceptDependency.js +6 -1
- package/lib/dependencies/HarmonyAcceptImportDependency.js +2 -1
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +12 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +35 -23
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +13 -9
- package/lib/dependencies/HarmonyExports.js +4 -4
- package/lib/dependencies/HarmonyImportDependency.js +28 -27
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +28 -69
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -3
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +10 -8
- package/lib/dependencies/ImportDependency.js +8 -2
- package/lib/dependencies/ImportEagerDependency.js +6 -3
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -1
- package/lib/dependencies/ImportMetaPlugin.js +154 -9
- package/lib/dependencies/ImportParserPlugin.js +21 -23
- package/lib/dependencies/ImportPhase.js +121 -0
- package/lib/dependencies/ImportWeakDependency.js +6 -3
- package/lib/dependencies/LocalModulesHelpers.js +3 -3
- package/lib/dependencies/ModuleDependency.js +5 -1
- package/lib/dependencies/ModuleHotAcceptDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +2 -2
- package/lib/dependencies/getFunctionExpression.js +1 -1
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -8
- package/lib/esm/ModuleChunkFormatPlugin.js +5 -4
- package/lib/hmr/HotModuleReplacement.runtime.js +2 -1
- package/lib/hmr/LazyCompilationPlugin.js +5 -3
- package/lib/ids/IdHelpers.js +20 -8
- package/lib/index.js +6 -0
- package/lib/javascript/ChunkHelpers.js +16 -5
- package/lib/javascript/JavascriptGenerator.js +105 -104
- package/lib/javascript/JavascriptModulesPlugin.js +80 -37
- package/lib/javascript/JavascriptParser.js +161 -44
- package/lib/json/JsonGenerator.js +5 -4
- package/lib/json/JsonParser.js +9 -2
- package/lib/library/AbstractLibraryPlugin.js +1 -1
- package/lib/library/AmdLibraryPlugin.js +4 -1
- package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
- package/lib/library/ModuleLibraryPlugin.js +41 -23
- package/lib/library/SystemLibraryPlugin.js +8 -1
- package/lib/library/UmdLibraryPlugin.js +2 -2
- package/lib/logging/Logger.js +5 -4
- package/lib/logging/createConsoleLogger.js +2 -2
- package/lib/node/NodeTargetPlugin.js +9 -1
- package/lib/node/ReadFileCompileWasmPlugin.js +0 -2
- package/lib/optimize/ConcatenatedModule.js +208 -167
- package/lib/optimize/ModuleConcatenationPlugin.js +5 -4
- package/lib/optimize/SideEffectsFlagPlugin.js +3 -2
- package/lib/optimize/SplitChunksPlugin.js +60 -46
- package/lib/rules/RuleSetCompiler.js +1 -1
- package/lib/runtime/AsyncModuleRuntimeModule.js +28 -18
- package/lib/runtime/AutoPublicPathRuntimeModule.js +8 -3
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +3 -2
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +89 -55
- package/lib/schemes/HttpUriPlugin.js +78 -7
- package/lib/serialization/AggregateErrorSerializer.js +1 -2
- package/lib/serialization/ObjectMiddleware.js +0 -2
- package/lib/serialization/SingleItemMiddleware.js +1 -1
- package/lib/sharing/ConsumeSharedModule.js +1 -1
- package/lib/sharing/ConsumeSharedPlugin.js +5 -3
- package/lib/sharing/ProvideSharedModule.js +1 -1
- package/lib/sharing/resolveMatchedConfigs.js +15 -9
- package/lib/sharing/utils.js +1 -1
- package/lib/stats/DefaultStatsFactoryPlugin.js +8 -5
- package/lib/stats/DefaultStatsPresetPlugin.js +1 -1
- package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
- package/lib/util/StringXor.js +1 -1
- package/lib/util/URLAbsoluteSpecifier.js +2 -2
- package/lib/util/binarySearchBounds.js +2 -2
- package/lib/util/comparators.js +54 -76
- package/lib/util/compileBooleanMatcher.js +78 -6
- package/lib/util/createHash.js +20 -199
- package/lib/util/deprecation.js +1 -1
- package/lib/util/deterministicGrouping.js +6 -3
- package/lib/util/fs.js +75 -75
- package/lib/util/hash/BatchedHash.js +10 -9
- package/lib/util/hash/BulkUpdateHash.js +138 -0
- package/lib/util/hash/DebugHash.js +75 -0
- package/lib/util/hash/hash-digest.js +216 -0
- package/lib/util/identifier.js +82 -17
- package/lib/util/internalSerializables.js +2 -6
- package/lib/util/runtime.js +3 -3
- package/lib/util/source.js +2 -2
- package/lib/wasm/EnableWasmLoadingPlugin.js +10 -4
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +3 -2
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +11 -7
- package/lib/wasm-sync/WebAssemblyGenerator.js +9 -6
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +11 -6
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +6 -2
- package/lib/web/FetchCompileWasmPlugin.js +0 -2
- package/lib/webpack.js +85 -82
- package/module.d.ts +5 -0
- package/package.json +34 -28
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +160 -101
- package/schemas/plugins/{css/CssAutoParserOptions.check.d.ts → ManifestPlugin.check.d.ts} +1 -1
- package/schemas/plugins/ManifestPlugin.check.js +6 -0
- package/schemas/plugins/ManifestPlugin.json +98 -0
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.json +16 -3
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.json +4 -1
- package/schemas/plugins/container/ExternalsType.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.json +4 -1
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssParserOptions.check.js +1 -1
- package/schemas/plugins/json/JsonModulesPluginParser.check.js +1 -1
- package/types.d.ts +771 -436
- package/lib/ModuleSourceTypesConstants.js +0 -123
- package/lib/dependencies/CssLocalIdentifierDependency.js +0 -250
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +0 -112
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +0 -7
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +0 -6
- package/schemas/plugins/css/CssAutoGeneratorOptions.json +0 -3
- package/schemas/plugins/css/CssAutoParserOptions.check.js +0 -6
- package/schemas/plugins/css/CssAutoParserOptions.json +0 -3
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.d.ts +0 -7
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +0 -6
- package/schemas/plugins/css/CssGlobalGeneratorOptions.json +0 -3
- package/schemas/plugins/css/CssGlobalParserOptions.check.d.ts +0 -7
- package/schemas/plugins/css/CssGlobalParserOptions.check.js +0 -6
- package/schemas/plugins/css/CssGlobalParserOptions.json +0 -3
|
@@ -16,14 +16,16 @@ const {
|
|
|
16
16
|
const ConcatenationScope = require("../ConcatenationScope");
|
|
17
17
|
const { UsageState } = require("../ExportsInfo");
|
|
18
18
|
const Module = require("../Module");
|
|
19
|
-
const {
|
|
19
|
+
const {
|
|
20
|
+
JAVASCRIPT_TYPE,
|
|
21
|
+
JAVASCRIPT_TYPES
|
|
22
|
+
} = require("../ModuleSourceTypeConstants");
|
|
20
23
|
const { JAVASCRIPT_MODULE_TYPE_ESM } = require("../ModuleTypeConstants");
|
|
21
24
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
|
22
25
|
const Template = require("../Template");
|
|
23
26
|
const { DEFAULTS } = require("../config/defaults");
|
|
24
27
|
const HarmonyImportDependency = require("../dependencies/HarmonyImportDependency");
|
|
25
|
-
const
|
|
26
|
-
const HarmonyImportSpecifierDependency = require("../dependencies/HarmonyImportSpecifierDependency");
|
|
28
|
+
const { ImportPhaseUtils } = require("../dependencies/ImportPhase");
|
|
27
29
|
const JavascriptParser = require("../javascript/JavascriptParser");
|
|
28
30
|
const {
|
|
29
31
|
getMakeDeferredNamespaceModeFromExportsType,
|
|
@@ -133,8 +135,10 @@ if (!ReferencerClass.prototype.PropertyDefinition) {
|
|
|
133
135
|
* @property {ExportName} exportName
|
|
134
136
|
*/
|
|
135
137
|
|
|
136
|
-
/** @typedef {ConcatenatedModuleInfo | ExternalModuleInfo
|
|
137
|
-
/** @typedef {ConcatenatedModuleInfo | ExternalModuleInfo | ReferenceToModuleInfo
|
|
138
|
+
/** @typedef {ConcatenatedModuleInfo | ExternalModuleInfo} ModuleInfo */
|
|
139
|
+
/** @typedef {ConcatenatedModuleInfo | ExternalModuleInfo | ReferenceToModuleInfo} ModuleInfoOrReference */
|
|
140
|
+
|
|
141
|
+
/** @typedef {Map<string, string>} ExportMap */
|
|
138
142
|
|
|
139
143
|
/**
|
|
140
144
|
* @typedef {object} ConcatenatedModuleInfo
|
|
@@ -149,8 +153,8 @@ if (!ReferencerClass.prototype.PropertyDefinition) {
|
|
|
149
153
|
* @property {Scope | undefined} globalScope
|
|
150
154
|
* @property {Scope | undefined} moduleScope
|
|
151
155
|
* @property {Map<string, string>} internalNames
|
|
152
|
-
* @property {
|
|
153
|
-
* @property {
|
|
156
|
+
* @property {ExportMap | undefined} exportMap
|
|
157
|
+
* @property {ExportMap | undefined} rawExportMap
|
|
154
158
|
* @property {string=} namespaceExportSymbol
|
|
155
159
|
* @property {string | undefined} namespaceObjectName
|
|
156
160
|
* @property {ConcatenationScope | undefined} concatenationScope
|
|
@@ -167,6 +171,7 @@ if (!ReferencerClass.prototype.PropertyDefinition) {
|
|
|
167
171
|
* @property {"external"} type
|
|
168
172
|
* @property {Module} module
|
|
169
173
|
* @property {RuntimeSpec | boolean} runtimeCondition
|
|
174
|
+
* @property {NonDeferAccess} nonDeferAccess
|
|
170
175
|
* @property {number} index
|
|
171
176
|
* @property {string | undefined} name module.exports / harmony namespace object
|
|
172
177
|
* @property {string | undefined} deferredName deferred module.exports / harmony namespace object
|
|
@@ -185,13 +190,14 @@ if (!ReferencerClass.prototype.PropertyDefinition) {
|
|
|
185
190
|
* @typedef {object} ReferenceToModuleInfo
|
|
186
191
|
* @property {"reference"} type
|
|
187
192
|
* @property {RuntimeSpec | boolean} runtimeCondition
|
|
193
|
+
* @property {NonDeferAccess} nonDeferAccess
|
|
188
194
|
* @property {ModuleInfo} target
|
|
189
195
|
*/
|
|
190
196
|
|
|
191
197
|
/**
|
|
192
198
|
* @template T
|
|
193
199
|
* @param {string} property property
|
|
194
|
-
* @param {
|
|
200
|
+
* @param {(a: T[keyof T], b: T[keyof T]) => 0 | 1 | -1} comparator comparator
|
|
195
201
|
* @returns {Comparator<T>} comparator
|
|
196
202
|
*/
|
|
197
203
|
|
|
@@ -223,16 +229,6 @@ const compareNumbers = (a, b) => {
|
|
|
223
229
|
};
|
|
224
230
|
const bySourceOrder = createComparator("sourceOrder", compareNumbers);
|
|
225
231
|
const byRangeStart = createComparator("rangeStart", compareNumbers);
|
|
226
|
-
const moveDeferToLast = (
|
|
227
|
-
/** @type {{ defer?: boolean }} */ a,
|
|
228
|
-
/** @type {{ defer?: boolean }} */ b
|
|
229
|
-
) => {
|
|
230
|
-
if (a.defer === b.defer) return 0;
|
|
231
|
-
if (a.defer) return 1;
|
|
232
|
-
return -1;
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
const INITIAL_USED_NAMES = new Set(RESERVED_NAMES);
|
|
236
232
|
|
|
237
233
|
/**
|
|
238
234
|
* @param {Iterable<string>} iterable iterable object
|
|
@@ -254,11 +250,28 @@ const joinIterableWithComma = (iterable) => {
|
|
|
254
250
|
return str;
|
|
255
251
|
};
|
|
256
252
|
|
|
253
|
+
/** @typedef {boolean} NonDeferAccess */
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* @param {NonDeferAccess} a a
|
|
257
|
+
* @param {NonDeferAccess} b b
|
|
258
|
+
* @returns {NonDeferAccess} merged
|
|
259
|
+
*/
|
|
260
|
+
const mergeNonDeferAccess = (a, b) => a || b;
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* @param {NonDeferAccess} a first
|
|
264
|
+
* @param {NonDeferAccess} b second
|
|
265
|
+
* @returns {NonDeferAccess} first - second
|
|
266
|
+
*/
|
|
267
|
+
const subtractNonDeferAccess = (a, b) => a && !b;
|
|
268
|
+
|
|
257
269
|
/**
|
|
258
270
|
* @typedef {object} ConcatenationEntry
|
|
259
271
|
* @property {"concatenated" | "external"} type
|
|
260
272
|
* @property {Module} module
|
|
261
273
|
* @property {RuntimeSpec | boolean} runtimeCondition
|
|
274
|
+
* @property {NonDeferAccess} nonDeferAccess
|
|
262
275
|
*/
|
|
263
276
|
|
|
264
277
|
/** @typedef {Set<ConcatenatedModuleInfo>} NeededNamespaceObjects */
|
|
@@ -300,11 +313,11 @@ const getFinalBinding = (
|
|
|
300
313
|
moduleGraph,
|
|
301
314
|
strictHarmonyModule
|
|
302
315
|
);
|
|
303
|
-
const
|
|
304
|
-
depDeferred &&
|
|
316
|
+
const moduleDeferred =
|
|
305
317
|
info.type === "external" &&
|
|
306
318
|
info.deferred &&
|
|
307
|
-
!
|
|
319
|
+
!(/** @type {BuildMeta} */ (info.module.buildMeta).async);
|
|
320
|
+
const deferred = depDeferred && moduleDeferred;
|
|
308
321
|
if (exportName.length === 0) {
|
|
309
322
|
switch (exportsType) {
|
|
310
323
|
case "default-only":
|
|
@@ -391,6 +404,14 @@ const getFinalBinding = (
|
|
|
391
404
|
exportName
|
|
392
405
|
};
|
|
393
406
|
}
|
|
407
|
+
if (moduleDeferred) {
|
|
408
|
+
return {
|
|
409
|
+
info,
|
|
410
|
+
rawName: /** @type {string} */ (info.name),
|
|
411
|
+
ids: exportName,
|
|
412
|
+
exportName
|
|
413
|
+
};
|
|
414
|
+
}
|
|
394
415
|
info.interopDefaultAccessUsed = true;
|
|
395
416
|
const defaultExport = asCall
|
|
396
417
|
? `${info.interopDefaultAccessName}()`
|
|
@@ -668,7 +689,7 @@ const getFinalName = (
|
|
|
668
689
|
|
|
669
690
|
/**
|
|
670
691
|
* @typedef {object} ConcatenateModuleHooks
|
|
671
|
-
* @property {SyncBailHook<[ConcatenatedModule], boolean>} onDemandExportsGeneration
|
|
692
|
+
* @property {SyncBailHook<[ConcatenatedModule, RuntimeSpec[], string, Record<string, string>], boolean>} onDemandExportsGeneration
|
|
672
693
|
* @property {SyncBailHook<[Partial<ConcatenatedModuleInfo>, ConcatenatedModuleInfo], boolean | void>} concatenatedModuleInfo
|
|
673
694
|
*/
|
|
674
695
|
|
|
@@ -718,7 +739,12 @@ class ConcatenatedModule extends Module {
|
|
|
718
739
|
let hooks = compilationHooksMap.get(compilation);
|
|
719
740
|
if (hooks === undefined) {
|
|
720
741
|
hooks = {
|
|
721
|
-
onDemandExportsGeneration: new SyncBailHook([
|
|
742
|
+
onDemandExportsGeneration: new SyncBailHook([
|
|
743
|
+
"module",
|
|
744
|
+
"runtimes",
|
|
745
|
+
"exportsFinalName",
|
|
746
|
+
"exportsSource"
|
|
747
|
+
]),
|
|
722
748
|
concatenatedModuleInfo: new SyncBailHook([
|
|
723
749
|
"updatedInfo",
|
|
724
750
|
"concatenatedModuleInfo"
|
|
@@ -768,7 +794,7 @@ class ConcatenatedModule extends Module {
|
|
|
768
794
|
* @returns {SourceTypes} types available (do not mutate)
|
|
769
795
|
*/
|
|
770
796
|
getSourceTypes() {
|
|
771
|
-
return
|
|
797
|
+
return JAVASCRIPT_TYPES;
|
|
772
798
|
}
|
|
773
799
|
|
|
774
800
|
get modules() {
|
|
@@ -951,13 +977,12 @@ class ConcatenatedModule extends Module {
|
|
|
951
977
|
_createConcatenationList(rootModule, modulesSet, runtime, moduleGraph) {
|
|
952
978
|
/** @type {ConcatenationEntry[]} */
|
|
953
979
|
const list = [];
|
|
954
|
-
/** @type {Map<Module, RuntimeSpec | true>} */
|
|
980
|
+
/** @type {Map<Module, { runtimeCondition: RuntimeSpec | true, nonDeferAccess: NonDeferAccess }>} */
|
|
955
981
|
const existingEntries = new Map();
|
|
956
|
-
const deferEnabled = this.compilation.options.experiments.deferImport;
|
|
957
982
|
|
|
958
983
|
/**
|
|
959
984
|
* @param {Module} module a module
|
|
960
|
-
* @returns {Iterable<{ connection: ModuleGraphConnection, runtimeCondition: RuntimeSpec | true }>} imported modules in order
|
|
985
|
+
* @returns {Iterable<{ connection: ModuleGraphConnection, runtimeCondition: RuntimeSpec | true, nonDeferAccess: NonDeferAccess }>} imported modules in order
|
|
961
986
|
*/
|
|
962
987
|
const getConcatenatedImports = (module) => {
|
|
963
988
|
const connections = [...moduleGraph.getOutgoingConnections(module)];
|
|
@@ -987,9 +1012,9 @@ class ConcatenatedModule extends Module {
|
|
|
987
1012
|
(connection.dependency);
|
|
988
1013
|
return {
|
|
989
1014
|
connection,
|
|
990
|
-
sourceOrder: dep.sourceOrder,
|
|
1015
|
+
sourceOrder: /** @type {number} */ (dep.sourceOrder),
|
|
991
1016
|
rangeStart: dep.range && dep.range[0],
|
|
992
|
-
defer: dep.
|
|
1017
|
+
defer: ImportPhaseUtils.isDefer(dep.phase)
|
|
993
1018
|
};
|
|
994
1019
|
});
|
|
995
1020
|
/**
|
|
@@ -1004,27 +1029,27 @@ class ConcatenatedModule extends Module {
|
|
|
1004
1029
|
* a.a(); // first range
|
|
1005
1030
|
* b.b(); // second range
|
|
1006
1031
|
*
|
|
1007
|
-
* If the import is deferred, we always move it to the last.
|
|
1008
1032
|
* If there is no reexport, we have the same source.
|
|
1009
1033
|
* If there is reexport, but module has side effects, this will lead to reexport module only.
|
|
1010
1034
|
* If there is side-effects-free reexport, we can get simple deterministic result with range start comparison.
|
|
1011
1035
|
*/
|
|
1012
1036
|
references.sort(concatComparators(bySourceOrder, byRangeStart));
|
|
1013
|
-
|
|
1014
|
-
// 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.
|
|
1015
|
-
references.sort(moveDeferToLast);
|
|
1016
|
-
}
|
|
1017
|
-
/** @type {Map<Module, { connection: ModuleGraphConnection, runtimeCondition: RuntimeSpec | true }>} */
|
|
1037
|
+
/** @type {Map<Module, { connection: ModuleGraphConnection, runtimeCondition: RuntimeSpec | true, nonDeferAccess: NonDeferAccess }>} */
|
|
1018
1038
|
const referencesMap = new Map();
|
|
1019
|
-
for (const { connection } of references) {
|
|
1039
|
+
for (const { connection, defer } of references) {
|
|
1020
1040
|
const runtimeCondition = filterRuntime(runtime, (r) =>
|
|
1021
1041
|
connection.isTargetActive(r)
|
|
1022
1042
|
);
|
|
1023
1043
|
if (runtimeCondition === false) continue;
|
|
1044
|
+
const nonDeferAccess = !defer;
|
|
1024
1045
|
const module = connection.module;
|
|
1025
1046
|
const entry = referencesMap.get(module);
|
|
1026
1047
|
if (entry === undefined) {
|
|
1027
|
-
referencesMap.set(module, {
|
|
1048
|
+
referencesMap.set(module, {
|
|
1049
|
+
connection,
|
|
1050
|
+
runtimeCondition,
|
|
1051
|
+
nonDeferAccess
|
|
1052
|
+
});
|
|
1028
1053
|
continue;
|
|
1029
1054
|
}
|
|
1030
1055
|
entry.runtimeCondition = mergeRuntimeConditionNonFalse(
|
|
@@ -1032,6 +1057,10 @@ class ConcatenatedModule extends Module {
|
|
|
1032
1057
|
runtimeCondition,
|
|
1033
1058
|
runtime
|
|
1034
1059
|
);
|
|
1060
|
+
entry.nonDeferAccess = mergeNonDeferAccess(
|
|
1061
|
+
entry.nonDeferAccess,
|
|
1062
|
+
nonDeferAccess
|
|
1063
|
+
);
|
|
1035
1064
|
}
|
|
1036
1065
|
return referencesMap.values();
|
|
1037
1066
|
};
|
|
@@ -1039,17 +1068,25 @@ class ConcatenatedModule extends Module {
|
|
|
1039
1068
|
/**
|
|
1040
1069
|
* @param {ModuleGraphConnection} connection graph connection
|
|
1041
1070
|
* @param {RuntimeSpec | true} runtimeCondition runtime condition
|
|
1071
|
+
* @param {NonDeferAccess} nonDeferAccess non-defer access
|
|
1042
1072
|
* @returns {void}
|
|
1043
1073
|
*/
|
|
1044
|
-
const enterModule = (connection, runtimeCondition) => {
|
|
1074
|
+
const enterModule = (connection, runtimeCondition, nonDeferAccess) => {
|
|
1045
1075
|
const module = connection.module;
|
|
1046
1076
|
if (!module) return;
|
|
1047
1077
|
const existingEntry = existingEntries.get(module);
|
|
1048
|
-
if (
|
|
1078
|
+
if (
|
|
1079
|
+
existingEntry &&
|
|
1080
|
+
existingEntry.runtimeCondition === true &&
|
|
1081
|
+
existingEntry.nonDeferAccess === true
|
|
1082
|
+
) {
|
|
1049
1083
|
return;
|
|
1050
1084
|
}
|
|
1051
1085
|
if (modulesSet.has(module)) {
|
|
1052
|
-
existingEntries.set(module,
|
|
1086
|
+
existingEntries.set(module, {
|
|
1087
|
+
runtimeCondition: true,
|
|
1088
|
+
nonDeferAccess: true
|
|
1089
|
+
});
|
|
1053
1090
|
if (runtimeCondition !== true) {
|
|
1054
1091
|
throw new Error(
|
|
1055
1092
|
`Cannot runtime-conditional concatenate a module (${module.identifier()} in ${this.rootModule.identifier()}, ${runtimeConditionToString(
|
|
@@ -1057,34 +1094,66 @@ class ConcatenatedModule extends Module {
|
|
|
1057
1094
|
)}). This should not happen.`
|
|
1058
1095
|
);
|
|
1059
1096
|
}
|
|
1097
|
+
if (nonDeferAccess !== true) {
|
|
1098
|
+
throw new Error(
|
|
1099
|
+
`Cannot deferred concatenate a module (${module.identifier()} in ${this.rootModule.identifier()}. This should not happen.`
|
|
1100
|
+
);
|
|
1101
|
+
}
|
|
1060
1102
|
const imports = getConcatenatedImports(module);
|
|
1061
|
-
for (const {
|
|
1062
|
-
|
|
1103
|
+
for (const {
|
|
1104
|
+
connection,
|
|
1105
|
+
runtimeCondition,
|
|
1106
|
+
nonDeferAccess
|
|
1107
|
+
} of imports) {
|
|
1108
|
+
enterModule(connection, runtimeCondition, nonDeferAccess);
|
|
1063
1109
|
}
|
|
1064
1110
|
list.push({
|
|
1065
1111
|
type: "concatenated",
|
|
1066
1112
|
module: connection.module,
|
|
1067
|
-
runtimeCondition
|
|
1113
|
+
runtimeCondition,
|
|
1114
|
+
nonDeferAccess
|
|
1068
1115
|
});
|
|
1069
1116
|
} else {
|
|
1117
|
+
/** @type {RuntimeSpec | boolean} */
|
|
1118
|
+
let reducedRuntimeCondition;
|
|
1119
|
+
/** @type {NonDeferAccess} */
|
|
1120
|
+
let reducedNonDeferAccess;
|
|
1070
1121
|
if (existingEntry !== undefined) {
|
|
1071
|
-
|
|
1122
|
+
reducedRuntimeCondition = subtractRuntimeCondition(
|
|
1072
1123
|
runtimeCondition,
|
|
1073
|
-
existingEntry,
|
|
1124
|
+
existingEntry.runtimeCondition,
|
|
1074
1125
|
runtime
|
|
1075
1126
|
);
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
connection.module,
|
|
1080
|
-
mergeRuntimeConditionNonFalse(
|
|
1081
|
-
existingEntry,
|
|
1082
|
-
runtimeCondition,
|
|
1083
|
-
runtime
|
|
1084
|
-
)
|
|
1127
|
+
reducedNonDeferAccess = subtractNonDeferAccess(
|
|
1128
|
+
nonDeferAccess,
|
|
1129
|
+
existingEntry.nonDeferAccess
|
|
1085
1130
|
);
|
|
1131
|
+
if (
|
|
1132
|
+
reducedRuntimeCondition === false &&
|
|
1133
|
+
reducedNonDeferAccess === false
|
|
1134
|
+
) {
|
|
1135
|
+
return;
|
|
1136
|
+
}
|
|
1137
|
+
if (reducedRuntimeCondition !== false) {
|
|
1138
|
+
existingEntry.runtimeCondition = mergeRuntimeConditionNonFalse(
|
|
1139
|
+
existingEntry.runtimeCondition,
|
|
1140
|
+
reducedRuntimeCondition,
|
|
1141
|
+
runtime
|
|
1142
|
+
);
|
|
1143
|
+
}
|
|
1144
|
+
if (reducedNonDeferAccess !== false) {
|
|
1145
|
+
existingEntry.nonDeferAccess = mergeNonDeferAccess(
|
|
1146
|
+
existingEntry.nonDeferAccess,
|
|
1147
|
+
reducedNonDeferAccess
|
|
1148
|
+
);
|
|
1149
|
+
}
|
|
1086
1150
|
} else {
|
|
1087
|
-
|
|
1151
|
+
reducedRuntimeCondition = runtimeCondition;
|
|
1152
|
+
reducedNonDeferAccess = nonDeferAccess;
|
|
1153
|
+
existingEntries.set(connection.module, {
|
|
1154
|
+
runtimeCondition,
|
|
1155
|
+
nonDeferAccess
|
|
1156
|
+
});
|
|
1088
1157
|
}
|
|
1089
1158
|
if (list.length > 0) {
|
|
1090
1159
|
const lastItem = list[list.length - 1];
|
|
@@ -1094,9 +1163,13 @@ class ConcatenatedModule extends Module {
|
|
|
1094
1163
|
) {
|
|
1095
1164
|
lastItem.runtimeCondition = mergeRuntimeCondition(
|
|
1096
1165
|
lastItem.runtimeCondition,
|
|
1097
|
-
|
|
1166
|
+
reducedRuntimeCondition,
|
|
1098
1167
|
runtime
|
|
1099
1168
|
);
|
|
1169
|
+
lastItem.nonDeferAccess = mergeNonDeferAccess(
|
|
1170
|
+
lastItem.nonDeferAccess,
|
|
1171
|
+
reducedNonDeferAccess
|
|
1172
|
+
);
|
|
1100
1173
|
return;
|
|
1101
1174
|
}
|
|
1102
1175
|
}
|
|
@@ -1108,20 +1181,25 @@ class ConcatenatedModule extends Module {
|
|
|
1108
1181
|
// concatenated module)
|
|
1109
1182
|
return connection.module;
|
|
1110
1183
|
},
|
|
1111
|
-
runtimeCondition
|
|
1184
|
+
runtimeCondition: reducedRuntimeCondition,
|
|
1185
|
+
nonDeferAccess: reducedNonDeferAccess
|
|
1112
1186
|
});
|
|
1113
1187
|
}
|
|
1114
1188
|
};
|
|
1115
1189
|
|
|
1116
|
-
existingEntries.set(rootModule,
|
|
1190
|
+
existingEntries.set(rootModule, {
|
|
1191
|
+
runtimeCondition: true,
|
|
1192
|
+
nonDeferAccess: true
|
|
1193
|
+
});
|
|
1117
1194
|
const imports = getConcatenatedImports(rootModule);
|
|
1118
|
-
for (const { connection, runtimeCondition } of imports) {
|
|
1119
|
-
enterModule(connection, runtimeCondition);
|
|
1195
|
+
for (const { connection, runtimeCondition, nonDeferAccess } of imports) {
|
|
1196
|
+
enterModule(connection, runtimeCondition, nonDeferAccess);
|
|
1120
1197
|
}
|
|
1121
1198
|
list.push({
|
|
1122
1199
|
type: "concatenated",
|
|
1123
1200
|
module: rootModule,
|
|
1124
|
-
runtimeCondition: true
|
|
1201
|
+
runtimeCondition: true,
|
|
1202
|
+
nonDeferAccess: true
|
|
1125
1203
|
});
|
|
1126
1204
|
|
|
1127
1205
|
return list;
|
|
@@ -1186,6 +1264,7 @@ class ConcatenatedModule extends Module {
|
|
|
1186
1264
|
moduleGraph,
|
|
1187
1265
|
chunkGraph,
|
|
1188
1266
|
runtime: generationRuntime,
|
|
1267
|
+
runtimes,
|
|
1189
1268
|
codeGenerationResults
|
|
1190
1269
|
}) {
|
|
1191
1270
|
const { concatenatedModuleInfo } = ConcatenatedModule.getCompilationHooks(
|
|
@@ -1207,18 +1286,8 @@ class ConcatenatedModule extends Module {
|
|
|
1207
1286
|
/** @type {NeededNamespaceObjects} */
|
|
1208
1287
|
const neededNamespaceObjects = new Set();
|
|
1209
1288
|
|
|
1210
|
-
//
|
|
1211
|
-
const allUsedNames = new Set(
|
|
1212
|
-
const chunks = chunkGraph.getModuleChunks(this);
|
|
1213
|
-
|
|
1214
|
-
// Add names already used in the current chunk scope
|
|
1215
|
-
for (const chunk of chunks) {
|
|
1216
|
-
if (ConcatenationScope.chunkUsedNames.has(chunk)) {
|
|
1217
|
-
for (const name of ConcatenationScope.chunkUsedNames.get(chunk) || []) {
|
|
1218
|
-
allUsedNames.add(name);
|
|
1219
|
-
}
|
|
1220
|
-
}
|
|
1221
|
-
}
|
|
1289
|
+
// List of all used names to avoid conflicts
|
|
1290
|
+
const allUsedNames = new Set(RESERVED_NAMES);
|
|
1222
1291
|
|
|
1223
1292
|
// Generate source code and analyse scopes
|
|
1224
1293
|
// Prepare a ReplaceSource for the final source
|
|
@@ -1231,29 +1300,13 @@ class ConcatenatedModule extends Module {
|
|
|
1231
1300
|
moduleGraph,
|
|
1232
1301
|
chunkGraph,
|
|
1233
1302
|
runtime,
|
|
1303
|
+
runtimes,
|
|
1234
1304
|
/** @type {CodeGenerationResults} */
|
|
1235
1305
|
(codeGenerationResults),
|
|
1236
1306
|
allUsedNames
|
|
1237
1307
|
);
|
|
1238
1308
|
}
|
|
1239
1309
|
|
|
1240
|
-
// Record the names registered by the current ConcatenatedModule into the chunk scope
|
|
1241
|
-
if (INITIAL_USED_NAMES.size !== allUsedNames.size) {
|
|
1242
|
-
for (const name of allUsedNames) {
|
|
1243
|
-
if (INITIAL_USED_NAMES.has(name)) continue;
|
|
1244
|
-
|
|
1245
|
-
for (const chunk of chunks) {
|
|
1246
|
-
if (!ConcatenationScope.chunkUsedNames.has(chunk)) {
|
|
1247
|
-
ConcatenationScope.chunkUsedNames.set(chunk, new Set([name]));
|
|
1248
|
-
} else {
|
|
1249
|
-
/** @type {Set<string>} */ (
|
|
1250
|
-
ConcatenationScope.chunkUsedNames.get(chunk)
|
|
1251
|
-
).add(name);
|
|
1252
|
-
}
|
|
1253
|
-
}
|
|
1254
|
-
}
|
|
1255
|
-
}
|
|
1256
|
-
|
|
1257
1310
|
// Updated Top level declarations are created by renaming
|
|
1258
1311
|
/** @type {TopLevelDeclarations} */
|
|
1259
1312
|
const topLevelDeclarations = new Set();
|
|
@@ -1366,7 +1419,7 @@ class ConcatenatedModule extends Module {
|
|
|
1366
1419
|
* @param {string} name the name to find a new name for
|
|
1367
1420
|
* @param {ConcatenatedModuleInfo} info the info of the module
|
|
1368
1421
|
* @param {Reference[]} references the references to the name
|
|
1369
|
-
* @returns {string|undefined} the new name or undefined if the name is not found
|
|
1422
|
+
* @returns {string | undefined} the new name or undefined if the name is not found
|
|
1370
1423
|
*/
|
|
1371
1424
|
const _findNewName = (name, info, references) => {
|
|
1372
1425
|
const { usedNames, alreadyCheckedScopes } = getUsedNamesInScopeInfo(
|
|
@@ -1400,7 +1453,7 @@ class ConcatenatedModule extends Module {
|
|
|
1400
1453
|
* @param {string} name the name to find a new name for
|
|
1401
1454
|
* @param {ConcatenatedModuleInfo} info the info of the module
|
|
1402
1455
|
* @param {Reference[]} references the references to the name
|
|
1403
|
-
* @returns {string|undefined} the new name or undefined if the name is not found
|
|
1456
|
+
* @returns {string | undefined} the new name or undefined if the name is not found
|
|
1404
1457
|
*/
|
|
1405
1458
|
const _findNewNameForSpecifier = (name, info, references) => {
|
|
1406
1459
|
const { usedNames: moduleUsedNames, alreadyCheckedScopes } =
|
|
@@ -1731,9 +1784,6 @@ class ConcatenatedModule extends Module {
|
|
|
1731
1784
|
);
|
|
1732
1785
|
}
|
|
1733
1786
|
|
|
1734
|
-
const { onDemandExportsGeneration } =
|
|
1735
|
-
ConcatenatedModule.getCompilationHooks(this.compilation);
|
|
1736
|
-
|
|
1737
1787
|
runtimeRequirements.add(RuntimeGlobals.exports);
|
|
1738
1788
|
runtimeRequirements.add(RuntimeGlobals.definePropertyGetters);
|
|
1739
1789
|
|
|
@@ -1747,21 +1797,24 @@ class ConcatenatedModule extends Module {
|
|
|
1747
1797
|
);
|
|
1748
1798
|
}
|
|
1749
1799
|
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1800
|
+
const exportsSource =
|
|
1801
|
+
"\n// EXPORTS\n" +
|
|
1802
|
+
`${RuntimeGlobals.definePropertyGetters}(${this.exportsArgument}, {${definitions.join(
|
|
1803
|
+
","
|
|
1804
|
+
)}\n});\n`;
|
|
1805
|
+
|
|
1806
|
+
const { onDemandExportsGeneration } =
|
|
1807
|
+
ConcatenatedModule.getCompilationHooks(this.compilation);
|
|
1808
|
+
|
|
1809
|
+
if (
|
|
1810
|
+
!onDemandExportsGeneration.call(
|
|
1811
|
+
this,
|
|
1812
|
+
runtimes,
|
|
1813
|
+
exportsSource,
|
|
1814
|
+
exportsFinalName
|
|
1815
|
+
)
|
|
1816
|
+
) {
|
|
1817
|
+
result.add(exportsSource);
|
|
1765
1818
|
}
|
|
1766
1819
|
}
|
|
1767
1820
|
|
|
@@ -1837,26 +1890,37 @@ ${defineGetters}`
|
|
|
1837
1890
|
if (info.type === "external" && info.deferred) {
|
|
1838
1891
|
const moduleId = JSON.stringify(chunkGraph.getModuleId(info.module));
|
|
1839
1892
|
const loader = getOptimizedDeferredModule(
|
|
1840
|
-
|
|
1893
|
+
moduleId,
|
|
1841
1894
|
info.module.getExportsType(
|
|
1842
1895
|
moduleGraph,
|
|
1843
1896
|
/** @type {BuildMeta} */
|
|
1844
1897
|
(this.rootModule.buildMeta).strictHarmonyModule
|
|
1845
1898
|
),
|
|
1846
|
-
moduleId,
|
|
1847
1899
|
// an async module will opt-out of the concat module optimization.
|
|
1848
|
-
[]
|
|
1900
|
+
[],
|
|
1901
|
+
runtimeRequirements
|
|
1849
1902
|
);
|
|
1850
1903
|
runtimeRequirements.add(RuntimeGlobals.require);
|
|
1851
1904
|
result.add(
|
|
1852
1905
|
`\n// DEFERRED EXTERNAL MODULE: ${info.module.readableIdentifier(requestShortener)}\nvar ${info.deferredName} = ${loader};`
|
|
1853
1906
|
);
|
|
1907
|
+
if (info.deferredNamespaceObjectUsed) {
|
|
1908
|
+
runtimeRequirements.add(RuntimeGlobals.makeDeferredNamespaceObject);
|
|
1909
|
+
result.add(
|
|
1910
|
+
`\nvar ${info.deferredNamespaceObjectName} = /*#__PURE__*/${
|
|
1911
|
+
RuntimeGlobals.makeDeferredNamespaceObject
|
|
1912
|
+
}(${JSON.stringify(
|
|
1913
|
+
chunkGraph.getModuleId(info.module)
|
|
1914
|
+
)}, ${getMakeDeferredNamespaceModeFromExportsType(
|
|
1915
|
+
info.module.getExportsType(moduleGraph, strictHarmonyModule)
|
|
1916
|
+
)});`
|
|
1917
|
+
);
|
|
1918
|
+
}
|
|
1854
1919
|
}
|
|
1855
1920
|
}
|
|
1856
1921
|
|
|
1857
1922
|
/** @type {InitFragment<ChunkRenderContext>[]} */
|
|
1858
1923
|
const chunkInitFragments = [];
|
|
1859
|
-
const deferEnabled = this.compilation.options.experiments.deferImport;
|
|
1860
1924
|
|
|
1861
1925
|
// evaluate modules in order
|
|
1862
1926
|
for (const rawInfo of modulesWithInfo) {
|
|
@@ -1868,41 +1932,6 @@ ${defineGetters}`
|
|
|
1868
1932
|
result.add(
|
|
1869
1933
|
`\n;// ${info.module.readableIdentifier(requestShortener)}\n`
|
|
1870
1934
|
);
|
|
1871
|
-
// If a module is deferred in other places, but used as non-deferred here,
|
|
1872
|
-
// the module itself will be emitted as mod_deferred (in the case "external"),
|
|
1873
|
-
// we need to emit an extra import declaration to evaluate it in order.
|
|
1874
|
-
if (deferEnabled) {
|
|
1875
|
-
for (const dep of info.module.dependencies) {
|
|
1876
|
-
if (
|
|
1877
|
-
!(/** @type {HarmonyImportDependency} */ (dep).defer) &&
|
|
1878
|
-
(dep instanceof HarmonyImportSideEffectDependency ||
|
|
1879
|
-
dep instanceof HarmonyImportSpecifierDependency)
|
|
1880
|
-
) {
|
|
1881
|
-
const referredModule = moduleGraph.getModule(dep);
|
|
1882
|
-
if (!referredModule) {
|
|
1883
|
-
if (dep instanceof HarmonyImportSideEffectDependency) {
|
|
1884
|
-
continue;
|
|
1885
|
-
} else {
|
|
1886
|
-
throw new Error(
|
|
1887
|
-
"Deferred module used, but no module in the graph."
|
|
1888
|
-
);
|
|
1889
|
-
}
|
|
1890
|
-
}
|
|
1891
|
-
if (moduleGraph.isDeferred(referredModule)) {
|
|
1892
|
-
const deferredModuleInfo = /** @type {ExternalModuleInfo} */ (
|
|
1893
|
-
modulesWithInfo.find(
|
|
1894
|
-
(i) =>
|
|
1895
|
-
i.type === "external" && i.module === referredModule
|
|
1896
|
-
)
|
|
1897
|
-
);
|
|
1898
|
-
if (!deferredModuleInfo) continue;
|
|
1899
|
-
result.add(
|
|
1900
|
-
`\n// non-deferred import to a deferred module (${referredModule.readableIdentifier(requestShortener)})\nvar ${deferredModuleInfo.name} = ${deferredModuleInfo.deferredName}.a;`
|
|
1901
|
-
);
|
|
1902
|
-
}
|
|
1903
|
-
}
|
|
1904
|
-
}
|
|
1905
|
-
}
|
|
1906
1935
|
result.add(/** @type {ReplaceSource} */ (info.source));
|
|
1907
1936
|
if (info.chunkInitFragments) {
|
|
1908
1937
|
for (const f of info.chunkInitFragments) chunkInitFragments.push(f);
|
|
@@ -1943,24 +1972,23 @@ ${defineGetters}`
|
|
|
1943
1972
|
result.add(`var ${info.name} = __webpack_require__(${moduleId});`);
|
|
1944
1973
|
name = info.name;
|
|
1945
1974
|
}
|
|
1975
|
+
// If a module is deferred in other places, but used as non-deferred here,
|
|
1976
|
+
// the module itself will be emitted as mod_deferred (in the case "external"),
|
|
1977
|
+
// we need to emit an extra import declaration to evaluate it in order.
|
|
1978
|
+
const { nonDeferAccess } =
|
|
1979
|
+
/** @type {ExternalModuleInfo | ReferenceToModuleInfo} */
|
|
1980
|
+
(rawInfo);
|
|
1981
|
+
if (info.deferred && nonDeferAccess) {
|
|
1982
|
+
result.add(
|
|
1983
|
+
`\n// non-deferred import to a deferred module (${info.module.readableIdentifier(requestShortener)})\nvar ${info.name} = ${info.deferredName}.a;`
|
|
1984
|
+
);
|
|
1985
|
+
}
|
|
1946
1986
|
break;
|
|
1947
1987
|
}
|
|
1948
1988
|
default:
|
|
1949
1989
|
// @ts-expect-error never is expected here
|
|
1950
1990
|
throw new Error(`Unsupported concatenation entry type ${info.type}`);
|
|
1951
1991
|
}
|
|
1952
|
-
if (info.type === "external" && info.deferredNamespaceObjectUsed) {
|
|
1953
|
-
runtimeRequirements.add(RuntimeGlobals.makeDeferredNamespaceObject);
|
|
1954
|
-
result.add(
|
|
1955
|
-
`\nvar ${info.deferredNamespaceObjectName} = /*#__PURE__*/${
|
|
1956
|
-
RuntimeGlobals.makeDeferredNamespaceObject
|
|
1957
|
-
}(${JSON.stringify(
|
|
1958
|
-
chunkGraph.getModuleId(info.module)
|
|
1959
|
-
)}, ${getMakeDeferredNamespaceModeFromExportsType(
|
|
1960
|
-
info.module.getExportsType(moduleGraph, strictHarmonyModule)
|
|
1961
|
-
)});`
|
|
1962
|
-
);
|
|
1963
|
-
}
|
|
1964
1992
|
if (info.interopNamespaceObjectUsed) {
|
|
1965
1993
|
runtimeRequirements.add(RuntimeGlobals.createFakeNamespaceObject);
|
|
1966
1994
|
result.add(
|
|
@@ -1992,7 +2020,7 @@ ${defineGetters}`
|
|
|
1992
2020
|
|
|
1993
2021
|
/** @type {CodeGenerationResult} */
|
|
1994
2022
|
const resultEntry = {
|
|
1995
|
-
sources: new Map([[
|
|
2023
|
+
sources: new Map([[JAVASCRIPT_TYPE, new CachedSource(result)]]),
|
|
1996
2024
|
data,
|
|
1997
2025
|
runtimeRequirements
|
|
1998
2026
|
};
|
|
@@ -2008,6 +2036,7 @@ ${defineGetters}`
|
|
|
2008
2036
|
* @param {ModuleGraph} moduleGraph moduleGraph
|
|
2009
2037
|
* @param {ChunkGraph} chunkGraph chunkGraph
|
|
2010
2038
|
* @param {RuntimeSpec} runtime runtime
|
|
2039
|
+
* @param {RuntimeSpec[]} runtimes runtimes
|
|
2011
2040
|
* @param {CodeGenerationResults} codeGenerationResults codeGenerationResults
|
|
2012
2041
|
* @param {Set<string>} usedNames used names
|
|
2013
2042
|
*/
|
|
@@ -2019,6 +2048,7 @@ ${defineGetters}`
|
|
|
2019
2048
|
moduleGraph,
|
|
2020
2049
|
chunkGraph,
|
|
2021
2050
|
runtime,
|
|
2051
|
+
runtimes,
|
|
2022
2052
|
codeGenerationResults,
|
|
2023
2053
|
usedNames
|
|
2024
2054
|
) {
|
|
@@ -2039,21 +2069,30 @@ ${defineGetters}`
|
|
|
2039
2069
|
moduleGraph,
|
|
2040
2070
|
chunkGraph,
|
|
2041
2071
|
runtime,
|
|
2072
|
+
runtimes,
|
|
2042
2073
|
concatenationScope,
|
|
2043
2074
|
codeGenerationResults,
|
|
2044
|
-
sourceTypes:
|
|
2075
|
+
sourceTypes: JAVASCRIPT_TYPES
|
|
2045
2076
|
});
|
|
2046
2077
|
const source =
|
|
2047
2078
|
/** @type {Source} */
|
|
2048
|
-
(codeGenResult.sources.get(
|
|
2079
|
+
(codeGenResult.sources.get(JAVASCRIPT_TYPE));
|
|
2049
2080
|
const data = codeGenResult.data;
|
|
2050
2081
|
const chunkInitFragments = data && data.get("chunkInitFragments");
|
|
2051
2082
|
const code = source.source().toString();
|
|
2083
|
+
|
|
2084
|
+
/** @type {Program} */
|
|
2052
2085
|
let ast;
|
|
2086
|
+
|
|
2053
2087
|
try {
|
|
2054
|
-
ast = JavascriptParser._parse(
|
|
2055
|
-
|
|
2056
|
-
|
|
2088
|
+
({ ast } = JavascriptParser._parse(
|
|
2089
|
+
code,
|
|
2090
|
+
{
|
|
2091
|
+
sourceType: "module",
|
|
2092
|
+
ranges: true
|
|
2093
|
+
},
|
|
2094
|
+
JavascriptParser._getModuleParseFunction(this.compilation, m)
|
|
2095
|
+
));
|
|
2057
2096
|
} catch (_err) {
|
|
2058
2097
|
const err =
|
|
2059
2098
|
/** @type {Error & { loc?: { line: number, column: number } }} */
|
|
@@ -2148,6 +2187,7 @@ ${defineGetters}`
|
|
|
2148
2187
|
type: "external",
|
|
2149
2188
|
module: info.module,
|
|
2150
2189
|
runtimeCondition: info.runtimeCondition,
|
|
2190
|
+
nonDeferAccess: info.nonDeferAccess,
|
|
2151
2191
|
index,
|
|
2152
2192
|
name: undefined,
|
|
2153
2193
|
deferredName: undefined,
|
|
@@ -2177,6 +2217,7 @@ ${defineGetters}`
|
|
|
2177
2217
|
const ref = {
|
|
2178
2218
|
type: "reference",
|
|
2179
2219
|
runtimeCondition: info.runtimeCondition,
|
|
2220
|
+
nonDeferAccess: info.nonDeferAccess,
|
|
2180
2221
|
target: item
|
|
2181
2222
|
};
|
|
2182
2223
|
return ref;
|