webpack 5.95.0 → 5.96.1
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 +1 -1
- package/lib/AsyncDependenciesBlock.js +1 -1
- package/lib/BannerPlugin.js +2 -1
- package/lib/Chunk.js +30 -0
- package/lib/ChunkGraph.js +11 -6
- package/lib/ChunkGroup.js +2 -2
- package/lib/CleanPlugin.js +4 -5
- package/lib/CodeGenerationResults.js +6 -5
- package/lib/Compilation.js +71 -48
- package/lib/Compiler.js +7 -5
- package/lib/ConcatenationScope.js +7 -20
- package/lib/ContextModule.js +7 -8
- package/lib/CssModule.js +25 -21
- package/lib/DefinePlugin.js +14 -8
- package/lib/DelegatedModule.js +3 -3
- package/lib/DllModule.js +4 -4
- package/lib/DynamicEntryPlugin.js +29 -22
- package/lib/EvalDevToolModulePlugin.js +5 -2
- package/lib/EvalSourceMapDevToolPlugin.js +5 -2
- package/lib/ExternalModule.js +40 -7
- package/lib/ExternalModuleFactoryPlugin.js +33 -9
- package/lib/FileSystemInfo.js +12 -8
- package/lib/Generator.js +5 -4
- package/lib/HotModuleReplacementPlugin.js +8 -6
- package/lib/IgnorePlugin.js +19 -1
- package/lib/LoaderOptionsPlugin.js +3 -1
- package/lib/Module.js +9 -8
- package/lib/ModuleSourceTypesConstants.js +100 -0
- package/lib/NormalModule.js +27 -17
- package/lib/NormalModuleFactory.js +38 -22
- package/lib/OptionsApply.js +12 -1
- package/lib/ProgressPlugin.js +50 -10
- package/lib/RawModule.js +3 -4
- package/lib/RuntimeModule.js +3 -4
- package/lib/RuntimePlugin.js +11 -4
- package/lib/RuntimeTemplate.js +13 -42
- package/lib/SourceMapDevToolPlugin.js +10 -7
- package/lib/Watching.js +2 -2
- package/lib/WebpackOptionsApply.js +42 -21
- package/lib/asset/AssetGenerator.js +347 -194
- package/lib/asset/AssetModulesPlugin.js +2 -1
- package/lib/asset/AssetSourceGenerator.js +82 -27
- package/lib/asset/RawDataUrlModule.js +5 -4
- package/lib/buildChunkGraph.js +2 -2
- package/lib/cache/PackFileCacheStrategy.js +69 -31
- package/lib/cache/ResolverCachePlugin.js +248 -173
- package/lib/config/defaults.js +134 -126
- package/lib/container/ContainerEntryModule.js +3 -4
- package/lib/container/ContainerPlugin.js +8 -0
- package/lib/container/FallbackModule.js +2 -2
- package/lib/container/HoistContainerReferencesPlugin.js +250 -0
- package/lib/container/ModuleFederationPlugin.js +38 -1
- package/lib/container/RemoteModule.js +4 -2
- package/lib/container/RemoteRuntimeModule.js +4 -2
- package/lib/css/CssExportsGenerator.js +16 -12
- package/lib/css/CssGenerator.js +22 -16
- package/lib/css/CssLoadingRuntimeModule.js +7 -6
- package/lib/css/CssModulesPlugin.js +122 -77
- package/lib/css/CssParser.js +655 -526
- package/lib/css/walkCssTokens.js +1168 -338
- package/lib/debug/ProfilingPlugin.js +5 -0
- package/lib/dependencies/CommonJsExportsParserPlugin.js +5 -2
- package/lib/dependencies/CommonJsImportsParserPlugin.js +3 -6
- package/lib/dependencies/CssExportDependency.js +3 -3
- package/lib/dependencies/CssLocalIdentifierDependency.js +26 -17
- package/lib/dependencies/CssUrlDependency.js +33 -3
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +3 -3
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +39 -14
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +15 -82
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +5 -2
- package/lib/dependencies/ImportParserPlugin.js +9 -7
- package/lib/dependencies/LoaderPlugin.js +19 -0
- package/lib/dependencies/SystemPlugin.js +2 -1
- package/lib/dependencies/URLPlugin.js +7 -1
- package/lib/dependencies/WorkerPlugin.js +1 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +4 -2
- package/lib/hmr/HotModuleReplacement.runtime.js +1 -0
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +1 -0
- package/lib/hmr/LazyCompilationPlugin.js +16 -4
- package/lib/hmr/lazyCompilationBackend.js +1 -7
- package/lib/index.js +37 -7
- package/lib/javascript/EnableChunkLoadingPlugin.js +2 -2
- package/lib/javascript/JavascriptGenerator.js +8 -8
- package/lib/javascript/JavascriptModulesPlugin.js +126 -73
- package/lib/javascript/JavascriptParser.js +338 -117
- package/lib/json/JsonGenerator.js +5 -5
- package/lib/library/EnableLibraryPlugin.js +2 -2
- package/lib/library/ExportPropertyLibraryPlugin.js +1 -1
- package/lib/library/UmdLibraryPlugin.js +16 -8
- package/lib/logging/Logger.js +11 -11
- package/lib/logging/createConsoleLogger.js +14 -14
- package/lib/logging/truncateArgs.js +1 -1
- package/lib/node/NodeWatchFileSystem.js +3 -1
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +20 -18
- package/lib/node/ReadFileCompileWasmPlugin.js +1 -2
- package/lib/node/nodeConsole.js +11 -8
- package/lib/optimize/AggressiveSplittingPlugin.js +21 -7
- package/lib/optimize/ConcatenatedModule.js +43 -145
- package/lib/optimize/FlagIncludedChunksPlugin.js +6 -0
- package/lib/optimize/InnerGraphPlugin.js +57 -16
- package/lib/optimize/LimitChunkCountPlugin.js +2 -4
- package/lib/optimize/ModuleConcatenationPlugin.js +4 -2
- package/lib/optimize/RealContentHashPlugin.js +1 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +6 -3
- package/lib/rules/RuleSetCompiler.js +2 -2
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +2 -2
- package/lib/schemes/DataUriPlugin.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +32 -19
- package/lib/serialization/ObjectMiddleware.js +23 -9
- package/lib/serialization/SerializerMiddleware.js +3 -2
- package/lib/serialization/types.js +2 -2
- package/lib/sharing/ConsumeSharedModule.js +2 -3
- package/lib/sharing/ConsumeSharedRuntimeModule.js +3 -1
- package/lib/sharing/ProvideSharedModule.js +2 -3
- package/lib/stats/DefaultStatsFactoryPlugin.js +22 -20
- package/lib/stats/StatsFactory.js +12 -12
- package/lib/stats/StatsPrinter.js +7 -7
- package/lib/util/AsyncQueue.js +17 -1
- package/lib/util/IterableHelpers.js +1 -1
- package/lib/util/SetHelpers.js +1 -1
- package/lib/util/cleverMerge.js +48 -24
- package/lib/util/concatenate.js +227 -0
- package/lib/util/create-schema-validation.js +22 -9
- package/lib/util/deprecation.js +86 -28
- package/lib/util/fs.js +9 -9
- package/lib/util/hash/wasm-hash.js +12 -1
- package/lib/util/magicComment.js +21 -0
- package/lib/util/makeSerializable.js +24 -1
- package/lib/util/memoize.js +2 -1
- package/lib/util/runtime.js +4 -1
- package/lib/util/semver.js +130 -23
- package/lib/wasm/EnableWasmLoadingPlugin.js +2 -2
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +3 -3
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +5 -5
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -5
- package/lib/wasm-sync/WebAssemblyGenerator.js +8 -9
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +5 -5
- package/lib/web/FetchCompileAsyncWasmPlugin.js +1 -2
- package/lib/web/FetchCompileWasmPlugin.js +1 -2
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +6 -6
- package/package.json +18 -19
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +8 -2
- package/types.d.ts +801 -259
- package/lib/util/mergeScope.js +0 -76
@@ -390,6 +390,11 @@ const interceptAllJavascriptModulesPluginHooks = (compilation, tracer) => {
|
|
390
390
|
);
|
391
391
|
};
|
392
392
|
|
393
|
+
/**
|
394
|
+
* @param {string} instance instance
|
395
|
+
* @param {Trace} tracer tracer
|
396
|
+
* @returns {TODO} interceptor
|
397
|
+
*/
|
393
398
|
const makeInterceptorFor = (instance, tracer) => hookName => ({
|
394
399
|
register: tapInfo => {
|
395
400
|
const { name, type, fn } = tapInfo;
|
@@ -26,6 +26,7 @@ const ModuleDecoratorDependency = require("./ModuleDecoratorDependency");
|
|
26
26
|
/** @typedef {import("../javascript/BasicEvaluatedExpression")} BasicEvaluatedExpression */
|
27
27
|
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
|
28
28
|
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
29
|
+
/** @typedef {import("../javascript/JavascriptParser").StatementPath} StatementPath */
|
29
30
|
/** @typedef {import("./CommonJsDependencyHelpers").CommonJSDependencyBaseKeywords} CommonJSDependencyBaseKeywords */
|
30
31
|
|
31
32
|
/**
|
@@ -219,7 +220,8 @@ class CommonJsExportsParserPlugin {
|
|
219
220
|
enableStructuredExports();
|
220
221
|
const remainingMembers = members;
|
221
222
|
checkNamespace(
|
222
|
-
|
223
|
+
/** @type {StatementPath} */
|
224
|
+
(parser.statementPath).length === 1 &&
|
223
225
|
parser.isStatementLevelExpression(expr),
|
224
226
|
remainingMembers,
|
225
227
|
expr.right
|
@@ -276,7 +278,8 @@ class CommonJsExportsParserPlugin {
|
|
276
278
|
enableStructuredExports();
|
277
279
|
const descArg = expr.arguments[2];
|
278
280
|
checkNamespace(
|
279
|
-
|
281
|
+
/** @type {StatementPath} */
|
282
|
+
(parser.statementPath).length === 1,
|
280
283
|
[property],
|
281
284
|
getValueOfPropertyDescription(descArg)
|
282
285
|
);
|
@@ -283,7 +283,7 @@ class CommonJsImportsParserPlugin {
|
|
283
283
|
parser.state.module.addWarning(
|
284
284
|
new CommentCompilationWarning(
|
285
285
|
`Compilation error while processing magic comment(-s): /*${comment.value}*/: ${e.message}`,
|
286
|
-
comment.loc
|
286
|
+
/** @type {DependencyLocation} */ (comment.loc)
|
287
287
|
)
|
288
288
|
);
|
289
289
|
}
|
@@ -590,12 +590,9 @@ class CommonJsImportsParserPlugin {
|
|
590
590
|
data: { context },
|
591
591
|
next: undefined
|
592
592
|
});
|
593
|
+
|
593
594
|
return new BasicEvaluatedExpression()
|
594
|
-
.setIdentifier(
|
595
|
-
/** @type {TODO} */ (ident),
|
596
|
-
/** @type {TODO} */ (ident),
|
597
|
-
() => []
|
598
|
-
)
|
595
|
+
.setIdentifier(ident, ident, () => [])
|
599
596
|
.setSideEffects(false)
|
600
597
|
.setRange(/** @type {Range} */ (expr.range));
|
601
598
|
});
|
@@ -129,9 +129,9 @@ CssExportDependency.Template = class CssExportDependencyTemplate extends (
|
|
129
129
|
) {
|
130
130
|
const dep = /** @type {CssExportDependency} */ (dependency);
|
131
131
|
const module = /** @type {CssModule} */ (m);
|
132
|
-
const convention =
|
133
|
-
|
134
|
-
|
132
|
+
const convention =
|
133
|
+
/** @type {CssGenerator | CssExportsGenerator} */
|
134
|
+
(module.generator).convention;
|
135
135
|
const names = dep.getExportsConventionNames(dep.name, convention);
|
136
136
|
const usedNames = /** @type {string[]} */ (
|
137
137
|
names
|
@@ -21,6 +21,7 @@ const NullDependency = require("./NullDependency");
|
|
21
21
|
/** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
|
22
22
|
/** @typedef {import("../DependencyTemplate").CssDependencyTemplateContext} DependencyTemplateContext */
|
23
23
|
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
24
|
+
/** @typedef {import("../NormalModuleFactory").ResourceDataWithData} ResourceDataWithData */
|
24
25
|
/** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
|
25
26
|
/** @typedef {import("../css/CssExportsGenerator")} CssExportsGenerator */
|
26
27
|
/** @typedef {import("../css/CssGenerator")} CssGenerator */
|
@@ -28,6 +29,7 @@ const NullDependency = require("./NullDependency");
|
|
28
29
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
29
30
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
30
31
|
/** @typedef {import("../util/Hash")} Hash */
|
32
|
+
/** @typedef {import("../util/createHash").Algorithm} Algorithm */
|
31
33
|
|
32
34
|
/**
|
33
35
|
* @param {string} local css local
|
@@ -41,12 +43,16 @@ const getLocalIdent = (local, module, chunkGraph, runtimeTemplate) => {
|
|
41
43
|
/** @type {CssGenerator | CssExportsGenerator} */
|
42
44
|
(module.generator).localIdentName;
|
43
45
|
const relativeResourcePath = makePathsRelative(
|
44
|
-
/** @type {string} */
|
45
|
-
module.
|
46
|
+
/** @type {string} */
|
47
|
+
(module.context),
|
48
|
+
/** @type {string} */ (
|
49
|
+
/** @type {ResourceDataWithData} */
|
50
|
+
(module.resourceResolveData).path
|
51
|
+
)
|
46
52
|
);
|
47
53
|
const { hashFunction, hashDigest, hashDigestLength, hashSalt, uniqueName } =
|
48
54
|
runtimeTemplate.outputOptions;
|
49
|
-
const hash = createHash(hashFunction);
|
55
|
+
const hash = createHash(/** @type {Algorithm} */ (hashFunction));
|
50
56
|
if (hashSalt) {
|
51
57
|
hash.update(hashSalt);
|
52
58
|
}
|
@@ -71,7 +77,7 @@ const getLocalIdent = (local, module, chunkGraph, runtimeTemplate) => {
|
|
71
77
|
module
|
72
78
|
})
|
73
79
|
.replace(/\[local\]/g, local)
|
74
|
-
.replace(/\[uniqueName\]/g, uniqueName);
|
80
|
+
.replace(/\[uniqueName\]/g, /** @type {string} */ (uniqueName));
|
75
81
|
};
|
76
82
|
|
77
83
|
class CssLocalIdentifierDependency extends NullDependency {
|
@@ -209,28 +215,31 @@ CssLocalIdentifierDependency.Template = class CssLocalIdentifierDependencyTempla
|
|
209
215
|
) {
|
210
216
|
const dep = /** @type {CssLocalIdentifierDependency} */ (dependency);
|
211
217
|
const module = /** @type {CssModule} */ (m);
|
212
|
-
const convention =
|
213
|
-
|
214
|
-
|
218
|
+
const convention =
|
219
|
+
/** @type {CssGenerator | CssExportsGenerator} */
|
220
|
+
(module.generator).convention;
|
215
221
|
const names = dep.getExportsConventionNames(dep.name, convention);
|
216
|
-
const usedNames =
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
222
|
+
const usedNames =
|
223
|
+
/** @type {(string)[]} */
|
224
|
+
(
|
225
|
+
names
|
226
|
+
.map(name =>
|
227
|
+
moduleGraph.getExportInfo(module, name).getUsedName(name, runtime)
|
228
|
+
)
|
229
|
+
.filter(Boolean)
|
230
|
+
);
|
231
|
+
const used = usedNames.length === 0 ? names[0] : usedNames[0];
|
224
232
|
|
225
233
|
// use the first usedName to generate localIdent, it's shorter when mangle exports enabled
|
226
234
|
const localIdent =
|
227
|
-
dep.prefix +
|
228
|
-
|
235
|
+
dep.prefix + getLocalIdent(used, module, chunkGraph, runtimeTemplate);
|
236
|
+
|
229
237
|
source.replace(
|
230
238
|
dep.range[0],
|
231
239
|
dep.range[1] - 1,
|
232
240
|
escapeCssIdentifier(localIdent, dep.prefix)
|
233
241
|
);
|
242
|
+
|
234
243
|
for (const used of usedNames) {
|
235
244
|
cssExportsData.exports.set(used, localIdent);
|
236
245
|
}
|
@@ -12,10 +12,12 @@ const ModuleDependency = require("./ModuleDependency");
|
|
12
12
|
|
13
13
|
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
14
14
|
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
15
|
+
/** @typedef {import("../CodeGenerationResults")} CodeGenerationResults */
|
15
16
|
/** @typedef {import("../Dependency")} Dependency */
|
16
17
|
/** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
|
17
18
|
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
18
19
|
/** @typedef {import("../Module")} Module */
|
20
|
+
/** @typedef {import("../Module").CodeGenerationResult} CodeGenerationResult */
|
19
21
|
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
20
22
|
/** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
|
21
23
|
/** @typedef {import("../ModuleGraphConnection").ConnectionState} ConnectionState */
|
@@ -33,7 +35,7 @@ class CssUrlDependency extends ModuleDependency {
|
|
33
35
|
/**
|
34
36
|
* @param {string} request request
|
35
37
|
* @param {Range} range range of the argument
|
36
|
-
* @param {"string" | "url"} urlType dependency type e.g. url() or string
|
38
|
+
* @param {"string" | "url" | "src"} urlType dependency type e.g. url() or string
|
37
39
|
*/
|
38
40
|
constructor(request, range, urlType) {
|
39
41
|
super(request);
|
@@ -133,7 +135,7 @@ CssUrlDependency.Template = class CssUrlDependencyTemplate extends (
|
|
133
135
|
switch (dep.urlType) {
|
134
136
|
case "string":
|
135
137
|
newValue = cssEscapeString(
|
136
|
-
|
138
|
+
this.assetUrl({
|
137
139
|
module,
|
138
140
|
codeGenerationResults
|
139
141
|
})
|
@@ -141,7 +143,15 @@ CssUrlDependency.Template = class CssUrlDependencyTemplate extends (
|
|
141
143
|
break;
|
142
144
|
case "url":
|
143
145
|
newValue = `url(${cssEscapeString(
|
144
|
-
|
146
|
+
this.assetUrl({
|
147
|
+
module,
|
148
|
+
codeGenerationResults
|
149
|
+
})
|
150
|
+
)})`;
|
151
|
+
break;
|
152
|
+
case "src":
|
153
|
+
newValue = `src(${cssEscapeString(
|
154
|
+
this.assetUrl({
|
145
155
|
module,
|
146
156
|
codeGenerationResults
|
147
157
|
})
|
@@ -155,6 +165,26 @@ CssUrlDependency.Template = class CssUrlDependencyTemplate extends (
|
|
155
165
|
/** @type {string} */ (newValue)
|
156
166
|
);
|
157
167
|
}
|
168
|
+
|
169
|
+
/**
|
170
|
+
* @param {object} options options object
|
171
|
+
* @param {Module} options.module the module
|
172
|
+
* @param {RuntimeSpec=} options.runtime runtime
|
173
|
+
* @param {CodeGenerationResults} options.codeGenerationResults the code generation results
|
174
|
+
* @returns {string} the url of the asset
|
175
|
+
*/
|
176
|
+
assetUrl({ runtime, module, codeGenerationResults }) {
|
177
|
+
if (!module) {
|
178
|
+
return "data:,";
|
179
|
+
}
|
180
|
+
const codeGen = codeGenerationResults.get(module, runtime);
|
181
|
+
const data =
|
182
|
+
/** @type {NonNullable<CodeGenerationResult["data"]>} */
|
183
|
+
(codeGen.data);
|
184
|
+
const url = data.get("url");
|
185
|
+
if (!url || !url["css-url"]) return "data:,";
|
186
|
+
return url["css-url"];
|
187
|
+
}
|
158
188
|
};
|
159
189
|
|
160
190
|
makeSerializable(CssUrlDependency, "webpack/lib/dependencies/CssUrlDependency");
|
@@ -5,6 +5,7 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
const { getImportAttributes } = require("../javascript/JavascriptParser");
|
8
9
|
const InnerGraph = require("../optimize/InnerGraph");
|
9
10
|
const ConstDependency = require("./ConstDependency");
|
10
11
|
const HarmonyExportExpressionDependency = require("./HarmonyExportExpressionDependency");
|
@@ -13,8 +14,7 @@ const HarmonyExportImportedSpecifierDependency = require("./HarmonyExportImporte
|
|
13
14
|
const HarmonyExportSpecifierDependency = require("./HarmonyExportSpecifierDependency");
|
14
15
|
const { ExportPresenceModes } = require("./HarmonyImportDependency");
|
15
16
|
const {
|
16
|
-
harmonySpecifierTag
|
17
|
-
getAttributes
|
17
|
+
harmonySpecifierTag
|
18
18
|
} = require("./HarmonyImportDependencyParserPlugin");
|
19
19
|
const HarmonyImportSideEffectDependency = require("./HarmonyImportSideEffectDependency");
|
20
20
|
|
@@ -78,7 +78,7 @@ module.exports = class HarmonyExportDependencyParserPlugin {
|
|
78
78
|
const sideEffectDep = new HarmonyImportSideEffectDependency(
|
79
79
|
/** @type {string} */ (source),
|
80
80
|
parser.state.lastHarmonyImportOrder,
|
81
|
-
|
81
|
+
getImportAttributes(statement)
|
82
82
|
);
|
83
83
|
sideEffectDep.loc = Object.create(
|
84
84
|
/** @type {DependencyLocation} */ (statement.loc)
|
@@ -102,7 +102,7 @@ class ExportMode {
|
|
102
102
|
this.ignored = null;
|
103
103
|
|
104
104
|
// for "dynamic-reexport" | "empty-star":
|
105
|
-
/** @type {ExportModeHidden | null} */
|
105
|
+
/** @type {ExportModeHidden | undefined | null} */
|
106
106
|
this.hidden = null;
|
107
107
|
|
108
108
|
// for "missing":
|
@@ -115,12 +115,19 @@ class ExportMode {
|
|
115
115
|
}
|
116
116
|
}
|
117
117
|
|
118
|
+
/**
|
119
|
+
* @param {ModuleGraph} moduleGraph module graph
|
120
|
+
* @param {TODO} dependencies dependencies
|
121
|
+
* @param {TODO=} additionalDependency additional dependency
|
122
|
+
* @returns {TODO} result
|
123
|
+
*/
|
118
124
|
const determineExportAssignments = (
|
119
125
|
moduleGraph,
|
120
126
|
dependencies,
|
121
127
|
additionalDependency
|
122
128
|
) => {
|
123
129
|
const names = new Set();
|
130
|
+
/** @type {number[]} */
|
124
131
|
const dependencyIndices = [];
|
125
132
|
|
126
133
|
if (additionalDependency) {
|
@@ -417,7 +424,8 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
417
424
|
* @returns {void}
|
418
425
|
*/
|
419
426
|
setIds(moduleGraph, ids) {
|
420
|
-
|
427
|
+
/** @type {TODO} */
|
428
|
+
(moduleGraph.getMeta(this))[idsSymbol] = ids;
|
421
429
|
}
|
422
430
|
|
423
431
|
/**
|
@@ -593,7 +601,11 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
593
601
|
case "normal-reexport": {
|
594
602
|
/** @type {ReferencedExports} */
|
595
603
|
const referencedExports = [];
|
596
|
-
for (const {
|
604
|
+
for (const {
|
605
|
+
ids,
|
606
|
+
exportInfo,
|
607
|
+
hidden
|
608
|
+
} of /** @type {NormalReexportItem[]} */ (mode.items)) {
|
597
609
|
if (hidden) continue;
|
598
610
|
processExportInfo(runtime, referencedExports, ids, exportInfo, false);
|
599
611
|
}
|
@@ -687,12 +699,15 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
687
699
|
/** @type {ModuleGraphConnection} */
|
688
700
|
(moduleGraph.getConnection(this));
|
689
701
|
return {
|
690
|
-
exports: Array.from(
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
702
|
+
exports: Array.from(
|
703
|
+
/** @type {NormalReexportItem[]} */ (mode.items),
|
704
|
+
item => ({
|
705
|
+
name: item.name,
|
706
|
+
from,
|
707
|
+
export: item.ids,
|
708
|
+
hidden: item.hidden
|
709
|
+
})
|
710
|
+
),
|
696
711
|
priority: 1,
|
697
712
|
dependencies: [from.module]
|
698
713
|
};
|
@@ -1040,7 +1055,9 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
|
|
1040
1055
|
this.getReexportFragment(
|
1041
1056
|
module,
|
1042
1057
|
"reexport default from dynamic",
|
1043
|
-
moduleGraph
|
1058
|
+
moduleGraph
|
1059
|
+
.getExportsInfo(module)
|
1060
|
+
.getUsedName(/** @type {string} */ (mode.name), runtime),
|
1044
1061
|
importVar,
|
1045
1062
|
null,
|
1046
1063
|
runtimeRequirements
|
@@ -1052,7 +1069,9 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
|
|
1052
1069
|
initFragments.push(
|
1053
1070
|
...this.getReexportFakeNamespaceObjectFragments(
|
1054
1071
|
module,
|
1055
|
-
moduleGraph
|
1072
|
+
moduleGraph
|
1073
|
+
.getExportsInfo(module)
|
1074
|
+
.getUsedName(/** @type {string} */ (mode.name), runtime),
|
1056
1075
|
importVar,
|
1057
1076
|
mode.fakeType,
|
1058
1077
|
runtimeRequirements
|
@@ -1065,7 +1084,9 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
|
|
1065
1084
|
this.getReexportFragment(
|
1066
1085
|
module,
|
1067
1086
|
"reexport non-default export from non-harmony",
|
1068
|
-
moduleGraph
|
1087
|
+
moduleGraph
|
1088
|
+
.getExportsInfo(module)
|
1089
|
+
.getUsedName(/** @type {string} */ (mode.name), runtime),
|
1069
1090
|
"undefined",
|
1070
1091
|
"",
|
1071
1092
|
runtimeRequirements
|
@@ -1078,7 +1099,9 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
|
|
1078
1099
|
this.getReexportFragment(
|
1079
1100
|
module,
|
1080
1101
|
"reexport default export from named module",
|
1081
|
-
moduleGraph
|
1102
|
+
moduleGraph
|
1103
|
+
.getExportsInfo(module)
|
1104
|
+
.getUsedName(/** @type {string} */ (mode.name), runtime),
|
1082
1105
|
importVar,
|
1083
1106
|
"",
|
1084
1107
|
runtimeRequirements
|
@@ -1091,7 +1114,9 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
|
|
1091
1114
|
this.getReexportFragment(
|
1092
1115
|
module,
|
1093
1116
|
"reexport module object",
|
1094
|
-
moduleGraph
|
1117
|
+
moduleGraph
|
1118
|
+
.getExportsInfo(module)
|
1119
|
+
.getUsedName(/** @type {string} */ (mode.name), runtime),
|
1095
1120
|
importVar,
|
1096
1121
|
"",
|
1097
1122
|
runtimeRequirements
|
@@ -6,6 +6,7 @@
|
|
6
6
|
"use strict";
|
7
7
|
|
8
8
|
const HotModuleReplacementPlugin = require("../HotModuleReplacementPlugin");
|
9
|
+
const { getImportAttributes } = require("../javascript/JavascriptParser");
|
9
10
|
const InnerGraph = require("../optimize/InnerGraph");
|
10
11
|
const ConstDependency = require("./ConstDependency");
|
11
12
|
const HarmonyAcceptDependency = require("./HarmonyAcceptDependency");
|
@@ -16,11 +17,7 @@ const { ExportPresenceModes } = require("./HarmonyImportDependency");
|
|
16
17
|
const HarmonyImportSideEffectDependency = require("./HarmonyImportSideEffectDependency");
|
17
18
|
const HarmonyImportSpecifierDependency = require("./HarmonyImportSpecifierDependency");
|
18
19
|
|
19
|
-
/** @typedef {import("estree").ExportAllDeclaration} ExportAllDeclaration */
|
20
|
-
/** @typedef {import("estree").ExportNamedDeclaration} ExportNamedDeclaration */
|
21
20
|
/** @typedef {import("estree").Identifier} Identifier */
|
22
|
-
/** @typedef {import("estree").ImportDeclaration} ImportDeclaration */
|
23
|
-
/** @typedef {import("estree").ImportExpression} ImportExpression */
|
24
21
|
/** @typedef {import("estree").Literal} Literal */
|
25
22
|
/** @typedef {import("estree").MemberExpression} MemberExpression */
|
26
23
|
/** @typedef {import("estree").ObjectExpression} ObjectExpression */
|
@@ -30,7 +27,11 @@ const HarmonyImportSpecifierDependency = require("./HarmonyImportSpecifierDepend
|
|
30
27
|
/** @typedef {import("../javascript/BasicEvaluatedExpression")} BasicEvaluatedExpression */
|
31
28
|
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
|
32
29
|
/** @typedef {import("../javascript/JavascriptParser").DestructuringAssignmentProperty} DestructuringAssignmentProperty */
|
30
|
+
/** @typedef {import("../javascript/JavascriptParser").ExportAllDeclaration} ExportAllDeclaration */
|
31
|
+
/** @typedef {import("../javascript/JavascriptParser").ExportNamedDeclaration} ExportNamedDeclaration */
|
33
32
|
/** @typedef {import("../javascript/JavascriptParser").ImportAttributes} ImportAttributes */
|
33
|
+
/** @typedef {import("../javascript/JavascriptParser").ImportDeclaration} ImportDeclaration */
|
34
|
+
/** @typedef {import("../javascript/JavascriptParser").ImportExpression} ImportExpression */
|
34
35
|
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
35
36
|
/** @typedef {import("../optimize/InnerGraph").InnerGraph} InnerGraph */
|
36
37
|
/** @typedef {import("../optimize/InnerGraph").TopLevelSymbol} TopLevelSymbol */
|
@@ -48,73 +49,6 @@ const harmonySpecifierTag = Symbol("harmony import");
|
|
48
49
|
* @property {Record<string, any> | undefined} assertions
|
49
50
|
*/
|
50
51
|
|
51
|
-
/**
|
52
|
-
* @param {ImportDeclaration | ExportNamedDeclaration | ExportAllDeclaration | (ImportExpression & { arguments?: ObjectExpression[] })} node node with assertions
|
53
|
-
* @returns {ImportAttributes | undefined} import attributes
|
54
|
-
*/
|
55
|
-
function getAttributes(node) {
|
56
|
-
if (
|
57
|
-
node.type === "ImportExpression" &&
|
58
|
-
node.arguments &&
|
59
|
-
node.arguments[0] &&
|
60
|
-
node.arguments[0].type === "ObjectExpression" &&
|
61
|
-
node.arguments[0].properties[0] &&
|
62
|
-
node.arguments[0].properties[0].type === "Property" &&
|
63
|
-
node.arguments[0].properties[0].value.type === "ObjectExpression" &&
|
64
|
-
node.arguments[0].properties[0].value.properties
|
65
|
-
) {
|
66
|
-
const properties =
|
67
|
-
/** @type {Property[]} */
|
68
|
-
(node.arguments[0].properties[0].value.properties);
|
69
|
-
const result = /** @type {ImportAttributes} */ ({});
|
70
|
-
for (const property of properties) {
|
71
|
-
const key =
|
72
|
-
/** @type {string} */
|
73
|
-
(
|
74
|
-
property.key.type === "Identifier"
|
75
|
-
? property.key.name
|
76
|
-
: /** @type {Literal} */ (property.key).value
|
77
|
-
);
|
78
|
-
result[key] =
|
79
|
-
/** @type {string} */
|
80
|
-
(/** @type {Literal} */ (property.value).value);
|
81
|
-
}
|
82
|
-
const key =
|
83
|
-
node.arguments[0].properties[0].key.type === "Identifier"
|
84
|
-
? node.arguments[0].properties[0].key.name
|
85
|
-
: /** @type {Literal} */ (node.arguments[0].properties[0].key).value;
|
86
|
-
if (key === "assert") {
|
87
|
-
result._isLegacyAssert = true;
|
88
|
-
}
|
89
|
-
return result;
|
90
|
-
}
|
91
|
-
// TODO remove cast when @types/estree has been updated to import assertions
|
92
|
-
const isImportAssertion =
|
93
|
-
/** @type {{ assertions?: ImportAttributeNode[] }} */ (node).assertions !==
|
94
|
-
undefined;
|
95
|
-
const attributes = isImportAssertion
|
96
|
-
? /** @type {{ assertions?: ImportAttributeNode[] }} */ (node).assertions
|
97
|
-
: /** @type {{ attributes?: ImportAttributeNode[] }} */ (node).attributes;
|
98
|
-
if (attributes === undefined) {
|
99
|
-
return;
|
100
|
-
}
|
101
|
-
const result = /** @type {ImportAttributes} */ ({});
|
102
|
-
for (const attribute of attributes) {
|
103
|
-
const key =
|
104
|
-
/** @type {string} */
|
105
|
-
(
|
106
|
-
attribute.key.type === "Identifier"
|
107
|
-
? attribute.key.name
|
108
|
-
: attribute.key.value
|
109
|
-
);
|
110
|
-
result[key] = /** @type {string} */ (attribute.value.value);
|
111
|
-
}
|
112
|
-
if (isImportAssertion) {
|
113
|
-
result._isLegacyAssert = true;
|
114
|
-
}
|
115
|
-
return result;
|
116
|
-
}
|
117
|
-
|
118
52
|
module.exports = class HarmonyImportDependencyParserPlugin {
|
119
53
|
/**
|
120
54
|
* @param {JavascriptParserOptions} options options
|
@@ -184,7 +118,7 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
184
118
|
clearDep.loc = /** @type {DependencyLocation} */ (statement.loc);
|
185
119
|
parser.state.module.addPresentationalDependency(clearDep);
|
186
120
|
parser.unsetAsiPosition(/** @type {Range} */ (statement.range)[1]);
|
187
|
-
const attributes =
|
121
|
+
const attributes = getImportAttributes(statement);
|
188
122
|
const sideEffectDep = new HarmonyImportSideEffectDependency(
|
189
123
|
/** @type {string} */ (source),
|
190
124
|
parser.state.lastHarmonyImportOrder,
|
@@ -204,7 +138,7 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
204
138
|
source,
|
205
139
|
ids,
|
206
140
|
sourceOrder: parser.state.lastHarmonyImportOrder,
|
207
|
-
assertions:
|
141
|
+
assertions: getImportAttributes(statement)
|
208
142
|
});
|
209
143
|
return true;
|
210
144
|
}
|
@@ -389,17 +323,18 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
389
323
|
}
|
390
324
|
const dependencies = requests.map(request => {
|
391
325
|
const dep = new HarmonyAcceptImportDependency(request);
|
392
|
-
dep.loc = expr.loc;
|
326
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
393
327
|
parser.state.module.addDependency(dep);
|
394
328
|
return dep;
|
395
329
|
});
|
396
330
|
if (dependencies.length > 0) {
|
397
331
|
const dep = new HarmonyAcceptDependency(
|
398
|
-
|
332
|
+
/** @type {Range} */
|
333
|
+
(expr.range),
|
399
334
|
dependencies,
|
400
335
|
true
|
401
336
|
);
|
402
|
-
dep.loc = expr.loc;
|
337
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
403
338
|
parser.state.module.addDependency(dep);
|
404
339
|
}
|
405
340
|
}
|
@@ -413,17 +348,18 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
413
348
|
}
|
414
349
|
const dependencies = requests.map(request => {
|
415
350
|
const dep = new HarmonyAcceptImportDependency(request);
|
416
|
-
dep.loc = expr.loc;
|
351
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
417
352
|
parser.state.module.addDependency(dep);
|
418
353
|
return dep;
|
419
354
|
});
|
420
355
|
if (dependencies.length > 0) {
|
421
356
|
const dep = new HarmonyAcceptDependency(
|
422
|
-
|
357
|
+
/** @type {Range} */
|
358
|
+
(expr.range),
|
423
359
|
dependencies,
|
424
360
|
false
|
425
361
|
);
|
426
|
-
dep.loc = expr.loc;
|
362
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
427
363
|
parser.state.module.addDependency(dep);
|
428
364
|
}
|
429
365
|
}
|
@@ -432,6 +368,3 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
432
368
|
};
|
433
369
|
|
434
370
|
module.exports.harmonySpecifierTag = harmonySpecifierTag;
|
435
|
-
// TODO remove it in webpack@6 in favor getAttributes
|
436
|
-
module.exports.getAssertions = getAttributes;
|
437
|
-
module.exports.getAttributes = getAttributes;
|
@@ -114,7 +114,8 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
|
|
114
114
|
* @returns {void}
|
115
115
|
*/
|
116
116
|
setIds(moduleGraph, ids) {
|
117
|
-
|
117
|
+
/** @type {TODO} */
|
118
|
+
(moduleGraph.getMeta(this))[idsSymbol] = ids;
|
118
119
|
}
|
119
120
|
|
120
121
|
/**
|
@@ -350,7 +351,9 @@ HarmonyImportSpecifierDependency.Template = class HarmonyImportSpecifierDependen
|
|
350
351
|
let prefixedIds = ids;
|
351
352
|
|
352
353
|
if (ids[0] === "default") {
|
353
|
-
const selfModule =
|
354
|
+
const selfModule =
|
355
|
+
/** @type {Module} */
|
356
|
+
(moduleGraph.getParentModule(dep));
|
354
357
|
const importedModule =
|
355
358
|
/** @type {Module} */
|
356
359
|
(moduleGraph.getModule(dep));
|
@@ -8,20 +8,20 @@
|
|
8
8
|
const AsyncDependenciesBlock = require("../AsyncDependenciesBlock");
|
9
9
|
const CommentCompilationWarning = require("../CommentCompilationWarning");
|
10
10
|
const UnsupportedFeatureWarning = require("../UnsupportedFeatureWarning");
|
11
|
+
const { getImportAttributes } = require("../javascript/JavascriptParser");
|
11
12
|
const ContextDependencyHelpers = require("./ContextDependencyHelpers");
|
12
|
-
const { getAttributes } = require("./HarmonyImportDependencyParserPlugin");
|
13
13
|
const ImportContextDependency = require("./ImportContextDependency");
|
14
14
|
const ImportDependency = require("./ImportDependency");
|
15
15
|
const ImportEagerDependency = require("./ImportEagerDependency");
|
16
16
|
const ImportWeakDependency = require("./ImportWeakDependency");
|
17
17
|
|
18
|
-
/** @typedef {import("estree").ImportExpression} ImportExpression */
|
19
18
|
/** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
|
20
19
|
/** @typedef {import("../ChunkGroup").RawChunkGroupOptions} RawChunkGroupOptions */
|
21
20
|
/** @typedef {import("../ContextModule").ContextMode} ContextMode */
|
22
21
|
/** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
|
23
22
|
/** @typedef {import("../Module").BuildMeta} BuildMeta */
|
24
23
|
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
|
24
|
+
/** @typedef {import("../javascript/JavascriptParser").ImportExpression} ImportExpression */
|
25
25
|
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
26
26
|
|
27
27
|
class ImportParserPlugin {
|
@@ -85,7 +85,7 @@ class ImportParserPlugin {
|
|
85
85
|
parser.state.module.addWarning(
|
86
86
|
new CommentCompilationWarning(
|
87
87
|
`Compilation error while processing magic comment(-s): /*${comment.value}*/: ${e.message}`,
|
88
|
-
comment.loc
|
88
|
+
/** @type {DependencyLocation} */ (comment.loc)
|
89
89
|
)
|
90
90
|
);
|
91
91
|
}
|
@@ -126,7 +126,7 @@ class ImportParserPlugin {
|
|
126
126
|
)
|
127
127
|
);
|
128
128
|
} else {
|
129
|
-
mode = importOptions.webpackMode;
|
129
|
+
mode = /** @type {ContextMode} */ (importOptions.webpackMode);
|
130
130
|
}
|
131
131
|
}
|
132
132
|
if (importOptions.webpackPrefetch !== undefined) {
|
@@ -162,7 +162,9 @@ class ImportParserPlugin {
|
|
162
162
|
typeof importOptions.webpackFetchPriority === "string" &&
|
163
163
|
["high", "low", "auto"].includes(importOptions.webpackFetchPriority)
|
164
164
|
) {
|
165
|
-
groupOptions.fetchPriority =
|
165
|
+
groupOptions.fetchPriority =
|
166
|
+
/** @type {"low" | "high" | "auto"} */
|
167
|
+
(importOptions.webpackFetchPriority);
|
166
168
|
} else {
|
167
169
|
parser.state.module.addWarning(
|
168
170
|
new UnsupportedFeatureWarning(
|
@@ -258,7 +260,7 @@ class ImportParserPlugin {
|
|
258
260
|
}
|
259
261
|
|
260
262
|
if (param.isString()) {
|
261
|
-
const attributes =
|
263
|
+
const attributes = getImportAttributes(expr);
|
262
264
|
|
263
265
|
if (mode === "eager") {
|
264
266
|
const dep = new ImportEagerDependency(
|
@@ -321,7 +323,7 @@ class ImportParserPlugin {
|
|
321
323
|
typePrefix: "import()",
|
322
324
|
category: "esm",
|
323
325
|
referencedExports: exports,
|
324
|
-
attributes:
|
326
|
+
attributes: getImportAttributes(expr)
|
325
327
|
},
|
326
328
|
parser
|
327
329
|
);
|