webpack 5.85.0 → 5.86.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 +150 -99
- package/lib/Chunk.js +35 -17
- package/lib/ChunkGroup.js +10 -6
- package/lib/Compiler.js +1 -2
- package/lib/ContextModule.js +4 -2
- package/lib/ContextModuleFactory.js +1 -0
- package/lib/DependenciesBlock.js +1 -1
- package/lib/DllModule.js +6 -0
- package/lib/EvalSourceMapDevToolPlugin.js +2 -1
- package/lib/ExternalModule.js +15 -8
- package/lib/Module.js +7 -1
- package/lib/ProgressPlugin.js +71 -15
- package/lib/WebpackOptionsApply.js +3 -1
- package/lib/css/CssExportsGenerator.js +9 -0
- package/lib/css/CssGenerator.js +1 -1
- package/lib/css/CssLoadingRuntimeModule.js +13 -6
- package/lib/css/CssModulesPlugin.js +37 -12
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +8 -10
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +12 -12
- package/lib/dependencies/JsonExportsDependency.js +1 -1
- package/lib/javascript/BasicEvaluatedExpression.js +6 -5
- package/lib/javascript/JavascriptModulesPlugin.js +1 -0
- package/lib/javascript/JavascriptParser.js +23 -23
- package/lib/json/JsonData.js +2 -2
- package/lib/json/JsonParser.js +25 -12
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +2 -1
- package/lib/optimize/AggressiveMergingPlugin.js +8 -0
- package/lib/optimize/AggressiveSplittingPlugin.js +9 -2
- package/lib/optimize/EnsureChunkConditionsPlugin.js +3 -0
- package/lib/optimize/FlagIncludedChunksPlugin.js +11 -5
- package/lib/optimize/InnerGraph.js +4 -4
- package/lib/optimize/LimitChunkCountPlugin.js +29 -4
- package/lib/optimize/MangleExportsPlugin.js +1 -1
- package/lib/optimize/MinMaxSizeWarning.js +5 -0
- package/lib/optimize/ModuleConcatenationPlugin.js +59 -2
- package/lib/optimize/RealContentHashPlugin.js +80 -30
- package/lib/optimize/RemoveParentModulesPlugin.js +6 -0
- package/lib/optimize/RuntimeChunkPlugin.js +9 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +10 -1
- package/lib/optimize/SplitChunksPlugin.js +71 -31
- package/lib/serialization/BinaryMiddleware.js +143 -1
- package/lib/serialization/ErrorObjectSerializer.js +3 -0
- package/lib/serialization/ObjectMiddleware.js +3 -0
- package/lib/serialization/types.js +1 -1
- package/package.json +1 -1
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +12 -0
- package/types.d.ts +53 -41
package/lib/ProgressPlugin.js
CHANGED
@@ -11,9 +11,20 @@ const NormalModule = require("./NormalModule");
|
|
11
11
|
const createSchemaValidation = require("./util/create-schema-validation");
|
12
12
|
const { contextify } = require("./util/identifier");
|
13
13
|
|
14
|
+
/** @typedef {import("tapable").Tap} Tap */
|
14
15
|
/** @typedef {import("../declarations/plugins/ProgressPlugin").HandlerFunction} HandlerFunction */
|
15
16
|
/** @typedef {import("../declarations/plugins/ProgressPlugin").ProgressPluginArgument} ProgressPluginArgument */
|
16
17
|
/** @typedef {import("../declarations/plugins/ProgressPlugin").ProgressPluginOptions} ProgressPluginOptions */
|
18
|
+
/** @typedef {import("./Dependency")} Dependency */
|
19
|
+
/** @typedef {import("./Entrypoint").EntryOptions} EntryOptions */
|
20
|
+
/** @typedef {import("./Module")} Module */
|
21
|
+
/** @typedef {import("./logging/Logger").Logger} Logger */
|
22
|
+
|
23
|
+
/**
|
24
|
+
* @typedef {Object} CountsData
|
25
|
+
* @property {number} modulesCount modules count
|
26
|
+
* @property {number} dependenciesCount dependencies count
|
27
|
+
*/
|
17
28
|
|
18
29
|
const validate = createSchemaValidation(
|
19
30
|
require("../schemas/plugins/ProgressPlugin.check.js"),
|
@@ -23,14 +34,31 @@ const validate = createSchemaValidation(
|
|
23
34
|
baseDataPath: "options"
|
24
35
|
}
|
25
36
|
);
|
37
|
+
|
38
|
+
/**
|
39
|
+
* @param {number} a a
|
40
|
+
* @param {number} b b
|
41
|
+
* @param {number} c c
|
42
|
+
* @returns {number} median
|
43
|
+
*/
|
26
44
|
const median3 = (a, b, c) => {
|
27
45
|
return a + b + c - Math.max(a, b, c) - Math.min(a, b, c);
|
28
46
|
};
|
29
47
|
|
48
|
+
/**
|
49
|
+
* @param {boolean | null | undefined} profile need profile
|
50
|
+
* @param {Logger} logger logger
|
51
|
+
* @returns {defaultHandler} default handler
|
52
|
+
*/
|
30
53
|
const createDefaultHandler = (profile, logger) => {
|
31
|
-
/** @type {{ value: string, time: number }[]} */
|
54
|
+
/** @type {{ value: string | undefined, time: number }[]} */
|
32
55
|
const lastStateInfo = [];
|
33
56
|
|
57
|
+
/**
|
58
|
+
* @param {number} percentage percentage
|
59
|
+
* @param {string} msg message
|
60
|
+
* @param {...string} args additional arguments
|
61
|
+
*/
|
34
62
|
const defaultHandler = (percentage, msg, ...args) => {
|
35
63
|
if (profile) {
|
36
64
|
if (percentage === 0) {
|
@@ -95,18 +123,18 @@ const createDefaultHandler = (profile, logger) => {
|
|
95
123
|
|
96
124
|
/**
|
97
125
|
* @callback ReportProgress
|
98
|
-
* @param {number} p
|
99
|
-
* @param {...string}
|
126
|
+
* @param {number} p percentage
|
127
|
+
* @param {...string} args additional arguments
|
100
128
|
* @returns {void}
|
101
129
|
*/
|
102
130
|
|
103
|
-
/** @type {WeakMap<Compiler,ReportProgress>} */
|
131
|
+
/** @type {WeakMap<Compiler, ReportProgress | undefined>} */
|
104
132
|
const progressReporters = new WeakMap();
|
105
133
|
|
106
134
|
class ProgressPlugin {
|
107
135
|
/**
|
108
136
|
* @param {Compiler} compiler the current compiler
|
109
|
-
* @returns {ReportProgress} a progress reporter, if any
|
137
|
+
* @returns {ReportProgress | undefined} a progress reporter, if any
|
110
138
|
*/
|
111
139
|
static getReporter(compiler) {
|
112
140
|
return progressReporters.get(compiler);
|
@@ -288,6 +316,9 @@ class ProgressPlugin {
|
|
288
316
|
};
|
289
317
|
|
290
318
|
// only used when showActiveModules is set
|
319
|
+
/**
|
320
|
+
* @param {Module} module the module
|
321
|
+
*/
|
291
322
|
const moduleBuild = module => {
|
292
323
|
const ident = module.identifier();
|
293
324
|
if (ident) {
|
@@ -297,11 +328,18 @@ class ProgressPlugin {
|
|
297
328
|
}
|
298
329
|
};
|
299
330
|
|
331
|
+
/**
|
332
|
+
* @param {Dependency} entry entry dependency
|
333
|
+
* @param {EntryOptions} options options object
|
334
|
+
*/
|
300
335
|
const entryAdd = (entry, options) => {
|
301
336
|
entriesCount++;
|
302
337
|
if (entriesCount < 5 || entriesCount % 10 === 0) updateThrottled();
|
303
338
|
};
|
304
339
|
|
340
|
+
/**
|
341
|
+
* @param {Module} module the module
|
342
|
+
*/
|
305
343
|
const moduleDone = module => {
|
306
344
|
doneModules++;
|
307
345
|
if (showActiveModules) {
|
@@ -321,6 +359,10 @@ class ProgressPlugin {
|
|
321
359
|
if (doneModules < 50 || doneModules % 100 === 0) updateThrottled();
|
322
360
|
};
|
323
361
|
|
362
|
+
/**
|
363
|
+
* @param {Dependency} entry entry dependency
|
364
|
+
* @param {EntryOptions} options options object
|
365
|
+
*/
|
324
366
|
const entryDone = (entry, options) => {
|
325
367
|
doneEntries++;
|
326
368
|
update();
|
@@ -330,6 +372,7 @@ class ProgressPlugin {
|
|
330
372
|
.getCache("ProgressPlugin")
|
331
373
|
.getItemCache("counts", null);
|
332
374
|
|
375
|
+
/** @type {Promise<CountsData> | undefined} */
|
333
376
|
let cacheGetPromise;
|
334
377
|
|
335
378
|
compiler.hooks.beforeCompile.tap("ProgressPlugin", () => {
|
@@ -352,15 +395,17 @@ class ProgressPlugin {
|
|
352
395
|
|
353
396
|
compiler.hooks.afterCompile.tapPromise("ProgressPlugin", compilation => {
|
354
397
|
if (compilation.compiler.isChild()) return Promise.resolve();
|
355
|
-
return cacheGetPromise.then(
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
398
|
+
return /** @type {Promise<CountsData>} */ (cacheGetPromise).then(
|
399
|
+
async oldData => {
|
400
|
+
if (
|
401
|
+
!oldData ||
|
402
|
+
oldData.modulesCount !== modulesCount ||
|
403
|
+
oldData.dependenciesCount !== dependenciesCount
|
404
|
+
) {
|
405
|
+
await cache.storePromise({ modulesCount, dependenciesCount });
|
406
|
+
}
|
362
407
|
}
|
363
|
-
|
408
|
+
);
|
364
409
|
});
|
365
410
|
|
366
411
|
compiler.hooks.compilation.tap("ProgressPlugin", compilation => {
|
@@ -463,9 +508,9 @@ class ProgressPlugin {
|
|
463
508
|
};
|
464
509
|
const numberOfHooks = Object.keys(hooks).length;
|
465
510
|
Object.keys(hooks).forEach((name, idx) => {
|
466
|
-
const title = hooks[name];
|
511
|
+
const title = hooks[/** @type {keyof typeof hooks} */ (name)];
|
467
512
|
const percentage = (idx / numberOfHooks) * 0.25 + 0.7;
|
468
|
-
compilation.hooks[name].intercept({
|
513
|
+
compilation.hooks[/** @type {keyof typeof hooks} */ (name)].intercept({
|
469
514
|
name: "ProgressPlugin",
|
470
515
|
call() {
|
471
516
|
handler(percentage, "sealing", title);
|
@@ -500,6 +545,12 @@ class ProgressPlugin {
|
|
500
545
|
handler(0.65, "building");
|
501
546
|
}
|
502
547
|
});
|
548
|
+
/**
|
549
|
+
* @param {TODO} hook hook
|
550
|
+
* @param {number} progress progress from 0 to 1
|
551
|
+
* @param {string} category category
|
552
|
+
* @param {string} name name
|
553
|
+
*/
|
503
554
|
const interceptHook = (hook, progress, category, name) => {
|
504
555
|
hook.intercept({
|
505
556
|
name: "ProgressPlugin",
|
@@ -516,6 +567,9 @@ class ProgressPlugin {
|
|
516
567
|
error() {
|
517
568
|
handler(progress, category, name);
|
518
569
|
},
|
570
|
+
/**
|
571
|
+
* @param {Tap} tap tap
|
572
|
+
*/
|
519
573
|
tap(tap) {
|
520
574
|
progressReporters.set(compiler, (p, ...args) => {
|
521
575
|
handler(progress, category, name, tap.name, ...args);
|
@@ -610,4 +664,6 @@ ProgressPlugin.defaultOptions = {
|
|
610
664
|
entries: true
|
611
665
|
};
|
612
666
|
|
667
|
+
ProgressPlugin.createDefaultHandler = createDefaultHandler;
|
668
|
+
|
613
669
|
module.exports = ProgressPlugin;
|
@@ -368,7 +368,9 @@ class WebpackOptionsApply extends OptionsApply {
|
|
368
368
|
const NodeStuffPlugin = require("./NodeStuffPlugin");
|
369
369
|
new NodeStuffPlugin(options.node).apply(compiler);
|
370
370
|
}
|
371
|
-
new APIPlugin(
|
371
|
+
new APIPlugin({
|
372
|
+
module: options.output.module
|
373
|
+
}).apply(compiler);
|
372
374
|
new ExportsInfoApiPlugin().apply(compiler);
|
373
375
|
new WebpackIsIncludedPlugin().apply(compiler);
|
374
376
|
new ConstPlugin().apply(compiler);
|
@@ -19,6 +19,11 @@ const Template = require("../Template");
|
|
19
19
|
/** @typedef {import("../NormalModule")} NormalModule */
|
20
20
|
/** @typedef {import("../util/Hash")} Hash */
|
21
21
|
|
22
|
+
/**
|
23
|
+
* @template T
|
24
|
+
* @typedef {import("../InitFragment")<T>} InitFragment
|
25
|
+
*/
|
26
|
+
|
22
27
|
const TYPES = new Set(["javascript"]);
|
23
28
|
|
24
29
|
class CssExportsGenerator extends Generator {
|
@@ -36,6 +41,7 @@ class CssExportsGenerator extends Generator {
|
|
36
41
|
*/
|
37
42
|
generate(module, generateContext) {
|
38
43
|
const source = new ReplaceSource(new RawSource(""));
|
44
|
+
/** @type {InitFragment<TODO>[]} */
|
39
45
|
const initFragments = [];
|
40
46
|
const cssExports = new Map();
|
41
47
|
|
@@ -57,6 +63,9 @@ class CssExportsGenerator extends Generator {
|
|
57
63
|
cssExports
|
58
64
|
};
|
59
65
|
|
66
|
+
/**
|
67
|
+
* @param {Dependency} dependency the dependency
|
68
|
+
*/
|
60
69
|
const handleDependency = dependency => {
|
61
70
|
const constructor = /** @type {new (...args: any[]) => Dependency} */ (
|
62
71
|
dependency.constructor
|
package/lib/css/CssGenerator.js
CHANGED
@@ -30,7 +30,7 @@ class CssGenerator extends Generator {
|
|
30
30
|
* @returns {Source} generated code
|
31
31
|
*/
|
32
32
|
generate(module, generateContext) {
|
33
|
-
const originalSource = module.originalSource();
|
33
|
+
const originalSource = /** @type {Source} */ (module.originalSource());
|
34
34
|
const source = new ReplaceSource(originalSource);
|
35
35
|
/** @type {InitFragment[]} */
|
36
36
|
const initFragments = [];
|
@@ -14,6 +14,7 @@ const compileBooleanMatcher = require("../util/compileBooleanMatcher");
|
|
14
14
|
const { chunkHasCss } = require("./CssModulesPlugin");
|
15
15
|
|
16
16
|
/** @typedef {import("../Chunk")} Chunk */
|
17
|
+
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
17
18
|
/** @typedef {import("../Compilation").RuntimeRequirementsContext} RuntimeRequirementsContext */
|
18
19
|
|
19
20
|
/**
|
@@ -67,10 +68,15 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
67
68
|
uniqueName,
|
68
69
|
chunkLoadTimeout: loadTimeout
|
69
70
|
}
|
70
|
-
} = compilation;
|
71
|
+
} = /** @type {Compilation} */ (compilation);
|
71
72
|
const fn = RuntimeGlobals.ensureChunkHandlers;
|
72
73
|
const conditionMap = chunkGraph.getChunkConditionMap(
|
73
|
-
chunk,
|
74
|
+
/** @type {Chunk} */ (chunk),
|
75
|
+
/**
|
76
|
+
* @param {Chunk} chunk the chunk
|
77
|
+
* @param {ChunkGraph} chunkGraph the chunk graph
|
78
|
+
* @returns {boolean} true, if the chunk has css
|
79
|
+
*/
|
74
80
|
(chunk, chunkGraph) =>
|
75
81
|
!!chunkGraph.getChunkModulesIterableBySourceType(chunk, "css")
|
76
82
|
);
|
@@ -87,7 +93,7 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
87
93
|
const initialChunkIdsWithCss = new Set();
|
88
94
|
/** @type {Set<number | string | null>} */
|
89
95
|
const initialChunkIdsWithoutCss = new Set();
|
90
|
-
for (const c of chunk.getAllInitialChunks()) {
|
96
|
+
for (const c of /** @type {Chunk} */ (chunk).getAllInitialChunks()) {
|
91
97
|
(chunkHasCss(c, chunkGraph)
|
92
98
|
? initialChunkIdsWithCss
|
93
99
|
: initialChunkIdsWithoutCss
|
@@ -98,8 +104,9 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
98
104
|
return null;
|
99
105
|
}
|
100
106
|
|
101
|
-
const { createStylesheet } =
|
102
|
-
|
107
|
+
const { createStylesheet } = CssLoadingRuntimeModule.getCompilationHooks(
|
108
|
+
/** @type {Compilation} */ (compilation)
|
109
|
+
);
|
103
110
|
|
104
111
|
const stateExpression = withHmr
|
105
112
|
? `${RuntimeGlobals.hmrRuntimeStatePrefix}_css`
|
@@ -239,7 +246,7 @@ class CssLoadingRuntimeModule extends RuntimeModule {
|
|
239
246
|
"if(!link) {",
|
240
247
|
Template.indent([
|
241
248
|
"needAttach = true;",
|
242
|
-
createStylesheet.call(code, this.chunk)
|
249
|
+
createStylesheet.call(code, /** @type {Chunk} */ (this.chunk))
|
243
250
|
]),
|
244
251
|
"}",
|
245
252
|
`var onLinkComplete = ${runtimeTemplate.basicFunction(
|
@@ -46,6 +46,10 @@ const getCssLoadingRuntimeModule = memoize(() =>
|
|
46
46
|
require("./CssLoadingRuntimeModule")
|
47
47
|
);
|
48
48
|
|
49
|
+
/**
|
50
|
+
* @param {string} name name
|
51
|
+
* @returns {{oneOf: [{$ref: string}], definitions: *}} schema
|
52
|
+
*/
|
49
53
|
const getSchema = name => {
|
50
54
|
const { definitions } = require("../../schemas/WebpackOptions.json");
|
51
55
|
return {
|
@@ -302,6 +306,10 @@ class CssModulesPlugin {
|
|
302
306
|
return result;
|
303
307
|
});
|
304
308
|
const globalChunkLoading = compilation.outputOptions.chunkLoading;
|
309
|
+
/**
|
310
|
+
* @param {Chunk} chunk the chunk
|
311
|
+
* @returns {boolean} true, when enabled
|
312
|
+
*/
|
305
313
|
const isEnabledForChunk = chunk => {
|
306
314
|
const options = chunk.getEntryOptions();
|
307
315
|
const chunkLoading =
|
@@ -311,6 +319,10 @@ class CssModulesPlugin {
|
|
311
319
|
return chunkLoading === "jsonp";
|
312
320
|
};
|
313
321
|
const onceForChunkSet = new WeakSet();
|
322
|
+
/**
|
323
|
+
* @param {Chunk} chunk chunk to check
|
324
|
+
* @param {Set<string>} set runtime requirements
|
325
|
+
*/
|
314
326
|
const handler = (chunk, set) => {
|
315
327
|
if (onceForChunkSet.has(chunk)) return;
|
316
328
|
onceForChunkSet.add(chunk);
|
@@ -361,7 +373,10 @@ class CssModulesPlugin {
|
|
361
373
|
};
|
362
374
|
})
|
363
375
|
.filter(item => item.index !== undefined)
|
364
|
-
.sort(
|
376
|
+
.sort(
|
377
|
+
(a, b) =>
|
378
|
+
/** @type {number} */ (b.index) - /** @type {number} */ (a.index)
|
379
|
+
)
|
365
380
|
.map(item => item.module);
|
366
381
|
|
367
382
|
return { list: sortedModules, set: new Set(sortedModules) };
|
@@ -455,19 +470,25 @@ class CssModulesPlugin {
|
|
455
470
|
return [
|
456
471
|
...this.getModulesInOrder(
|
457
472
|
chunk,
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
473
|
+
/** @type {Iterable<Module>} */
|
474
|
+
(
|
475
|
+
chunkGraph.getOrderedChunkModulesIterableBySourceType(
|
476
|
+
chunk,
|
477
|
+
"css-import",
|
478
|
+
compareModulesByIdentifier
|
479
|
+
)
|
462
480
|
),
|
463
481
|
compilation
|
464
482
|
),
|
465
483
|
...this.getModulesInOrder(
|
466
484
|
chunk,
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
485
|
+
/** @type {Iterable<Module>} */
|
486
|
+
(
|
487
|
+
chunkGraph.getOrderedChunkModulesIterableBySourceType(
|
488
|
+
chunk,
|
489
|
+
"css",
|
490
|
+
compareModulesByIdentifier
|
491
|
+
)
|
471
492
|
),
|
472
493
|
compilation
|
473
494
|
)
|
@@ -498,8 +519,11 @@ class CssModulesPlugin {
|
|
498
519
|
const codeGenResult = codeGenerationResults.get(module, chunk.runtime);
|
499
520
|
|
500
521
|
let moduleSource =
|
501
|
-
|
502
|
-
|
522
|
+
/** @type {Source} */
|
523
|
+
(
|
524
|
+
codeGenResult.sources.get("css") ||
|
525
|
+
codeGenResult.sources.get("css-import")
|
526
|
+
);
|
503
527
|
|
504
528
|
let inheritance = [[module.cssLayer, module.supports, module.media]];
|
505
529
|
|
@@ -569,7 +593,8 @@ class CssModulesPlugin {
|
|
569
593
|
}${escapeCss(moduleId)}`
|
570
594
|
);
|
571
595
|
} catch (e) {
|
572
|
-
|
596
|
+
/** @type {Error} */
|
597
|
+
(e).message += `\nduring rendering of css ${module.identifier()}`;
|
573
598
|
throw e;
|
574
599
|
}
|
575
600
|
}
|
@@ -212,7 +212,7 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
212
212
|
.for(harmonySpecifierTag)
|
213
213
|
.tap(
|
214
214
|
"HarmonyImportDependencyParserPlugin",
|
215
|
-
(expression, members, membersOptionals,
|
215
|
+
(expression, members, membersOptionals, memberRanges) => {
|
216
216
|
const settings = /** @type {HarmonySettings} */ (
|
217
217
|
parser.currentTagData
|
218
218
|
);
|
@@ -220,10 +220,9 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
220
220
|
members,
|
221
221
|
membersOptionals
|
222
222
|
);
|
223
|
-
const
|
223
|
+
const ranges = memberRanges.slice(
|
224
224
|
0,
|
225
|
-
|
226
|
-
(members.length - nonOptionalMembers.length)
|
225
|
+
memberRanges.length - (members.length - nonOptionalMembers.length)
|
227
226
|
);
|
228
227
|
const expr =
|
229
228
|
nonOptionalMembers !== members
|
@@ -241,7 +240,7 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
241
240
|
expr.range,
|
242
241
|
exportPresenceMode,
|
243
242
|
settings.assertions,
|
244
|
-
|
243
|
+
ranges
|
245
244
|
);
|
246
245
|
dep.referencedPropertiesInDestructuring =
|
247
246
|
parser.destructuringAssignmentPropertiesFor(expr);
|
@@ -256,7 +255,7 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
256
255
|
.for(harmonySpecifierTag)
|
257
256
|
.tap(
|
258
257
|
"HarmonyImportDependencyParserPlugin",
|
259
|
-
(expression, members, membersOptionals,
|
258
|
+
(expression, members, membersOptionals, memberRanges) => {
|
260
259
|
const { arguments: args, callee } = expression;
|
261
260
|
const settings = /** @type {HarmonySettings} */ (
|
262
261
|
parser.currentTagData
|
@@ -265,10 +264,9 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
265
264
|
members,
|
266
265
|
membersOptionals
|
267
266
|
);
|
268
|
-
const
|
267
|
+
const ranges = memberRanges.slice(
|
269
268
|
0,
|
270
|
-
|
271
|
-
(members.length - nonOptionalMembers.length)
|
269
|
+
memberRanges.length - (members.length - nonOptionalMembers.length)
|
272
270
|
);
|
273
271
|
const expr =
|
274
272
|
nonOptionalMembers !== members
|
@@ -286,7 +284,7 @@ module.exports = class HarmonyImportDependencyParserPlugin {
|
|
286
284
|
expr.range,
|
287
285
|
exportPresenceMode,
|
288
286
|
settings.assertions,
|
289
|
-
|
287
|
+
ranges
|
290
288
|
);
|
291
289
|
dep.directImport = members.length === 0;
|
292
290
|
dep.call = true;
|
@@ -43,7 +43,7 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
|
|
43
43
|
* @param {Range} range range
|
44
44
|
* @param {TODO} exportPresenceMode export presence mode
|
45
45
|
* @param {Assertions=} assertions assertions
|
46
|
-
* @param {
|
46
|
+
* @param {Range[]=} idRanges ranges for members of ids; the two arrays are right-aligned
|
47
47
|
*/
|
48
48
|
constructor(
|
49
49
|
request,
|
@@ -53,13 +53,13 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
|
|
53
53
|
range,
|
54
54
|
exportPresenceMode,
|
55
55
|
assertions,
|
56
|
-
|
56
|
+
idRanges // TODO webpack 6 make this non-optional. It must always be set to properly trim ids.
|
57
57
|
) {
|
58
58
|
super(request, sourceOrder, assertions);
|
59
59
|
this.ids = ids;
|
60
60
|
this.name = name;
|
61
61
|
this.range = range;
|
62
|
-
this.
|
62
|
+
this.idRanges = idRanges;
|
63
63
|
this.exportPresenceMode = exportPresenceMode;
|
64
64
|
this.namespaceObjectAsContext = false;
|
65
65
|
this.call = undefined;
|
@@ -261,7 +261,7 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
|
|
261
261
|
write(this.ids);
|
262
262
|
write(this.name);
|
263
263
|
write(this.range);
|
264
|
-
write(this.
|
264
|
+
write(this.idRanges);
|
265
265
|
write(this.exportPresenceMode);
|
266
266
|
write(this.namespaceObjectAsContext);
|
267
267
|
write(this.call);
|
@@ -281,7 +281,7 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
|
|
281
281
|
this.ids = read();
|
282
282
|
this.name = read();
|
283
283
|
this.range = read();
|
284
|
-
this.
|
284
|
+
this.idRanges = read();
|
285
285
|
this.exportPresenceMode = read();
|
286
286
|
this.namespaceObjectAsContext = read();
|
287
287
|
this.call = read();
|
@@ -320,15 +320,15 @@ HarmonyImportSpecifierDependency.Template = class HarmonyImportSpecifierDependen
|
|
320
320
|
|
321
321
|
let [rangeStart, rangeEnd] = dep.range;
|
322
322
|
if (trimmedIds.length !== ids.length) {
|
323
|
-
// The array returned from dep.
|
323
|
+
// The array returned from dep.idRanges is right-aligned with the array returned from dep.getIds.
|
324
324
|
// Meaning, the two arrays may not always have the same number of elements, but the last element of
|
325
|
-
// dep.
|
326
|
-
// Use this to find the correct range
|
325
|
+
// dep.idRanges corresponds to [the expression fragment to the left of] the last element of dep.getIds.
|
326
|
+
// Use this to find the correct replacement range based on the number of ids that were trimmed.
|
327
327
|
const idx =
|
328
|
-
dep.
|
328
|
+
dep.idRanges === undefined
|
329
329
|
? -1 /* trigger failure case below */
|
330
|
-
: dep.
|
331
|
-
if (idx < 0 || idx >= dep.
|
330
|
+
: dep.idRanges.length + (trimmedIds.length - ids.length);
|
331
|
+
if (idx < 0 || idx >= dep.idRanges.length) {
|
332
332
|
// cspell:ignore minifiers
|
333
333
|
// Should not happen but we can't throw an error here because of backward compatibility with
|
334
334
|
// external plugins in wp5. Instead, we just disable trimming for now. This may break some minifiers.
|
@@ -336,7 +336,7 @@ HarmonyImportSpecifierDependency.Template = class HarmonyImportSpecifierDependen
|
|
336
336
|
// TODO webpack 6 remove the "trimmedIds = ids" above and uncomment the following line instead.
|
337
337
|
// throw new Error("Missing range starts data for id replacement trimming.");
|
338
338
|
} else {
|
339
|
-
rangeEnd = dep.
|
339
|
+
[rangeStart, rangeEnd] = dep.idRanges[idx];
|
340
340
|
}
|
341
341
|
}
|
342
342
|
|
@@ -6,6 +6,7 @@
|
|
6
6
|
"use strict";
|
7
7
|
|
8
8
|
/** @typedef {import("estree").Node} EsTreeNode */
|
9
|
+
/** @typedef {import("./JavascriptParser").Range} Range */
|
9
10
|
/** @typedef {import("./JavascriptParser").VariableInfoInterface} VariableInfoInterface */
|
10
11
|
|
11
12
|
const TypeUnknown = 0;
|
@@ -70,8 +71,8 @@ class BasicEvaluatedExpression {
|
|
70
71
|
this.getMembers = undefined;
|
71
72
|
/** @type {() => boolean[]} */
|
72
73
|
this.getMembersOptionals = undefined;
|
73
|
-
/** @type {() =>
|
74
|
-
this.
|
74
|
+
/** @type {() => Range[]} */
|
75
|
+
this.getMemberRanges = undefined;
|
75
76
|
/** @type {EsTreeNode} */
|
76
77
|
this.expression = undefined;
|
77
78
|
}
|
@@ -386,7 +387,7 @@ class BasicEvaluatedExpression {
|
|
386
387
|
* @param {string | VariableInfoInterface} rootInfo root info
|
387
388
|
* @param {() => string[]} getMembers members
|
388
389
|
* @param {() => boolean[]=} getMembersOptionals optional members
|
389
|
-
* @param {() =>
|
390
|
+
* @param {() => Range[]=} getMemberRanges ranges of progressively increasing sub-expressions
|
390
391
|
* @returns {this} this
|
391
392
|
*/
|
392
393
|
setIdentifier(
|
@@ -394,14 +395,14 @@ class BasicEvaluatedExpression {
|
|
394
395
|
rootInfo,
|
395
396
|
getMembers,
|
396
397
|
getMembersOptionals,
|
397
|
-
|
398
|
+
getMemberRanges
|
398
399
|
) {
|
399
400
|
this.type = TypeIdentifier;
|
400
401
|
this.identifier = identifier;
|
401
402
|
this.rootInfo = rootInfo;
|
402
403
|
this.getMembers = getMembers;
|
403
404
|
this.getMembersOptionals = getMembersOptionals;
|
404
|
-
this.
|
405
|
+
this.getMemberRanges = getMemberRanges;
|
405
406
|
this.sideEffects = true;
|
406
407
|
return this;
|
407
408
|
}
|
@@ -937,6 +937,7 @@ class JavascriptModulesPlugin {
|
|
937
937
|
"JavascriptModulesPlugin error: JavascriptModulesPlugin.getCompilationHooks().renderContent plugins should return something"
|
938
938
|
);
|
939
939
|
}
|
940
|
+
|
940
941
|
finalSource = InitFragment.addToSource(
|
941
942
|
finalSource,
|
942
943
|
chunkRenderContext.chunkInitFragments,
|