webpack 5.83.1 → 5.85.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.
Potentially problematic release.
This version of webpack might be problematic. Click here for more details.
- package/README.md +2 -2
- package/lib/AsyncDependenciesBlock.js +2 -2
- package/lib/AutomaticPrefetchPlugin.js +1 -0
- package/lib/BannerPlugin.js +4 -0
- package/lib/CacheFacade.js +4 -0
- package/lib/ChunkGroup.js +5 -1
- package/lib/CleanPlugin.js +30 -7
- package/lib/CompatibilityPlugin.js +4 -3
- package/lib/Compilation.js +3 -3
- package/lib/Compiler.js +1 -1
- package/lib/ContextModule.js +3 -3
- package/lib/ContextModuleFactory.js +1 -1
- package/lib/DefinePlugin.js +11 -2
- package/lib/DllEntryPlugin.js +5 -0
- package/lib/DllModule.js +1 -1
- package/lib/DllModuleFactory.js +1 -1
- package/lib/EvalSourceMapDevToolPlugin.js +3 -1
- package/lib/HookWebpackError.js +1 -1
- package/lib/IgnoreErrorModuleFactory.js +1 -1
- package/lib/MainTemplate.js +2 -2
- package/lib/Module.js +21 -9
- package/lib/ModuleFactory.js +1 -1
- package/lib/ModuleTypeConstants.js +2 -1
- package/lib/NormalModuleFactory.js +1 -1
- package/lib/NormalModuleReplacementPlugin.js +4 -2
- package/lib/NullFactory.js +1 -1
- package/lib/PrefetchPlugin.js +4 -0
- package/lib/RecordIdsPlugin.js +4 -4
- package/lib/RuntimeModule.js +5 -5
- package/lib/RuntimePlugin.js +4 -0
- package/lib/RuntimeTemplate.js +7 -7
- package/lib/SelfModuleFactory.js +12 -0
- package/lib/SourceMapDevToolPlugin.js +9 -2
- package/lib/Template.js +3 -2
- package/lib/UseStrictPlugin.js +4 -0
- package/lib/WarnDeprecatedOptionPlugin.js +7 -0
- package/lib/WatchIgnorePlugin.js +4 -0
- package/lib/WebpackOptionsApply.js +2 -1
- package/lib/asset/AssetGenerator.js +7 -2
- package/lib/asset/AssetModulesPlugin.js +7 -1
- package/lib/asset/AssetParser.js +4 -1
- package/lib/asset/RawDataUrlModule.js +5 -3
- package/lib/async-modules/InferAsyncModulesPlugin.js +1 -1
- package/lib/cache/PackFileCacheStrategy.js +7 -1
- package/lib/config/browserslistTargetHandler.js +3 -3
- package/lib/config/defaults.js +240 -73
- package/lib/config/normalization.js +104 -71
- package/lib/config/target.js +37 -10
- package/lib/container/ContainerEntryModule.js +4 -0
- package/lib/container/ContainerEntryModuleFactory.js +1 -1
- package/lib/container/FallbackDependency.js +7 -0
- package/lib/container/FallbackItemDependency.js +3 -0
- package/lib/container/FallbackModule.js +5 -1
- package/lib/container/FallbackModuleFactory.js +1 -1
- package/lib/container/RemoteModule.js +4 -0
- package/lib/container/RemoteRuntimeModule.js +2 -1
- package/lib/container/RemoteToExternalDependency.js +3 -0
- package/lib/css/CssParser.js +168 -73
- package/lib/debug/ProfilingPlugin.js +11 -0
- package/lib/dependencies/AMDDefineDependency.js +12 -6
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +8 -2
- package/lib/dependencies/AMDPlugin.js +7 -0
- package/lib/dependencies/AMDRequireArrayDependency.js +5 -0
- package/lib/dependencies/AMDRequireContextDependency.js +6 -0
- package/lib/dependencies/AMDRequireDependenciesBlock.js +6 -0
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +8 -2
- package/lib/dependencies/AMDRequireDependency.js +8 -1
- package/lib/dependencies/AMDRequireItemDependency.js +6 -0
- package/lib/dependencies/CachedConstDependency.js +6 -0
- package/lib/dependencies/CommonJsExportRequireDependency.js +11 -0
- package/lib/dependencies/CommonJsExportsDependency.js +8 -0
- package/lib/dependencies/CommonJsExportsParserPlugin.js +2 -2
- package/lib/dependencies/CommonJsFullRequireDependency.js +2 -1
- package/lib/dependencies/CommonJsPlugin.js +28 -12
- package/lib/dependencies/CommonJsRequireContextDependency.js +8 -0
- package/lib/dependencies/CommonJsRequireDependency.js +7 -0
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +8 -0
- package/lib/dependencies/ConstDependency.js +2 -1
- package/lib/dependencies/ContextDependencyHelpers.js +3 -3
- package/lib/dependencies/CreateScriptUrlDependency.js +2 -1
- package/lib/dependencies/CriticalDependencyWarning.js +3 -0
- package/lib/dependencies/CssImportDependency.js +2 -1
- package/lib/dependencies/CssLocalIdentifierDependency.js +2 -1
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +2 -1
- package/lib/dependencies/CssUrlDependency.js +12 -2
- package/lib/dependencies/DelegatedSourceDependency.js +3 -0
- package/lib/dependencies/ExportsInfoDependency.js +6 -0
- package/lib/dependencies/HarmonyAcceptDependency.js +2 -1
- package/lib/dependencies/HarmonyAcceptImportDependency.js +3 -0
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +16 -0
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +12 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +3 -0
- package/lib/dependencies/HarmonyExportExpressionDependency.js +8 -0
- package/lib/dependencies/HarmonyExportHeaderDependency.js +5 -0
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +2 -1
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +4 -0
- package/lib/dependencies/HarmonyExports.js +3 -1
- package/lib/dependencies/HarmonyImportDependency.js +2 -1
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +18 -5
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +6 -0
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +86 -6
- package/lib/dependencies/HarmonyModulesPlugin.js +12 -0
- package/lib/dependencies/ImportContextDependency.js +6 -0
- package/lib/dependencies/ImportDependency.js +2 -1
- package/lib/dependencies/ImportEagerDependency.js +2 -1
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +32 -13
- package/lib/dependencies/ImportMetaContextPlugin.js +7 -0
- package/lib/dependencies/ImportMetaHotAcceptDependency.js +6 -0
- package/lib/dependencies/ImportMetaHotDeclineDependency.js +6 -0
- package/lib/dependencies/ImportParserPlugin.js +5 -0
- package/lib/dependencies/ImportPlugin.js +7 -0
- package/lib/dependencies/ImportWeakDependency.js +2 -1
- package/lib/dependencies/LocalModule.js +16 -0
- package/lib/dependencies/LocalModuleDependency.js +7 -0
- package/lib/dependencies/LocalModulesHelpers.js +18 -0
- package/lib/dependencies/ModuleHotAcceptDependency.js +6 -0
- package/lib/dependencies/ModuleHotDeclineDependency.js +6 -0
- package/lib/dependencies/PrefetchDependency.js +3 -0
- package/lib/dependencies/ProvidedDependency.js +2 -1
- package/lib/dependencies/PureExpressionDependency.js +2 -1
- package/lib/dependencies/RequireContextDependency.js +6 -0
- package/lib/dependencies/RequireContextPlugin.js +7 -0
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +4 -0
- package/lib/dependencies/RequireEnsureDependency.js +8 -2
- package/lib/dependencies/RequireEnsureItemDependency.js +3 -0
- package/lib/dependencies/RequireEnsurePlugin.js +14 -0
- package/lib/dependencies/RequireHeaderDependency.js +5 -1
- package/lib/dependencies/RequireIncludeDependency.js +5 -0
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +3 -0
- package/lib/dependencies/RequireIncludePlugin.js +14 -0
- package/lib/dependencies/RequireResolveContextDependency.js +8 -0
- package/lib/dependencies/RequireResolveDependency.js +6 -0
- package/lib/dependencies/RequireResolveHeaderDependency.js +4 -0
- package/lib/dependencies/SystemPlugin.js +10 -1
- package/lib/dependencies/URLDependency.js +3 -2
- package/lib/dependencies/URLPlugin.js +7 -5
- package/lib/dependencies/UnsupportedDependency.js +5 -0
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +6 -0
- package/lib/dependencies/WebpackIsIncludedDependency.js +5 -0
- package/lib/dependencies/WorkerDependency.js +2 -1
- package/lib/dependencies/WorkerPlugin.js +30 -3
- package/lib/dependencies/getFunctionExpression.js +7 -0
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +2 -1
- package/lib/esm/ModuleChunkFormatPlugin.js +15 -7
- package/lib/esm/ModuleChunkLoadingPlugin.js +9 -0
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +14 -9
- package/lib/hmr/LazyCompilationPlugin.js +1 -1
- package/lib/ids/ChunkModuleIdRangePlugin.js +11 -0
- package/lib/ids/DeterministicChunkIdsPlugin.js +11 -2
- package/lib/ids/DeterministicModuleIdsPlugin.js +11 -7
- package/lib/ids/HashedModuleIdsPlugin.js +8 -1
- package/lib/ids/IdHelpers.js +6 -0
- package/lib/ids/NamedChunkIdsPlugin.js +13 -1
- package/lib/ids/NamedModuleIdsPlugin.js +14 -3
- package/lib/ids/OccurrenceChunkIdsPlugin.js +6 -2
- package/lib/ids/SyncModuleIdsPlugin.js +2 -2
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +3 -3
- package/lib/javascript/BasicEvaluatedExpression.js +11 -1
- package/lib/javascript/ChunkHelpers.js +2 -2
- package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -1
- package/lib/javascript/EnableChunkLoadingPlugin.js +4 -0
- package/lib/javascript/JavascriptModulesPlugin.js +36 -31
- package/lib/javascript/JavascriptParser.js +586 -192
- package/lib/javascript/StartupHelpers.js +2 -2
- package/lib/json/JsonGenerator.js +7 -5
- package/lib/json/JsonParser.js +1 -1
- package/lib/library/AbstractLibraryPlugin.js +4 -0
- package/lib/library/AssignLibraryPlugin.js +6 -4
- package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
- package/lib/library/ModuleLibraryPlugin.js +6 -3
- package/lib/library/SystemLibraryPlugin.js +1 -0
- package/lib/library/UmdLibraryPlugin.js +4 -0
- package/lib/node/CommonJsChunkLoadingPlugin.js +17 -2
- package/lib/node/NodeTemplatePlugin.js +10 -2
- package/lib/node/NodeWatchFileSystem.js +1 -1
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +6 -3
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +8 -0
- package/lib/node/ReadFileCompileWasmPlugin.js +19 -2
- package/lib/node/RequireChunkLoadingRuntimeModule.js +6 -3
- package/lib/optimize/ConcatenatedModule.js +1 -1
- package/lib/optimize/InnerGraphPlugin.js +11 -4
- package/lib/runtime/AsyncModuleRuntimeModule.js +1 -1
- package/lib/runtime/AutoPublicPathRuntimeModule.js +5 -1
- package/lib/runtime/BaseUriRuntimeModule.js +5 -1
- package/lib/runtime/EnsureChunkRuntimeModule.js +3 -0
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +35 -16
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -1
- package/lib/runtime/LoadScriptRuntimeModule.js +1 -1
- package/lib/runtime/PublicPathRuntimeModule.js +5 -0
- package/lib/runtime/StartupChunkDependenciesPlugin.js +15 -0
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +4 -1
- package/lib/runtime/StartupEntrypointRuntimeModule.js +8 -5
- package/lib/serialization/ArraySerializer.js +22 -6
- package/lib/serialization/BinaryMiddleware.js +21 -0
- package/lib/serialization/DateObjectSerializer.js +15 -4
- package/lib/serialization/ErrorObjectSerializer.js +20 -8
- package/lib/serialization/FileMiddleware.js +17 -0
- package/lib/serialization/MapObjectSerializer.js +24 -8
- package/lib/serialization/NullPrototypeObjectSerializer.js +25 -8
- package/lib/serialization/ObjectMiddleware.js +23 -0
- package/lib/serialization/PlainObjectSerializer.js +23 -12
- package/lib/serialization/RegExpObjectSerializer.js +16 -5
- package/lib/serialization/SetObjectSerializer.js +21 -6
- package/lib/sharing/ProvideSharedModuleFactory.js +1 -1
- package/lib/sharing/ShareRuntimeModule.js +1 -1
- package/lib/util/createHash.js +1 -1
- package/lib/util/makeSerializable.js +7 -0
- package/lib/util/serialization.js +10 -0
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +9 -0
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +9 -1
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +13 -3
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +19 -2
- package/lib/wasm-async/AsyncWebAssemblyParser.js +3 -0
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +25 -1
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +14 -5
- package/lib/wasm-sync/WebAssemblyGenerator.js +18 -5
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +1 -1
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +12 -1
- package/lib/wasm-sync/WebAssemblyParser.js +9 -2
- package/lib/wasm-sync/WebAssemblyUtils.js +1 -1
- package/lib/web/FetchCompileAsyncWasmPlugin.js +9 -0
- package/lib/web/FetchCompileWasmPlugin.js +19 -2
- package/lib/web/JsonpChunkLoadingPlugin.js +9 -0
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +4 -1
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +9 -0
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +6 -2
- package/package.json +3 -3
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +12 -0
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.json +4 -0
- package/types.d.ts +655 -290
@@ -195,7 +195,8 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
195
195
|
settings.name,
|
196
196
|
expr.range,
|
197
197
|
exportPresenceMode,
|
198
|
-
settings.assertions
|
198
|
+
settings.assertions,
|
199
|
+
[]
|
199
200
|
);
|
200
201
|
dep.referencedPropertiesInDestructuring =
|
201
202
|
parser.destructuringAssignmentPropertiesFor(expr);
|
@@ -211,7 +212,7 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
211
212
|
.for(harmonySpecifierTag)
|
212
213
|
.tap(
|
213
214
|
"HarmonyImportDependencyParserPlugin",
|
214
|
-
(expression, members, membersOptionals) => {
|
215
|
+
(expression, members, membersOptionals, memberRangeStarts) => {
|
215
216
|
const settings = /** @type {HarmonySettings} */ (
|
216
217
|
parser.currentTagData
|
217
218
|
);
|
@@ -219,6 +220,11 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
219
220
|
members,
|
220
221
|
membersOptionals
|
221
222
|
);
|
223
|
+
const rangeStarts = memberRangeStarts.slice(
|
224
|
+
0,
|
225
|
+
memberRangeStarts.length -
|
226
|
+
(members.length - nonOptionalMembers.length)
|
227
|
+
);
|
222
228
|
const expr =
|
223
229
|
nonOptionalMembers !== members
|
224
230
|
? getNonOptionalMemberChain(
|
@@ -234,7 +240,8 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
234
240
|
settings.name,
|
235
241
|
expr.range,
|
236
242
|
exportPresenceMode,
|
237
|
-
settings.assertions
|
243
|
+
settings.assertions,
|
244
|
+
rangeStarts
|
238
245
|
);
|
239
246
|
dep.referencedPropertiesInDestructuring =
|
240
247
|
parser.destructuringAssignmentPropertiesFor(expr);
|
@@ -249,7 +256,7 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
249
256
|
.for(harmonySpecifierTag)
|
250
257
|
.tap(
|
251
258
|
"HarmonyImportDependencyParserPlugin",
|
252
|
-
(expression, members, membersOptionals) => {
|
259
|
+
(expression, members, membersOptionals, memberRangeStarts) => {
|
253
260
|
const { arguments: args, callee } = expression;
|
254
261
|
const settings = /** @type {HarmonySettings} */ (
|
255
262
|
parser.currentTagData
|
@@ -258,6 +265,11 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
258
265
|
members,
|
259
266
|
membersOptionals
|
260
267
|
);
|
268
|
+
const rangeStarts = memberRangeStarts.slice(
|
269
|
+
0,
|
270
|
+
memberRangeStarts.length -
|
271
|
+
(members.length - nonOptionalMembers.length)
|
272
|
+
);
|
261
273
|
const expr =
|
262
274
|
nonOptionalMembers !== members
|
263
275
|
? getNonOptionalMemberChain(
|
@@ -273,7 +285,8 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
273
285
|
settings.name,
|
274
286
|
expr.range,
|
275
287
|
exportPresenceMode,
|
276
|
-
settings.assertions
|
288
|
+
settings.assertions,
|
289
|
+
rangeStarts
|
277
290
|
);
|
278
291
|
dep.directImport = members.length === 0;
|
279
292
|
dep.call = true;
|
@@ -16,10 +16,16 @@ const HarmonyImportDependency = require("./HarmonyImportDependency");
|
|
16
16
|
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
17
17
|
/** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
|
18
18
|
/** @typedef {import("../ModuleGraphConnection").ConnectionState} ConnectionState */
|
19
|
+
/** @typedef {import("../javascript/JavascriptParser").Assertions} Assertions */
|
19
20
|
/** @typedef {import("../util/Hash")} Hash */
|
20
21
|
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
21
22
|
|
22
23
|
class HarmonyImportSideEffectDependency extends HarmonyImportDependency {
|
24
|
+
/**
|
25
|
+
* @param {TODO} request the request string
|
26
|
+
* @param {number} sourceOrder source order
|
27
|
+
* @param {Assertions=} assertions assertions
|
28
|
+
*/
|
23
29
|
constructor(request, sourceOrder, assertions) {
|
24
30
|
super(request, sourceOrder, assertions);
|
25
31
|
}
|
@@ -23,6 +23,8 @@ const HarmonyImportDependency = require("./HarmonyImportDependency");
|
|
23
23
|
/** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
|
24
24
|
/** @typedef {import("../ModuleGraphConnection").ConnectionState} ConnectionState */
|
25
25
|
/** @typedef {import("../WebpackError")} WebpackError */
|
26
|
+
/** @typedef {import("../javascript/JavascriptParser").Assertions} Assertions */
|
27
|
+
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
26
28
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
27
29
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
28
30
|
/** @typedef {import("../util/Hash")} Hash */
|
@@ -33,6 +35,16 @@ const idsSymbol = Symbol("HarmonyImportSpecifierDependency.ids");
|
|
33
35
|
const { ExportPresenceModes } = HarmonyImportDependency;
|
34
36
|
|
35
37
|
class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
|
38
|
+
/**
|
39
|
+
* @param {TODO} request request
|
40
|
+
* @param {number} sourceOrder source order
|
41
|
+
* @param {string[]} ids ids
|
42
|
+
* @param {string} name name
|
43
|
+
* @param {Range} range range
|
44
|
+
* @param {TODO} exportPresenceMode export presence mode
|
45
|
+
* @param {Assertions=} assertions assertions
|
46
|
+
* @param {number[]=} idRangeStarts range starts for members of ids; the two arrays are right-aligned
|
47
|
+
*/
|
36
48
|
constructor(
|
37
49
|
request,
|
38
50
|
sourceOrder,
|
@@ -40,12 +52,14 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
|
|
40
52
|
name,
|
41
53
|
range,
|
42
54
|
exportPresenceMode,
|
43
|
-
assertions
|
55
|
+
assertions,
|
56
|
+
idRangeStarts // TODO webpack 6 make this non-optional. It must always be set to properly trim ids.
|
44
57
|
) {
|
45
58
|
super(request, sourceOrder, assertions);
|
46
59
|
this.ids = ids;
|
47
60
|
this.name = name;
|
48
61
|
this.range = range;
|
62
|
+
this.idRangeStarts = idRangeStarts;
|
49
63
|
this.exportPresenceMode = exportPresenceMode;
|
50
64
|
this.namespaceObjectAsContext = false;
|
51
65
|
this.call = undefined;
|
@@ -247,6 +261,7 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
|
|
247
261
|
write(this.ids);
|
248
262
|
write(this.name);
|
249
263
|
write(this.range);
|
264
|
+
write(this.idRangeStarts);
|
250
265
|
write(this.exportPresenceMode);
|
251
266
|
write(this.namespaceObjectAsContext);
|
252
267
|
write(this.call);
|
@@ -266,6 +281,7 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
|
|
266
281
|
this.ids = read();
|
267
282
|
this.name = read();
|
268
283
|
this.range = read();
|
284
|
+
this.idRangeStarts = read();
|
269
285
|
this.exportPresenceMode = read();
|
270
286
|
this.namespaceObjectAsContext = read();
|
271
287
|
this.call = read();
|
@@ -299,14 +315,78 @@ HarmonyImportSpecifierDependency.Template = class HarmonyImportSpecifierDependen
|
|
299
315
|
// Skip rendering depending when dependency is conditional
|
300
316
|
if (connection && !connection.isTargetActive(runtime)) return;
|
301
317
|
|
302
|
-
const ids = dep.getIds(moduleGraph);
|
303
|
-
|
304
|
-
|
318
|
+
const ids = dep.getIds(moduleGraph); // determine minimal set of IDs.
|
319
|
+
let trimmedIds = this._trimIdsToThoseImported(ids, moduleGraph, dep);
|
320
|
+
|
321
|
+
let [rangeStart, rangeEnd] = dep.range;
|
322
|
+
if (trimmedIds.length !== ids.length) {
|
323
|
+
// The array returned from dep.idRangeStarts is right-aligned with the array returned from dep.getIds.
|
324
|
+
// Meaning, the two arrays may not always have the same number of elements, but the last element of
|
325
|
+
// dep.idRangeStarts corresponds to [the starting range position of] the last element of dep.getIds.
|
326
|
+
// Use this to find the correct range end position based on the number of ids that were trimmed.
|
327
|
+
const idx =
|
328
|
+
dep.idRangeStarts === undefined
|
329
|
+
? -1 /* trigger failure case below */
|
330
|
+
: dep.idRangeStarts.length + (trimmedIds.length - ids.length);
|
331
|
+
if (idx < 0 || idx >= dep.idRangeStarts.length) {
|
332
|
+
// cspell:ignore minifiers
|
333
|
+
// Should not happen but we can't throw an error here because of backward compatibility with
|
334
|
+
// external plugins in wp5. Instead, we just disable trimming for now. This may break some minifiers.
|
335
|
+
trimmedIds = ids;
|
336
|
+
// TODO webpack 6 remove the "trimmedIds = ids" above and uncomment the following line instead.
|
337
|
+
// throw new Error("Missing range starts data for id replacement trimming.");
|
338
|
+
} else {
|
339
|
+
rangeEnd = dep.idRangeStarts[idx];
|
340
|
+
}
|
341
|
+
}
|
342
|
+
|
343
|
+
const exportExpr = this._getCodeForIds(
|
344
|
+
dep,
|
345
|
+
source,
|
346
|
+
templateContext,
|
347
|
+
trimmedIds
|
348
|
+
);
|
305
349
|
if (dep.shorthand) {
|
306
|
-
source.insert(
|
350
|
+
source.insert(rangeEnd, `: ${exportExpr}`);
|
307
351
|
} else {
|
308
|
-
source.replace(
|
352
|
+
source.replace(rangeStart, rangeEnd - 1, exportExpr);
|
353
|
+
}
|
354
|
+
}
|
355
|
+
|
356
|
+
/**
|
357
|
+
* @summary Determine which IDs in the id chain are actually referring to namespaces or imports,
|
358
|
+
* and which are deeper member accessors on the imported object. Only the former should be re-rendered.
|
359
|
+
* @param {string[]} ids ids
|
360
|
+
* @param {ModuleGraph} moduleGraph moduleGraph
|
361
|
+
* @param {HarmonyImportSpecifierDependency} dependency dependency
|
362
|
+
* @returns {string[]} generated code
|
363
|
+
*/
|
364
|
+
_trimIdsToThoseImported(ids, moduleGraph, dependency) {
|
365
|
+
let trimmedIds = [];
|
366
|
+
const exportsInfo = moduleGraph.getExportsInfo(
|
367
|
+
moduleGraph.getModule(dependency)
|
368
|
+
);
|
369
|
+
let currentExportsInfo = /** @type {ExportsInfo=} */ exportsInfo;
|
370
|
+
for (let i = 0; i < ids.length; i++) {
|
371
|
+
if (i === 0 && ids[i] === "default") {
|
372
|
+
continue; // ExportInfo for the next level under default is still at the root ExportsInfo, so don't advance currentExportsInfo
|
373
|
+
}
|
374
|
+
const exportInfo = currentExportsInfo.getExportInfo(ids[i]);
|
375
|
+
if (exportInfo.provided === false) {
|
376
|
+
// json imports have nested ExportInfo for elements that things that are not actually exported, so check .provided
|
377
|
+
trimmedIds = ids.slice(0, i);
|
378
|
+
break;
|
379
|
+
}
|
380
|
+
const nestedInfo = exportInfo.getNestedExportsInfo();
|
381
|
+
if (!nestedInfo) {
|
382
|
+
// once all nested exports are traversed, the next item is the actual import so stop there
|
383
|
+
trimmedIds = ids.slice(0, i + 1);
|
384
|
+
break;
|
385
|
+
}
|
386
|
+
currentExportsInfo = nestedInfo;
|
309
387
|
}
|
388
|
+
// Never trim to nothing. This can happen for invalid imports (e.g. import { notThere } from "./module", or import { anything } from "./missingModule")
|
389
|
+
return trimmedIds.length ? trimmedIds : ids;
|
310
390
|
}
|
311
391
|
|
312
392
|
/**
|
@@ -25,11 +25,18 @@ const HarmonyExportDependencyParserPlugin = require("./HarmonyExportDependencyPa
|
|
25
25
|
const HarmonyImportDependencyParserPlugin = require("./HarmonyImportDependencyParserPlugin");
|
26
26
|
const HarmonyTopLevelThisParserPlugin = require("./HarmonyTopLevelThisParserPlugin");
|
27
27
|
|
28
|
+
/** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
|
28
29
|
/** @typedef {import("../Compiler")} Compiler */
|
30
|
+
/** @typedef {import("../javascript/JavascriptParser")} Parser */
|
29
31
|
|
30
32
|
const PLUGIN_NAME = "HarmonyModulesPlugin";
|
31
33
|
|
34
|
+
/** @typedef {{ topLevelAwait?: boolean }} HarmonyModulesPluginOptions */
|
35
|
+
|
32
36
|
class HarmonyModulesPlugin {
|
37
|
+
/**
|
38
|
+
* @param {HarmonyModulesPluginOptions} options options
|
39
|
+
*/
|
33
40
|
constructor(options) {
|
34
41
|
this.options = options;
|
35
42
|
}
|
@@ -113,6 +120,11 @@ class HarmonyModulesPlugin {
|
|
113
120
|
new HarmonyAcceptImportDependency.Template()
|
114
121
|
);
|
115
122
|
|
123
|
+
/**
|
124
|
+
* @param {Parser} parser parser parser
|
125
|
+
* @param {JavascriptParserOptions} parserOptions parserOptions
|
126
|
+
* @returns {void}
|
127
|
+
*/
|
116
128
|
const handler = (parser, parserOptions) => {
|
117
129
|
// TODO webpack 6: rename harmony to esm or module
|
118
130
|
if (parserOptions.harmony !== undefined && !parserOptions.harmony)
|
@@ -9,10 +9,16 @@ const makeSerializable = require("../util/makeSerializable");
|
|
9
9
|
const ContextDependency = require("./ContextDependency");
|
10
10
|
const ContextDependencyTemplateAsRequireCall = require("./ContextDependencyTemplateAsRequireCall");
|
11
11
|
|
12
|
+
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
12
13
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
13
14
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
14
15
|
|
15
16
|
class ImportContextDependency extends ContextDependency {
|
17
|
+
/**
|
18
|
+
* @param {TODO} options options
|
19
|
+
* @param {Range} range range
|
20
|
+
* @param {Range} valueRange value range
|
21
|
+
*/
|
16
22
|
constructor(options, range, valueRange) {
|
17
23
|
super(options);
|
18
24
|
|
@@ -14,6 +14,7 @@ const ModuleDependency = require("./ModuleDependency");
|
|
14
14
|
/** @typedef {import("../Dependency").ReferencedExport} ReferencedExport */
|
15
15
|
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
16
16
|
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
17
|
+
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
17
18
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
18
19
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
19
20
|
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
@@ -21,7 +22,7 @@ const ModuleDependency = require("./ModuleDependency");
|
|
21
22
|
class ImportDependency extends ModuleDependency {
|
22
23
|
/**
|
23
24
|
* @param {string} request the request
|
24
|
-
* @param {
|
25
|
+
* @param {Range} range expression range
|
25
26
|
* @param {string[][]=} referencedExports list of referenced exports
|
26
27
|
*/
|
27
28
|
constructor(request, range, referencedExports) {
|
@@ -13,11 +13,12 @@ const ImportDependency = require("./ImportDependency");
|
|
13
13
|
/** @typedef {import("../Dependency").ReferencedExport} ReferencedExport */
|
14
14
|
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
15
15
|
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
16
|
+
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
16
17
|
|
17
18
|
class ImportEagerDependency extends ImportDependency {
|
18
19
|
/**
|
19
20
|
* @param {string} request the request
|
20
|
-
* @param {
|
21
|
+
* @param {Range} range expression range
|
21
22
|
* @param {string[][]=} referencedExports list of referenced exports
|
22
23
|
*/
|
23
24
|
constructor(request, range, referencedExports) {
|
@@ -11,13 +11,20 @@ const {
|
|
11
11
|
} = require("../javascript/JavascriptParserHelpers");
|
12
12
|
const ImportMetaContextDependency = require("./ImportMetaContextDependency");
|
13
13
|
|
14
|
-
/** @typedef {import("estree").Expression}
|
15
|
-
/** @typedef {import("estree").ObjectExpression}
|
14
|
+
/** @typedef {import("estree").Expression} Expression */
|
15
|
+
/** @typedef {import("estree").ObjectExpression} ObjectExpression */
|
16
|
+
/** @typedef {import("estree").Property} Property */
|
17
|
+
/** @typedef {import("estree").SourceLocation} SourceLocation */
|
16
18
|
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
|
17
19
|
/** @typedef {import("../ContextModule").ContextModuleOptions} ContextModuleOptions */
|
18
20
|
/** @typedef {import("../ChunkGroup").RawChunkGroupOptions} RawChunkGroupOptions */
|
19
21
|
/** @typedef {Pick<ContextModuleOptions, 'mode'|'recursive'|'regExp'|'include'|'exclude'|'chunkName'>&{groupOptions: RawChunkGroupOptions, exports?: ContextModuleOptions["referencedExports"]}} ImportMetaContextOptions */
|
20
22
|
|
23
|
+
/**
|
24
|
+
* @param {TODO} prop property
|
25
|
+
* @param {string} expect except message
|
26
|
+
* @returns {WebpackError} error
|
27
|
+
*/
|
21
28
|
function createPropertyParseError(prop, expect) {
|
22
29
|
return createError(
|
23
30
|
`Parsing import.meta.webpackContext options failed. Unknown value for property ${JSON.stringify(
|
@@ -27,6 +34,11 @@ function createPropertyParseError(prop, expect) {
|
|
27
34
|
);
|
28
35
|
}
|
29
36
|
|
37
|
+
/**
|
38
|
+
* @param {string} msg message
|
39
|
+
* @param {SourceLocation} loc location
|
40
|
+
* @returns {WebpackError} error
|
41
|
+
*/
|
30
42
|
function createError(msg, loc) {
|
31
43
|
const error = new WebpackError(msg);
|
32
44
|
error.name = "ImportMetaContextError";
|
@@ -35,6 +47,10 @@ function createError(msg, loc) {
|
|
35
47
|
}
|
36
48
|
|
37
49
|
module.exports = class ImportMetaContextDependencyParserPlugin {
|
50
|
+
/**
|
51
|
+
* @param {JavascriptParser} parser the parser
|
52
|
+
* @returns {void}
|
53
|
+
*/
|
38
54
|
apply(parser) {
|
39
55
|
parser.hooks.evaluateIdentifier
|
40
56
|
.for("import.meta.webpackContext")
|
@@ -52,7 +68,9 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
|
|
52
68
|
if (expr.arguments.length < 1 || expr.arguments.length > 2) return;
|
53
69
|
const [directoryNode, optionsNode] = expr.arguments;
|
54
70
|
if (optionsNode && optionsNode.type !== "ObjectExpression") return;
|
55
|
-
const requestExpr = parser.evaluateExpression(
|
71
|
+
const requestExpr = parser.evaluateExpression(
|
72
|
+
/** @type {Expression} */ (directoryNode)
|
73
|
+
);
|
56
74
|
if (!requestExpr.isString()) return;
|
57
75
|
const request = requestExpr.string;
|
58
76
|
const errors = [];
|
@@ -71,7 +89,8 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
|
|
71
89
|
/** @type {ContextModuleOptions["referencedExports"]} */
|
72
90
|
let exports;
|
73
91
|
if (optionsNode) {
|
74
|
-
for (const prop of optionsNode
|
92
|
+
for (const prop of /** @type {ObjectExpression} */ (optionsNode)
|
93
|
+
.properties) {
|
75
94
|
if (prop.type !== "Property" || prop.key.type !== "Identifier") {
|
76
95
|
errors.push(
|
77
96
|
createError(
|
@@ -84,7 +103,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
|
|
84
103
|
switch (prop.key.name) {
|
85
104
|
case "regExp": {
|
86
105
|
const regExpExpr = parser.evaluateExpression(
|
87
|
-
/** @type {
|
106
|
+
/** @type {Expression} */ (prop.value)
|
88
107
|
);
|
89
108
|
if (!regExpExpr.isRegExp()) {
|
90
109
|
errors.push(createPropertyParseError(prop, "RegExp"));
|
@@ -95,7 +114,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
|
|
95
114
|
}
|
96
115
|
case "include": {
|
97
116
|
const regExpExpr = parser.evaluateExpression(
|
98
|
-
/** @type {
|
117
|
+
/** @type {Expression} */ (prop.value)
|
99
118
|
);
|
100
119
|
if (!regExpExpr.isRegExp()) {
|
101
120
|
errors.push(createPropertyParseError(prop, "RegExp"));
|
@@ -106,7 +125,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
|
|
106
125
|
}
|
107
126
|
case "exclude": {
|
108
127
|
const regExpExpr = parser.evaluateExpression(
|
109
|
-
/** @type {
|
128
|
+
/** @type {Expression} */ (prop.value)
|
110
129
|
);
|
111
130
|
if (!regExpExpr.isRegExp()) {
|
112
131
|
errors.push(createPropertyParseError(prop, "RegExp"));
|
@@ -117,7 +136,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
|
|
117
136
|
}
|
118
137
|
case "mode": {
|
119
138
|
const modeExpr = parser.evaluateExpression(
|
120
|
-
/** @type {
|
139
|
+
/** @type {Expression} */ (prop.value)
|
121
140
|
);
|
122
141
|
if (!modeExpr.isString()) {
|
123
142
|
errors.push(createPropertyParseError(prop, "string"));
|
@@ -130,7 +149,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
|
|
130
149
|
}
|
131
150
|
case "chunkName": {
|
132
151
|
const expr = parser.evaluateExpression(
|
133
|
-
/** @type {
|
152
|
+
/** @type {Expression} */ (prop.value)
|
134
153
|
);
|
135
154
|
if (!expr.isString()) {
|
136
155
|
errors.push(createPropertyParseError(prop, "string"));
|
@@ -141,7 +160,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
|
|
141
160
|
}
|
142
161
|
case "exports": {
|
143
162
|
const expr = parser.evaluateExpression(
|
144
|
-
/** @type {
|
163
|
+
/** @type {Expression} */ (prop.value)
|
145
164
|
);
|
146
165
|
if (expr.isString()) {
|
147
166
|
exports = [[expr.string]];
|
@@ -176,7 +195,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
|
|
176
195
|
}
|
177
196
|
case "prefetch": {
|
178
197
|
const expr = parser.evaluateExpression(
|
179
|
-
/** @type {
|
198
|
+
/** @type {Expression} */ (prop.value)
|
180
199
|
);
|
181
200
|
if (expr.isBoolean()) {
|
182
201
|
groupOptions.prefetchOrder = 0;
|
@@ -189,7 +208,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
|
|
189
208
|
}
|
190
209
|
case "preload": {
|
191
210
|
const expr = parser.evaluateExpression(
|
192
|
-
/** @type {
|
211
|
+
/** @type {Expression} */ (prop.value)
|
193
212
|
);
|
194
213
|
if (expr.isBoolean()) {
|
195
214
|
groupOptions.preloadOrder = 0;
|
@@ -202,7 +221,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
|
|
202
221
|
}
|
203
222
|
case "recursive": {
|
204
223
|
const recursiveExpr = parser.evaluateExpression(
|
205
|
-
/** @type {
|
224
|
+
/** @type {Expression} */ (prop.value)
|
206
225
|
);
|
207
226
|
if (!recursiveExpr.isBoolean()) {
|
208
227
|
errors.push(createPropertyParseError(prop, "boolean"));
|
@@ -13,8 +13,10 @@ const ContextElementDependency = require("./ContextElementDependency");
|
|
13
13
|
const ImportMetaContextDependency = require("./ImportMetaContextDependency");
|
14
14
|
const ImportMetaContextDependencyParserPlugin = require("./ImportMetaContextDependencyParserPlugin");
|
15
15
|
|
16
|
+
/** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
|
16
17
|
/** @typedef {import("../../declarations/WebpackOptions").ResolveOptions} ResolveOptions */
|
17
18
|
/** @typedef {import("../Compiler")} Compiler */
|
19
|
+
/** @typedef {import("../javascript/JavascriptParser")} Parser */
|
18
20
|
|
19
21
|
const PLUGIN_NAME = "ImportMetaContextPlugin";
|
20
22
|
|
@@ -41,6 +43,11 @@ class ImportMetaContextPlugin {
|
|
41
43
|
normalModuleFactory
|
42
44
|
);
|
43
45
|
|
46
|
+
/**
|
47
|
+
* @param {Parser} parser parser parser
|
48
|
+
* @param {JavascriptParserOptions} parserOptions parserOptions
|
49
|
+
* @returns {void}
|
50
|
+
*/
|
44
51
|
const handler = (parser, parserOptions) => {
|
45
52
|
if (
|
46
53
|
parserOptions.importMetaContext !== undefined &&
|
@@ -9,7 +9,13 @@ const makeSerializable = require("../util/makeSerializable");
|
|
9
9
|
const ModuleDependency = require("./ModuleDependency");
|
10
10
|
const ModuleDependencyTemplateAsId = require("./ModuleDependencyTemplateAsId");
|
11
11
|
|
12
|
+
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
13
|
+
|
12
14
|
class ImportMetaHotAcceptDependency extends ModuleDependency {
|
15
|
+
/**
|
16
|
+
* @param {string} request the request string
|
17
|
+
* @param {Range} range location in source code
|
18
|
+
*/
|
13
19
|
constructor(request, range) {
|
14
20
|
super(request);
|
15
21
|
this.range = range;
|
@@ -9,7 +9,13 @@ const makeSerializable = require("../util/makeSerializable");
|
|
9
9
|
const ModuleDependency = require("./ModuleDependency");
|
10
10
|
const ModuleDependencyTemplateAsId = require("./ModuleDependencyTemplateAsId");
|
11
11
|
|
12
|
+
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
13
|
+
|
12
14
|
class ImportMetaHotDeclineDependency extends ModuleDependency {
|
15
|
+
/**
|
16
|
+
* @param {string} request the request string
|
17
|
+
* @param {Range} range location in source code
|
18
|
+
*/
|
13
19
|
constructor(request, range) {
|
14
20
|
super(request);
|
15
21
|
|
@@ -17,6 +17,7 @@ const ImportWeakDependency = require("./ImportWeakDependency");
|
|
17
17
|
/** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
|
18
18
|
/** @typedef {import("../ChunkGroup").RawChunkGroupOptions} RawChunkGroupOptions */
|
19
19
|
/** @typedef {import("../ContextModule").ContextMode} ContextMode */
|
20
|
+
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
|
20
21
|
|
21
22
|
class ImportParserPlugin {
|
22
23
|
/**
|
@@ -26,6 +27,10 @@ class ImportParserPlugin {
|
|
26
27
|
this.options = options;
|
27
28
|
}
|
28
29
|
|
30
|
+
/**
|
31
|
+
* @param {JavascriptParser} parser the parser
|
32
|
+
* @returns {void}
|
33
|
+
*/
|
29
34
|
apply(parser) {
|
30
35
|
const exportsFromEnumerable = enumerable =>
|
31
36
|
Array.from(enumerable, e => [e]);
|
@@ -16,7 +16,9 @@ const ImportEagerDependency = require("./ImportEagerDependency");
|
|
16
16
|
const ImportParserPlugin = require("./ImportParserPlugin");
|
17
17
|
const ImportWeakDependency = require("./ImportWeakDependency");
|
18
18
|
|
19
|
+
/** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
|
19
20
|
/** @typedef {import("../Compiler")} Compiler */
|
21
|
+
/** @typedef {import("../javascript/JavascriptParser")} Parser */
|
20
22
|
|
21
23
|
const PLUGIN_NAME = "ImportPlugin";
|
22
24
|
|
@@ -66,6 +68,11 @@ class ImportPlugin {
|
|
66
68
|
new ImportContextDependency.Template()
|
67
69
|
);
|
68
70
|
|
71
|
+
/**
|
72
|
+
* @param {Parser} parser parser parser
|
73
|
+
* @param {JavascriptParserOptions} parserOptions parserOptions
|
74
|
+
* @returns {void}
|
75
|
+
*/
|
69
76
|
const handler = (parser, parserOptions) => {
|
70
77
|
if (parserOptions.import !== undefined && !parserOptions.import)
|
71
78
|
return;
|
@@ -13,11 +13,12 @@ const ImportDependency = require("./ImportDependency");
|
|
13
13
|
/** @typedef {import("../Dependency").ReferencedExport} ReferencedExport */
|
14
14
|
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
15
15
|
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
16
|
+
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
16
17
|
|
17
18
|
class ImportWeakDependency extends ImportDependency {
|
18
19
|
/**
|
19
20
|
* @param {string} request the request
|
20
|
-
* @param {
|
21
|
+
* @param {Range} range expression range
|
21
22
|
* @param {string[][]=} referencedExports list of referenced exports
|
22
23
|
*/
|
23
24
|
constructor(request, range, referencedExports) {
|
@@ -7,7 +7,14 @@
|
|
7
7
|
|
8
8
|
const makeSerializable = require("../util/makeSerializable");
|
9
9
|
|
10
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
11
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
12
|
+
|
10
13
|
class LocalModule {
|
14
|
+
/**
|
15
|
+
* @param {string} name name
|
16
|
+
* @param {number} idx index
|
17
|
+
*/
|
11
18
|
constructor(name, idx) {
|
12
19
|
this.name = name;
|
13
20
|
this.idx = idx;
|
@@ -18,10 +25,16 @@ class LocalModule {
|
|
18
25
|
this.used = true;
|
19
26
|
}
|
20
27
|
|
28
|
+
/**
|
29
|
+
* @returns {string} variable name
|
30
|
+
*/
|
21
31
|
variableName() {
|
22
32
|
return "__WEBPACK_LOCAL_MODULE_" + this.idx + "__";
|
23
33
|
}
|
24
34
|
|
35
|
+
/**
|
36
|
+
* @param {ObjectSerializerContext} context context
|
37
|
+
*/
|
25
38
|
serialize(context) {
|
26
39
|
const { write } = context;
|
27
40
|
|
@@ -30,6 +43,9 @@ class LocalModule {
|
|
30
43
|
write(this.used);
|
31
44
|
}
|
32
45
|
|
46
|
+
/**
|
47
|
+
* @param {ObjectDeserializerContext} context context
|
48
|
+
*/
|
33
49
|
deserialize(context) {
|
34
50
|
const { read } = context;
|
35
51
|
|
@@ -11,10 +11,17 @@ const NullDependency = require("./NullDependency");
|
|
11
11
|
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
12
12
|
/** @typedef {import("../Dependency")} Dependency */
|
13
13
|
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
14
|
+
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
14
15
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
15
16
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
17
|
+
/** @typedef {import("./LocalModule")} LocalModule */
|
16
18
|
|
17
19
|
class LocalModuleDependency extends NullDependency {
|
20
|
+
/**
|
21
|
+
* @param {LocalModule} localModule local module
|
22
|
+
* @param {Range} range range
|
23
|
+
* @param {boolean} callNew true, when the local module should be called with new
|
24
|
+
*/
|
18
25
|
constructor(localModule, range, callNew) {
|
19
26
|
super();
|
20
27
|
|
@@ -7,6 +7,13 @@
|
|
7
7
|
|
8
8
|
const LocalModule = require("./LocalModule");
|
9
9
|
|
10
|
+
/** @typedef {import("../javascript/JavascriptParser").ParserState} ParserState */
|
11
|
+
|
12
|
+
/**
|
13
|
+
* @param {string} parent parent module
|
14
|
+
* @param {string} mod module to resolve
|
15
|
+
* @returns {string} resolved module
|
16
|
+
*/
|
10
17
|
const lookup = (parent, mod) => {
|
11
18
|
if (mod.charAt(0) !== ".") return mod;
|
12
19
|
|
@@ -26,6 +33,11 @@ const lookup = (parent, mod) => {
|
|
26
33
|
return path.join("/");
|
27
34
|
};
|
28
35
|
|
36
|
+
/**
|
37
|
+
* @param {ParserState} state parser state
|
38
|
+
* @param {string} name name
|
39
|
+
* @returns {LocalModule} local module
|
40
|
+
*/
|
29
41
|
exports.addLocalModule = (state, name) => {
|
30
42
|
if (!state.localModules) {
|
31
43
|
state.localModules = [];
|
@@ -35,6 +47,12 @@ exports.addLocalModule = (state, name) => {
|
|
35
47
|
return m;
|
36
48
|
};
|
37
49
|
|
50
|
+
/**
|
51
|
+
* @param {ParserState} state parser state
|
52
|
+
* @param {string} name name
|
53
|
+
* @param {string} [namedModule] named module
|
54
|
+
* @returns {LocalModule | null} local module or null
|
55
|
+
*/
|
38
56
|
exports.getLocalModule = (state, name, namedModule) => {
|
39
57
|
if (!state.localModules) return null;
|
40
58
|
if (namedModule) {
|