webpack 5.91.0 → 5.92.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.
Potentially problematic release.
This version of webpack might be problematic. Click here for more details.
- package/bin/webpack.js +1 -2
- package/lib/APIPlugin.js +6 -2
- package/lib/Cache.js +1 -1
- package/lib/Chunk.js +7 -4
- package/lib/ChunkGraph.js +20 -7
- package/lib/ChunkGroup.js +9 -3
- package/lib/CleanPlugin.js +1 -1
- package/lib/Compilation.js +33 -27
- package/lib/Compiler.js +28 -8
- package/lib/ConcatenationScope.js +3 -3
- package/lib/ContextModule.js +95 -43
- package/lib/DefinePlugin.js +14 -4
- package/lib/Dependency.js +8 -8
- package/lib/DependencyTemplate.js +10 -5
- package/lib/DllReferencePlugin.js +1 -1
- package/lib/EvalDevToolModulePlugin.js +11 -0
- package/lib/ExportsInfo.js +22 -4
- package/lib/ExternalModule.js +49 -18
- package/lib/FileSystemInfo.js +68 -41
- package/lib/FlagDependencyExportsPlugin.js +21 -7
- package/lib/Generator.js +2 -3
- package/lib/HotModuleReplacementPlugin.js +108 -45
- package/lib/IgnorePlugin.js +4 -1
- package/lib/LibManifestPlugin.js +2 -2
- package/lib/Module.js +11 -12
- package/lib/ModuleFactory.js +3 -3
- package/lib/ModuleFilenameHelpers.js +29 -16
- package/lib/ModuleGraph.js +5 -5
- package/lib/MultiCompiler.js +36 -1
- package/lib/NormalModule.js +10 -12
- package/lib/NormalModuleFactory.js +17 -8
- package/lib/Parser.js +1 -1
- package/lib/PlatformPlugin.js +39 -0
- package/lib/ProgressPlugin.js +1 -1
- package/lib/RecordIdsPlugin.js +4 -4
- package/lib/ResolverFactory.js +3 -3
- package/lib/RuntimeTemplate.js +22 -18
- package/lib/Stats.js +1 -1
- package/lib/Template.js +5 -5
- package/lib/TemplatedPathPlugin.js +16 -1
- package/lib/asset/AssetGenerator.js +15 -0
- package/lib/buildChunkGraph.js +3 -3
- package/lib/cache/MemoryWithGcCachePlugin.js +1 -1
- package/lib/cache/PackFileCacheStrategy.js +2 -2
- package/lib/cache/ResolverCachePlugin.js +8 -8
- package/lib/cache/getLazyHashedEtag.js +1 -1
- package/lib/cli.js +5 -5
- package/lib/config/browserslistTargetHandler.js +7 -1
- package/lib/config/defaults.js +85 -34
- package/lib/config/target.js +18 -11
- package/lib/container/ContainerEntryModule.js +1 -1
- package/lib/css/CssExportsGenerator.js +43 -17
- package/lib/css/CssGenerator.js +22 -12
- package/lib/css/CssLoadingRuntimeModule.js +8 -5
- package/lib/css/CssModulesPlugin.js +197 -100
- package/lib/css/CssParser.js +24 -15
- package/lib/css/walkCssTokens.js +1 -1
- package/lib/debug/ProfilingPlugin.js +1 -1
- package/lib/dependencies/ContextElementDependency.js +2 -2
- package/lib/dependencies/CssExportDependency.js +2 -2
- package/lib/dependencies/CssLocalIdentifierDependency.js +9 -2
- package/lib/dependencies/CssUrlDependency.js +5 -4
- package/lib/dependencies/ExportsInfoDependency.js +1 -1
- package/lib/dependencies/ExternalModuleDependency.js +4 -2
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +2 -2
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +2 -2
- package/lib/dependencies/HarmonyImportDependency.js +2 -2
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +41 -18
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +2 -2
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +43 -32
- package/lib/dependencies/ImportDependency.js +2 -2
- package/lib/dependencies/ImportEagerDependency.js +2 -2
- package/lib/dependencies/ImportMetaPlugin.js +1 -1
- package/lib/dependencies/ImportParserPlugin.js +3 -1
- package/lib/dependencies/ImportWeakDependency.js +2 -2
- package/lib/dependencies/LoaderPlugin.js +2 -2
- package/lib/dependencies/ModuleDependency.js +2 -2
- package/lib/dependencies/PureExpressionDependency.js +63 -49
- package/lib/dependencies/WorkerDependency.js +1 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +90 -2
- 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/CommonJsChunkFormatPlugin.js +1 -1
- package/lib/javascript/JavascriptGenerator.js +0 -1
- package/lib/javascript/JavascriptModulesPlugin.js +174 -17
- package/lib/javascript/JavascriptParser.js +37 -16
- 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/createConsoleLogger.js +2 -2
- package/lib/node/CommonJsChunkLoadingPlugin.js +2 -1
- package/lib/node/NodeEnvironmentPlugin.js +1 -1
- package/lib/node/NodeTemplatePlugin.js +1 -1
- package/lib/node/ReadFileCompileWasmPlugin.js +1 -1
- package/lib/node/nodeConsole.js +1 -1
- package/lib/optimize/AggressiveMergingPlugin.js +1 -1
- package/lib/optimize/ConcatenatedModule.js +11 -76
- package/lib/optimize/InnerGraph.js +1 -1
- package/lib/optimize/LimitChunkCountPlugin.js +1 -2
- package/lib/optimize/ModuleConcatenationPlugin.js +1 -1
- package/lib/optimize/RealContentHashPlugin.js +3 -3
- package/lib/optimize/SideEffectsFlagPlugin.js +2 -2
- package/lib/optimize/SplitChunksPlugin.js +8 -8
- package/lib/performance/SizeLimitsPlugin.js +2 -2
- package/lib/rules/ObjectMatcherRulePlugin.js +11 -1
- package/lib/rules/RuleSetCompiler.js +9 -7
- 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 +3 -3
- package/lib/serialization/NullPrototypeObjectSerializer.js +2 -2
- package/lib/serialization/ObjectMiddleware.js +6 -5
- package/lib/serialization/PlainObjectSerializer.js +2 -2
- 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 +1 -1
- package/lib/sharing/ProvideSharedPlugin.js +1 -1
- package/lib/sharing/resolveMatchedConfigs.js +1 -1
- 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/TupleQueue.js +8 -2
- package/lib/util/WeakTupleMap.js +3 -3
- package/lib/util/binarySearchBounds.js +1 -1
- package/lib/util/cleverMerge.js +2 -2
- package/lib/util/comparators.js +4 -2
- package/lib/util/conventions.js +1 -1
- 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 +15 -15
- 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/AsyncWebAssemblyModulesPlugin.js +3 -3
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +1 -1
- package/lib/wasm-sync/WebAssemblyGenerator.js +17 -17
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +1 -1
- package/lib/wasm-sync/WebAssemblyUtils.js +2 -1
- package/lib/web/FetchCompileWasmPlugin.js +1 -1
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -1
- package/lib/webpack.js +12 -3
- package/package.json +20 -18
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +30 -2
- 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 +213 -81
@@ -126,6 +126,7 @@ CssUrlDependency.Template = class CssUrlDependencyTemplate extends (
|
|
126
126
|
{ moduleGraph, runtimeTemplate, codeGenerationResults }
|
127
127
|
) {
|
128
128
|
const dep = /** @type {CssUrlDependency} */ (dependency);
|
129
|
+
const module = /** @type {Module} */ (moduleGraph.getModule(dep));
|
129
130
|
|
130
131
|
/** @type {string | undefined} */
|
131
132
|
let newValue;
|
@@ -134,8 +135,7 @@ CssUrlDependency.Template = class CssUrlDependencyTemplate extends (
|
|
134
135
|
case "string":
|
135
136
|
newValue = cssEscapeString(
|
136
137
|
runtimeTemplate.assetUrl({
|
137
|
-
|
138
|
-
module: /** @type {Module} */ (moduleGraph.getModule(dep)),
|
138
|
+
module,
|
139
139
|
codeGenerationResults
|
140
140
|
})
|
141
141
|
);
|
@@ -143,8 +143,7 @@ CssUrlDependency.Template = class CssUrlDependencyTemplate extends (
|
|
143
143
|
case "url":
|
144
144
|
newValue = `url(${cssEscapeString(
|
145
145
|
runtimeTemplate.assetUrl({
|
146
|
-
|
147
|
-
module: /** @type {Module} */ (moduleGraph.getModule(dep)),
|
146
|
+
module,
|
148
147
|
codeGenerationResults
|
149
148
|
})
|
150
149
|
)})`;
|
@@ -161,4 +160,6 @@ CssUrlDependency.Template = class CssUrlDependencyTemplate extends (
|
|
161
160
|
|
162
161
|
makeSerializable(CssUrlDependency, "webpack/lib/dependencies/CssUrlDependency");
|
163
162
|
|
163
|
+
CssUrlDependency.PUBLIC_PATH_AUTO = "__WEBPACK_CSS_PUBLIC_PATH_AUTO__";
|
164
|
+
|
164
165
|
module.exports = CssUrlDependency;
|
@@ -52,7 +52,7 @@ const getProperty = (moduleGraph, module, _exportName, property, runtime) => {
|
|
52
52
|
switch (property) {
|
53
53
|
case "canMangle": {
|
54
54
|
const exportsInfo = moduleGraph.getExportsInfo(module);
|
55
|
-
const exportInfo = exportsInfo.
|
55
|
+
const exportInfo = exportsInfo.getReadOnlyExportInfoRecursive(exportName);
|
56
56
|
if (exportInfo) return exportInfo.canMangle;
|
57
57
|
return exportsInfo.otherExportsInfo.canMangle;
|
58
58
|
}
|
@@ -92,11 +92,13 @@ ExternalModuleDependency.Template = class ExternalModuleDependencyTemplate exten
|
|
92
92
|
apply(dependency, source, templateContext) {
|
93
93
|
super.apply(dependency, source, templateContext);
|
94
94
|
const dep = /** @type {ExternalModuleDependency} */ (dependency);
|
95
|
-
const { chunkInitFragments } = templateContext;
|
95
|
+
const { chunkInitFragments, runtimeTemplate } = templateContext;
|
96
96
|
|
97
97
|
chunkInitFragments.push(
|
98
98
|
new ExternalModuleInitFragment(
|
99
|
-
|
99
|
+
`${runtimeTemplate.supportNodePrefixForCoreModules() ? "node:" : ""}${
|
100
|
+
dep.importedModule
|
101
|
+
}`,
|
100
102
|
dep.specifiers,
|
101
103
|
dep.default
|
102
104
|
)
|
@@ -14,7 +14,7 @@ const HarmonyImportSpecifierDependency = require("./HarmonyImportSpecifierDepend
|
|
14
14
|
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
15
15
|
/** @typedef {import("../Module").BuildMeta} BuildMeta */
|
16
16
|
/** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
|
17
|
-
/** @typedef {import("../javascript/JavascriptParser").
|
17
|
+
/** @typedef {import("../javascript/JavascriptParser").ImportAttributes} ImportAttributes */
|
18
18
|
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
19
19
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
20
20
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
@@ -33,7 +33,7 @@ class HarmonyEvaluatedImportSpecifierDependency extends HarmonyImportSpecifierDe
|
|
33
33
|
* @param {TODO} ids ids
|
34
34
|
* @param {TODO} name name
|
35
35
|
* @param {Range} range location in source code
|
36
|
-
* @param {
|
36
|
+
* @param {ImportAttributes} attributes import assertions
|
37
37
|
* @param {string} operator operator
|
38
38
|
*/
|
39
39
|
constructor(request, sourceOrder, ids, name, range, attributes, operator) {
|
@@ -40,7 +40,7 @@ const processExportInfo = require("./processExportInfo");
|
|
40
40
|
/** @typedef {import("../ModuleGraphConnection").ConnectionState} ConnectionState */
|
41
41
|
/** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
|
42
42
|
/** @typedef {import("../WebpackError")} WebpackError */
|
43
|
-
/** @typedef {import("../javascript/JavascriptParser").
|
43
|
+
/** @typedef {import("../javascript/JavascriptParser").ImportAttributes} ImportAttributes */
|
44
44
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
45
45
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
46
46
|
/** @typedef {import("../util/Hash")} Hash */
|
@@ -337,7 +337,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
|
|
337
337
|
* @param {ReadonlyArray<HarmonyExportImportedSpecifierDependency> | Iterable<HarmonyExportImportedSpecifierDependency> | null} otherStarExports other star exports in the module before this import
|
338
338
|
* @param {number} exportPresenceMode mode of checking export names
|
339
339
|
* @param {HarmonyStarExportsList | null} allStarExports all star exports in the module
|
340
|
-
* @param {
|
340
|
+
* @param {ImportAttributes=} attributes import attributes
|
341
341
|
*/
|
342
342
|
constructor(
|
343
343
|
request,
|
@@ -26,7 +26,7 @@ const ModuleDependency = require("./ModuleDependency");
|
|
26
26
|
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
27
27
|
/** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
|
28
28
|
/** @typedef {import("../WebpackError")} WebpackError */
|
29
|
-
/** @typedef {import("../javascript/JavascriptParser").
|
29
|
+
/** @typedef {import("../javascript/JavascriptParser").ImportAttributes} ImportAttributes */
|
30
30
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
31
31
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
32
32
|
/** @typedef {import("../util/Hash")} Hash */
|
@@ -62,7 +62,7 @@ class HarmonyImportDependency extends ModuleDependency {
|
|
62
62
|
*
|
63
63
|
* @param {string} request request string
|
64
64
|
* @param {number} sourceOrder source order
|
65
|
-
* @param {
|
65
|
+
* @param {ImportAttributes=} attributes import attributes
|
66
66
|
*/
|
67
67
|
constructor(request, sourceOrder, attributes) {
|
68
68
|
super(request);
|
@@ -29,6 +29,8 @@ const HarmonyImportSpecifierDependency = require("./HarmonyImportSpecifierDepend
|
|
29
29
|
/** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
|
30
30
|
/** @typedef {import("../javascript/BasicEvaluatedExpression")} BasicEvaluatedExpression */
|
31
31
|
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
|
32
|
+
/** @typedef {import("../javascript/JavascriptParser").DestructuringAssignmentProperty} DestructuringAssignmentProperty */
|
33
|
+
/** @typedef {import("../javascript/JavascriptParser").ImportAttributes} ImportAttributes */
|
32
34
|
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
33
35
|
/** @typedef {import("../optimize/InnerGraph").InnerGraph} InnerGraph */
|
34
36
|
/** @typedef {import("../optimize/InnerGraph").TopLevelSymbol} TopLevelSymbol */
|
@@ -37,7 +39,7 @@ const HarmonyImportSpecifierDependency = require("./HarmonyImportSpecifierDepend
|
|
37
39
|
const harmonySpecifierTag = Symbol("harmony import");
|
38
40
|
|
39
41
|
/**
|
40
|
-
* @typedef {
|
42
|
+
* @typedef {object} HarmonySettings
|
41
43
|
* @property {string[]} ids
|
42
44
|
* @property {string} source
|
43
45
|
* @property {number} sourceOrder
|
@@ -48,7 +50,7 @@ const harmonySpecifierTag = Symbol("harmony import");
|
|
48
50
|
|
49
51
|
/**
|
50
52
|
* @param {ImportDeclaration | ExportNamedDeclaration | ExportAllDeclaration | (ImportExpression & { arguments?: ObjectExpression[] })} node node with assertions
|
51
|
-
* @returns {
|
53
|
+
* @returns {ImportAttributes} import attributes
|
52
54
|
*/
|
53
55
|
function getAttributes(node) {
|
54
56
|
if (
|
@@ -61,33 +63,54 @@ function getAttributes(node) {
|
|
61
63
|
node.arguments[0].properties[0].value.type === "ObjectExpression" &&
|
62
64
|
node.arguments[0].properties[0].value.properties
|
63
65
|
) {
|
64
|
-
const properties =
|
65
|
-
|
66
|
-
|
67
|
-
const result = {};
|
66
|
+
const properties =
|
67
|
+
/** @type {Property[]} */
|
68
|
+
(node.arguments[0].properties[0].value.properties);
|
69
|
+
const result = /** @type {ImportAttributes} */ ({});
|
68
70
|
for (const property of properties) {
|
69
71
|
const key =
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
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;
|
74
88
|
}
|
75
89
|
return result;
|
76
90
|
}
|
77
91
|
// TODO remove cast when @types/estree has been updated to import assertions
|
78
|
-
const
|
79
|
-
/** @type {{ assertions?: ImportAttributeNode[] }} */
|
80
|
-
|
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;
|
81
98
|
if (attributes === undefined) {
|
82
99
|
return undefined;
|
83
100
|
}
|
84
|
-
const result = {};
|
101
|
+
const result = /** @type {ImportAttributes} */ ({});
|
85
102
|
for (const attribute of attributes) {
|
86
103
|
const key =
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
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;
|
91
114
|
}
|
92
115
|
return result;
|
93
116
|
}
|
@@ -16,7 +16,7 @@ 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").
|
19
|
+
/** @typedef {import("../javascript/JavascriptParser").ImportAttributes} ImportAttributes */
|
20
20
|
/** @typedef {import("../util/Hash")} Hash */
|
21
21
|
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
22
22
|
|
@@ -24,7 +24,7 @@ class HarmonyImportSideEffectDependency extends HarmonyImportDependency {
|
|
24
24
|
/**
|
25
25
|
* @param {string} request the request string
|
26
26
|
* @param {number} sourceOrder source order
|
27
|
-
* @param {
|
27
|
+
* @param {ImportAttributes=} attributes import attributes
|
28
28
|
*/
|
29
29
|
constructor(request, sourceOrder, attributes) {
|
30
30
|
super(request, sourceOrder, attributes);
|
@@ -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");
|
@@ -27,7 +28,8 @@ const HarmonyImportDependency = require("./HarmonyImportDependency");
|
|
27
28
|
/** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
|
28
29
|
/** @typedef {import("../ModuleGraphConnection").ConnectionState} ConnectionState */
|
29
30
|
/** @typedef {import("../WebpackError")} WebpackError */
|
30
|
-
/** @typedef {import("../javascript/JavascriptParser").
|
31
|
+
/** @typedef {import("../javascript/JavascriptParser").DestructuringAssignmentProperty} DestructuringAssignmentProperty */
|
32
|
+
/** @typedef {import("../javascript/JavascriptParser").ImportAttributes} ImportAttributes */
|
31
33
|
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
32
34
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
33
35
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
@@ -46,8 +48,8 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
|
|
46
48
|
* @param {string} name name
|
47
49
|
* @param {Range} range range
|
48
50
|
* @param {TODO} exportPresenceMode export presence mode
|
49
|
-
* @param {
|
50
|
-
* @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
|
51
53
|
*/
|
52
54
|
constructor(
|
53
55
|
request,
|
@@ -73,7 +75,7 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
|
|
73
75
|
this.asiSafe = undefined;
|
74
76
|
/** @type {Set<string> | boolean | undefined} */
|
75
77
|
this.usedByExports = undefined;
|
76
|
-
/** @type {Set<
|
78
|
+
/** @type {Set<DestructuringAssignmentProperty> | undefined} */
|
77
79
|
this.referencedPropertiesInDestructuring = undefined;
|
78
80
|
}
|
79
81
|
|
@@ -144,8 +146,7 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
|
|
144
146
|
*/
|
145
147
|
getReferencedExports(moduleGraph, runtime) {
|
146
148
|
let ids = this.getIds(moduleGraph);
|
147
|
-
if (ids.length === 0)
|
148
|
-
return this._getReferencedExportsInDestructuring(moduleGraph);
|
149
|
+
if (ids.length === 0) return this._getReferencedExportsInDestructuring();
|
149
150
|
let namespaceObjectAsContext = this.namespaceObjectAsContext;
|
150
151
|
if (ids[0] === "default") {
|
151
152
|
const selfModule = moduleGraph.getParentModule(this);
|
@@ -162,7 +163,7 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
|
|
162
163
|
case "default-only":
|
163
164
|
case "default-with-named":
|
164
165
|
if (ids.length === 1)
|
165
|
-
return this._getReferencedExportsInDestructuring(
|
166
|
+
return this._getReferencedExportsInDestructuring();
|
166
167
|
ids = ids.slice(1);
|
167
168
|
namespaceObjectAsContext = true;
|
168
169
|
break;
|
@@ -180,31 +181,19 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
|
|
180
181
|
ids = ids.slice(0, -1);
|
181
182
|
}
|
182
183
|
|
183
|
-
return this._getReferencedExportsInDestructuring(
|
184
|
+
return this._getReferencedExportsInDestructuring(ids);
|
184
185
|
}
|
185
186
|
|
186
187
|
/**
|
187
|
-
* @param {ModuleGraph} moduleGraph module graph
|
188
188
|
* @param {string[]=} ids ids
|
189
|
-
* @returns {
|
189
|
+
* @returns {string[][]} referenced exports
|
190
190
|
*/
|
191
|
-
_getReferencedExportsInDestructuring(
|
191
|
+
_getReferencedExportsInDestructuring(ids) {
|
192
192
|
if (this.referencedPropertiesInDestructuring) {
|
193
|
-
/** @type {
|
193
|
+
/** @type {string[][]} */
|
194
194
|
const refs = [];
|
195
|
-
const
|
196
|
-
|
197
|
-
Array.isArray(ids) &&
|
198
|
-
ids.length > 0 &&
|
199
|
-
!moduleGraph
|
200
|
-
.getExportsInfo(importedModule)
|
201
|
-
.getExportInfo(ids[0])
|
202
|
-
.isReexport();
|
203
|
-
for (const key of this.referencedPropertiesInDestructuring) {
|
204
|
-
refs.push({
|
205
|
-
name: ids ? ids.concat([key]) : [key],
|
206
|
-
canMangle
|
207
|
-
});
|
195
|
+
for (const { id } of this.referencedPropertiesInDestructuring) {
|
196
|
+
refs.push(ids ? ids.concat([id]) : [id]);
|
208
197
|
}
|
209
198
|
return refs;
|
210
199
|
} else {
|
@@ -336,16 +325,11 @@ HarmonyImportSpecifierDependency.Template = class HarmonyImportSpecifierDependen
|
|
336
325
|
// Skip rendering depending when dependency is conditional
|
337
326
|
if (connection && !connection.isTargetActive(runtime)) return;
|
338
327
|
|
328
|
+
const ids = dep.getIds(moduleGraph);
|
339
329
|
const {
|
340
330
|
trimmedRange: [trimmedRangeStart, trimmedRangeEnd],
|
341
331
|
trimmedIds
|
342
|
-
} = getTrimmedIdsAndRange(
|
343
|
-
dep.getIds(moduleGraph),
|
344
|
-
dep.range,
|
345
|
-
dep.idRanges,
|
346
|
-
moduleGraph,
|
347
|
-
dep
|
348
|
-
);
|
332
|
+
} = getTrimmedIdsAndRange(ids, dep.range, dep.idRanges, moduleGraph, dep);
|
349
333
|
|
350
334
|
const exportExpr = this._getCodeForIds(
|
351
335
|
dep,
|
@@ -358,6 +342,33 @@ HarmonyImportSpecifierDependency.Template = class HarmonyImportSpecifierDependen
|
|
358
342
|
} else {
|
359
343
|
source.replace(trimmedRangeStart, trimmedRangeEnd - 1, exportExpr);
|
360
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
|
+
}
|
361
372
|
}
|
362
373
|
|
363
374
|
/**
|
@@ -16,7 +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").
|
19
|
+
/** @typedef {import("../javascript/JavascriptParser").ImportAttributes} ImportAttributes */
|
20
20
|
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
21
21
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
22
22
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
@@ -27,7 +27,7 @@ class ImportDependency extends ModuleDependency {
|
|
27
27
|
* @param {string} request the request
|
28
28
|
* @param {Range} range expression range
|
29
29
|
* @param {(string[][] | null)=} referencedExports list of referenced exports
|
30
|
-
* @param {
|
30
|
+
* @param {ImportAttributes=} attributes import attributes
|
31
31
|
*/
|
32
32
|
constructor(request, range, referencedExports, attributes) {
|
33
33
|
super(request);
|
@@ -15,7 +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").
|
18
|
+
/** @typedef {import("../javascript/JavascriptParser").ImportAttributes} ImportAttributes */
|
19
19
|
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
20
20
|
|
21
21
|
class ImportEagerDependency extends ImportDependency {
|
@@ -23,7 +23,7 @@ class ImportEagerDependency extends ImportDependency {
|
|
23
23
|
* @param {string} request the request
|
24
24
|
* @param {Range} range expression range
|
25
25
|
* @param {(string[][] | null)=} referencedExports list of referenced exports
|
26
|
-
* @param {
|
26
|
+
* @param {ImportAttributes=} attributes import attributes
|
27
27
|
*/
|
28
28
|
constructor(request, range, referencedExports, attributes) {
|
29
29
|
super(request, range, referencedExports, attributes);
|
@@ -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()},`;
|
@@ -256,7 +256,9 @@ class ImportParserPlugin {
|
|
256
256
|
)
|
257
257
|
);
|
258
258
|
}
|
259
|
-
exports = exportsFromEnumerable(
|
259
|
+
exports = exportsFromEnumerable(
|
260
|
+
[...referencedPropertiesInDestructuring].map(({ id }) => id)
|
261
|
+
);
|
260
262
|
}
|
261
263
|
|
262
264
|
if (param.isString()) {
|
@@ -15,7 +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").
|
18
|
+
/** @typedef {import("../javascript/JavascriptParser").ImportAttributes} ImportAttributes */
|
19
19
|
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
20
20
|
|
21
21
|
class ImportWeakDependency extends ImportDependency {
|
@@ -23,7 +23,7 @@ class ImportWeakDependency extends ImportDependency {
|
|
23
23
|
* @param {string} request the request
|
24
24
|
* @param {Range} range expression range
|
25
25
|
* @param {(string[][] | null)=} referencedExports list of referenced exports
|
26
|
-
* @param {
|
26
|
+
* @param {ImportAttributes=} attributes import attributes
|
27
27
|
*/
|
28
28
|
constructor(request, range, referencedExports, attributes) {
|
29
29
|
super(request, range, referencedExports, attributes);
|
@@ -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
|
|
@@ -11,7 +11,7 @@ const RawModule = require("../RawModule");
|
|
11
11
|
|
12
12
|
/** @typedef {import("../Dependency").TRANSITIVE} TRANSITIVE */
|
13
13
|
/** @typedef {import("../Module")} Module */
|
14
|
-
/** @typedef {import("../javascript/JavascriptParser").
|
14
|
+
/** @typedef {import("../javascript/JavascriptParser").ImportAttributes} ImportAttributes */
|
15
15
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
16
16
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
17
17
|
|
@@ -26,7 +26,7 @@ class ModuleDependency extends Dependency {
|
|
26
26
|
this.range = undefined;
|
27
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
|
}
|
@@ -7,12 +7,13 @@
|
|
7
7
|
|
8
8
|
const { UsageState } = require("../ExportsInfo");
|
9
9
|
const makeSerializable = require("../util/makeSerializable");
|
10
|
-
const { filterRuntime,
|
10
|
+
const { filterRuntime, runtimeToString } = require("../util/runtime");
|
11
11
|
const NullDependency = require("./NullDependency");
|
12
12
|
|
13
13
|
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
14
14
|
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
15
15
|
/** @typedef {import("../Dependency")} Dependency */
|
16
|
+
/** @typedef {import("../Dependency").RuntimeSpec} RuntimeSpec */
|
16
17
|
/** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
|
17
18
|
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
18
19
|
/** @typedef {import("../Module")} Module */
|
@@ -32,7 +33,31 @@ class PureExpressionDependency extends NullDependency {
|
|
32
33
|
this.range = range;
|
33
34
|
/** @type {Set<string> | false} */
|
34
35
|
this.usedByExports = false;
|
35
|
-
|
36
|
+
}
|
37
|
+
|
38
|
+
/**
|
39
|
+
* @param {ModuleGraph} moduleGraph module graph
|
40
|
+
* @param {RuntimeSpec} runtime current runtimes
|
41
|
+
* @returns {boolean | RuntimeSpec} runtime condition
|
42
|
+
*/
|
43
|
+
_getRuntimeCondition(moduleGraph, runtime) {
|
44
|
+
const usedByExports = this.usedByExports;
|
45
|
+
if (usedByExports !== false) {
|
46
|
+
const selfModule =
|
47
|
+
/** @type {Module} */
|
48
|
+
(moduleGraph.getParentModule(this));
|
49
|
+
const exportsInfo = moduleGraph.getExportsInfo(selfModule);
|
50
|
+
const runtimeCondition = filterRuntime(runtime, runtime => {
|
51
|
+
for (const exportName of usedByExports) {
|
52
|
+
if (exportsInfo.getUsed(exportName, runtime) !== UsageState.Unused) {
|
53
|
+
return true;
|
54
|
+
}
|
55
|
+
}
|
56
|
+
return false;
|
57
|
+
});
|
58
|
+
return runtimeCondition;
|
59
|
+
}
|
60
|
+
return false;
|
36
61
|
}
|
37
62
|
|
38
63
|
/**
|
@@ -42,10 +67,22 @@ class PureExpressionDependency extends NullDependency {
|
|
42
67
|
* @returns {void}
|
43
68
|
*/
|
44
69
|
updateHash(hash, context) {
|
45
|
-
|
46
|
-
|
70
|
+
const runtimeCondition = this._getRuntimeCondition(
|
71
|
+
context.chunkGraph.moduleGraph,
|
72
|
+
context.runtime
|
73
|
+
);
|
74
|
+
if (runtimeCondition === true) {
|
75
|
+
return;
|
76
|
+
} else if (runtimeCondition === false) {
|
77
|
+
hash.update("null");
|
78
|
+
} else {
|
79
|
+
hash.update(
|
80
|
+
runtimeToString(runtimeCondition) +
|
81
|
+
"|" +
|
82
|
+
runtimeToString(context.runtime)
|
83
|
+
);
|
47
84
|
}
|
48
|
-
hash.update(this.
|
85
|
+
hash.update(this.range + "");
|
49
86
|
}
|
50
87
|
|
51
88
|
/**
|
@@ -94,54 +131,31 @@ PureExpressionDependency.Template = class PureExpressionDependencyTemplate exten
|
|
94
131
|
apply(
|
95
132
|
dependency,
|
96
133
|
source,
|
97
|
-
{
|
98
|
-
chunkGraph,
|
99
|
-
moduleGraph,
|
100
|
-
runtime,
|
101
|
-
runtimes,
|
102
|
-
runtimeTemplate,
|
103
|
-
runtimeRequirements
|
104
|
-
}
|
134
|
+
{ chunkGraph, moduleGraph, runtime, runtimeTemplate, runtimeRequirements }
|
105
135
|
) {
|
106
136
|
const dep = /** @type {PureExpressionDependency} */ (dependency);
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
137
|
+
const runtimeCondition = dep._getRuntimeCondition(moduleGraph, runtime);
|
138
|
+
if (runtimeCondition === true) {
|
139
|
+
return;
|
140
|
+
} else if (runtimeCondition === false) {
|
141
|
+
source.insert(
|
142
|
+
dep.range[0],
|
143
|
+
`(/* unused pure expression or super */ null && (`
|
144
|
+
);
|
145
|
+
source.insert(dep.range[1], "))");
|
146
|
+
} else {
|
147
|
+
const condition = runtimeTemplate.runtimeConditionExpression({
|
148
|
+
chunkGraph,
|
149
|
+
runtime,
|
150
|
+
runtimeCondition,
|
151
|
+
runtimeRequirements
|
122
152
|
});
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
runtimeCondition,
|
129
|
-
runtimeRequirements
|
130
|
-
});
|
131
|
-
source.insert(
|
132
|
-
dep.range[0],
|
133
|
-
`(/* runtime-dependent pure expression or super */ ${condition} ? (`
|
134
|
-
);
|
135
|
-
source.insert(dep.range[1], ") : null)");
|
136
|
-
return;
|
137
|
-
}
|
153
|
+
source.insert(
|
154
|
+
dep.range[0],
|
155
|
+
`(/* runtime-dependent pure expression or super */ ${condition} ? (`
|
156
|
+
);
|
157
|
+
source.insert(dep.range[1], ") : null)");
|
138
158
|
}
|
139
|
-
|
140
|
-
source.insert(
|
141
|
-
dep.range[0],
|
142
|
-
`(/* unused pure expression or super */ null && (`
|
143
|
-
);
|
144
|
-
source.insert(dep.range[1], "))");
|
145
159
|
}
|
146
160
|
};
|
147
161
|
|
@@ -28,7 +28,7 @@ class WorkerDependency extends ModuleDependency {
|
|
28
28
|
/**
|
29
29
|
* @param {string} request request
|
30
30
|
* @param {Range} range range
|
31
|
-
* @param {
|
31
|
+
* @param {object} workerDependencyOptions options
|
32
32
|
* @param {string=} workerDependencyOptions.publicPath public path for the worker
|
33
33
|
*/
|
34
34
|
constructor(request, range, workerDependencyOptions) {
|