webpack 5.90.0 → 5.90.2
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 +16 -12
- package/lib/Compilation.js +1 -1
- package/lib/ConditionalInitFragment.js +3 -3
- package/lib/DefinePlugin.js +47 -26
- package/lib/EvalSourceMapDevToolPlugin.js +1 -1
- package/lib/InitFragment.js +7 -7
- package/lib/NodeStuffPlugin.js +3 -3
- package/lib/Stats.js +4 -0
- package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
- package/lib/buildChunkGraph.js +101 -15
- package/lib/config/browserslistTargetHandler.js +18 -16
- package/lib/config/defaults.js +1 -0
- 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/ExportsInfoDependency.js +6 -12
- package/lib/dependencies/ExternalModuleDependency.js +9 -0
- package/lib/dependencies/ExternalModuleInitFragment.js +10 -3
- package/lib/dependencies/HarmonyExportInitFragment.js +2 -2
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +1 -1
- package/lib/dependencies/ImportParserPlugin.js +1 -0
- package/lib/dependencies/LocalModuleDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +3 -2
- package/lib/dependencies/getFunctionExpression.js +2 -2
- package/lib/hmr/HotModuleReplacement.runtime.js +1 -1
- package/lib/javascript/JavascriptParser.js +212 -74
- package/lib/optimize/MangleExportsPlugin.js +5 -1
- package/lib/runtime/AutoPublicPathRuntimeModule.js +1 -1
- package/lib/util/chainedImports.js +7 -6
- package/lib/util/comparators.js +59 -23
- package/lib/util/numberHash.js +53 -52
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +53 -28
- package/package.json +4 -59
- package/types.d.ts +101 -74
@@ -90,7 +90,9 @@ const resolve = browsers => {
|
|
90
90
|
// safari TP supports all features for normal safari
|
91
91
|
parsedVersion === "TP"
|
92
92
|
? [Infinity, Infinity]
|
93
|
-
: parsedVersion.
|
93
|
+
: parsedVersion.includes("-")
|
94
|
+
? parsedVersion.split("-")[0].split(".")
|
95
|
+
: parsedVersion.split(".");
|
94
96
|
if (typeof requiredVersion === "number") {
|
95
97
|
return +parsedMajor >= requiredVersion;
|
96
98
|
}
|
@@ -118,8 +120,8 @@ const resolve = browsers => {
|
|
118
120
|
samsung: [8, 2],
|
119
121
|
android: 63,
|
120
122
|
and_qq: [10, 4],
|
121
|
-
|
122
|
-
|
123
|
+
baidu: [13, 18],
|
124
|
+
and_uc: [15, 5],
|
123
125
|
kaios: [3, 0],
|
124
126
|
node: [12, 17]
|
125
127
|
});
|
@@ -144,7 +146,7 @@ const resolve = browsers => {
|
|
144
146
|
android: 37,
|
145
147
|
and_qq: [10, 4],
|
146
148
|
// Supported correctly in strict mode, otherwise supported without block scope
|
147
|
-
|
149
|
+
baidu: [13, 18],
|
148
150
|
and_uc: [12, 12],
|
149
151
|
kaios: [2, 5],
|
150
152
|
node: [6, 0]
|
@@ -222,9 +224,9 @@ const resolve = browsers => {
|
|
222
224
|
ios_saf: 14,
|
223
225
|
samsung: [9, 2],
|
224
226
|
android: 67,
|
225
|
-
|
226
|
-
|
227
|
-
|
227
|
+
and_qq: [13, 1],
|
228
|
+
baidu: [13, 18],
|
229
|
+
and_uc: [15, 5],
|
228
230
|
kaios: [3, 0],
|
229
231
|
node: [10, 4]
|
230
232
|
}),
|
@@ -244,8 +246,8 @@ const resolve = browsers => {
|
|
244
246
|
samsung: [8, 0],
|
245
247
|
android: 61,
|
246
248
|
and_qq: [10, 4],
|
247
|
-
|
248
|
-
|
249
|
+
baidu: [13, 18],
|
250
|
+
and_uc: [15, 5],
|
249
251
|
kaios: [3, 0],
|
250
252
|
node: [12, 17]
|
251
253
|
}),
|
@@ -319,14 +321,14 @@ const resolve = browsers => {
|
|
319
321
|
// ie: Not supported,
|
320
322
|
opera: 42,
|
321
323
|
op_mob: 42,
|
322
|
-
safari:
|
323
|
-
ios_saf:
|
324
|
-
samsung: 6,
|
324
|
+
safari: 11,
|
325
|
+
ios_saf: 11,
|
326
|
+
samsung: [6, 2],
|
325
327
|
android: 55,
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
328
|
+
and_qq: [13, 1],
|
329
|
+
baidu: [13, 18],
|
330
|
+
and_uc: [15, 5],
|
331
|
+
kaios: 3,
|
330
332
|
node: [7, 6]
|
331
333
|
}),
|
332
334
|
browser: browserProperty,
|
package/lib/config/defaults.js
CHANGED
@@ -108,10 +108,10 @@ const DEFINITIONS = {
|
|
108
108
|
class AMDDefineDependency extends NullDependency {
|
109
109
|
/**
|
110
110
|
* @param {Range} range range
|
111
|
-
* @param {Range} arrayRange array range
|
112
|
-
* @param {Range} functionRange function range
|
113
|
-
* @param {Range} objectRange object range
|
114
|
-
* @param {boolean} namedModule true, when define is called with a name
|
111
|
+
* @param {Range | null} arrayRange array range
|
112
|
+
* @param {Range | null} functionRange function range
|
113
|
+
* @param {Range | null} objectRange object range
|
114
|
+
* @param {boolean | null} namedModule true, when define is called with a name
|
115
115
|
*/
|
116
116
|
constructor(range, arrayRange, functionRange, objectRange, namedModule) {
|
117
117
|
super();
|
@@ -16,11 +16,20 @@ const DynamicExports = require("./DynamicExports");
|
|
16
16
|
const LocalModuleDependency = require("./LocalModuleDependency");
|
17
17
|
const { addLocalModule, getLocalModule } = require("./LocalModulesHelpers");
|
18
18
|
|
19
|
+
/** @typedef {import("estree").ArrowFunctionExpression} ArrowFunctionExpression */
|
19
20
|
/** @typedef {import("estree").CallExpression} CallExpression */
|
21
|
+
/** @typedef {import("estree").Expression} Expression */
|
22
|
+
/** @typedef {import("estree").FunctionExpression} FunctionExpression */
|
23
|
+
/** @typedef {import("estree").Literal} Literal */
|
24
|
+
/** @typedef {import("estree").SpreadElement} SpreadElement */
|
25
|
+
/** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
|
26
|
+
/** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
|
27
|
+
/** @typedef {import("../javascript/BasicEvaluatedExpression")} BasicEvaluatedExpression */
|
20
28
|
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
|
29
|
+
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
21
30
|
|
22
31
|
/**
|
23
|
-
* @param {
|
32
|
+
* @param {Expression | SpreadElement} expr expression
|
24
33
|
* @returns {boolean} true if it's a bound function expression
|
25
34
|
*/
|
26
35
|
const isBoundFunctionExpression = expr => {
|
@@ -33,12 +42,22 @@ const isBoundFunctionExpression = expr => {
|
|
33
42
|
return true;
|
34
43
|
};
|
35
44
|
|
45
|
+
/** @typedef {FunctionExpression | ArrowFunctionExpression} UnboundFunctionExpression */
|
46
|
+
|
47
|
+
/**
|
48
|
+
* @param {Expression | SpreadElement} expr expression
|
49
|
+
* @returns {boolean} true when unbound function expression
|
50
|
+
*/
|
36
51
|
const isUnboundFunctionExpression = expr => {
|
37
52
|
if (expr.type === "FunctionExpression") return true;
|
38
53
|
if (expr.type === "ArrowFunctionExpression") return true;
|
39
54
|
return false;
|
40
55
|
};
|
41
56
|
|
57
|
+
/**
|
58
|
+
* @param {Expression | SpreadElement} expr expression
|
59
|
+
* @returns {boolean} true when callable
|
60
|
+
*/
|
42
61
|
const isCallable = expr => {
|
43
62
|
if (isUnboundFunctionExpression(expr)) return true;
|
44
63
|
if (isBoundFunctionExpression(expr)) return true;
|
@@ -46,6 +65,9 @@ const isCallable = expr => {
|
|
46
65
|
};
|
47
66
|
|
48
67
|
class AMDDefineDependencyParserPlugin {
|
68
|
+
/**
|
69
|
+
* @param {JavascriptParserOptions} options parserOptions
|
70
|
+
*/
|
49
71
|
constructor(options) {
|
50
72
|
this.options = options;
|
51
73
|
}
|
@@ -63,12 +85,23 @@ class AMDDefineDependencyParserPlugin {
|
|
63
85
|
);
|
64
86
|
}
|
65
87
|
|
88
|
+
/**
|
89
|
+
* @param {JavascriptParser} parser the parser
|
90
|
+
* @param {CallExpression} expr call expression
|
91
|
+
* @param {BasicEvaluatedExpression} param param
|
92
|
+
* @param {Record<number, string>} identifiers identifiers
|
93
|
+
* @param {string=} namedModule named module
|
94
|
+
* @returns {boolean | undefined} result
|
95
|
+
*/
|
66
96
|
processArray(parser, expr, param, identifiers, namedModule) {
|
67
97
|
if (param.isArray()) {
|
68
|
-
|
98
|
+
/** @type {BasicEvaluatedExpression[]} */
|
99
|
+
(param.items).forEach((param, idx) => {
|
69
100
|
if (
|
70
101
|
param.isString() &&
|
71
|
-
["require", "module", "exports"].includes(
|
102
|
+
["require", "module", "exports"].includes(
|
103
|
+
/** @type {string} */ (param.string)
|
104
|
+
)
|
72
105
|
)
|
73
106
|
identifiers[idx] = param.string;
|
74
107
|
const result = this.processItem(parser, expr, param, namedModule);
|
@@ -78,6 +111,7 @@ class AMDDefineDependencyParserPlugin {
|
|
78
111
|
});
|
79
112
|
return true;
|
80
113
|
} else if (param.isConstArray()) {
|
114
|
+
/** @type {(string | LocalModuleDependency | AMDRequireItemDependency)[]} */
|
81
115
|
const deps = [];
|
82
116
|
param.array.forEach((request, idx) => {
|
83
117
|
let dep;
|
@@ -91,26 +125,38 @@ class AMDDefineDependencyParserPlugin {
|
|
91
125
|
} else if ((localModule = getLocalModule(parser.state, request))) {
|
92
126
|
localModule.flagUsed();
|
93
127
|
dep = new LocalModuleDependency(localModule, undefined, false);
|
94
|
-
dep.loc = expr.loc;
|
128
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
95
129
|
parser.state.module.addPresentationalDependency(dep);
|
96
130
|
} else {
|
97
131
|
dep = this.newRequireItemDependency(request);
|
98
|
-
dep.loc = expr.loc;
|
132
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
99
133
|
dep.optional = !!parser.scope.inTry;
|
100
134
|
parser.state.current.addDependency(dep);
|
101
135
|
}
|
102
136
|
deps.push(dep);
|
103
137
|
});
|
104
|
-
const dep = this.newRequireArrayDependency(
|
105
|
-
|
138
|
+
const dep = this.newRequireArrayDependency(
|
139
|
+
deps,
|
140
|
+
/** @type {Range} */ (param.range)
|
141
|
+
);
|
142
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
106
143
|
dep.optional = !!parser.scope.inTry;
|
107
144
|
parser.state.module.addPresentationalDependency(dep);
|
108
145
|
return true;
|
109
146
|
}
|
110
147
|
}
|
148
|
+
|
149
|
+
/**
|
150
|
+
* @param {JavascriptParser} parser the parser
|
151
|
+
* @param {CallExpression} expr call expression
|
152
|
+
* @param {BasicEvaluatedExpression} param param
|
153
|
+
* @param {string=} namedModule named module
|
154
|
+
* @returns {boolean} result
|
155
|
+
*/
|
111
156
|
processItem(parser, expr, param, namedModule) {
|
112
157
|
if (param.isConditional()) {
|
113
|
-
|
158
|
+
/** @type {BasicEvaluatedExpression[]} */
|
159
|
+
(param.options).forEach(param => {
|
114
160
|
const result = this.processItem(parser, expr, param);
|
115
161
|
if (result === undefined) {
|
116
162
|
this.processContext(parser, expr, param);
|
@@ -120,19 +166,29 @@ class AMDDefineDependencyParserPlugin {
|
|
120
166
|
} else if (param.isString()) {
|
121
167
|
let dep, localModule;
|
122
168
|
if (param.string === "require") {
|
123
|
-
dep = new ConstDependency(
|
124
|
-
RuntimeGlobals.require
|
125
|
-
|
169
|
+
dep = new ConstDependency(
|
170
|
+
RuntimeGlobals.require,
|
171
|
+
/** @type {Range} */ (param.range),
|
172
|
+
[RuntimeGlobals.require]
|
173
|
+
);
|
126
174
|
} else if (param.string === "exports") {
|
127
|
-
dep = new ConstDependency(
|
128
|
-
|
129
|
-
|
175
|
+
dep = new ConstDependency(
|
176
|
+
"exports",
|
177
|
+
/** @type {Range} */ (param.range),
|
178
|
+
[RuntimeGlobals.exports]
|
179
|
+
);
|
130
180
|
} else if (param.string === "module") {
|
131
|
-
dep = new ConstDependency(
|
132
|
-
|
133
|
-
|
181
|
+
dep = new ConstDependency(
|
182
|
+
"module",
|
183
|
+
/** @type {Range} */ (param.range),
|
184
|
+
[RuntimeGlobals.module]
|
185
|
+
);
|
134
186
|
} else if (
|
135
|
-
(localModule = getLocalModule(
|
187
|
+
(localModule = getLocalModule(
|
188
|
+
parser.state,
|
189
|
+
/** @type {string} */ (param.string),
|
190
|
+
namedModule
|
191
|
+
))
|
136
192
|
) {
|
137
193
|
localModule.flagUsed();
|
138
194
|
dep = new LocalModuleDependency(localModule, param.range, false);
|
@@ -142,15 +198,22 @@ class AMDDefineDependencyParserPlugin {
|
|
142
198
|
parser.state.current.addDependency(dep);
|
143
199
|
return true;
|
144
200
|
}
|
145
|
-
dep.loc = expr.loc;
|
201
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
146
202
|
parser.state.module.addPresentationalDependency(dep);
|
147
203
|
return true;
|
148
204
|
}
|
149
205
|
}
|
206
|
+
|
207
|
+
/**
|
208
|
+
* @param {JavascriptParser} parser the parser
|
209
|
+
* @param {CallExpression} expr call expression
|
210
|
+
* @param {BasicEvaluatedExpression} param param
|
211
|
+
* @returns {boolean | undefined} result
|
212
|
+
*/
|
150
213
|
processContext(parser, expr, param) {
|
151
214
|
const dep = ContextDependencyHelpers.create(
|
152
215
|
AMDRequireContextDependency,
|
153
|
-
param.range,
|
216
|
+
/** @type {Range} */ (param.range),
|
154
217
|
param,
|
155
218
|
expr,
|
156
219
|
this.options,
|
@@ -160,12 +223,17 @@ class AMDDefineDependencyParserPlugin {
|
|
160
223
|
parser
|
161
224
|
);
|
162
225
|
if (!dep) return;
|
163
|
-
dep.loc = expr.loc;
|
226
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
164
227
|
dep.optional = !!parser.scope.inTry;
|
165
228
|
parser.state.current.addDependency(dep);
|
166
229
|
return true;
|
167
230
|
}
|
168
231
|
|
232
|
+
/**
|
233
|
+
* @param {JavascriptParser} parser the parser
|
234
|
+
* @param {CallExpression} expr call expression
|
235
|
+
* @returns {boolean | undefined} result
|
236
|
+
*/
|
169
237
|
processCallDefine(parser, expr) {
|
170
238
|
let array, fn, obj, namedModule;
|
171
239
|
switch (expr.arguments.length) {
|
@@ -214,7 +282,7 @@ class AMDDefineDependencyParserPlugin {
|
|
214
282
|
break;
|
215
283
|
case 3:
|
216
284
|
// define("…", […], f() {…})
|
217
|
-
namedModule = expr.arguments[0].value;
|
285
|
+
namedModule = /** @type {TODO} */ (expr).arguments[0].value;
|
218
286
|
array = expr.arguments[1];
|
219
287
|
if (isCallable(expr.arguments[2])) {
|
220
288
|
// define("…", […], f() {})
|
@@ -236,10 +304,10 @@ class AMDDefineDependencyParserPlugin {
|
|
236
304
|
let fnParamsOffset = 0;
|
237
305
|
if (fn) {
|
238
306
|
if (isUnboundFunctionExpression(fn)) {
|
239
|
-
fnParams = fn.params;
|
307
|
+
fnParams = /** @type {UnboundFunctionExpression} */ (fn).params;
|
240
308
|
} else if (isBoundFunctionExpression(fn)) {
|
241
|
-
fnParams = fn.callee.object.params;
|
242
|
-
fnParamsOffset = fn.arguments.length - 1;
|
309
|
+
fnParams = /** @type {TODO} */ (fn).callee.object.params;
|
310
|
+
fnParamsOffset = /** @type {TODO} */ (fn).arguments.length - 1;
|
243
311
|
if (fnParamsOffset < 0) {
|
244
312
|
fnParamsOffset = 0;
|
245
313
|
}
|
@@ -247,6 +315,7 @@ class AMDDefineDependencyParserPlugin {
|
|
247
315
|
}
|
248
316
|
let fnRenames = new Map();
|
249
317
|
if (array) {
|
318
|
+
/** @type {Record<number, string>} */
|
250
319
|
const identifiers = {};
|
251
320
|
const param = parser.evaluateExpression(array);
|
252
321
|
const result = this.processArray(
|
@@ -278,6 +347,7 @@ class AMDDefineDependencyParserPlugin {
|
|
278
347
|
});
|
279
348
|
}
|
280
349
|
}
|
350
|
+
/** @type {boolean | undefined} */
|
281
351
|
let inTry;
|
282
352
|
if (fn && isUnboundFunctionExpression(fn)) {
|
283
353
|
inTry = parser.scope.inTry;
|
@@ -285,7 +355,7 @@ class AMDDefineDependencyParserPlugin {
|
|
285
355
|
for (const [name, varInfo] of fnRenames) {
|
286
356
|
parser.setVariable(name, varInfo);
|
287
357
|
}
|
288
|
-
parser.scope.inTry = inTry;
|
358
|
+
parser.scope.inTry = /** @type {boolean} */ (inTry);
|
289
359
|
if (fn.body.type === "BlockStatement") {
|
290
360
|
parser.detectMode(fn.body.body);
|
291
361
|
const prev = parser.prevStatement;
|
@@ -299,7 +369,8 @@ class AMDDefineDependencyParserPlugin {
|
|
299
369
|
} else if (fn && isBoundFunctionExpression(fn)) {
|
300
370
|
inTry = parser.scope.inTry;
|
301
371
|
parser.inScope(
|
302
|
-
|
372
|
+
/** @type {TODO} */
|
373
|
+
(fn).callee.object.params.filter(
|
303
374
|
i => !["require", "module", "exports"].includes(i.name)
|
304
375
|
),
|
305
376
|
() => {
|
@@ -318,21 +389,21 @@ class AMDDefineDependencyParserPlugin {
|
|
318
389
|
}
|
319
390
|
}
|
320
391
|
);
|
321
|
-
if (fn.arguments) {
|
322
|
-
parser.walkExpressions(fn.arguments);
|
392
|
+
if (/** @type {TODO} */ (fn).arguments) {
|
393
|
+
parser.walkExpressions(/** @type {TODO} */ (fn).arguments);
|
323
394
|
}
|
324
395
|
} else if (fn || obj) {
|
325
396
|
parser.walkExpression(fn || obj);
|
326
397
|
}
|
327
398
|
|
328
399
|
const dep = this.newDefineDependency(
|
329
|
-
expr.range,
|
330
|
-
array ? array.range : null,
|
331
|
-
fn ? fn.range : null,
|
332
|
-
obj ? obj.range : null,
|
400
|
+
/** @type {Range} */ (expr.range),
|
401
|
+
array ? /** @type {Range} */ (array.range) : null,
|
402
|
+
fn ? /** @type {Range} */ (fn.range) : null,
|
403
|
+
obj ? /** @type {Range} */ (obj.range) : null,
|
333
404
|
namedModule ? namedModule : null
|
334
405
|
);
|
335
|
-
dep.loc = expr.loc;
|
406
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
336
407
|
if (namedModule) {
|
337
408
|
dep.localModule = addLocalModule(parser.state, namedModule);
|
338
409
|
}
|
@@ -340,6 +411,14 @@ class AMDDefineDependencyParserPlugin {
|
|
340
411
|
return true;
|
341
412
|
}
|
342
413
|
|
414
|
+
/**
|
415
|
+
* @param {Range} range range
|
416
|
+
* @param {Range | null} arrayRange array range
|
417
|
+
* @param {Range | null} functionRange function range
|
418
|
+
* @param {Range | null} objectRange object range
|
419
|
+
* @param {boolean | null} namedModule true, when define is called with a name
|
420
|
+
* @returns {AMDDefineDependency} AMDDefineDependency
|
421
|
+
*/
|
343
422
|
newDefineDependency(
|
344
423
|
range,
|
345
424
|
arrayRange,
|
@@ -355,11 +434,24 @@ class AMDDefineDependencyParserPlugin {
|
|
355
434
|
namedModule
|
356
435
|
);
|
357
436
|
}
|
437
|
+
|
438
|
+
/**
|
439
|
+
* @param {TODO[]} depsArray deps array
|
440
|
+
* @param {Range} range range
|
441
|
+
* @returns {AMDRequireArrayDependency} AMDRequireArrayDependency
|
442
|
+
*/
|
358
443
|
newRequireArrayDependency(depsArray, range) {
|
359
444
|
return new AMDRequireArrayDependency(depsArray, range);
|
360
445
|
}
|
446
|
+
|
447
|
+
/**
|
448
|
+
* @param {string} request request
|
449
|
+
* @param {Range=} range range
|
450
|
+
* @returns {AMDRequireItemDependency} AMDRequireItemDependency
|
451
|
+
*/
|
361
452
|
newRequireItemDependency(request, range) {
|
362
453
|
return new AMDRequireItemDependency(request, range);
|
363
454
|
}
|
364
455
|
}
|
456
|
+
|
365
457
|
module.exports = AMDDefineDependencyParserPlugin;
|
@@ -35,7 +35,9 @@ const UnsupportedDependency = require("./UnsupportedDependency");
|
|
35
35
|
/** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
|
36
36
|
/** @typedef {import("../../declarations/WebpackOptions").ModuleOptionsNormalized} ModuleOptions */
|
37
37
|
/** @typedef {import("../Compiler")} Compiler */
|
38
|
+
/** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
|
38
39
|
/** @typedef {import("../javascript/JavascriptParser")} Parser */
|
40
|
+
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
39
41
|
|
40
42
|
const PLUGIN_NAME = "AMDPlugin";
|
41
43
|
|
@@ -135,6 +137,11 @@ class AMDPlugin {
|
|
135
137
|
const handler = (parser, parserOptions) => {
|
136
138
|
if (parserOptions.amd !== undefined && !parserOptions.amd) return;
|
137
139
|
|
140
|
+
/**
|
141
|
+
* @param {string} optionExpr option expression
|
142
|
+
* @param {string} rootName root name
|
143
|
+
* @param {function(): TODO} getMembers callback
|
144
|
+
*/
|
138
145
|
const tapOptionsHooks = (optionExpr, rootName, getMembers) => {
|
139
146
|
parser.hooks.expression
|
140
147
|
.for(optionExpr)
|
@@ -177,10 +184,10 @@ class AMDPlugin {
|
|
177
184
|
parser.hooks.expression.for("define").tap(PLUGIN_NAME, expr => {
|
178
185
|
const dep = new ConstDependency(
|
179
186
|
RuntimeGlobals.amdDefine,
|
180
|
-
expr.range,
|
187
|
+
/** @type {Range} */ (expr.range),
|
181
188
|
[RuntimeGlobals.amdDefine]
|
182
189
|
);
|
183
|
-
dep.loc = expr.loc;
|
190
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
184
191
|
parser.state.module.addPresentationalDependency(dep);
|
185
192
|
return true;
|
186
193
|
});
|
@@ -197,10 +204,10 @@ class AMDPlugin {
|
|
197
204
|
parser.hooks.rename.for("define").tap(PLUGIN_NAME, expr => {
|
198
205
|
const dep = new ConstDependency(
|
199
206
|
RuntimeGlobals.amdDefine,
|
200
|
-
expr.range,
|
207
|
+
/** @type {Range} */ (expr.range),
|
201
208
|
[RuntimeGlobals.amdDefine]
|
202
209
|
);
|
203
|
-
dep.loc = expr.loc;
|
210
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
204
211
|
parser.state.module.addPresentationalDependency(dep);
|
205
212
|
return false;
|
206
213
|
});
|
@@ -15,10 +15,12 @@ const NullDependency = require("./NullDependency");
|
|
15
15
|
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
16
16
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
17
17
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
18
|
+
/** @typedef {import("./AMDRequireItemDependency")} AMDRequireItemDependency */
|
19
|
+
/** @typedef {import("./LocalModuleDependency")} LocalModuleDependency */
|
18
20
|
|
19
21
|
class AMDRequireArrayDependency extends NullDependency {
|
20
22
|
/**
|
21
|
-
* @param {
|
23
|
+
* @param {(string | LocalModuleDependency | AMDRequireItemDependency)[]} depsArray deps array
|
22
24
|
* @param {Range} range range
|
23
25
|
*/
|
24
26
|
constructor(depsArray, range) {
|
@@ -81,6 +83,11 @@ AMDRequireArrayDependency.Template = class AMDRequireArrayDependencyTemplate ext
|
|
81
83
|
source.replace(dep.range[0], dep.range[1] - 1, content);
|
82
84
|
}
|
83
85
|
|
86
|
+
/**
|
87
|
+
* @param {AMDRequireArrayDependency} dep the dependency for which the template should be applied
|
88
|
+
* @param {DependencyTemplateContext} templateContext the context object
|
89
|
+
* @returns {string} content
|
90
|
+
*/
|
84
91
|
getContent(dep, templateContext) {
|
85
92
|
const requires = dep.depsArray.map(dependency => {
|
86
93
|
return this.contentForDependency(dependency, templateContext);
|
@@ -88,6 +95,11 @@ AMDRequireArrayDependency.Template = class AMDRequireArrayDependencyTemplate ext
|
|
88
95
|
return `[${requires.join(", ")}]`;
|
89
96
|
}
|
90
97
|
|
98
|
+
/**
|
99
|
+
* @param {TODO} dep the dependency for which the template should be applied
|
100
|
+
* @param {DependencyTemplateContext} templateContext the context object
|
101
|
+
* @returns {string} content
|
102
|
+
*/
|
91
103
|
contentForDependency(
|
92
104
|
dep,
|
93
105
|
{ runtimeTemplate, moduleGraph, chunkGraph, runtimeRequirements }
|