webpack 5.87.0 → 5.88.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/lib/APIPlugin.js +1 -1
- package/lib/AsyncDependenciesBlock.js +3 -3
- package/lib/ChunkGraph.js +4 -4
- package/lib/ChunkGroup.js +9 -3
- package/lib/CompatibilityPlugin.js +50 -30
- package/lib/Compilation.js +2 -1
- package/lib/ContextModule.js +4 -1
- package/lib/ContextReplacementPlugin.js +13 -0
- package/lib/DelegatedModule.js +15 -3
- package/lib/DelegatedModuleFactoryPlugin.js +6 -0
- package/lib/Dependency.js +11 -5
- package/lib/DllEntryPlugin.js +11 -1
- package/lib/DllReferencePlugin.js +13 -1
- package/lib/Entrypoint.js +1 -1
- package/lib/ErrorHelpers.js +1 -0
- package/lib/EvalSourceMapDevToolPlugin.js +4 -0
- package/lib/ExportsInfo.js +17 -3
- package/lib/ExportsInfoApiPlugin.js +14 -5
- package/lib/ExternalModule.js +5 -0
- package/lib/FlagAllModulesAsUsedPlugin.js +6 -1
- package/lib/FlagDependencyUsagePlugin.js +3 -1
- package/lib/HotModuleReplacementPlugin.js +8 -0
- package/lib/InitFragment.js +28 -5
- package/lib/JavascriptMetaInfoPlugin.js +11 -6
- package/lib/LibManifestPlugin.js +20 -4
- package/lib/Module.js +7 -2
- package/lib/ModuleProfile.js +1 -0
- package/lib/ModuleRestoreError.js +2 -0
- package/lib/NodeStuffPlugin.js +32 -6
- package/lib/ProvidePlugin.js +13 -4
- package/lib/RawModule.js +3 -1
- package/lib/RequireJsStuffPlugin.js +7 -0
- package/lib/RuntimeModule.js +3 -3
- package/lib/RuntimePlugin.js +4 -2
- package/lib/RuntimeTemplate.js +2 -2
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +4 -0
- package/lib/SourceMapDevToolPlugin.js +7 -2
- package/lib/UseStrictPlugin.js +10 -3
- package/lib/WebpackIsIncludedPlugin.js +6 -4
- package/lib/asset/AssetGenerator.js +2 -1
- package/lib/asset/AssetParser.js +11 -6
- package/lib/asset/AssetSourceParser.js +8 -3
- package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -0
- package/lib/cache/IdleFileCachePlugin.js +2 -1
- package/lib/cache/PackFileCacheStrategy.js +35 -14
- package/lib/config/browserslistTargetHandler.js +7 -7
- package/lib/config/defaults.js +12 -24
- package/lib/container/RemoteRuntimeModule.js +1 -1
- package/lib/css/CssLoadingRuntimeModule.js +30 -13
- package/lib/css/CssParser.js +11 -1
- package/lib/dependencies/AMDDefineDependency.js +34 -4
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +5 -0
- package/lib/dependencies/AMDRuntimeModules.js +2 -2
- package/lib/dependencies/CommonJsExportsParserPlugin.js +14 -4
- package/lib/dependencies/CommonJsImportsParserPlugin.js +169 -59
- package/lib/dependencies/CommonJsPlugin.js +13 -8
- package/lib/dependencies/CommonJsRequireContextDependency.js +2 -2
- package/lib/dependencies/ContextDependency.js +7 -2
- package/lib/dependencies/CssImportDependency.js +1 -1
- package/lib/dependencies/CssLocalIdentifierDependency.js +5 -0
- package/lib/dependencies/CssUrlDependency.js +3 -3
- package/lib/dependencies/DllEntryDependency.js +5 -0
- package/lib/dependencies/DynamicExports.js +10 -6
- package/lib/dependencies/ExportsInfoDependency.js +14 -4
- package/lib/dependencies/HarmonyCompatibilityDependency.js +2 -1
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +3 -1
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +12 -5
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +2 -0
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +4 -4
- package/lib/dependencies/HarmonyExports.js +9 -5
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +32 -17
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +1 -2
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +19 -9
- package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -3
- package/lib/dependencies/ImportDependency.js +5 -3
- package/lib/dependencies/ImportEagerDependency.js +5 -3
- package/lib/dependencies/ImportMetaPlugin.js +31 -15
- package/lib/dependencies/ImportParserPlugin.js +38 -25
- package/lib/dependencies/ImportWeakDependency.js +5 -3
- package/lib/dependencies/ModuleDependency.js +1 -1
- package/lib/dependencies/ModuleDependencyTemplateAsId.js +2 -1
- package/lib/dependencies/ProvidedDependency.js +4 -1
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +13 -5
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +5 -2
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +6 -1
- package/lib/dependencies/RequireHeaderDependency.js +4 -0
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +26 -5
- package/lib/dependencies/RequireResolveHeaderDependency.js +9 -0
- package/lib/dependencies/SystemPlugin.js +17 -5
- package/lib/dependencies/SystemRuntimeModule.js +1 -1
- package/lib/dependencies/URLDependency.js +2 -2
- package/lib/dependencies/URLPlugin.js +9 -4
- package/lib/dependencies/WebAssemblyImportDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +59 -22
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -1
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
- package/lib/ids/HashedModuleIdsPlugin.js +1 -1
- package/lib/javascript/JavascriptParser.js +17 -5
- package/lib/logging/runtime.js +1 -1
- package/lib/logging/truncateArgs.js +4 -0
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +10 -6
- package/lib/node/RequireChunkLoadingRuntimeModule.js +10 -6
- package/lib/optimize/InnerGraph.js +1 -1
- package/lib/optimize/InnerGraphPlugin.js +2 -1
- package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +1 -1
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +1 -1
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +1 -1
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +1 -1
- package/lib/runtime/AsyncModuleRuntimeModule.js +4 -4
- package/lib/runtime/AutoPublicPathRuntimeModule.js +1 -1
- package/lib/runtime/BaseUriRuntimeModule.js +1 -1
- package/lib/runtime/ChunkNameRuntimeModule.js +1 -1
- package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +1 -1
- package/lib/runtime/CompatRuntimeModule.js +1 -1
- package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +1 -1
- package/lib/runtime/CreateScriptRuntimeModule.js +1 -1
- package/lib/runtime/CreateScriptUrlRuntimeModule.js +1 -1
- package/lib/runtime/DefinePropertyGettersRuntimeModule.js +1 -1
- package/lib/runtime/EnsureChunkRuntimeModule.js +1 -1
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +1 -1
- package/lib/runtime/GetFullHashRuntimeModule.js +1 -1
- package/lib/runtime/GetMainFilenameRuntimeModule.js +1 -1
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -1
- package/lib/runtime/GlobalRuntimeModule.js +1 -1
- package/lib/runtime/HasOwnPropertyRuntimeModule.js +1 -1
- package/lib/runtime/LoadScriptRuntimeModule.js +1 -1
- package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +1 -1
- package/lib/runtime/NonceRuntimeModule.js +1 -1
- package/lib/runtime/OnChunksLoadedRuntimeModule.js +1 -1
- package/lib/runtime/PublicPathRuntimeModule.js +1 -1
- package/lib/runtime/RelativeUrlRuntimeModule.js +1 -1
- package/lib/runtime/RuntimeIdRuntimeModule.js +1 -1
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -1
- package/lib/runtime/StartupEntrypointRuntimeModule.js +1 -1
- package/lib/runtime/SystemContextRuntimeModule.js +1 -1
- package/lib/sharing/ConsumeSharedRuntimeModule.js +1 -1
- package/lib/sharing/ShareRuntimeModule.js +1 -1
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +1 -1
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +1 -1
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -1
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +1 -1
- package/package.json +2 -1
- package/types.d.ts +86 -38
@@ -26,8 +26,10 @@ const ConstDependency = require("./ConstDependency");
|
|
26
26
|
/** @typedef {import("estree").MemberExpression} MemberExpression */
|
27
27
|
/** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
|
28
28
|
/** @typedef {import("../Compiler")} Compiler */
|
29
|
+
/** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
|
29
30
|
/** @typedef {import("../NormalModule")} NormalModule */
|
30
31
|
/** @typedef {import("../javascript/JavascriptParser")} Parser */
|
32
|
+
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
31
33
|
|
32
34
|
const getCriticalDependencyWarning = memoize(() =>
|
33
35
|
require("./CriticalDependencyWarning")
|
@@ -64,10 +66,10 @@ class ImportMetaPlugin {
|
|
64
66
|
.for("import.meta")
|
65
67
|
.tap(PLUGIN_NAME, metaProperty => {
|
66
68
|
const dep = new ConstDependency(
|
67
|
-
importMetaName,
|
68
|
-
metaProperty.range
|
69
|
+
/** @type {string} */ (importMetaName),
|
70
|
+
/** @type {Range} */ (metaProperty.range)
|
69
71
|
);
|
70
|
-
dep.loc = metaProperty.loc;
|
72
|
+
dep.loc = /** @type {DependencyLocation} */ (metaProperty.loc);
|
71
73
|
parser.state.module.addPresentationalDependency(dep);
|
72
74
|
return true;
|
73
75
|
});
|
@@ -82,6 +84,10 @@ class ImportMetaPlugin {
|
|
82
84
|
const importMetaUrl = () =>
|
83
85
|
JSON.stringify(getUrl(parser.state.module));
|
84
86
|
const importMetaWebpackVersion = () => JSON.stringify(webpackVersion);
|
87
|
+
/**
|
88
|
+
* @param {string[]} members members
|
89
|
+
* @returns {string} error message
|
90
|
+
*/
|
85
91
|
const importMetaUnknownProperty = members =>
|
86
92
|
`${Template.toNormalComment(
|
87
93
|
"unsupported import.meta." + members.join(".")
|
@@ -106,16 +112,20 @@ class ImportMetaPlugin {
|
|
106
112
|
new CriticalDependencyWarning(
|
107
113
|
"Accessing import.meta directly is unsupported (only property access or destructuring is supported)"
|
108
114
|
),
|
109
|
-
metaProperty.loc
|
115
|
+
/** @type {DependencyLocation} */ (metaProperty.loc)
|
110
116
|
)
|
111
117
|
);
|
112
118
|
const dep = new ConstDependency(
|
113
119
|
`${
|
114
|
-
parser.isAsiPosition(
|
120
|
+
parser.isAsiPosition(
|
121
|
+
/** @type {Range} */ (metaProperty.range)[0]
|
122
|
+
)
|
123
|
+
? ";"
|
124
|
+
: ""
|
115
125
|
}({})`,
|
116
|
-
metaProperty.range
|
126
|
+
/** @type {Range} */ (metaProperty.range)
|
117
127
|
);
|
118
|
-
dep.loc = metaProperty.loc;
|
128
|
+
dep.loc = /** @type {DependencyLocation} */ (metaProperty.loc);
|
119
129
|
parser.state.module.addPresentationalDependency(dep);
|
120
130
|
return true;
|
121
131
|
}
|
@@ -136,8 +146,11 @@ class ImportMetaPlugin {
|
|
136
146
|
break;
|
137
147
|
}
|
138
148
|
}
|
139
|
-
const dep = new ConstDependency(
|
140
|
-
|
149
|
+
const dep = new ConstDependency(
|
150
|
+
`({${str}})`,
|
151
|
+
/** @type {Range} */ (metaProperty.range)
|
152
|
+
);
|
153
|
+
dep.loc = /** @type {DependencyLocation} */ (metaProperty.loc);
|
141
154
|
parser.state.module.addPresentationalDependency(dep);
|
142
155
|
return true;
|
143
156
|
});
|
@@ -159,8 +172,11 @@ class ImportMetaPlugin {
|
|
159
172
|
parser.hooks.expression
|
160
173
|
.for("import.meta.url")
|
161
174
|
.tap(PLUGIN_NAME, expr => {
|
162
|
-
const dep = new ConstDependency(
|
163
|
-
|
175
|
+
const dep = new ConstDependency(
|
176
|
+
importMetaUrl(),
|
177
|
+
/** @type {Range} */ (expr.range)
|
178
|
+
);
|
179
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
164
180
|
parser.state.module.addPresentationalDependency(dep);
|
165
181
|
return true;
|
166
182
|
});
|
@@ -172,7 +188,7 @@ class ImportMetaPlugin {
|
|
172
188
|
.tap(PLUGIN_NAME, expr => {
|
173
189
|
return new BasicEvaluatedExpression()
|
174
190
|
.setString(getUrl(parser.state.module))
|
175
|
-
.setRange(expr.range);
|
191
|
+
.setRange(/** @type {Range} */ (expr.range));
|
176
192
|
});
|
177
193
|
|
178
194
|
/// import.meta.webpack ///
|
@@ -201,9 +217,9 @@ class ImportMetaPlugin {
|
|
201
217
|
.tap(PLUGIN_NAME, (expr, members) => {
|
202
218
|
const dep = new ConstDependency(
|
203
219
|
importMetaUnknownProperty(members),
|
204
|
-
expr.range
|
220
|
+
/** @type {Range} */ (expr.range)
|
205
221
|
);
|
206
|
-
dep.loc = expr.loc;
|
222
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
207
223
|
parser.state.module.addPresentationalDependency(dep);
|
208
224
|
return true;
|
209
225
|
});
|
@@ -220,7 +236,7 @@ class ImportMetaPlugin {
|
|
220
236
|
) {
|
221
237
|
return new BasicEvaluatedExpression()
|
222
238
|
.setUndefined()
|
223
|
-
.setRange(expr.range);
|
239
|
+
.setRange(/** @type {Range} */ (expr.range));
|
224
240
|
}
|
225
241
|
});
|
226
242
|
};
|
@@ -17,7 +17,10 @@ const ImportWeakDependency = require("./ImportWeakDependency");
|
|
17
17
|
/** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
|
18
18
|
/** @typedef {import("../ChunkGroup").RawChunkGroupOptions} RawChunkGroupOptions */
|
19
19
|
/** @typedef {import("../ContextModule").ContextMode} ContextMode */
|
20
|
+
/** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
|
21
|
+
/** @typedef {import("../Module").BuildMeta} BuildMeta */
|
20
22
|
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
|
23
|
+
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
21
24
|
|
22
25
|
class ImportParserPlugin {
|
23
26
|
/**
|
@@ -32,14 +35,18 @@ class ImportParserPlugin {
|
|
32
35
|
* @returns {void}
|
33
36
|
*/
|
34
37
|
apply(parser) {
|
38
|
+
/**
|
39
|
+
* @template T
|
40
|
+
* @param {Iterable<T>} enumerable enumerable
|
41
|
+
* @returns {T[][]} array of array
|
42
|
+
*/
|
35
43
|
const exportsFromEnumerable = enumerable =>
|
36
44
|
Array.from(enumerable, e => [e]);
|
37
45
|
parser.hooks.importCall.tap("ImportParserPlugin", expr => {
|
38
46
|
const param = parser.evaluateExpression(expr.source);
|
39
47
|
|
40
48
|
let chunkName = null;
|
41
|
-
/** @type {ContextMode} */
|
42
|
-
let mode = this.options.dynamicImportMode;
|
49
|
+
let mode = /** @type {ContextMode} */ (this.options.dynamicImportMode);
|
43
50
|
let include = null;
|
44
51
|
let exclude = null;
|
45
52
|
/** @type {string[][] | null} */
|
@@ -68,7 +75,7 @@ class ImportParserPlugin {
|
|
68
75
|
groupOptions.fetchPriority = dynamicImportFetchPriority;
|
69
76
|
|
70
77
|
const { options: importOptions, errors: commentErrors } =
|
71
|
-
parser.parseCommentOptions(expr.range);
|
78
|
+
parser.parseCommentOptions(/** @type {Range} */ (expr.range));
|
72
79
|
|
73
80
|
if (commentErrors) {
|
74
81
|
for (const e of commentErrors) {
|
@@ -88,7 +95,7 @@ class ImportParserPlugin {
|
|
88
95
|
parser.state.module.addWarning(
|
89
96
|
new UnsupportedFeatureWarning(
|
90
97
|
`\`webpackIgnore\` expected a boolean, but received: ${importOptions.webpackIgnore}.`,
|
91
|
-
expr.loc
|
98
|
+
/** @type {DependencyLocation} */ (expr.loc)
|
92
99
|
)
|
93
100
|
);
|
94
101
|
} else {
|
@@ -103,7 +110,7 @@ class ImportParserPlugin {
|
|
103
110
|
parser.state.module.addWarning(
|
104
111
|
new UnsupportedFeatureWarning(
|
105
112
|
`\`webpackChunkName\` expected a string, but received: ${importOptions.webpackChunkName}.`,
|
106
|
-
expr.loc
|
113
|
+
/** @type {DependencyLocation} */ (expr.loc)
|
107
114
|
)
|
108
115
|
);
|
109
116
|
} else {
|
@@ -115,7 +122,7 @@ class ImportParserPlugin {
|
|
115
122
|
parser.state.module.addWarning(
|
116
123
|
new UnsupportedFeatureWarning(
|
117
124
|
`\`webpackMode\` expected a string, but received: ${importOptions.webpackMode}.`,
|
118
|
-
expr.loc
|
125
|
+
/** @type {DependencyLocation} */ (expr.loc)
|
119
126
|
)
|
120
127
|
);
|
121
128
|
} else {
|
@@ -131,7 +138,7 @@ class ImportParserPlugin {
|
|
131
138
|
parser.state.module.addWarning(
|
132
139
|
new UnsupportedFeatureWarning(
|
133
140
|
`\`webpackPrefetch\` expected true or a number, but received: ${importOptions.webpackPrefetch}.`,
|
134
|
-
expr.loc
|
141
|
+
/** @type {DependencyLocation} */ (expr.loc)
|
135
142
|
)
|
136
143
|
);
|
137
144
|
}
|
@@ -145,7 +152,7 @@ class ImportParserPlugin {
|
|
145
152
|
parser.state.module.addWarning(
|
146
153
|
new UnsupportedFeatureWarning(
|
147
154
|
`\`webpackPreload\` expected true or a number, but received: ${importOptions.webpackPreload}.`,
|
148
|
-
expr.loc
|
155
|
+
/** @type {DependencyLocation} */ (expr.loc)
|
149
156
|
)
|
150
157
|
);
|
151
158
|
}
|
@@ -160,7 +167,7 @@ class ImportParserPlugin {
|
|
160
167
|
parser.state.module.addWarning(
|
161
168
|
new UnsupportedFeatureWarning(
|
162
169
|
`\`webpackFetchPriority\` expected true or "low", "high" or "auto", but received: ${importOptions.webpackFetchPriority}.`,
|
163
|
-
expr.loc
|
170
|
+
/** @type {DependencyLocation} */ (expr.loc)
|
164
171
|
)
|
165
172
|
);
|
166
173
|
}
|
@@ -173,7 +180,7 @@ class ImportParserPlugin {
|
|
173
180
|
parser.state.module.addWarning(
|
174
181
|
new UnsupportedFeatureWarning(
|
175
182
|
`\`webpackInclude\` expected a regular expression, but received: ${importOptions.webpackInclude}.`,
|
176
|
-
expr.loc
|
183
|
+
/** @type {DependencyLocation} */ (expr.loc)
|
177
184
|
)
|
178
185
|
);
|
179
186
|
} else {
|
@@ -188,7 +195,7 @@ class ImportParserPlugin {
|
|
188
195
|
parser.state.module.addWarning(
|
189
196
|
new UnsupportedFeatureWarning(
|
190
197
|
`\`webpackExclude\` expected a regular expression, but received: ${importOptions.webpackExclude}.`,
|
191
|
-
expr.loc
|
198
|
+
/** @type {DependencyLocation} */ (expr.loc)
|
192
199
|
)
|
193
200
|
);
|
194
201
|
} else {
|
@@ -200,7 +207,7 @@ class ImportParserPlugin {
|
|
200
207
|
!(
|
201
208
|
typeof importOptions.webpackExports === "string" ||
|
202
209
|
(Array.isArray(importOptions.webpackExports) &&
|
203
|
-
importOptions.webpackExports.every(
|
210
|
+
/** @type {string[]} */ (importOptions.webpackExports).every(
|
204
211
|
item => typeof item === "string"
|
205
212
|
))
|
206
213
|
)
|
@@ -208,7 +215,7 @@ class ImportParserPlugin {
|
|
208
215
|
parser.state.module.addWarning(
|
209
216
|
new UnsupportedFeatureWarning(
|
210
217
|
`\`webpackExports\` expected a string or an array of strings, but received: ${importOptions.webpackExports}.`,
|
211
|
-
expr.loc
|
218
|
+
/** @type {DependencyLocation} */ (expr.loc)
|
212
219
|
)
|
213
220
|
);
|
214
221
|
} else {
|
@@ -230,7 +237,7 @@ class ImportParserPlugin {
|
|
230
237
|
parser.state.module.addWarning(
|
231
238
|
new UnsupportedFeatureWarning(
|
232
239
|
`\`webpackMode\` expected 'lazy', 'lazy-once', 'eager' or 'weak', but received: ${mode}.`,
|
233
|
-
expr.loc
|
240
|
+
/** @type {DependencyLocation} */ (expr.loc)
|
234
241
|
)
|
235
242
|
);
|
236
243
|
mode = "lazy";
|
@@ -243,7 +250,7 @@ class ImportParserPlugin {
|
|
243
250
|
parser.state.module.addWarning(
|
244
251
|
new UnsupportedFeatureWarning(
|
245
252
|
`\`webpackExports\` could not be used with destructuring assignment.`,
|
246
|
-
expr.loc
|
253
|
+
/** @type {DependencyLocation} */ (expr.loc)
|
247
254
|
)
|
248
255
|
);
|
249
256
|
}
|
@@ -253,15 +260,15 @@ class ImportParserPlugin {
|
|
253
260
|
if (param.isString()) {
|
254
261
|
if (mode === "eager") {
|
255
262
|
const dep = new ImportEagerDependency(
|
256
|
-
param.string,
|
257
|
-
expr.range,
|
263
|
+
/** @type {string} */ (param.string),
|
264
|
+
/** @type {Range} */ (expr.range),
|
258
265
|
exports
|
259
266
|
);
|
260
267
|
parser.state.current.addDependency(dep);
|
261
268
|
} else if (mode === "weak") {
|
262
269
|
const dep = new ImportWeakDependency(
|
263
|
-
param.string,
|
264
|
-
expr.range,
|
270
|
+
/** @type {string} */ (param.string),
|
271
|
+
/** @type {Range} */ (expr.range),
|
265
272
|
exports
|
266
273
|
);
|
267
274
|
parser.state.current.addDependency(dep);
|
@@ -271,11 +278,15 @@ class ImportParserPlugin {
|
|
271
278
|
...groupOptions,
|
272
279
|
name: chunkName
|
273
280
|
},
|
274
|
-
expr.loc,
|
281
|
+
/** @type {DependencyLocation} */ (expr.loc),
|
275
282
|
param.string
|
276
283
|
);
|
277
|
-
const dep = new ImportDependency(
|
278
|
-
|
284
|
+
const dep = new ImportDependency(
|
285
|
+
/** @type {string} */ (param.string),
|
286
|
+
/** @type {Range} */ (expr.range),
|
287
|
+
exports
|
288
|
+
);
|
289
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
279
290
|
depBlock.addDependency(dep);
|
280
291
|
parser.state.current.addBlock(depBlock);
|
281
292
|
}
|
@@ -286,7 +297,7 @@ class ImportParserPlugin {
|
|
286
297
|
}
|
287
298
|
const dep = ContextDependencyHelpers.create(
|
288
299
|
ImportContextDependency,
|
289
|
-
expr.range,
|
300
|
+
/** @type {Range} */ (expr.range),
|
290
301
|
param,
|
291
302
|
expr,
|
292
303
|
this.options,
|
@@ -296,7 +307,9 @@ class ImportParserPlugin {
|
|
296
307
|
include,
|
297
308
|
exclude,
|
298
309
|
mode,
|
299
|
-
namespaceObject:
|
310
|
+
namespaceObject: /** @type {BuildMeta} */ (
|
311
|
+
parser.state.module.buildMeta
|
312
|
+
).strictHarmonyModule
|
300
313
|
? "strict"
|
301
314
|
: true,
|
302
315
|
typePrefix: "import()",
|
@@ -306,7 +319,7 @@ class ImportParserPlugin {
|
|
306
319
|
parser
|
307
320
|
);
|
308
321
|
if (!dep) return;
|
309
|
-
dep.loc = expr.loc;
|
322
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
310
323
|
dep.optional = !!parser.scope.inTry;
|
311
324
|
parser.state.current.addDependency(dep);
|
312
325
|
return true;
|
@@ -12,6 +12,8 @@ const ImportDependency = require("./ImportDependency");
|
|
12
12
|
/** @typedef {import("../Dependency")} Dependency */
|
13
13
|
/** @typedef {import("../Dependency").ReferencedExport} ReferencedExport */
|
14
14
|
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
15
|
+
/** @typedef {import("../Module")} Module */
|
16
|
+
/** @typedef {import("../Module").BuildMeta} BuildMeta */
|
15
17
|
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
16
18
|
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
17
19
|
|
@@ -19,7 +21,7 @@ class ImportWeakDependency extends ImportDependency {
|
|
19
21
|
/**
|
20
22
|
* @param {string} request the request
|
21
23
|
* @param {Range} range expression range
|
22
|
-
* @param {string[][]=} referencedExports list of referenced exports
|
24
|
+
* @param {(string[][] | null)=} referencedExports list of referenced exports
|
23
25
|
*/
|
24
26
|
constructor(request, range, referencedExports) {
|
25
27
|
super(request, range, referencedExports);
|
@@ -53,9 +55,9 @@ ImportWeakDependency.Template = class ImportDependencyTemplate extends (
|
|
53
55
|
const dep = /** @type {ImportWeakDependency} */ (dependency);
|
54
56
|
const content = runtimeTemplate.moduleNamespacePromise({
|
55
57
|
chunkGraph,
|
56
|
-
module: moduleGraph.getModule(dep),
|
58
|
+
module: /** @type {Module} */ (moduleGraph.getModule(dep)),
|
57
59
|
request: dep.request,
|
58
|
-
strict: module.buildMeta.strictHarmonyModule,
|
60
|
+
strict: /** @type {BuildMeta} */ (module.buildMeta).strictHarmonyModule,
|
59
61
|
message: "import() weak",
|
60
62
|
weak: true,
|
61
63
|
runtimeRequirements
|
@@ -10,6 +10,7 @@ const ModuleDependency = require("./ModuleDependency");
|
|
10
10
|
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
11
11
|
/** @typedef {import("../Dependency")} Dependency */
|
12
12
|
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
13
|
+
/** @typedef {import("../Module")} Module */
|
13
14
|
|
14
15
|
class ModuleDependencyTemplateAsId extends ModuleDependency.Template {
|
15
16
|
/**
|
@@ -22,7 +23,7 @@ class ModuleDependencyTemplateAsId extends ModuleDependency.Template {
|
|
22
23
|
const dep = /** @type {ModuleDependency} */ (dependency);
|
23
24
|
if (!dep.range) return;
|
24
25
|
const content = runtimeTemplate.moduleId({
|
25
|
-
module: moduleGraph.getModule(dep),
|
26
|
+
module: /** @type {Module} */ (moduleGraph.getModule(dep)),
|
26
27
|
chunkGraph,
|
27
28
|
request: dep.request,
|
28
29
|
weak: dep.weak
|
@@ -17,6 +17,7 @@ const ModuleDependency = require("./ModuleDependency");
|
|
17
17
|
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
18
18
|
/** @typedef {import("../DependencyTemplates")} DependencyTemplates */
|
19
19
|
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
20
|
+
/** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
|
20
21
|
/** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
|
21
22
|
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
22
23
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
@@ -127,7 +128,9 @@ class ProvidedDependencyTemplate extends ModuleDependency.Template {
|
|
127
128
|
}
|
128
129
|
) {
|
129
130
|
const dep = /** @type {ProvidedDependency} */ (dependency);
|
130
|
-
const connection =
|
131
|
+
const connection =
|
132
|
+
/** @type {ModuleGraphConnection} */
|
133
|
+
(moduleGraph.getConnection(dep));
|
131
134
|
const exportsInfo = moduleGraph.getExportsInfo(connection.module);
|
132
135
|
const usedName = exportsInfo.getUsedName(dep.ids, runtime);
|
133
136
|
initFragments.push(
|
@@ -7,7 +7,15 @@
|
|
7
7
|
|
8
8
|
const RequireContextDependency = require("./RequireContextDependency");
|
9
9
|
|
10
|
+
/** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
|
11
|
+
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
|
12
|
+
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
13
|
+
|
10
14
|
module.exports = class RequireContextDependencyParserPlugin {
|
15
|
+
/**
|
16
|
+
* @param {JavascriptParser} parser the parser
|
17
|
+
* @returns {void}
|
18
|
+
*/
|
11
19
|
apply(parser) {
|
12
20
|
parser.hooks.call
|
13
21
|
.for("require.context")
|
@@ -19,19 +27,19 @@ module.exports = class RequireContextDependencyParserPlugin {
|
|
19
27
|
case 4: {
|
20
28
|
const modeExpr = parser.evaluateExpression(expr.arguments[3]);
|
21
29
|
if (!modeExpr.isString()) return;
|
22
|
-
mode = modeExpr.string;
|
30
|
+
mode = /** @type {string} */ (modeExpr.string);
|
23
31
|
}
|
24
32
|
// falls through
|
25
33
|
case 3: {
|
26
34
|
const regExpExpr = parser.evaluateExpression(expr.arguments[2]);
|
27
35
|
if (!regExpExpr.isRegExp()) return;
|
28
|
-
regExp = regExpExpr.regExp;
|
36
|
+
regExp = /** @type {RegExp} */ (regExpExpr.regExp);
|
29
37
|
}
|
30
38
|
// falls through
|
31
39
|
case 2: {
|
32
40
|
const recursiveExpr = parser.evaluateExpression(expr.arguments[1]);
|
33
41
|
if (!recursiveExpr.isBoolean()) return;
|
34
|
-
recursive = recursiveExpr.bool;
|
42
|
+
recursive = /** @type {boolean} */ (recursiveExpr.bool);
|
35
43
|
}
|
36
44
|
// falls through
|
37
45
|
case 1: {
|
@@ -45,9 +53,9 @@ module.exports = class RequireContextDependencyParserPlugin {
|
|
45
53
|
mode,
|
46
54
|
category: "commonjs"
|
47
55
|
},
|
48
|
-
expr.range
|
56
|
+
/** @type {Range} */ (expr.range)
|
49
57
|
);
|
50
|
-
dep.loc = expr.loc;
|
58
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
51
59
|
dep.optional = !!parser.scope.inTry;
|
52
60
|
parser.state.current.addDependency(dep);
|
53
61
|
return true;
|
@@ -8,10 +8,13 @@
|
|
8
8
|
const AsyncDependenciesBlock = require("../AsyncDependenciesBlock");
|
9
9
|
const makeSerializable = require("../util/makeSerializable");
|
10
10
|
|
11
|
+
/** @typedef {import("../ChunkGroup").ChunkGroupOptions} ChunkGroupOptions */
|
12
|
+
/** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
|
13
|
+
|
11
14
|
class RequireEnsureDependenciesBlock extends AsyncDependenciesBlock {
|
12
15
|
/**
|
13
|
-
* @param {TODO} chunkName chunk name
|
14
|
-
* @param {
|
16
|
+
* @param {ChunkGroupOptions & { entryOptions?: TODO }} chunkName chunk name
|
17
|
+
* @param {DependencyLocation} loc location info
|
15
18
|
*/
|
16
19
|
constructor(chunkName, loc) {
|
17
20
|
super(chunkName, loc, null);
|
@@ -10,6 +10,9 @@ const RequireEnsureDependency = require("./RequireEnsureDependency");
|
|
10
10
|
const RequireEnsureItemDependency = require("./RequireEnsureItemDependency");
|
11
11
|
const getFunctionExpression = require("./getFunctionExpression");
|
12
12
|
|
13
|
+
/** @typedef {import("../ChunkGroup").ChunkGroupOptions} ChunkGroupOptions */
|
14
|
+
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
|
15
|
+
|
13
16
|
module.exports = class RequireEnsureDependenciesBlockParserPlugin {
|
14
17
|
apply(parser) {
|
15
18
|
parser.hooks.call
|
@@ -57,7 +60,9 @@ module.exports = class RequireEnsureDependenciesBlockParserPlugin {
|
|
57
60
|
}
|
58
61
|
|
59
62
|
const depBlock = new RequireEnsureDependenciesBlock(
|
60
|
-
|
63
|
+
/** @type {ChunkGroupOptions & { entryOptions?: TODO }} */ (
|
64
|
+
chunkName
|
65
|
+
),
|
61
66
|
expr.loc
|
62
67
|
);
|
63
68
|
const errorCallbackExists =
|
@@ -35,6 +35,10 @@ class RequireHeaderDependency extends NullDependency {
|
|
35
35
|
super.serialize(context);
|
36
36
|
}
|
37
37
|
|
38
|
+
/**
|
39
|
+
* @param {ObjectDeserializerContext} context context
|
40
|
+
* @returns {RequireHeaderDependency} RequireHeaderDependency
|
41
|
+
*/
|
38
42
|
static deserialize(context) {
|
39
43
|
const obj = new RequireHeaderDependency(context.read());
|
40
44
|
obj.deserialize(context);
|
@@ -13,6 +13,10 @@ const {
|
|
13
13
|
const makeSerializable = require("../util/makeSerializable");
|
14
14
|
const RequireIncludeDependency = require("./RequireIncludeDependency");
|
15
15
|
|
16
|
+
/** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
|
17
|
+
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
|
18
|
+
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
19
|
+
|
16
20
|
module.exports = class RequireIncludeDependencyParserPlugin {
|
17
21
|
/**
|
18
22
|
* @param {boolean} warn true: warn about deprecation, false: don't warn
|
@@ -20,6 +24,11 @@ module.exports = class RequireIncludeDependencyParserPlugin {
|
|
20
24
|
constructor(warn) {
|
21
25
|
this.warn = warn;
|
22
26
|
}
|
27
|
+
|
28
|
+
/**
|
29
|
+
* @param {JavascriptParser} parser the parser
|
30
|
+
* @returns {void}
|
31
|
+
*/
|
23
32
|
apply(parser) {
|
24
33
|
const { warn } = this;
|
25
34
|
parser.hooks.call
|
@@ -31,12 +40,17 @@ module.exports = class RequireIncludeDependencyParserPlugin {
|
|
31
40
|
|
32
41
|
if (warn) {
|
33
42
|
parser.state.module.addWarning(
|
34
|
-
new RequireIncludeDeprecationWarning(
|
43
|
+
new RequireIncludeDeprecationWarning(
|
44
|
+
/** @type {DependencyLocation} */ (expr.loc)
|
45
|
+
)
|
35
46
|
);
|
36
47
|
}
|
37
48
|
|
38
|
-
const dep = new RequireIncludeDependency(
|
39
|
-
|
49
|
+
const dep = new RequireIncludeDependency(
|
50
|
+
/** @type {string} */ (param.string),
|
51
|
+
/** @type {Range} */ (expr.range)
|
52
|
+
);
|
53
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
40
54
|
parser.state.current.addDependency(dep);
|
41
55
|
return true;
|
42
56
|
});
|
@@ -45,7 +59,9 @@ module.exports = class RequireIncludeDependencyParserPlugin {
|
|
45
59
|
.tap("RequireIncludePlugin", expr => {
|
46
60
|
if (warn) {
|
47
61
|
parser.state.module.addWarning(
|
48
|
-
new RequireIncludeDeprecationWarning(
|
62
|
+
new RequireIncludeDeprecationWarning(
|
63
|
+
/** @type {DependencyLocation} */ (expr.loc)
|
64
|
+
)
|
49
65
|
);
|
50
66
|
}
|
51
67
|
return evaluateToString("function")(expr);
|
@@ -55,7 +71,9 @@ module.exports = class RequireIncludeDependencyParserPlugin {
|
|
55
71
|
.tap("RequireIncludePlugin", expr => {
|
56
72
|
if (warn) {
|
57
73
|
parser.state.module.addWarning(
|
58
|
-
new RequireIncludeDeprecationWarning(
|
74
|
+
new RequireIncludeDeprecationWarning(
|
75
|
+
/** @type {DependencyLocation} */ (expr.loc)
|
76
|
+
)
|
59
77
|
);
|
60
78
|
}
|
61
79
|
return toConstantDependency(parser, JSON.stringify("function"))(expr);
|
@@ -64,6 +82,9 @@ module.exports = class RequireIncludeDependencyParserPlugin {
|
|
64
82
|
};
|
65
83
|
|
66
84
|
class RequireIncludeDeprecationWarning extends WebpackError {
|
85
|
+
/**
|
86
|
+
* @param {DependencyLocation} loc location
|
87
|
+
*/
|
67
88
|
constructor(loc) {
|
68
89
|
super("require.include() is deprecated and will be removed soon.");
|
69
90
|
|
@@ -38,6 +38,10 @@ class RequireResolveHeaderDependency extends NullDependency {
|
|
38
38
|
super.serialize(context);
|
39
39
|
}
|
40
40
|
|
41
|
+
/**
|
42
|
+
* @param {ObjectDeserializerContext} context context
|
43
|
+
* @returns {RequireResolveHeaderDependency} RequireResolveHeaderDependency
|
44
|
+
*/
|
41
45
|
static deserialize(context) {
|
42
46
|
const obj = new RequireResolveHeaderDependency(context.read());
|
43
47
|
obj.deserialize(context);
|
@@ -64,6 +68,11 @@ RequireResolveHeaderDependency.Template = class RequireResolveHeaderDependencyTe
|
|
64
68
|
source.replace(dep.range[0], dep.range[1] - 1, "/*require.resolve*/");
|
65
69
|
}
|
66
70
|
|
71
|
+
/**
|
72
|
+
* @param {string} name name
|
73
|
+
* @param {RequireResolveHeaderDependency} dep dependency
|
74
|
+
* @param {ReplaceSource} source source
|
75
|
+
*/
|
67
76
|
applyAsTemplateArgument(name, dep, source) {
|
68
77
|
source.replace(dep.range[0], dep.range[1] - 1, "/*require.resolve*/");
|
69
78
|
}
|
@@ -22,7 +22,9 @@ const SystemRuntimeModule = require("./SystemRuntimeModule");
|
|
22
22
|
|
23
23
|
/** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
|
24
24
|
/** @typedef {import("../Compiler")} Compiler */
|
25
|
+
/** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
|
25
26
|
/** @typedef {import("../javascript/JavascriptParser")} Parser */
|
27
|
+
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
26
28
|
|
27
29
|
const PLUGIN_NAME = "SystemPlugin";
|
28
30
|
|
@@ -58,6 +60,9 @@ class SystemPlugin {
|
|
58
60
|
return;
|
59
61
|
}
|
60
62
|
|
63
|
+
/**
|
64
|
+
* @param {string} name name
|
65
|
+
*/
|
61
66
|
const setNotSupported = name => {
|
62
67
|
parser.hooks.evaluateTypeof
|
63
68
|
.for(name)
|
@@ -97,17 +102,21 @@ class SystemPlugin {
|
|
97
102
|
setNotSupported("System.register");
|
98
103
|
|
99
104
|
parser.hooks.expression.for("System").tap(PLUGIN_NAME, expr => {
|
100
|
-
const dep = new ConstDependency(
|
101
|
-
RuntimeGlobals.system
|
102
|
-
|
103
|
-
|
105
|
+
const dep = new ConstDependency(
|
106
|
+
RuntimeGlobals.system,
|
107
|
+
/** @type {Range} */ (expr.range),
|
108
|
+
[RuntimeGlobals.system]
|
109
|
+
);
|
110
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
104
111
|
parser.state.module.addPresentationalDependency(dep);
|
105
112
|
return true;
|
106
113
|
});
|
107
114
|
|
108
115
|
parser.hooks.call.for("System.import").tap(PLUGIN_NAME, expr => {
|
109
116
|
parser.state.module.addWarning(
|
110
|
-
new SystemImportDeprecationWarning(
|
117
|
+
new SystemImportDeprecationWarning(
|
118
|
+
/** @type {DependencyLocation} */ (expr.loc)
|
119
|
+
)
|
111
120
|
);
|
112
121
|
|
113
122
|
return parser.hooks.importCall.call({
|
@@ -133,6 +142,9 @@ class SystemPlugin {
|
|
133
142
|
}
|
134
143
|
|
135
144
|
class SystemImportDeprecationWarning extends WebpackError {
|
145
|
+
/**
|
146
|
+
* @param {DependencyLocation} loc location
|
147
|
+
*/
|
136
148
|
constructor(loc) {
|
137
149
|
super(
|
138
150
|
"System.import() is deprecated and will be removed soon. Use import() instead.\n" +
|