webpack 5.89.0 → 5.90.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/README.md +3 -0
- package/bin/webpack.js +1 -3
- package/hot/log.js +0 -2
- package/lib/APIPlugin.js +17 -13
- package/lib/ChunkGraph.js +1 -1
- package/lib/CleanPlugin.js +12 -12
- package/lib/Compilation.js +26 -17
- package/lib/Compiler.js +13 -0
- package/lib/ConcatenationScope.js +2 -2
- package/lib/ConditionalInitFragment.js +3 -3
- package/lib/ContextModule.js +4 -4
- package/lib/ContextModuleFactory.js +1 -1
- package/lib/DefinePlugin.js +47 -26
- package/lib/DependencyTemplate.js +3 -1
- package/lib/EnvironmentNotSupportAsyncWarning.js +52 -0
- package/lib/EvalDevToolModulePlugin.js +1 -1
- package/lib/EvalSourceMapDevToolPlugin.js +2 -2
- package/lib/ExportsInfoApiPlugin.js +2 -2
- package/lib/ExternalModule.js +47 -12
- package/lib/ExternalModuleFactoryPlugin.js +1 -1
- package/lib/FileSystemInfo.js +20 -3
- package/lib/FlagDependencyExportsPlugin.js +1 -1
- package/lib/Generator.js +1 -0
- package/lib/HotModuleReplacementPlugin.js +3 -3
- package/lib/InitFragment.js +7 -7
- package/lib/LibManifestPlugin.js +4 -1
- package/lib/Module.js +2 -1
- package/lib/ModuleFilenameHelpers.js +1 -1
- package/lib/ModuleInfoHeaderPlugin.js +1 -1
- package/lib/MultiStats.js +2 -2
- package/lib/NodeStuffPlugin.js +48 -0
- package/lib/NormalModule.js +13 -11
- package/lib/NormalModuleFactory.js +7 -7
- package/lib/RuntimeTemplate.js +15 -11
- package/lib/SourceMapDevToolPlugin.js +2 -2
- package/lib/Stats.js +4 -0
- package/lib/WebpackOptionsApply.js +4 -3
- package/lib/asset/AssetModulesPlugin.js +2 -3
- package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
- package/lib/buildChunkGraph.js +53 -0
- package/lib/cache/AddManagedPathsPlugin.js +6 -1
- package/lib/cache/IdleFileCachePlugin.js +12 -5
- package/lib/cache/PackFileCacheStrategy.js +3 -3
- package/lib/cache/ResolverCachePlugin.js +2 -2
- package/lib/config/browserslistTargetHandler.js +35 -14
- package/lib/config/defaults.js +88 -52
- package/lib/config/normalization.js +17 -18
- package/lib/config/target.js +5 -0
- package/lib/container/ContainerReferencePlugin.js +1 -1
- package/lib/css/CssExportsGenerator.js +14 -1
- package/lib/css/CssGenerator.js +14 -1
- package/lib/css/CssLoadingRuntimeModule.js +23 -23
- package/lib/css/CssModulesPlugin.js +68 -32
- package/lib/css/CssParser.js +8 -3
- package/lib/debug/ProfilingPlugin.js +2 -2
- package/lib/dependencies/AMDDefineDependency.js +4 -4
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +126 -34
- package/lib/dependencies/AMDPlugin.js +11 -4
- package/lib/dependencies/AMDRequireArrayDependency.js +13 -1
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +159 -43
- package/lib/dependencies/AMDRequireDependency.js +2 -2
- package/lib/dependencies/AMDRequireItemDependency.js +1 -1
- package/lib/dependencies/CachedConstDependency.js +8 -1
- package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -1
- package/lib/dependencies/ContextElementDependency.js +1 -1
- package/lib/dependencies/ExternalModuleDependency.js +107 -0
- package/lib/dependencies/ExternalModuleInitFragment.js +131 -0
- package/lib/dependencies/HarmonyAcceptDependency.js +1 -1
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +7 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +18 -18
- package/lib/dependencies/HarmonyExportInitFragment.js +6 -6
- package/lib/dependencies/HarmonyImportDependency.js +4 -4
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +6 -6
- package/lib/dependencies/ImportDependency.js +26 -6
- package/lib/dependencies/JsonExportsDependency.js +1 -1
- package/lib/dependencies/LoaderPlugin.js +2 -1
- package/lib/dependencies/LocalModuleDependency.js +1 -1
- package/lib/dependencies/PureExpressionDependency.js +12 -4
- package/lib/dependencies/RequireIncludeDependency.js +1 -1
- package/lib/dependencies/WebpackIsIncludedDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +10 -3
- package/lib/dependencies/getFunctionExpression.js +2 -2
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +6 -6
- package/lib/hmr/HotModuleReplacement.runtime.js +3 -5
- package/lib/hmr/lazyCompilationBackend.js +4 -4
- package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
- package/lib/index.js +4 -0
- package/lib/javascript/JavascriptGenerator.js +16 -1
- package/lib/javascript/JavascriptModulesPlugin.js +33 -33
- package/lib/javascript/JavascriptParser.js +220 -74
- package/lib/json/JsonGenerator.js +1 -1
- package/lib/library/AmdLibraryPlugin.js +5 -1
- package/lib/library/AssignLibraryPlugin.js +1 -1
- package/lib/library/SystemLibraryPlugin.js +1 -1
- package/lib/library/UmdLibraryPlugin.js +39 -39
- package/lib/logging/createConsoleLogger.js +1 -19
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +8 -8
- package/lib/node/RequireChunkLoadingRuntimeModule.js +8 -8
- package/lib/node/nodeConsole.js +1 -5
- package/lib/optimize/ConcatenatedModule.js +7 -7
- package/lib/optimize/InnerGraphPlugin.js +9 -1
- package/lib/optimize/MangleExportsPlugin.js +5 -1
- package/lib/optimize/ModuleConcatenationPlugin.js +2 -2
- package/lib/optimize/RemoveParentModulesPlugin.js +123 -47
- package/lib/optimize/SideEffectsFlagPlugin.js +15 -3
- package/lib/optimize/SplitChunksPlugin.js +16 -16
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +2 -2
- package/lib/rules/RuleSetCompiler.js +1 -1
- package/lib/runtime/AutoPublicPathRuntimeModule.js +2 -2
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +4 -4
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +4 -4
- package/lib/runtime/LoadScriptRuntimeModule.js +2 -2
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +23 -22
- package/lib/runtime/StartupEntrypointRuntimeModule.js +2 -2
- package/lib/schemes/HttpUriPlugin.js +1 -1
- package/lib/serialization/FileMiddleware.js +4 -4
- package/lib/serialization/ObjectMiddleware.js +4 -4
- package/lib/sharing/ConsumeSharedPlugin.js +5 -5
- package/lib/sharing/ConsumeSharedRuntimeModule.js +8 -4
- package/lib/sharing/ProvideSharedModule.js +2 -2
- package/lib/sharing/SharePlugin.js +2 -2
- package/lib/sharing/ShareRuntimeModule.js +1 -1
- package/lib/sharing/utils.js +24 -28
- package/lib/stats/DefaultStatsFactoryPlugin.js +10 -10
- package/lib/stats/DefaultStatsPresetPlugin.js +3 -7
- package/lib/stats/DefaultStatsPrinterPlugin.js +34 -31
- package/lib/util/chainedImports.js +7 -6
- package/lib/util/cleverMerge.js +4 -4
- package/lib/util/comparators.js +59 -23
- package/lib/util/hash/xxhash64.js +2 -2
- package/lib/util/identifier.js +2 -2
- package/lib/util/internalSerializables.js +6 -0
- package/lib/util/numberHash.js +64 -52
- package/lib/util/runtime.js +18 -1
- package/lib/util/semver.js +19 -24
- package/lib/util/smartGrouping.js +1 -1
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +53 -28
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +2 -2
- package/lib/wasm-async/AsyncWebAssemblyParser.js +6 -0
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +2 -2
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +2 -2
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +13 -13
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +6 -6
- package/package.json +25 -80
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +140 -32
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +6 -0
- package/schemas/plugins/css/CssAutoGeneratorOptions.json +3 -0
- package/schemas/plugins/css/CssAutoParserOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssAutoParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssAutoParserOptions.json +3 -0
- package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +6 -0
- package/schemas/plugins/css/CssGlobalGeneratorOptions.json +3 -0
- package/schemas/plugins/css/CssGlobalParserOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssGlobalParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssGlobalParserOptions.json +3 -0
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +6 -0
- package/schemas/plugins/css/CssModuleGeneratorOptions.json +3 -0
- package/schemas/plugins/css/CssModuleParserOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssModuleParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssModuleParserOptions.json +3 -0
- package/schemas/plugins/css/CssParserOptions.check.js +1 -1
- package/types.d.ts +273 -94
@@ -19,13 +19,30 @@ const { getLocalModule } = require("./LocalModulesHelpers");
|
|
19
19
|
const UnsupportedDependency = require("./UnsupportedDependency");
|
20
20
|
const getFunctionExpression = require("./getFunctionExpression");
|
21
21
|
|
22
|
+
/** @typedef {import("estree").CallExpression} CallExpression */
|
23
|
+
/** @typedef {import("estree").Expression} Expression */
|
24
|
+
/** @typedef {import("estree").SourceLocation} SourceLocation */
|
25
|
+
/** @typedef {import("estree").SpreadElement} SpreadElement */
|
26
|
+
/** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
|
27
|
+
/** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
|
28
|
+
/** @typedef {import("../Module").BuildInfo} BuildInfo */
|
29
|
+
/** @typedef {import("../javascript/BasicEvaluatedExpression")} BasicEvaluatedExpression */
|
22
30
|
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
|
31
|
+
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
23
32
|
|
24
33
|
class AMDRequireDependenciesBlockParserPlugin {
|
34
|
+
/**
|
35
|
+
* @param {JavascriptParserOptions} options parserOptions
|
36
|
+
*/
|
25
37
|
constructor(options) {
|
26
38
|
this.options = options;
|
27
39
|
}
|
28
40
|
|
41
|
+
/**
|
42
|
+
* @param {JavascriptParser} parser the parser
|
43
|
+
* @param {Expression | SpreadElement} expression expression
|
44
|
+
* @returns {boolean} need bind this
|
45
|
+
*/
|
29
46
|
processFunctionArgument(parser, expression) {
|
30
47
|
let bindThis = true;
|
31
48
|
const fnData = getFunctionExpression(expression);
|
@@ -65,9 +82,15 @@ class AMDRequireDependenciesBlockParserPlugin {
|
|
65
82
|
);
|
66
83
|
}
|
67
84
|
|
85
|
+
/**
|
86
|
+
* @param {JavascriptParser} parser the parser
|
87
|
+
* @param {CallExpression} expr call expression
|
88
|
+
* @param {BasicEvaluatedExpression} param param
|
89
|
+
* @returns {boolean | undefined} result
|
90
|
+
*/
|
68
91
|
processArray(parser, expr, param) {
|
69
92
|
if (param.isArray()) {
|
70
|
-
for (const p of param.items) {
|
93
|
+
for (const p of /** @type {BasicEvaluatedExpression[]} */ (param.items)) {
|
71
94
|
const result = this.processItem(parser, expr, p);
|
72
95
|
if (result === undefined) {
|
73
96
|
this.processContext(parser, expr, p);
|
@@ -75,8 +98,9 @@ class AMDRequireDependenciesBlockParserPlugin {
|
|
75
98
|
}
|
76
99
|
return true;
|
77
100
|
} else if (param.isConstArray()) {
|
101
|
+
/** @type {(string | LocalModuleDependency | AMDRequireItemDependency)[]} */
|
78
102
|
const deps = [];
|
79
|
-
for (const request of param.array) {
|
103
|
+
for (const request of /** @type {any[]} */ (param.array)) {
|
80
104
|
let dep, localModule;
|
81
105
|
if (request === "require") {
|
82
106
|
dep = RuntimeGlobals.require;
|
@@ -85,26 +109,38 @@ class AMDRequireDependenciesBlockParserPlugin {
|
|
85
109
|
} else if ((localModule = getLocalModule(parser.state, request))) {
|
86
110
|
localModule.flagUsed();
|
87
111
|
dep = new LocalModuleDependency(localModule, undefined, false);
|
88
|
-
dep.loc = expr.loc;
|
112
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
89
113
|
parser.state.module.addPresentationalDependency(dep);
|
90
114
|
} else {
|
91
115
|
dep = this.newRequireItemDependency(request);
|
92
|
-
dep.loc = expr.loc;
|
116
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
93
117
|
dep.optional = !!parser.scope.inTry;
|
94
118
|
parser.state.current.addDependency(dep);
|
95
119
|
}
|
96
120
|
deps.push(dep);
|
97
121
|
}
|
98
|
-
const dep = this.newRequireArrayDependency(
|
99
|
-
|
122
|
+
const dep = this.newRequireArrayDependency(
|
123
|
+
deps,
|
124
|
+
/** @type {Range} */ (param.range)
|
125
|
+
);
|
126
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
100
127
|
dep.optional = !!parser.scope.inTry;
|
101
128
|
parser.state.module.addPresentationalDependency(dep);
|
102
129
|
return true;
|
103
130
|
}
|
104
131
|
}
|
132
|
+
|
133
|
+
/**
|
134
|
+
* @param {JavascriptParser} parser the parser
|
135
|
+
* @param {CallExpression} expr call expression
|
136
|
+
* @param {BasicEvaluatedExpression} param param
|
137
|
+
* @returns {boolean | undefined} result
|
138
|
+
*/
|
105
139
|
processItem(parser, expr, param) {
|
106
140
|
if (param.isConditional()) {
|
107
|
-
for (const p of
|
141
|
+
for (const p of /** @type {BasicEvaluatedExpression[]} */ (
|
142
|
+
param.options
|
143
|
+
)) {
|
108
144
|
const result = this.processItem(parser, expr, p);
|
109
145
|
if (result === undefined) {
|
110
146
|
this.processContext(parser, expr, p);
|
@@ -114,40 +150,59 @@ class AMDRequireDependenciesBlockParserPlugin {
|
|
114
150
|
} else if (param.isString()) {
|
115
151
|
let dep, localModule;
|
116
152
|
if (param.string === "require") {
|
117
|
-
dep = new ConstDependency(
|
118
|
-
RuntimeGlobals.require
|
119
|
-
|
153
|
+
dep = new ConstDependency(
|
154
|
+
RuntimeGlobals.require,
|
155
|
+
/** @type {TODO} */ (param.string),
|
156
|
+
[RuntimeGlobals.require]
|
157
|
+
);
|
120
158
|
} else if (param.string === "module") {
|
121
159
|
dep = new ConstDependency(
|
122
|
-
|
123
|
-
|
160
|
+
/** @type {BuildInfo} */
|
161
|
+
(parser.state.module.buildInfo).moduleArgument,
|
162
|
+
/** @type {Range} */ (param.range),
|
124
163
|
[RuntimeGlobals.module]
|
125
164
|
);
|
126
165
|
} else if (param.string === "exports") {
|
127
166
|
dep = new ConstDependency(
|
128
|
-
|
129
|
-
|
167
|
+
/** @type {BuildInfo} */
|
168
|
+
(parser.state.module.buildInfo).exportsArgument,
|
169
|
+
/** @type {Range} */ (param.range),
|
130
170
|
[RuntimeGlobals.exports]
|
131
171
|
);
|
132
|
-
} else if (
|
172
|
+
} else if (
|
173
|
+
(localModule = getLocalModule(
|
174
|
+
parser.state,
|
175
|
+
/** @type {string} */ (param.string)
|
176
|
+
))
|
177
|
+
) {
|
133
178
|
localModule.flagUsed();
|
134
179
|
dep = new LocalModuleDependency(localModule, param.range, false);
|
135
180
|
} else {
|
136
|
-
dep = this.newRequireItemDependency(
|
137
|
-
|
181
|
+
dep = this.newRequireItemDependency(
|
182
|
+
/** @type {string} */ (param.string),
|
183
|
+
param.range
|
184
|
+
);
|
185
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
138
186
|
dep.optional = !!parser.scope.inTry;
|
139
187
|
parser.state.current.addDependency(dep);
|
140
188
|
return true;
|
141
189
|
}
|
142
|
-
dep.loc = expr.loc;
|
190
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
143
191
|
parser.state.module.addPresentationalDependency(dep);
|
144
192
|
return true;
|
145
193
|
}
|
146
194
|
}
|
195
|
+
|
196
|
+
/**
|
197
|
+
* @param {JavascriptParser} parser the parser
|
198
|
+
* @param {CallExpression} expr call expression
|
199
|
+
* @param {BasicEvaluatedExpression} param param
|
200
|
+
* @returns {boolean | undefined} result
|
201
|
+
*/
|
147
202
|
processContext(parser, expr, param) {
|
148
203
|
const dep = ContextDependencyHelpers.create(
|
149
204
|
AMDRequireContextDependency,
|
150
|
-
param.range,
|
205
|
+
/** @type {Range} */ (param.range),
|
151
206
|
param,
|
152
207
|
expr,
|
153
208
|
this.options,
|
@@ -157,38 +212,55 @@ class AMDRequireDependenciesBlockParserPlugin {
|
|
157
212
|
parser
|
158
213
|
);
|
159
214
|
if (!dep) return;
|
160
|
-
dep.loc = expr.loc;
|
215
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
161
216
|
dep.optional = !!parser.scope.inTry;
|
162
217
|
parser.state.current.addDependency(dep);
|
163
218
|
return true;
|
164
219
|
}
|
165
220
|
|
221
|
+
/**
|
222
|
+
* @param {BasicEvaluatedExpression} param param
|
223
|
+
* @returns {string | undefined} result
|
224
|
+
*/
|
166
225
|
processArrayForRequestString(param) {
|
167
226
|
if (param.isArray()) {
|
168
|
-
const result =
|
169
|
-
|
170
|
-
|
227
|
+
const result =
|
228
|
+
/** @type {BasicEvaluatedExpression[]} */
|
229
|
+
(param.items).map(item => this.processItemForRequestString(item));
|
171
230
|
if (result.every(Boolean)) return result.join(" ");
|
172
231
|
} else if (param.isConstArray()) {
|
173
|
-
return param.array.join(" ");
|
232
|
+
return /** @type {string[]} */ (param.array).join(" ");
|
174
233
|
}
|
175
234
|
}
|
176
235
|
|
236
|
+
/**
|
237
|
+
* @param {BasicEvaluatedExpression} param param
|
238
|
+
* @returns {string | undefined} result
|
239
|
+
*/
|
177
240
|
processItemForRequestString(param) {
|
178
241
|
if (param.isConditional()) {
|
179
|
-
const result =
|
180
|
-
|
181
|
-
|
242
|
+
const result =
|
243
|
+
/** @type {BasicEvaluatedExpression[]} */
|
244
|
+
(param.options).map(item => this.processItemForRequestString(item));
|
182
245
|
if (result.every(Boolean)) return result.join("|");
|
183
246
|
} else if (param.isString()) {
|
184
247
|
return param.string;
|
185
248
|
}
|
186
249
|
}
|
187
250
|
|
251
|
+
/**
|
252
|
+
* @param {JavascriptParser} parser the parser
|
253
|
+
* @param {CallExpression} expr call expression
|
254
|
+
* @returns {boolean | undefined} result
|
255
|
+
*/
|
188
256
|
processCallRequire(parser, expr) {
|
257
|
+
/** @type {BasicEvaluatedExpression | undefined} */
|
189
258
|
let param;
|
259
|
+
/** @type {AMDRequireDependenciesBlock | undefined | null} */
|
190
260
|
let depBlock;
|
261
|
+
/** @type {AMDRequireDependency | undefined} */
|
191
262
|
let dep;
|
263
|
+
/** @type {boolean | undefined} */
|
192
264
|
let result;
|
193
265
|
|
194
266
|
const old = parser.state.current;
|
@@ -196,57 +268,76 @@ class AMDRequireDependenciesBlockParserPlugin {
|
|
196
268
|
if (expr.arguments.length >= 1) {
|
197
269
|
param = parser.evaluateExpression(expr.arguments[0]);
|
198
270
|
depBlock = this.newRequireDependenciesBlock(
|
199
|
-
expr.loc,
|
200
|
-
this.processArrayForRequestString(param)
|
271
|
+
/** @type {DependencyLocation} */ (expr.loc),
|
272
|
+
/** @type {string} */ (this.processArrayForRequestString(param))
|
201
273
|
);
|
202
274
|
dep = this.newRequireDependency(
|
203
|
-
expr.range,
|
204
|
-
param.range,
|
205
|
-
expr.arguments.length > 1
|
206
|
-
|
275
|
+
/** @type {Range} */ (expr.range),
|
276
|
+
/** @type {Range} */ (param.range),
|
277
|
+
expr.arguments.length > 1
|
278
|
+
? /** @type {Range} */ (expr.arguments[1].range)
|
279
|
+
: null,
|
280
|
+
expr.arguments.length > 2
|
281
|
+
? /** @type {Range} */ (expr.arguments[2].range)
|
282
|
+
: null
|
207
283
|
);
|
208
|
-
dep.loc = expr.loc;
|
284
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
209
285
|
depBlock.addDependency(dep);
|
210
286
|
|
211
|
-
parser.state.current = depBlock;
|
287
|
+
parser.state.current = /** @type {TODO} */ (depBlock);
|
212
288
|
}
|
213
289
|
|
214
290
|
if (expr.arguments.length === 1) {
|
215
291
|
parser.inScope([], () => {
|
216
|
-
result = this.processArray(
|
292
|
+
result = this.processArray(
|
293
|
+
parser,
|
294
|
+
expr,
|
295
|
+
/** @type {BasicEvaluatedExpression} */ (param)
|
296
|
+
);
|
217
297
|
});
|
218
298
|
parser.state.current = old;
|
219
299
|
if (!result) return;
|
220
|
-
parser.state.current.addBlock(
|
300
|
+
parser.state.current.addBlock(
|
301
|
+
/** @type {AMDRequireDependenciesBlock} */ (depBlock)
|
302
|
+
);
|
221
303
|
return true;
|
222
304
|
}
|
223
305
|
|
224
306
|
if (expr.arguments.length === 2 || expr.arguments.length === 3) {
|
225
307
|
try {
|
226
308
|
parser.inScope([], () => {
|
227
|
-
result = this.processArray(
|
309
|
+
result = this.processArray(
|
310
|
+
parser,
|
311
|
+
expr,
|
312
|
+
/** @type {BasicEvaluatedExpression} */ (param)
|
313
|
+
);
|
228
314
|
});
|
229
315
|
if (!result) {
|
230
|
-
const dep = new UnsupportedDependency(
|
316
|
+
const dep = new UnsupportedDependency(
|
317
|
+
"unsupported",
|
318
|
+
/** @type {Range} */ (expr.range)
|
319
|
+
);
|
231
320
|
old.addPresentationalDependency(dep);
|
232
321
|
if (parser.state.module) {
|
233
322
|
parser.state.module.addError(
|
234
323
|
new UnsupportedFeatureWarning(
|
235
324
|
"Cannot statically analyse 'require(…, …)' in line " +
|
236
|
-
expr.loc.start.line,
|
237
|
-
expr.loc
|
325
|
+
/** @type {SourceLocation} */ (expr.loc).start.line,
|
326
|
+
/** @type {DependencyLocation} */ (expr.loc)
|
238
327
|
)
|
239
328
|
);
|
240
329
|
}
|
241
330
|
depBlock = null;
|
242
331
|
return true;
|
243
332
|
}
|
244
|
-
|
333
|
+
/** @type {AMDRequireDependency} */
|
334
|
+
(dep).functionBindThis = this.processFunctionArgument(
|
245
335
|
parser,
|
246
336
|
expr.arguments[1]
|
247
337
|
);
|
248
338
|
if (expr.arguments.length === 3) {
|
249
|
-
|
339
|
+
/** @type {AMDRequireDependency} */
|
340
|
+
(dep).errorCallbackBindThis = this.processFunctionArgument(
|
250
341
|
parser,
|
251
342
|
expr.arguments[2]
|
252
343
|
);
|
@@ -259,9 +350,22 @@ class AMDRequireDependenciesBlockParserPlugin {
|
|
259
350
|
}
|
260
351
|
}
|
261
352
|
|
353
|
+
/**
|
354
|
+
* @param {DependencyLocation} loc location
|
355
|
+
* @param {string} request request
|
356
|
+
* @returns {AMDRequireDependenciesBlock} AMDRequireDependenciesBlock
|
357
|
+
*/
|
262
358
|
newRequireDependenciesBlock(loc, request) {
|
263
359
|
return new AMDRequireDependenciesBlock(loc, request);
|
264
360
|
}
|
361
|
+
|
362
|
+
/**
|
363
|
+
* @param {Range} outerRange outer range
|
364
|
+
* @param {Range} arrayRange array range
|
365
|
+
* @param {Range | null} functionRange function range
|
366
|
+
* @param {Range | null} errorCallbackRange error callback range
|
367
|
+
* @returns {AMDRequireDependency} dependency
|
368
|
+
*/
|
265
369
|
newRequireDependency(
|
266
370
|
outerRange,
|
267
371
|
arrayRange,
|
@@ -275,9 +379,21 @@ class AMDRequireDependenciesBlockParserPlugin {
|
|
275
379
|
errorCallbackRange
|
276
380
|
);
|
277
381
|
}
|
382
|
+
|
383
|
+
/**
|
384
|
+
* @param {string} request request
|
385
|
+
* @param {Range=} range range
|
386
|
+
* @returns {AMDRequireItemDependency} AMDRequireItemDependency
|
387
|
+
*/
|
278
388
|
newRequireItemDependency(request, range) {
|
279
389
|
return new AMDRequireItemDependency(request, range);
|
280
390
|
}
|
391
|
+
|
392
|
+
/**
|
393
|
+
* @param {(string | LocalModuleDependency | AMDRequireItemDependency)[]} depsArray deps array
|
394
|
+
* @param {Range} range range
|
395
|
+
* @returns {AMDRequireArrayDependency} AMDRequireArrayDependency
|
396
|
+
*/
|
281
397
|
newRequireArrayDependency(depsArray, range) {
|
282
398
|
return new AMDRequireArrayDependency(depsArray, range);
|
283
399
|
}
|
@@ -21,8 +21,8 @@ class AMDRequireDependency extends NullDependency {
|
|
21
21
|
/**
|
22
22
|
* @param {Range} outerRange outer range
|
23
23
|
* @param {Range} arrayRange array range
|
24
|
-
* @param {Range} functionRange function range
|
25
|
-
* @param {Range} errorCallbackRange error callback range
|
24
|
+
* @param {Range | null} functionRange function range
|
25
|
+
* @param {Range | null} errorCallbackRange error callback range
|
26
26
|
*/
|
27
27
|
constructor(outerRange, arrayRange, functionRange, errorCallbackRange) {
|
28
28
|
super();
|
@@ -14,7 +14,7 @@ const ModuleDependencyTemplateAsRequireId = require("./ModuleDependencyTemplateA
|
|
14
14
|
class AMDRequireItemDependency extends ModuleDependency {
|
15
15
|
/**
|
16
16
|
* @param {string} request the request string
|
17
|
-
* @param {Range} range location in source code
|
17
|
+
* @param {Range=} range location in source code
|
18
18
|
*/
|
19
19
|
constructor(request, range) {
|
20
20
|
super(request);
|
@@ -38,6 +38,13 @@ class CachedConstDependency extends NullDependency {
|
|
38
38
|
this._hashUpdate = undefined;
|
39
39
|
}
|
40
40
|
|
41
|
+
/**
|
42
|
+
* @returns {string} hash update
|
43
|
+
*/
|
44
|
+
_createHashUpdate() {
|
45
|
+
return `${this.identifier}${this.range}${this.expression}`;
|
46
|
+
}
|
47
|
+
|
41
48
|
/**
|
42
49
|
* Update the hash
|
43
50
|
* @param {Hash} hash hash to be updated
|
@@ -46,7 +53,7 @@ class CachedConstDependency extends NullDependency {
|
|
46
53
|
*/
|
47
54
|
updateHash(hash, context) {
|
48
55
|
if (this._hashUpdate === undefined)
|
49
|
-
this._hashUpdate =
|
56
|
+
this._hashUpdate = this._createHashUpdate();
|
50
57
|
hash.update(this._hashUpdate);
|
51
58
|
}
|
52
59
|
|
@@ -65,7 +65,7 @@ class CommonJsImportsParserPlugin {
|
|
65
65
|
|
66
66
|
//#region metadata
|
67
67
|
/**
|
68
|
-
* @param {
|
68
|
+
* @param {string} expression expression
|
69
69
|
* @param {() => string[]} getMembers get members
|
70
70
|
*/
|
71
71
|
const tapRequireExpression = (expression, getMembers) => {
|
@@ -0,0 +1,107 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Ivan Kopeykin @vankop
|
4
|
+
*/
|
5
|
+
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
const makeSerializable = require("../util/makeSerializable");
|
9
|
+
const CachedConstDependency = require("./CachedConstDependency");
|
10
|
+
const ExternalModuleInitFragment = require("./ExternalModuleInitFragment");
|
11
|
+
|
12
|
+
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
13
|
+
/** @typedef {import("../Dependency")} Dependency */
|
14
|
+
/** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
|
15
|
+
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
16
|
+
/** @typedef {import("../javascript/JavascriptModulesPlugin").ChunkRenderContext} ChunkRenderContext */
|
17
|
+
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
18
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
19
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
20
|
+
/** @typedef {import("../util/Hash")} Hash */
|
21
|
+
|
22
|
+
class ExternalModuleDependency extends CachedConstDependency {
|
23
|
+
/**
|
24
|
+
* @param {string} module module
|
25
|
+
* @param {{ name: string, value: string }[]} importSpecifiers import specifiers
|
26
|
+
* @param {string | undefined} defaultImport default import
|
27
|
+
* @param {string} expression expression
|
28
|
+
* @param {Range} range range
|
29
|
+
* @param {string} identifier identifier
|
30
|
+
*/
|
31
|
+
constructor(
|
32
|
+
module,
|
33
|
+
importSpecifiers,
|
34
|
+
defaultImport,
|
35
|
+
expression,
|
36
|
+
range,
|
37
|
+
identifier
|
38
|
+
) {
|
39
|
+
super(expression, range, identifier);
|
40
|
+
|
41
|
+
this.importedModule = module;
|
42
|
+
this.specifiers = importSpecifiers;
|
43
|
+
this.default = defaultImport;
|
44
|
+
}
|
45
|
+
|
46
|
+
/**
|
47
|
+
* @returns {string} hash update
|
48
|
+
*/
|
49
|
+
_createHashUpdate() {
|
50
|
+
return `${this.importedModule}${JSON.stringify(this.specifiers)}${
|
51
|
+
this.default || "null"
|
52
|
+
}${super._createHashUpdate()}`;
|
53
|
+
}
|
54
|
+
|
55
|
+
/**
|
56
|
+
* @param {ObjectSerializerContext} context context
|
57
|
+
*/
|
58
|
+
serialize(context) {
|
59
|
+
super.serialize(context);
|
60
|
+
const { write } = context;
|
61
|
+
write(this.importedModule);
|
62
|
+
write(this.specifiers);
|
63
|
+
write(this.default);
|
64
|
+
}
|
65
|
+
|
66
|
+
/**
|
67
|
+
* @param {ObjectDeserializerContext} context context
|
68
|
+
*/
|
69
|
+
deserialize(context) {
|
70
|
+
super.deserialize(context);
|
71
|
+
const { read } = context;
|
72
|
+
this.importedModule = read();
|
73
|
+
this.specifiers = read();
|
74
|
+
this.default = read();
|
75
|
+
}
|
76
|
+
}
|
77
|
+
|
78
|
+
makeSerializable(
|
79
|
+
ExternalModuleDependency,
|
80
|
+
"webpack/lib/dependencies/ExternalModuleDependency"
|
81
|
+
);
|
82
|
+
|
83
|
+
ExternalModuleDependency.Template = class ExternalModuleDependencyTemplate extends (
|
84
|
+
CachedConstDependency.Template
|
85
|
+
) {
|
86
|
+
/**
|
87
|
+
* @param {Dependency} dependency the dependency for which the template should be applied
|
88
|
+
* @param {ReplaceSource} source the current replace source which can be modified
|
89
|
+
* @param {DependencyTemplateContext} templateContext the context object
|
90
|
+
* @returns {void}
|
91
|
+
*/
|
92
|
+
apply(dependency, source, templateContext) {
|
93
|
+
super.apply(dependency, source, templateContext);
|
94
|
+
const dep = /** @type {ExternalModuleDependency} */ (dependency);
|
95
|
+
const { chunkInitFragments } = templateContext;
|
96
|
+
|
97
|
+
chunkInitFragments.push(
|
98
|
+
new ExternalModuleInitFragment(
|
99
|
+
dep.importedModule,
|
100
|
+
dep.specifiers,
|
101
|
+
dep.default
|
102
|
+
)
|
103
|
+
);
|
104
|
+
}
|
105
|
+
};
|
106
|
+
|
107
|
+
module.exports = ExternalModuleDependency;
|
@@ -0,0 +1,131 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Ivan Kopeykin @vankop
|
4
|
+
*/
|
5
|
+
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
const InitFragment = require("../InitFragment");
|
9
|
+
const makeSerializable = require("../util/makeSerializable");
|
10
|
+
|
11
|
+
/** @typedef {import("webpack-sources").Source} Source */
|
12
|
+
/** @typedef {import("../Generator").GenerateContext} GenerateContext */
|
13
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
14
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
15
|
+
/** @typedef {Map<string, Set<string>>} ImportSpecifiers */
|
16
|
+
|
17
|
+
/**
|
18
|
+
* @extends {InitFragment<GenerateContext>}
|
19
|
+
*/
|
20
|
+
class ExternalModuleInitFragment extends InitFragment {
|
21
|
+
/**
|
22
|
+
* @param {string} importedModule imported module
|
23
|
+
* @param {Array<{ name: string, value?: string }>|ImportSpecifiers} specifiers import specifiers
|
24
|
+
* @param {string=} defaultImport default import
|
25
|
+
*/
|
26
|
+
constructor(importedModule, specifiers, defaultImport) {
|
27
|
+
super(
|
28
|
+
undefined,
|
29
|
+
InitFragment.STAGE_CONSTANTS,
|
30
|
+
0,
|
31
|
+
`external module imports|${importedModule}|${defaultImport || "null"}`
|
32
|
+
);
|
33
|
+
this.importedModule = importedModule;
|
34
|
+
if (Array.isArray(specifiers)) {
|
35
|
+
/** @type {ImportSpecifiers} */
|
36
|
+
this.specifiers = new Map();
|
37
|
+
for (const { name, value } of specifiers) {
|
38
|
+
let specifiers = this.specifiers.get(name);
|
39
|
+
if (!specifiers) {
|
40
|
+
specifiers = new Set();
|
41
|
+
this.specifiers.set(name, specifiers);
|
42
|
+
}
|
43
|
+
specifiers.add(value || name);
|
44
|
+
}
|
45
|
+
} else {
|
46
|
+
this.specifiers = specifiers;
|
47
|
+
}
|
48
|
+
this.defaultImport = defaultImport;
|
49
|
+
}
|
50
|
+
|
51
|
+
/**
|
52
|
+
* @param {ExternalModuleInitFragment} other other
|
53
|
+
* @returns {ExternalModuleInitFragment} ExternalModuleInitFragment
|
54
|
+
*/
|
55
|
+
merge(other) {
|
56
|
+
const newSpecifiersMap = new Map(this.specifiers);
|
57
|
+
for (const [name, specifiers] of other.specifiers) {
|
58
|
+
if (newSpecifiersMap.has(name)) {
|
59
|
+
const currentSpecifiers = newSpecifiersMap.get(name);
|
60
|
+
for (const spec of specifiers) currentSpecifiers.add(spec);
|
61
|
+
} else {
|
62
|
+
newSpecifiersMap.set(name, specifiers);
|
63
|
+
}
|
64
|
+
}
|
65
|
+
return new ExternalModuleInitFragment(
|
66
|
+
this.importedModule,
|
67
|
+
newSpecifiersMap,
|
68
|
+
this.defaultImport
|
69
|
+
);
|
70
|
+
}
|
71
|
+
|
72
|
+
/**
|
73
|
+
* @param {GenerateContext} context context
|
74
|
+
* @returns {string | Source} the source code that will be included as initialization code
|
75
|
+
*/
|
76
|
+
getContent({ runtimeRequirements }) {
|
77
|
+
const namedImports = [];
|
78
|
+
|
79
|
+
for (const [name, specifiers] of this.specifiers) {
|
80
|
+
for (const spec of specifiers) {
|
81
|
+
if (spec === name) {
|
82
|
+
namedImports.push(name);
|
83
|
+
} else {
|
84
|
+
namedImports.push(`${name} as ${spec}`);
|
85
|
+
}
|
86
|
+
}
|
87
|
+
}
|
88
|
+
|
89
|
+
let importsString =
|
90
|
+
namedImports.length > 0 ? `{${namedImports.join(",")}}` : "";
|
91
|
+
|
92
|
+
if (this.defaultImport) {
|
93
|
+
importsString = `${this.defaultImport}${
|
94
|
+
importsString ? `, ${importsString}` : ""
|
95
|
+
}`;
|
96
|
+
}
|
97
|
+
|
98
|
+
return `import ${importsString} from ${JSON.stringify(
|
99
|
+
this.importedModule
|
100
|
+
)};`;
|
101
|
+
}
|
102
|
+
|
103
|
+
/**
|
104
|
+
* @param {ObjectSerializerContext} context context
|
105
|
+
*/
|
106
|
+
serialize(context) {
|
107
|
+
super.serialize(context);
|
108
|
+
const { write } = context;
|
109
|
+
write(this.importedModule);
|
110
|
+
write(this.specifiers);
|
111
|
+
write(this.defaultImport);
|
112
|
+
}
|
113
|
+
|
114
|
+
/**
|
115
|
+
* @param {ObjectDeserializerContext} context context
|
116
|
+
*/
|
117
|
+
deserialize(context) {
|
118
|
+
super.deserialize(context);
|
119
|
+
const { read } = context;
|
120
|
+
this.importedModule = read();
|
121
|
+
this.specifiers = read();
|
122
|
+
this.defaultImport = read();
|
123
|
+
}
|
124
|
+
}
|
125
|
+
|
126
|
+
makeSerializable(
|
127
|
+
ExternalModuleInitFragment,
|
128
|
+
"webpack/lib/dependencies/ExternalModuleInitFragment"
|
129
|
+
);
|
130
|
+
|
131
|
+
module.exports = ExternalModuleInitFragment;
|