webpack 5.90.3 → 5.92.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 +5 -5
- package/bin/webpack.js +6 -3
- package/lib/APIPlugin.js +14 -6
- package/lib/AutomaticPrefetchPlugin.js +1 -1
- package/lib/BannerPlugin.js +3 -1
- package/lib/Cache.js +8 -2
- package/lib/CacheFacade.js +3 -3
- package/lib/Chunk.js +7 -4
- package/lib/ChunkGraph.js +52 -25
- package/lib/ChunkGroup.js +23 -17
- package/lib/CleanPlugin.js +8 -6
- package/lib/Compilation.js +295 -120
- package/lib/Compiler.js +223 -87
- package/lib/ConcatenationScope.js +3 -3
- package/lib/ConditionalInitFragment.js +4 -5
- package/lib/ContextModule.js +95 -41
- package/lib/ContextModuleFactory.js +4 -2
- package/lib/ContextReplacementPlugin.js +3 -2
- package/lib/DefinePlugin.js +18 -6
- package/lib/Dependency.js +12 -10
- package/lib/DependencyTemplate.js +17 -7
- package/lib/DllModule.js +1 -0
- package/lib/DllReferencePlugin.js +7 -3
- package/lib/EntryOptionPlugin.js +4 -1
- package/lib/EntryPlugin.js +6 -1
- package/lib/Entrypoint.js +1 -1
- package/lib/EvalDevToolModulePlugin.js +11 -0
- package/lib/ExportsInfo.js +23 -8
- package/lib/ExternalModule.js +160 -35
- package/lib/ExternalModuleFactoryPlugin.js +37 -2
- package/lib/FileSystemInfo.js +69 -42
- package/lib/FlagDependencyExportsPlugin.js +21 -7
- package/lib/Generator.js +4 -4
- package/lib/HookWebpackError.js +2 -2
- package/lib/HotModuleReplacementPlugin.js +108 -45
- package/lib/IgnorePlugin.js +4 -1
- package/lib/InitFragment.js +5 -3
- package/lib/LibManifestPlugin.js +17 -9
- package/lib/Module.js +41 -14
- package/lib/ModuleFactory.js +3 -3
- package/lib/ModuleFilenameHelpers.js +30 -17
- package/lib/ModuleGraph.js +60 -31
- package/lib/ModuleGraphConnection.js +2 -1
- package/lib/MultiCompiler.js +62 -9
- package/lib/NodeStuffPlugin.js +14 -3
- package/lib/NormalModule.js +13 -13
- package/lib/NormalModuleFactory.js +18 -9
- package/lib/NormalModuleReplacementPlugin.js +5 -1
- package/lib/Parser.js +1 -1
- package/lib/PlatformPlugin.js +39 -0
- package/lib/ProgressPlugin.js +1 -1
- package/lib/ProvidePlugin.js +3 -1
- package/lib/RawModule.js +2 -1
- package/lib/RecordIdsPlugin.js +4 -4
- package/lib/ResolverFactory.js +6 -4
- package/lib/RuntimeModule.js +4 -4
- package/lib/RuntimePlugin.js +1 -0
- package/lib/RuntimeTemplate.js +124 -52
- package/lib/SourceMapDevToolPlugin.js +4 -1
- package/lib/Stats.js +11 -4
- package/lib/Template.js +5 -5
- package/lib/TemplatedPathPlugin.js +48 -7
- package/lib/Watching.js +67 -60
- package/lib/WebpackError.js +6 -6
- package/lib/WebpackOptionsApply.js +18 -5
- package/lib/asset/AssetGenerator.js +15 -0
- package/lib/asset/RawDataUrlModule.js +3 -1
- package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
- package/lib/buildChunkGraph.js +120 -67
- package/lib/cache/IdleFileCachePlugin.js +8 -3
- package/lib/cache/MemoryCachePlugin.js +1 -1
- package/lib/cache/MemoryWithGcCachePlugin.js +6 -2
- package/lib/cache/PackFileCacheStrategy.js +51 -18
- package/lib/cache/ResolverCachePlugin.js +22 -14
- package/lib/cache/getLazyHashedEtag.js +2 -2
- package/lib/cli.js +5 -5
- package/lib/config/browserslistTargetHandler.js +7 -1
- package/lib/config/defaults.js +108 -34
- package/lib/config/normalization.js +3 -1
- package/lib/config/target.js +18 -11
- package/lib/container/ContainerEntryDependency.js +2 -1
- package/lib/container/ContainerEntryModule.js +4 -2
- package/lib/container/ContainerPlugin.js +14 -10
- package/lib/container/FallbackModule.js +1 -1
- package/lib/container/RemoteRuntimeModule.js +12 -3
- package/lib/css/CssExportsGenerator.js +68 -25
- package/lib/css/CssGenerator.js +34 -6
- package/lib/css/CssLoadingRuntimeModule.js +217 -98
- package/lib/css/CssModulesPlugin.js +238 -107
- package/lib/css/CssParser.js +24 -15
- package/lib/css/walkCssTokens.js +1 -1
- package/lib/debug/ProfilingPlugin.js +28 -3
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +9 -5
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +4 -1
- package/lib/dependencies/CommonJsDependencyHelpers.js +2 -1
- package/lib/dependencies/CommonJsExportRequireDependency.js +33 -18
- package/lib/dependencies/CommonJsExportsDependency.js +13 -5
- package/lib/dependencies/CommonJsExportsParserPlugin.js +20 -15
- package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -2
- package/lib/dependencies/ContextDependencyHelpers.js +49 -29
- package/lib/dependencies/ContextElementDependency.js +8 -1
- package/lib/dependencies/CssExportDependency.js +2 -2
- package/lib/dependencies/CssLocalIdentifierDependency.js +71 -9
- package/lib/dependencies/CssUrlDependency.js +10 -7
- package/lib/dependencies/ExportsInfoDependency.js +5 -4
- package/lib/dependencies/ExternalModuleDependency.js +4 -2
- package/lib/dependencies/ExternalModuleInitFragment.js +5 -3
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +4 -4
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +43 -23
- package/lib/dependencies/HarmonyExportHeaderDependency.js +1 -1
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +73 -32
- package/lib/dependencies/HarmonyExportInitFragment.js +10 -2
- package/lib/dependencies/HarmonyImportDependency.js +28 -12
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +70 -19
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +7 -6
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +47 -35
- package/lib/dependencies/ImportDependency.js +9 -2
- package/lib/dependencies/ImportEagerDependency.js +4 -2
- package/lib/dependencies/ImportMetaContextDependency.js +7 -0
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +25 -14
- package/lib/dependencies/ImportMetaPlugin.js +1 -1
- package/lib/dependencies/ImportParserPlugin.js +15 -5
- package/lib/dependencies/ImportWeakDependency.js +4 -2
- package/lib/dependencies/LoaderDependency.js +2 -1
- package/lib/dependencies/LoaderImportDependency.js +2 -1
- package/lib/dependencies/LoaderPlugin.js +2 -2
- package/lib/dependencies/ModuleDependency.js +4 -5
- package/lib/dependencies/PureExpressionDependency.js +64 -47
- package/lib/dependencies/RequireContextPlugin.js +1 -1
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +26 -14
- package/lib/dependencies/RequireEnsureDependency.js +1 -1
- package/lib/dependencies/URLDependency.js +7 -4
- package/lib/dependencies/WorkerDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +2 -1
- package/lib/dependencies/getFunctionExpression.js +3 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +92 -3
- package/lib/hmr/LazyCompilationPlugin.js +2 -2
- package/lib/ids/ChunkModuleIdRangePlugin.js +1 -1
- package/lib/ids/DeterministicChunkIdsPlugin.js +1 -1
- package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
- package/lib/ids/IdHelpers.js +6 -6
- package/lib/ids/NamedChunkIdsPlugin.js +1 -1
- package/lib/ids/NamedModuleIdsPlugin.js +1 -1
- package/lib/ids/SyncModuleIdsPlugin.js +2 -2
- package/lib/index.js +11 -0
- package/lib/javascript/BasicEvaluatedExpression.js +2 -2
- package/lib/javascript/ChunkHelpers.js +2 -2
- package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -1
- package/lib/javascript/JavascriptGenerator.js +0 -1
- package/lib/javascript/JavascriptModulesPlugin.js +174 -17
- package/lib/javascript/JavascriptParser.js +204 -71
- package/lib/javascript/JavascriptParserHelpers.js +1 -1
- package/lib/javascript/StartupHelpers.js +22 -5
- package/lib/library/AbstractLibraryPlugin.js +2 -2
- package/lib/library/AmdLibraryPlugin.js +2 -2
- package/lib/library/AssignLibraryPlugin.js +3 -3
- package/lib/library/ExportPropertyLibraryPlugin.js +2 -2
- package/lib/library/JsonpLibraryPlugin.js +2 -2
- package/lib/library/ModuleLibraryPlugin.js +2 -2
- package/lib/library/SystemLibraryPlugin.js +2 -2
- package/lib/library/UmdLibraryPlugin.js +33 -12
- package/lib/logging/Logger.js +27 -2
- package/lib/logging/createConsoleLogger.js +13 -9
- package/lib/node/CommonJsChunkLoadingPlugin.js +2 -1
- package/lib/node/NodeEnvironmentPlugin.js +14 -8
- package/lib/node/NodeTemplatePlugin.js +1 -1
- package/lib/node/NodeWatchFileSystem.js +37 -26
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -1
- package/lib/node/ReadFileCompileWasmPlugin.js +1 -1
- package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -1
- package/lib/node/nodeConsole.js +24 -1
- package/lib/optimize/AggressiveMergingPlugin.js +1 -1
- package/lib/optimize/AggressiveSplittingPlugin.js +1 -0
- package/lib/optimize/ConcatenatedModule.js +140 -121
- package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -1
- package/lib/optimize/InnerGraph.js +8 -3
- package/lib/optimize/InnerGraphPlugin.js +36 -13
- package/lib/optimize/LimitChunkCountPlugin.js +1 -2
- package/lib/optimize/ModuleConcatenationPlugin.js +13 -3
- package/lib/optimize/RealContentHashPlugin.js +3 -3
- package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
- package/lib/optimize/RuntimeChunkPlugin.js +6 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +48 -17
- package/lib/optimize/SplitChunksPlugin.js +10 -10
- package/lib/performance/SizeLimitsPlugin.js +13 -2
- package/lib/rules/ObjectMatcherRulePlugin.js +15 -1
- package/lib/rules/RuleSetCompiler.js +9 -7
- package/lib/runtime/EnsureChunkRuntimeModule.js +2 -1
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +2 -1
- package/lib/runtime/LoadScriptRuntimeModule.js +1 -1
- package/lib/runtime/StartupChunkDependenciesPlugin.js +1 -1
- package/lib/schemes/HttpUriPlugin.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +4 -4
- package/lib/serialization/FileMiddleware.js +4 -3
- package/lib/serialization/NullPrototypeObjectSerializer.js +2 -2
- package/lib/serialization/ObjectMiddleware.js +8 -5
- package/lib/serialization/PlainObjectSerializer.js +2 -2
- package/lib/serialization/Serializer.js +19 -0
- package/lib/serialization/SerializerMiddleware.js +2 -2
- package/lib/serialization/SingleItemMiddleware.js +2 -2
- package/lib/serialization/types.js +1 -1
- package/lib/sharing/ConsumeSharedModule.js +2 -2
- package/lib/sharing/ConsumeSharedPlugin.js +17 -3
- package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -2
- package/lib/sharing/ProvideSharedPlugin.js +13 -6
- package/lib/sharing/resolveMatchedConfigs.js +3 -3
- package/lib/sharing/utils.js +13 -6
- package/lib/stats/DefaultStatsFactoryPlugin.js +20 -20
- package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
- package/lib/stats/StatsFactory.js +2 -2
- package/lib/stats/StatsPrinter.js +6 -6
- package/lib/util/ArrayQueue.js +14 -21
- package/lib/util/AsyncQueue.js +1 -1
- package/lib/util/Queue.js +8 -2
- package/lib/util/SortableSet.js +16 -4
- package/lib/util/StackedCacheMap.js +26 -0
- package/lib/util/TupleQueue.js +8 -2
- package/lib/util/WeakTupleMap.js +57 -13
- package/lib/util/binarySearchBounds.js +1 -1
- package/lib/util/cleverMerge.js +26 -13
- package/lib/util/comparators.js +37 -15
- package/lib/util/conventions.js +129 -0
- package/lib/util/createHash.js +3 -5
- package/lib/util/deprecation.js +3 -3
- package/lib/util/deterministicGrouping.js +2 -2
- package/lib/util/findGraphRoots.js +1 -1
- package/lib/util/fs.js +383 -69
- package/lib/util/hash/BatchedHash.js +3 -0
- package/lib/util/hash/xxhash64.js +2 -2
- package/lib/util/identifier.js +5 -5
- package/lib/util/mergeScope.js +79 -0
- package/lib/util/runtime.js +2 -17
- package/lib/util/semver.js +3 -0
- package/lib/util/smartGrouping.js +3 -3
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +4 -2
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -1
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -2
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -3
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +16 -7
- package/lib/wasm-sync/WebAssemblyGenerator.js +40 -19
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +1 -1
- package/lib/wasm-sync/WebAssemblyParser.js +7 -4
- package/lib/wasm-sync/WebAssemblyUtils.js +2 -1
- package/lib/web/FetchCompileWasmPlugin.js +1 -1
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +3 -2
- package/lib/webpack.js +19 -6
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +2 -1
- package/package.json +40 -39
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +97 -8
- package/schemas/plugins/BannerPlugin.check.js +1 -1
- package/schemas/plugins/BannerPlugin.json +5 -1
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
- package/types.d.ts +1826 -639
@@ -6,6 +6,7 @@
|
|
6
6
|
"use strict";
|
7
7
|
|
8
8
|
const Dependency = require("../Dependency");
|
9
|
+
const Template = require("../Template");
|
9
10
|
const {
|
10
11
|
getDependencyUsedByExportsCondition
|
11
12
|
} = require("../optimize/InnerGraph");
|
@@ -17,6 +18,7 @@ const HarmonyImportDependency = require("./HarmonyImportDependency");
|
|
17
18
|
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
18
19
|
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
19
20
|
/** @typedef {import("../Dependency").ExportsSpec} ExportsSpec */
|
21
|
+
/** @typedef {import("../Dependency").GetConditionFn} GetConditionFn */
|
20
22
|
/** @typedef {import("../Dependency").ReferencedExport} ReferencedExport */
|
21
23
|
/** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
|
22
24
|
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
@@ -26,7 +28,8 @@ const HarmonyImportDependency = require("./HarmonyImportDependency");
|
|
26
28
|
/** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
|
27
29
|
/** @typedef {import("../ModuleGraphConnection").ConnectionState} ConnectionState */
|
28
30
|
/** @typedef {import("../WebpackError")} WebpackError */
|
29
|
-
/** @typedef {import("../javascript/JavascriptParser").
|
31
|
+
/** @typedef {import("../javascript/JavascriptParser").DestructuringAssignmentProperty} DestructuringAssignmentProperty */
|
32
|
+
/** @typedef {import("../javascript/JavascriptParser").ImportAttributes} ImportAttributes */
|
30
33
|
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
31
34
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
32
35
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
@@ -45,8 +48,8 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
|
|
45
48
|
* @param {string} name name
|
46
49
|
* @param {Range} range range
|
47
50
|
* @param {TODO} exportPresenceMode export presence mode
|
48
|
-
* @param {
|
49
|
-
* @param {Range[]
|
51
|
+
* @param {ImportAttributes | undefined} attributes import attributes
|
52
|
+
* @param {Range[] | undefined} idRanges ranges for members of ids; the two arrays are right-aligned
|
50
53
|
*/
|
51
54
|
constructor(
|
52
55
|
request,
|
@@ -55,10 +58,10 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
|
|
55
58
|
name,
|
56
59
|
range,
|
57
60
|
exportPresenceMode,
|
58
|
-
|
61
|
+
attributes,
|
59
62
|
idRanges // TODO webpack 6 make this non-optional. It must always be set to properly trim ids.
|
60
63
|
) {
|
61
|
-
super(request, sourceOrder,
|
64
|
+
super(request, sourceOrder, attributes);
|
62
65
|
this.ids = ids;
|
63
66
|
this.name = name;
|
64
67
|
this.range = range;
|
@@ -72,7 +75,7 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
|
|
72
75
|
this.asiSafe = undefined;
|
73
76
|
/** @type {Set<string> | boolean | undefined} */
|
74
77
|
this.usedByExports = undefined;
|
75
|
-
/** @type {Set<
|
78
|
+
/** @type {Set<DestructuringAssignmentProperty> | undefined} */
|
76
79
|
this.referencedPropertiesInDestructuring = undefined;
|
77
80
|
}
|
78
81
|
|
@@ -117,7 +120,7 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
|
|
117
120
|
|
118
121
|
/**
|
119
122
|
* @param {ModuleGraph} moduleGraph module graph
|
120
|
-
* @returns {null | false |
|
123
|
+
* @returns {null | false | GetConditionFn} function to determine if the connection is active
|
121
124
|
*/
|
122
125
|
getCondition(moduleGraph) {
|
123
126
|
return getDependencyUsedByExportsCondition(
|
@@ -143,8 +146,7 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
|
|
143
146
|
*/
|
144
147
|
getReferencedExports(moduleGraph, runtime) {
|
145
148
|
let ids = this.getIds(moduleGraph);
|
146
|
-
if (ids.length === 0)
|
147
|
-
return this._getReferencedExportsInDestructuring(moduleGraph);
|
149
|
+
if (ids.length === 0) return this._getReferencedExportsInDestructuring();
|
148
150
|
let namespaceObjectAsContext = this.namespaceObjectAsContext;
|
149
151
|
if (ids[0] === "default") {
|
150
152
|
const selfModule = moduleGraph.getParentModule(this);
|
@@ -161,7 +163,7 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
|
|
161
163
|
case "default-only":
|
162
164
|
case "default-with-named":
|
163
165
|
if (ids.length === 1)
|
164
|
-
return this._getReferencedExportsInDestructuring(
|
166
|
+
return this._getReferencedExportsInDestructuring();
|
165
167
|
ids = ids.slice(1);
|
166
168
|
namespaceObjectAsContext = true;
|
167
169
|
break;
|
@@ -179,31 +181,19 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
|
|
179
181
|
ids = ids.slice(0, -1);
|
180
182
|
}
|
181
183
|
|
182
|
-
return this._getReferencedExportsInDestructuring(
|
184
|
+
return this._getReferencedExportsInDestructuring(ids);
|
183
185
|
}
|
184
186
|
|
185
187
|
/**
|
186
|
-
* @param {ModuleGraph} moduleGraph module graph
|
187
188
|
* @param {string[]=} ids ids
|
188
|
-
* @returns {
|
189
|
+
* @returns {string[][]} referenced exports
|
189
190
|
*/
|
190
|
-
_getReferencedExportsInDestructuring(
|
191
|
+
_getReferencedExportsInDestructuring(ids) {
|
191
192
|
if (this.referencedPropertiesInDestructuring) {
|
192
|
-
/** @type {
|
193
|
+
/** @type {string[][]} */
|
193
194
|
const refs = [];
|
194
|
-
const
|
195
|
-
|
196
|
-
Array.isArray(ids) &&
|
197
|
-
ids.length > 0 &&
|
198
|
-
!moduleGraph
|
199
|
-
.getExportsInfo(importedModule)
|
200
|
-
.getExportInfo(ids[0])
|
201
|
-
.isReexport();
|
202
|
-
for (const key of this.referencedPropertiesInDestructuring) {
|
203
|
-
refs.push({
|
204
|
-
name: ids ? ids.concat([key]) : [key],
|
205
|
-
canMangle
|
206
|
-
});
|
195
|
+
for (const { id } of this.referencedPropertiesInDestructuring) {
|
196
|
+
refs.push(ids ? ids.concat([id]) : [id]);
|
207
197
|
}
|
208
198
|
return refs;
|
209
199
|
} else {
|
@@ -335,16 +325,11 @@ HarmonyImportSpecifierDependency.Template = class HarmonyImportSpecifierDependen
|
|
335
325
|
// Skip rendering depending when dependency is conditional
|
336
326
|
if (connection && !connection.isTargetActive(runtime)) return;
|
337
327
|
|
328
|
+
const ids = dep.getIds(moduleGraph);
|
338
329
|
const {
|
339
330
|
trimmedRange: [trimmedRangeStart, trimmedRangeEnd],
|
340
331
|
trimmedIds
|
341
|
-
} = getTrimmedIdsAndRange(
|
342
|
-
dep.getIds(moduleGraph),
|
343
|
-
dep.range,
|
344
|
-
dep.idRanges,
|
345
|
-
moduleGraph,
|
346
|
-
dep
|
347
|
-
);
|
332
|
+
} = getTrimmedIdsAndRange(ids, dep.range, dep.idRanges, moduleGraph, dep);
|
348
333
|
|
349
334
|
const exportExpr = this._getCodeForIds(
|
350
335
|
dep,
|
@@ -357,6 +342,33 @@ HarmonyImportSpecifierDependency.Template = class HarmonyImportSpecifierDependen
|
|
357
342
|
} else {
|
358
343
|
source.replace(trimmedRangeStart, trimmedRangeEnd - 1, exportExpr);
|
359
344
|
}
|
345
|
+
|
346
|
+
if (dep.referencedPropertiesInDestructuring) {
|
347
|
+
for (let {
|
348
|
+
id,
|
349
|
+
shorthand,
|
350
|
+
range
|
351
|
+
} of dep.referencedPropertiesInDestructuring) {
|
352
|
+
const concatedIds = ids.concat([id]);
|
353
|
+
if (concatedIds[0] === "default") concatedIds.shift();
|
354
|
+
const module = moduleGraph.getModule(dep);
|
355
|
+
const used = moduleGraph
|
356
|
+
.getExportsInfo(module)
|
357
|
+
.getUsedName(concatedIds, runtime);
|
358
|
+
if (!used) return;
|
359
|
+
const newName = used[used.length - 1];
|
360
|
+
const name = concatedIds[concatedIds.length - 1];
|
361
|
+
if (newName === name) continue;
|
362
|
+
|
363
|
+
const comment = Template.toNormalComment(name) + " ";
|
364
|
+
const key = comment + JSON.stringify(newName);
|
365
|
+
source.replace(
|
366
|
+
range[0],
|
367
|
+
range[1] - 1,
|
368
|
+
shorthand ? `${key}: ${name}` : `${key}`
|
369
|
+
);
|
370
|
+
}
|
371
|
+
}
|
360
372
|
}
|
361
373
|
|
362
374
|
/**
|
@@ -16,6 +16,7 @@ const ModuleDependency = require("./ModuleDependency");
|
|
16
16
|
/** @typedef {import("../Module")} Module */
|
17
17
|
/** @typedef {import("../Module").BuildMeta} BuildMeta */
|
18
18
|
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
19
|
+
/** @typedef {import("../javascript/JavascriptParser").ImportAttributes} ImportAttributes */
|
19
20
|
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
20
21
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
21
22
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
@@ -26,11 +27,13 @@ class ImportDependency extends ModuleDependency {
|
|
26
27
|
* @param {string} request the request
|
27
28
|
* @param {Range} range expression range
|
28
29
|
* @param {(string[][] | null)=} referencedExports list of referenced exports
|
30
|
+
* @param {ImportAttributes=} attributes import attributes
|
29
31
|
*/
|
30
|
-
constructor(request, range, referencedExports) {
|
32
|
+
constructor(request, range, referencedExports, attributes) {
|
31
33
|
super(request);
|
32
34
|
this.range = range;
|
33
35
|
this.referencedExports = referencedExports;
|
36
|
+
this.assertions = attributes;
|
34
37
|
}
|
35
38
|
|
36
39
|
get type() {
|
@@ -52,7 +55,9 @@ class ImportDependency extends ModuleDependency {
|
|
52
55
|
const refs = [];
|
53
56
|
for (const referencedExport of this.referencedExports) {
|
54
57
|
if (referencedExport[0] === "default") {
|
55
|
-
const selfModule =
|
58
|
+
const selfModule =
|
59
|
+
/** @type {Module} */
|
60
|
+
(moduleGraph.getParentModule(this));
|
56
61
|
const importedModule =
|
57
62
|
/** @type {Module} */
|
58
63
|
(moduleGraph.getModule(this));
|
@@ -82,6 +87,7 @@ class ImportDependency extends ModuleDependency {
|
|
82
87
|
serialize(context) {
|
83
88
|
context.write(this.range);
|
84
89
|
context.write(this.referencedExports);
|
90
|
+
context.write(this.assertions);
|
85
91
|
super.serialize(context);
|
86
92
|
}
|
87
93
|
|
@@ -91,6 +97,7 @@ class ImportDependency extends ModuleDependency {
|
|
91
97
|
deserialize(context) {
|
92
98
|
this.range = context.read();
|
93
99
|
this.referencedExports = context.read();
|
100
|
+
this.assertions = context.read();
|
94
101
|
super.deserialize(context);
|
95
102
|
}
|
96
103
|
}
|
@@ -15,6 +15,7 @@ const ImportDependency = require("./ImportDependency");
|
|
15
15
|
/** @typedef {import("../Module")} Module */
|
16
16
|
/** @typedef {import("../Module").BuildMeta} BuildMeta */
|
17
17
|
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
18
|
+
/** @typedef {import("../javascript/JavascriptParser").ImportAttributes} ImportAttributes */
|
18
19
|
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
19
20
|
|
20
21
|
class ImportEagerDependency extends ImportDependency {
|
@@ -22,9 +23,10 @@ class ImportEagerDependency extends ImportDependency {
|
|
22
23
|
* @param {string} request the request
|
23
24
|
* @param {Range} range expression range
|
24
25
|
* @param {(string[][] | null)=} referencedExports list of referenced exports
|
26
|
+
* @param {ImportAttributes=} attributes import attributes
|
25
27
|
*/
|
26
|
-
constructor(request, range, referencedExports) {
|
27
|
-
super(request, range, referencedExports);
|
28
|
+
constructor(request, range, referencedExports, attributes) {
|
29
|
+
super(request, range, referencedExports, attributes);
|
28
30
|
}
|
29
31
|
|
30
32
|
get type() {
|
@@ -9,7 +9,14 @@ const makeSerializable = require("../util/makeSerializable");
|
|
9
9
|
const ContextDependency = require("./ContextDependency");
|
10
10
|
const ModuleDependencyTemplateAsRequireId = require("./ModuleDependencyTemplateAsRequireId");
|
11
11
|
|
12
|
+
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
13
|
+
/** @typedef {import("./ContextDependency").ContextDependencyOptions} ContextDependencyOptions */
|
14
|
+
|
12
15
|
class ImportMetaContextDependency extends ContextDependency {
|
16
|
+
/**
|
17
|
+
* @param {ContextDependencyOptions} options options
|
18
|
+
* @param {Range} range range
|
19
|
+
*/
|
13
20
|
constructor(options, range) {
|
14
21
|
super(options);
|
15
22
|
|
@@ -16,8 +16,11 @@ const ImportMetaContextDependency = require("./ImportMetaContextDependency");
|
|
16
16
|
/** @typedef {import("estree").Property} Property */
|
17
17
|
/** @typedef {import("estree").SourceLocation} SourceLocation */
|
18
18
|
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
|
19
|
+
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
19
20
|
/** @typedef {import("../ContextModule").ContextModuleOptions} ContextModuleOptions */
|
20
21
|
/** @typedef {import("../ChunkGroup").RawChunkGroupOptions} RawChunkGroupOptions */
|
22
|
+
/** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
|
23
|
+
/** @typedef {import("../javascript/BasicEvaluatedExpression")} BasicEvaluatedExpression */
|
21
24
|
/** @typedef {Pick<ContextModuleOptions, 'mode'|'recursive'|'regExp'|'include'|'exclude'|'chunkName'>&{groupOptions: RawChunkGroupOptions, exports?: ContextModuleOptions["referencedExports"]}} ImportMetaContextOptions */
|
22
25
|
|
23
26
|
/**
|
@@ -36,7 +39,7 @@ function createPropertyParseError(prop, expect) {
|
|
36
39
|
|
37
40
|
/**
|
38
41
|
* @param {string} msg message
|
39
|
-
* @param {
|
42
|
+
* @param {DependencyLocation} loc location
|
40
43
|
* @returns {WebpackError} error
|
41
44
|
*/
|
42
45
|
function createError(msg, loc) {
|
@@ -72,7 +75,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
|
|
72
75
|
/** @type {Expression} */ (directoryNode)
|
73
76
|
);
|
74
77
|
if (!requestExpr.isString()) return;
|
75
|
-
const request = requestExpr.string;
|
78
|
+
const request = /** @type {string} */ (requestExpr.string);
|
76
79
|
const errors = [];
|
77
80
|
let regExp = /^\.\/.*$/;
|
78
81
|
let recursive = true;
|
@@ -95,7 +98,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
|
|
95
98
|
errors.push(
|
96
99
|
createError(
|
97
100
|
"Parsing import.meta.webpackContext options failed.",
|
98
|
-
optionsNode.loc
|
101
|
+
/** @type {DependencyLocation} */ (optionsNode.loc)
|
99
102
|
)
|
100
103
|
);
|
101
104
|
break;
|
@@ -108,7 +111,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
|
|
108
111
|
if (!regExpExpr.isRegExp()) {
|
109
112
|
errors.push(createPropertyParseError(prop, "RegExp"));
|
110
113
|
} else {
|
111
|
-
regExp = regExpExpr.regExp;
|
114
|
+
regExp = /** @type {RegExp} */ (regExpExpr.regExp);
|
112
115
|
}
|
113
116
|
break;
|
114
117
|
}
|
@@ -163,21 +166,27 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
|
|
163
166
|
/** @type {Expression} */ (prop.value)
|
164
167
|
);
|
165
168
|
if (expr.isString()) {
|
166
|
-
exports = [[expr.string]];
|
169
|
+
exports = [[/** @type {string} */ (expr.string)]];
|
167
170
|
} else if (expr.isArray()) {
|
168
|
-
const items =
|
171
|
+
const items =
|
172
|
+
/** @type {BasicEvaluatedExpression[]} */
|
173
|
+
(expr.items);
|
169
174
|
if (
|
170
175
|
items.every(i => {
|
171
176
|
if (!i.isArray()) return false;
|
172
|
-
const innerItems =
|
177
|
+
const innerItems =
|
178
|
+
/** @type {BasicEvaluatedExpression[]} */ (i.items);
|
173
179
|
return innerItems.every(i => i.isString());
|
174
180
|
})
|
175
181
|
) {
|
176
182
|
exports = [];
|
177
183
|
for (const i1 of items) {
|
184
|
+
/** @type {string[]} */
|
178
185
|
const export_ = [];
|
179
|
-
for (const i2 of
|
180
|
-
|
186
|
+
for (const i2 of /** @type {BasicEvaluatedExpression[]} */ (
|
187
|
+
i1.items
|
188
|
+
)) {
|
189
|
+
export_.push(/** @type {string} */ (i2.string));
|
181
190
|
}
|
182
191
|
exports.push(export_);
|
183
192
|
}
|
@@ -225,7 +234,9 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
|
|
225
234
|
);
|
226
235
|
if (
|
227
236
|
expr.isString() &&
|
228
|
-
["high", "low", "auto"].includes(
|
237
|
+
["high", "low", "auto"].includes(
|
238
|
+
/** @type {string} */ (expr.string)
|
239
|
+
)
|
229
240
|
) {
|
230
241
|
groupOptions.fetchPriority =
|
231
242
|
/** @type {RawChunkGroupOptions["fetchPriority"]} */ (
|
@@ -245,7 +256,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
|
|
245
256
|
if (!recursiveExpr.isBoolean()) {
|
246
257
|
errors.push(createPropertyParseError(prop, "boolean"));
|
247
258
|
} else {
|
248
|
-
recursive = recursiveExpr.bool;
|
259
|
+
recursive = /** @type {boolean} */ (recursiveExpr.bool);
|
249
260
|
}
|
250
261
|
break;
|
251
262
|
}
|
@@ -255,7 +266,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
|
|
255
266
|
`Parsing import.meta.webpackContext options failed. Unknown property ${JSON.stringify(
|
256
267
|
prop.key.name
|
257
268
|
)}.`,
|
258
|
-
optionsNode.loc
|
269
|
+
/** @type {DependencyLocation} */ (optionsNode.loc)
|
259
270
|
)
|
260
271
|
);
|
261
272
|
}
|
@@ -279,9 +290,9 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
|
|
279
290
|
mode,
|
280
291
|
category: "esm"
|
281
292
|
},
|
282
|
-
expr.range
|
293
|
+
/** @type {Range} */ (expr.range)
|
283
294
|
);
|
284
|
-
dep.loc = expr.loc;
|
295
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
285
296
|
dep.optional = !!parser.scope.inTry;
|
286
297
|
parser.state.current.addDependency(dep);
|
287
298
|
return true;
|
@@ -131,7 +131,7 @@ class ImportMetaPlugin {
|
|
131
131
|
}
|
132
132
|
|
133
133
|
let str = "";
|
134
|
-
for (const prop of referencedPropertiesInDestructuring) {
|
134
|
+
for (const { id: prop } of referencedPropertiesInDestructuring) {
|
135
135
|
switch (prop) {
|
136
136
|
case "url":
|
137
137
|
str += `url: ${importMetaUrl()},`;
|
@@ -9,11 +9,13 @@ const AsyncDependenciesBlock = require("../AsyncDependenciesBlock");
|
|
9
9
|
const CommentCompilationWarning = require("../CommentCompilationWarning");
|
10
10
|
const UnsupportedFeatureWarning = require("../UnsupportedFeatureWarning");
|
11
11
|
const ContextDependencyHelpers = require("./ContextDependencyHelpers");
|
12
|
+
const { getAttributes } = require("./HarmonyImportDependencyParserPlugin");
|
12
13
|
const ImportContextDependency = require("./ImportContextDependency");
|
13
14
|
const ImportDependency = require("./ImportDependency");
|
14
15
|
const ImportEagerDependency = require("./ImportEagerDependency");
|
15
16
|
const ImportWeakDependency = require("./ImportWeakDependency");
|
16
17
|
|
18
|
+
/** @typedef {import("estree").ImportExpression} ImportExpression */
|
17
19
|
/** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
|
18
20
|
/** @typedef {import("../ChunkGroup").RawChunkGroupOptions} RawChunkGroupOptions */
|
19
21
|
/** @typedef {import("../ContextModule").ContextMode} ContextMode */
|
@@ -254,22 +256,28 @@ class ImportParserPlugin {
|
|
254
256
|
)
|
255
257
|
);
|
256
258
|
}
|
257
|
-
exports = exportsFromEnumerable(
|
259
|
+
exports = exportsFromEnumerable(
|
260
|
+
[...referencedPropertiesInDestructuring].map(({ id }) => id)
|
261
|
+
);
|
258
262
|
}
|
259
263
|
|
260
264
|
if (param.isString()) {
|
265
|
+
const attributes = getAttributes(expr);
|
266
|
+
|
261
267
|
if (mode === "eager") {
|
262
268
|
const dep = new ImportEagerDependency(
|
263
269
|
/** @type {string} */ (param.string),
|
264
270
|
/** @type {Range} */ (expr.range),
|
265
|
-
exports
|
271
|
+
exports,
|
272
|
+
attributes
|
266
273
|
);
|
267
274
|
parser.state.current.addDependency(dep);
|
268
275
|
} else if (mode === "weak") {
|
269
276
|
const dep = new ImportWeakDependency(
|
270
277
|
/** @type {string} */ (param.string),
|
271
278
|
/** @type {Range} */ (expr.range),
|
272
|
-
exports
|
279
|
+
exports,
|
280
|
+
attributes
|
273
281
|
);
|
274
282
|
parser.state.current.addDependency(dep);
|
275
283
|
} else {
|
@@ -284,7 +292,8 @@ class ImportParserPlugin {
|
|
284
292
|
const dep = new ImportDependency(
|
285
293
|
/** @type {string} */ (param.string),
|
286
294
|
/** @type {Range} */ (expr.range),
|
287
|
-
exports
|
295
|
+
exports,
|
296
|
+
attributes
|
288
297
|
);
|
289
298
|
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
290
299
|
dep.optional = !!parser.scope.inTry;
|
@@ -315,7 +324,8 @@ class ImportParserPlugin {
|
|
315
324
|
: true,
|
316
325
|
typePrefix: "import()",
|
317
326
|
category: "esm",
|
318
|
-
referencedExports: exports
|
327
|
+
referencedExports: exports,
|
328
|
+
attributes: getAttributes(expr)
|
319
329
|
},
|
320
330
|
parser
|
321
331
|
);
|
@@ -15,6 +15,7 @@ const ImportDependency = require("./ImportDependency");
|
|
15
15
|
/** @typedef {import("../Module")} Module */
|
16
16
|
/** @typedef {import("../Module").BuildMeta} BuildMeta */
|
17
17
|
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
18
|
+
/** @typedef {import("../javascript/JavascriptParser").ImportAttributes} ImportAttributes */
|
18
19
|
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
19
20
|
|
20
21
|
class ImportWeakDependency extends ImportDependency {
|
@@ -22,9 +23,10 @@ class ImportWeakDependency extends ImportDependency {
|
|
22
23
|
* @param {string} request the request
|
23
24
|
* @param {Range} range expression range
|
24
25
|
* @param {(string[][] | null)=} referencedExports list of referenced exports
|
26
|
+
* @param {ImportAttributes=} attributes import attributes
|
25
27
|
*/
|
26
|
-
constructor(request, range, referencedExports) {
|
27
|
-
super(request, range, referencedExports);
|
28
|
+
constructor(request, range, referencedExports, attributes) {
|
29
|
+
super(request, range, referencedExports, attributes);
|
28
30
|
this.weak = true;
|
29
31
|
}
|
30
32
|
|
@@ -7,6 +7,7 @@
|
|
7
7
|
|
8
8
|
const ModuleDependency = require("./ModuleDependency");
|
9
9
|
|
10
|
+
/** @typedef {import("../Dependency").GetConditionFn} GetConditionFn */
|
10
11
|
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
11
12
|
/** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
|
12
13
|
/** @typedef {import("../ModuleGraphConnection").ConnectionState} ConnectionState */
|
@@ -30,7 +31,7 @@ class LoaderDependency extends ModuleDependency {
|
|
30
31
|
|
31
32
|
/**
|
32
33
|
* @param {ModuleGraph} moduleGraph module graph
|
33
|
-
* @returns {null | false |
|
34
|
+
* @returns {null | false | GetConditionFn} function to determine if the connection is active
|
34
35
|
*/
|
35
36
|
getCondition(moduleGraph) {
|
36
37
|
return false;
|
@@ -7,6 +7,7 @@
|
|
7
7
|
|
8
8
|
const ModuleDependency = require("./ModuleDependency");
|
9
9
|
|
10
|
+
/** @typedef {import("../Dependency").GetConditionFn} GetConditionFn */
|
10
11
|
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
11
12
|
/** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
|
12
13
|
/** @typedef {import("../ModuleGraphConnection").ConnectionState} ConnectionState */
|
@@ -31,7 +32,7 @@ class LoaderImportDependency extends ModuleDependency {
|
|
31
32
|
|
32
33
|
/**
|
33
34
|
* @param {ModuleGraph} moduleGraph module graph
|
34
|
-
* @returns {null | false |
|
35
|
+
* @returns {null | false | GetConditionFn} function to determine if the connection is active
|
35
36
|
*/
|
36
37
|
getCondition(moduleGraph) {
|
37
38
|
return false;
|
@@ -29,7 +29,7 @@ const LoaderImportDependency = require("./LoaderImportDependency");
|
|
29
29
|
*/
|
30
30
|
|
31
31
|
/**
|
32
|
-
* @typedef {
|
32
|
+
* @typedef {object} ImportModuleOptions
|
33
33
|
* @property {string=} layer the target layer
|
34
34
|
* @property {string=} publicPath the target public path
|
35
35
|
* @property {string=} baseUri target base uri
|
@@ -37,7 +37,7 @@ const LoaderImportDependency = require("./LoaderImportDependency");
|
|
37
37
|
|
38
38
|
class LoaderPlugin {
|
39
39
|
/**
|
40
|
-
* @param {
|
40
|
+
* @param {object} options options
|
41
41
|
*/
|
42
42
|
constructor(options = {}) {}
|
43
43
|
|
@@ -7,15 +7,14 @@
|
|
7
7
|
|
8
8
|
const Dependency = require("../Dependency");
|
9
9
|
const DependencyTemplate = require("../DependencyTemplate");
|
10
|
-
const
|
10
|
+
const RawModule = require("../RawModule");
|
11
11
|
|
12
12
|
/** @typedef {import("../Dependency").TRANSITIVE} TRANSITIVE */
|
13
13
|
/** @typedef {import("../Module")} Module */
|
14
|
+
/** @typedef {import("../javascript/JavascriptParser").ImportAttributes} ImportAttributes */
|
14
15
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
15
16
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
16
17
|
|
17
|
-
const getRawModule = memoize(() => require("../RawModule"));
|
18
|
-
|
19
18
|
class ModuleDependency extends Dependency {
|
20
19
|
/**
|
21
20
|
* @param {string} request request path which needs resolving
|
@@ -25,8 +24,9 @@ class ModuleDependency extends Dependency {
|
|
25
24
|
this.request = request;
|
26
25
|
this.userRequest = request;
|
27
26
|
this.range = undefined;
|
27
|
+
// TODO move it to subclasses and rename
|
28
28
|
// assertions must be serialized by subclasses that use it
|
29
|
-
/** @type {
|
29
|
+
/** @type {ImportAttributes | undefined} */
|
30
30
|
this.assertions = undefined;
|
31
31
|
this._context = undefined;
|
32
32
|
}
|
@@ -61,7 +61,6 @@ class ModuleDependency extends Dependency {
|
|
61
61
|
* @returns {Module | null} a module
|
62
62
|
*/
|
63
63
|
createIgnoredModule(context) {
|
64
|
-
const RawModule = getRawModule();
|
65
64
|
return new RawModule(
|
66
65
|
"/* (ignored) */",
|
67
66
|
`ignored|${context}|${this.request}`,
|