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.

Files changed (48) hide show
  1. package/lib/APIPlugin.js +150 -99
  2. package/lib/Chunk.js +35 -17
  3. package/lib/ChunkGroup.js +10 -6
  4. package/lib/Compiler.js +1 -2
  5. package/lib/ContextModule.js +4 -2
  6. package/lib/ContextModuleFactory.js +1 -0
  7. package/lib/DependenciesBlock.js +1 -1
  8. package/lib/DllModule.js +6 -0
  9. package/lib/EvalSourceMapDevToolPlugin.js +2 -1
  10. package/lib/ExternalModule.js +15 -8
  11. package/lib/Module.js +7 -1
  12. package/lib/ProgressPlugin.js +71 -15
  13. package/lib/WebpackOptionsApply.js +3 -1
  14. package/lib/css/CssExportsGenerator.js +9 -0
  15. package/lib/css/CssGenerator.js +1 -1
  16. package/lib/css/CssLoadingRuntimeModule.js +13 -6
  17. package/lib/css/CssModulesPlugin.js +37 -12
  18. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +8 -10
  19. package/lib/dependencies/HarmonyImportSpecifierDependency.js +12 -12
  20. package/lib/dependencies/JsonExportsDependency.js +1 -1
  21. package/lib/javascript/BasicEvaluatedExpression.js +6 -5
  22. package/lib/javascript/JavascriptModulesPlugin.js +1 -0
  23. package/lib/javascript/JavascriptParser.js +23 -23
  24. package/lib/json/JsonData.js +2 -2
  25. package/lib/json/JsonParser.js +25 -12
  26. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +2 -1
  27. package/lib/optimize/AggressiveMergingPlugin.js +8 -0
  28. package/lib/optimize/AggressiveSplittingPlugin.js +9 -2
  29. package/lib/optimize/EnsureChunkConditionsPlugin.js +3 -0
  30. package/lib/optimize/FlagIncludedChunksPlugin.js +11 -5
  31. package/lib/optimize/InnerGraph.js +4 -4
  32. package/lib/optimize/LimitChunkCountPlugin.js +29 -4
  33. package/lib/optimize/MangleExportsPlugin.js +1 -1
  34. package/lib/optimize/MinMaxSizeWarning.js +5 -0
  35. package/lib/optimize/ModuleConcatenationPlugin.js +59 -2
  36. package/lib/optimize/RealContentHashPlugin.js +80 -30
  37. package/lib/optimize/RemoveParentModulesPlugin.js +6 -0
  38. package/lib/optimize/RuntimeChunkPlugin.js +9 -1
  39. package/lib/optimize/SideEffectsFlagPlugin.js +10 -1
  40. package/lib/optimize/SplitChunksPlugin.js +71 -31
  41. package/lib/serialization/BinaryMiddleware.js +143 -1
  42. package/lib/serialization/ErrorObjectSerializer.js +3 -0
  43. package/lib/serialization/ObjectMiddleware.js +3 -0
  44. package/lib/serialization/types.js +1 -1
  45. package/package.json +1 -1
  46. package/schemas/WebpackOptions.check.js +1 -1
  47. package/schemas/WebpackOptions.json +12 -0
  48. package/types.d.ts +53 -41
@@ -91,7 +91,7 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
91
91
  /** @typedef {import("../Parser").ParserState} ParserState */
92
92
  /** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
93
93
  /** @typedef {{declaredScope: ScopeInfo, freeName: string | true, tagInfo: TagInfo | undefined}} VariableInfoInterface */
94
- /** @typedef {{ name: string | VariableInfo, rootInfo: string | VariableInfo, getMembers: () => string[], getMembersOptionals: () => boolean[], getMemberRangeStarts: () => number[] }} GetInfoResult */
94
+ /** @typedef {{ name: string | VariableInfo, rootInfo: string | VariableInfo, getMembers: () => string[], getMembersOptionals: () => boolean[], getMemberRanges: () => Range[] }} GetInfoResult */
95
95
 
96
96
  const EMPTY_ARRAY = [];
97
97
  const ALLOWED_MEMBER_TYPES_CALL_EXPRESSION = 0b01;
@@ -350,14 +350,14 @@ class JavascriptParser extends Parser {
350
350
  /** @type {HookMap<SyncBailHook<[BaseCallExpression], boolean | void>>} */
351
351
  call: new HookMap(() => new SyncBailHook(["expression"])),
352
352
  /** Something like "a.b()" */
353
- /** @type {HookMap<SyncBailHook<[CallExpression, string[], boolean[], number[]], boolean | void>>} */
353
+ /** @type {HookMap<SyncBailHook<[CallExpression, string[], boolean[], Range[]], boolean | void>>} */
354
354
  callMemberChain: new HookMap(
355
355
  () =>
356
356
  new SyncBailHook([
357
357
  "expression",
358
358
  "members",
359
359
  "membersOptionals",
360
- "memberRangeStarts"
360
+ "memberRanges"
361
361
  ])
362
362
  ),
363
363
  /** Something like "a.b().c.d" */
@@ -390,14 +390,14 @@ class JavascriptParser extends Parser {
390
390
  binaryExpression: new SyncBailHook(["binaryExpression"]),
391
391
  /** @type {HookMap<SyncBailHook<[Expression], boolean | void>>} */
392
392
  expression: new HookMap(() => new SyncBailHook(["expression"])),
393
- /** @type {HookMap<SyncBailHook<[Expression, string[], boolean[], number[]], boolean | void>>} */
393
+ /** @type {HookMap<SyncBailHook<[Expression, string[], boolean[], Range[]], boolean | void>>} */
394
394
  expressionMemberChain: new HookMap(
395
395
  () =>
396
396
  new SyncBailHook([
397
397
  "expression",
398
398
  "members",
399
399
  "membersOptionals",
400
- "memberRangeStarts"
400
+ "memberRanges"
401
401
  ])
402
402
  ),
403
403
  /** @type {HookMap<SyncBailHook<[Expression, string[]], boolean | void>>} */
@@ -1163,7 +1163,7 @@ class JavascriptParser extends Parser {
1163
1163
  info.rootInfo,
1164
1164
  info.getMembers,
1165
1165
  info.getMembersOptionals,
1166
- info.getMemberRangeStarts
1166
+ info.getMemberRanges
1167
1167
  )
1168
1168
  .setRange(expr.range);
1169
1169
  }
@@ -1184,7 +1184,7 @@ class JavascriptParser extends Parser {
1184
1184
  rootInfo: info,
1185
1185
  getMembers: () => [],
1186
1186
  getMembersOptionals: () => [],
1187
- getMemberRangeStarts: () => []
1187
+ getMemberRanges: () => []
1188
1188
  };
1189
1189
  }
1190
1190
  });
@@ -1199,7 +1199,7 @@ class JavascriptParser extends Parser {
1199
1199
  rootInfo: info,
1200
1200
  getMembers: () => [],
1201
1201
  getMembersOptionals: () => [],
1202
- getMemberRangeStarts: () => []
1202
+ getMemberRanges: () => []
1203
1203
  };
1204
1204
  }
1205
1205
  });
@@ -3264,7 +3264,7 @@ class JavascriptParser extends Parser {
3264
3264
  callee.getMembersOptionals
3265
3265
  ? callee.getMembersOptionals()
3266
3266
  : callee.getMembers().map(() => false),
3267
- callee.getMemberRangeStarts ? callee.getMemberRangeStarts() : []
3267
+ callee.getMemberRanges ? callee.getMemberRanges() : []
3268
3268
  );
3269
3269
  if (result1 === true) return;
3270
3270
  const result2 = this.callHooksForInfo(
@@ -3308,14 +3308,14 @@ class JavascriptParser extends Parser {
3308
3308
  if (result1 === true) return;
3309
3309
  const members = exprInfo.getMembers();
3310
3310
  const membersOptionals = exprInfo.getMembersOptionals();
3311
- const memberRangeStarts = exprInfo.getMemberRangeStarts();
3311
+ const memberRanges = exprInfo.getMemberRanges();
3312
3312
  const result2 = this.callHooksForInfo(
3313
3313
  this.hooks.expressionMemberChain,
3314
3314
  exprInfo.rootInfo,
3315
3315
  expression,
3316
3316
  members,
3317
3317
  membersOptionals,
3318
- memberRangeStarts
3318
+ memberRanges
3319
3319
  );
3320
3320
  if (result2 === true) return;
3321
3321
  this.walkMemberExpressionWithExpressionName(
@@ -4271,23 +4271,23 @@ class JavascriptParser extends Parser {
4271
4271
 
4272
4272
  /**
4273
4273
  * @param {MemberExpression} expression a member expression
4274
- * @returns {{ members: string[], object: Expression | Super, membersOptionals: boolean[], memberRangeStarts: number[] }} member names (reverse order) and remaining object
4274
+ * @returns {{ members: string[], object: Expression | Super, membersOptionals: boolean[], memberRanges: Range[] }} member names (reverse order) and remaining object
4275
4275
  */
4276
4276
  extractMemberExpressionChain(expression) {
4277
4277
  /** @type {AnyNode} */
4278
4278
  let expr = expression;
4279
4279
  const members = [];
4280
4280
  const membersOptionals = [];
4281
- const memberRangeStarts = [];
4281
+ const memberRanges = [];
4282
4282
  while (expr.type === "MemberExpression") {
4283
4283
  if (expr.computed) {
4284
4284
  if (expr.property.type !== "Literal") break;
4285
- members.push(`${expr.property.value}`);
4286
- memberRangeStarts.push(expr.object.range[1]);
4285
+ members.push(`${expr.property.value}`); // the literal
4286
+ memberRanges.push(expr.object.range); // the range of the expression fragment before the literal
4287
4287
  } else {
4288
4288
  if (expr.property.type !== "Identifier") break;
4289
- members.push(expr.property.name);
4290
- memberRangeStarts.push(expr.object.range[1]);
4289
+ members.push(expr.property.name); // the identifier
4290
+ memberRanges.push(expr.object.range); // the range of the expression fragment before the identifier
4291
4291
  }
4292
4292
  membersOptionals.push(expr.optional);
4293
4293
  expr = expr.object;
@@ -4296,7 +4296,7 @@ class JavascriptParser extends Parser {
4296
4296
  return {
4297
4297
  members,
4298
4298
  membersOptionals,
4299
- memberRangeStarts,
4299
+ memberRanges,
4300
4300
  object: expr
4301
4301
  };
4302
4302
  }
@@ -4319,8 +4319,8 @@ class JavascriptParser extends Parser {
4319
4319
  return { info, name };
4320
4320
  }
4321
4321
 
4322
- /** @typedef {{ type: "call", call: CallExpression, calleeName: string, rootInfo: string | VariableInfo, getCalleeMembers: () => string[], name: string, getMembers: () => string[], getMembersOptionals: () => boolean[], getMemberRangeStarts: () => number[]}} CallExpressionInfo */
4323
- /** @typedef {{ type: "expression", rootInfo: string | VariableInfo, name: string, getMembers: () => string[], getMembersOptionals: () => boolean[], getMemberRangeStarts: () => number[]}} ExpressionExpressionInfo */
4322
+ /** @typedef {{ type: "call", call: CallExpression, calleeName: string, rootInfo: string | VariableInfo, getCalleeMembers: () => string[], name: string, getMembers: () => string[], getMembersOptionals: () => boolean[], getMemberRanges: () => Range[]}} CallExpressionInfo */
4323
+ /** @typedef {{ type: "expression", rootInfo: string | VariableInfo, name: string, getMembers: () => string[], getMembersOptionals: () => boolean[], getMemberRanges: () => Range[]}} ExpressionExpressionInfo */
4324
4324
 
4325
4325
  /**
4326
4326
  * @param {MemberExpression} expression a member expression
@@ -4328,7 +4328,7 @@ class JavascriptParser extends Parser {
4328
4328
  * @returns {CallExpressionInfo | ExpressionExpressionInfo | undefined} expression info
4329
4329
  */
4330
4330
  getMemberExpressionInfo(expression, allowedTypes) {
4331
- const { object, members, membersOptionals, memberRangeStarts } =
4331
+ const { object, members, membersOptionals, memberRanges } =
4332
4332
  this.extractMemberExpressionChain(expression);
4333
4333
  switch (object.type) {
4334
4334
  case "CallExpression": {
@@ -4355,7 +4355,7 @@ class JavascriptParser extends Parser {
4355
4355
  name: objectAndMembersToName(`${calleeName}()`, members),
4356
4356
  getMembers: memoize(() => members.reverse()),
4357
4357
  getMembersOptionals: memoize(() => membersOptionals.reverse()),
4358
- getMemberRangeStarts: memoize(() => memberRangeStarts.reverse())
4358
+ getMemberRanges: memoize(() => memberRanges.reverse())
4359
4359
  };
4360
4360
  }
4361
4361
  case "Identifier":
@@ -4375,7 +4375,7 @@ class JavascriptParser extends Parser {
4375
4375
  rootInfo,
4376
4376
  getMembers: memoize(() => members.reverse()),
4377
4377
  getMembersOptionals: memoize(() => membersOptionals.reverse()),
4378
- getMemberRangeStarts: memoize(() => memberRangeStarts.reverse())
4378
+ getMemberRanges: memoize(() => memberRanges.reverse())
4379
4379
  };
4380
4380
  }
4381
4381
  }
@@ -40,14 +40,14 @@ class JsonData {
40
40
 
41
41
  /**
42
42
  * @param {Hash} hash hash to be updated
43
- * @returns {Hash} the updated hash
43
+ * @returns {void} the updated hash
44
44
  */
45
45
  updateHash(hash) {
46
46
  if (this._buffer === undefined && this._data !== undefined) {
47
47
  this._buffer = Buffer.from(JSON.stringify(this._data));
48
48
  }
49
49
 
50
- if (this._buffer) return hash.update(this._buffer);
50
+ if (this._buffer) hash.update(this._buffer);
51
51
  }
52
52
  }
53
53
 
@@ -5,16 +5,20 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- const parseJson = require("json-parse-even-better-errors");
9
8
  const Parser = require("../Parser");
10
9
  const JsonExportsDependency = require("../dependencies/JsonExportsDependency");
10
+ const memoize = require("../util/memoize");
11
11
  const JsonData = require("./JsonData");
12
12
 
13
13
  /** @typedef {import("../../declarations/plugins/JsonModulesPluginParser").JsonModulesPluginParserOptions} JsonModulesPluginParserOptions */
14
+ /** @typedef {import("../Module").BuildInfo} BuildInfo */
15
+ /** @typedef {import("../Module").BuildMeta} BuildMeta */
14
16
  /** @typedef {import("../Parser").ParserState} ParserState */
15
17
  /** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
16
18
  /** @typedef {import("./JsonModulesPlugin").RawJsonData} RawJsonData */
17
19
 
20
+ const getParseJson = memoize(() => require("json-parse-even-better-errors"));
21
+
18
22
  class JsonParser extends Parser {
19
23
  /**
20
24
  * @param {JsonModulesPluginParserOptions} options parser options
@@ -36,17 +40,26 @@ class JsonParser extends Parser {
36
40
 
37
41
  /** @type {NonNullable<JsonModulesPluginParserOptions["parse"]>} */
38
42
  const parseFn =
39
- typeof this.options.parse === "function" ? this.options.parse : parseJson;
40
- /** @type {Buffer | RawJsonData} */
41
- const data =
42
- typeof source === "object"
43
- ? source
44
- : parseFn(source[0] === "\ufeff" ? source.slice(1) : source);
45
- const jsonData = new JsonData(data);
46
- state.module.buildInfo.jsonData = jsonData;
47
- state.module.buildInfo.strict = true;
48
- state.module.buildMeta.exportsType = "default";
49
- state.module.buildMeta.defaultObject =
43
+ typeof this.options.parse === "function"
44
+ ? this.options.parse
45
+ : getParseJson();
46
+ /** @type {Buffer | RawJsonData | undefined} */
47
+ let data;
48
+ try {
49
+ data =
50
+ typeof source === "object"
51
+ ? source
52
+ : parseFn(source[0] === "\ufeff" ? source.slice(1) : source);
53
+ } catch (e) {
54
+ throw new Error(`Cannot parse JSON: ${/** @type {Error} */ (e).message}`);
55
+ }
56
+ const jsonData = new JsonData(/** @type {Buffer | RawJsonData} */ (data));
57
+ const buildInfo = /** @type {BuildInfo} */ (state.module.buildInfo);
58
+ buildInfo.jsonData = jsonData;
59
+ buildInfo.strict = true;
60
+ const buildMeta = /** @type {BuildMeta} */ (state.module.buildMeta);
61
+ buildMeta.exportsType = "default";
62
+ buildMeta.defaultObject =
50
63
  typeof data === "object" ? "redirect-warn" : false;
51
64
  state.module.addDependency(new JsonExportsDependency(jsonData));
52
65
  return state;
@@ -40,6 +40,7 @@ class ReadFileCompileAsyncWasmPlugin {
40
40
  : globalWasmLoading;
41
41
  return wasmLoading === this._type;
42
42
  };
43
+ const { importMetaName } = compilation.outputOptions;
43
44
  /**
44
45
  * @type {(path: string) => string}
45
46
  */
@@ -48,7 +49,7 @@ class ReadFileCompileAsyncWasmPlugin {
48
49
  Template.asString([
49
50
  "Promise.all([import('fs'), import('url')]).then(([{ readFile }, { URL }]) => new Promise((resolve, reject) => {",
50
51
  Template.indent([
51
- `readFile(new URL(${path}, import.meta.url), (err, buffer) => {`,
52
+ `readFile(new URL(${path}, ${importMetaName}.url), (err, buffer) => {`,
52
53
  Template.indent([
53
54
  "if (err) return reject(err);",
54
55
  "",
@@ -10,7 +10,15 @@ const { STAGE_ADVANCED } = require("../OptimizationStages");
10
10
  /** @typedef {import("../Chunk")} Chunk */
11
11
  /** @typedef {import("../Compiler")} Compiler */
12
12
 
13
+ /**
14
+ * @typedef {Object} AggressiveMergingPluginOptions
15
+ * @property {number=} minSizeReduce minimal size reduction to trigger merging
16
+ */
17
+
13
18
  class AggressiveMergingPlugin {
19
+ /**
20
+ * @param {AggressiveMergingPluginOptions=} [options] options object
21
+ */
14
22
  constructor(options) {
15
23
  if (
16
24
  (options !== undefined && typeof options !== "object") ||
@@ -30,6 +30,12 @@ const validate = createSchemaValidation(
30
30
  }
31
31
  );
32
32
 
33
+ /**
34
+ * @param {ChunkGraph} chunkGraph the chunk graph
35
+ * @param {Chunk} oldChunk the old chunk
36
+ * @param {Chunk} newChunk the new chunk
37
+ * @returns {(module: Module) => void} function to move module between chunks
38
+ */
33
39
  const moveModuleBetween = (chunkGraph, oldChunk, newChunk) => {
34
40
  return module => {
35
41
  chunkGraph.disconnectChunkAndModule(oldChunk, module);
@@ -92,6 +98,7 @@ class AggressiveSplittingPlugin {
92
98
  compilation => {
93
99
  let needAdditionalSeal = false;
94
100
  let newSplits;
101
+ /** @type {Set<Chunk>} */
95
102
  let fromAggressiveSplittingSet;
96
103
  let chunkSplitDataMap;
97
104
  compilation.hooks.optimize.tap("AggressiveSplittingPlugin", () => {
@@ -133,8 +140,8 @@ class AggressiveSplittingPlugin {
133
140
  ? recordedSplits.concat(newSplits)
134
141
  : recordedSplits;
135
142
 
136
- const minSize = this.options.minSize;
137
- const maxSize = this.options.maxSize;
143
+ const minSize = /** @type {number} */ (this.options.minSize);
144
+ const maxSize = /** @type {number} */ (this.options.maxSize);
138
145
 
139
146
  const applySplit = splitData => {
140
147
  // Cannot split if id is already taken
@@ -21,6 +21,9 @@ class EnsureChunkConditionsPlugin {
21
21
  compiler.hooks.compilation.tap(
22
22
  "EnsureChunkConditionsPlugin",
23
23
  compilation => {
24
+ /**
25
+ * @param {Iterable<Chunk>} chunks the chunks
26
+ */
24
27
  const handler = chunks => {
25
28
  const chunkGraph = compilation.chunkGraph;
26
29
  // These sets are hoisted here to save memory
@@ -6,6 +6,7 @@
6
6
  "use strict";
7
7
 
8
8
  /** @typedef {import("../Chunk")} Chunk */
9
+ /** @typedef {import("../Chunk").ChunkId} ChunkId */
9
10
  /** @typedef {import("../Compiler")} Compiler */
10
11
  /** @typedef {import("../Module")} Module */
11
12
 
@@ -61,13 +62,15 @@ class FlagIncludedChunksPlugin {
61
62
  for (const chunk of chunks) {
62
63
  let hash = 0;
63
64
  for (const module of chunkGraph.getChunkModulesIterable(chunk)) {
64
- hash |= moduleBits.get(module);
65
+ hash |= /** @type {number} */ (moduleBits.get(module));
65
66
  }
66
67
  chunkModulesHash.set(chunk, hash);
67
68
  }
68
69
 
69
70
  for (const chunkA of chunks) {
70
- const chunkAHash = chunkModulesHash.get(chunkA);
71
+ const chunkAHash =
72
+ /** @type {number} */
73
+ (chunkModulesHash.get(chunkA));
71
74
  const chunkAModulesCount =
72
75
  chunkGraph.getNumberOfChunkModules(chunkA);
73
76
  if (chunkAModulesCount === 0) continue;
@@ -81,7 +84,7 @@ class FlagIncludedChunksPlugin {
81
84
  bestModule = module;
82
85
  }
83
86
  loopB: for (const chunkB of chunkGraph.getModuleChunksIterable(
84
- bestModule
87
+ /** @type {Module} */ (bestModule)
85
88
  )) {
86
89
  // as we iterate the same iterables twice
87
90
  // skip if we find ourselves
@@ -100,14 +103,17 @@ class FlagIncludedChunksPlugin {
100
103
  // is chunkA in chunkB?
101
104
 
102
105
  // we do a cheap check for the hash value
103
- const chunkBHash = chunkModulesHash.get(chunkB);
106
+ const chunkBHash =
107
+ /** @type {number} */
108
+ (chunkModulesHash.get(chunkB));
104
109
  if ((chunkBHash & chunkAHash) !== chunkAHash) continue;
105
110
 
106
111
  // compare all modules
107
112
  for (const m of chunkGraph.getChunkModulesIterable(chunkA)) {
108
113
  if (!chunkGraph.isModuleInChunk(m, chunkB)) continue loopB;
109
114
  }
110
- chunkB.ids.push(chunkA.id);
115
+ /** @type {ChunkId[]} */
116
+ (chunkB.ids).push(/** @type {ChunkId} */ (chunkA.id));
111
117
  }
112
118
  }
113
119
  }
@@ -16,7 +16,7 @@ const { UsageState } = require("../ExportsInfo");
16
16
  /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
17
17
  /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
18
18
 
19
- /** @typedef {Map<TopLevelSymbol | null, Set<string | TopLevelSymbol> | true>} InnerGraph */
19
+ /** @typedef {Map<TopLevelSymbol | null, Set<string | TopLevelSymbol> | true | undefined>} InnerGraph */
20
20
  /** @typedef {function(boolean | Set<string> | undefined): void} UsageCallback */
21
21
 
22
22
  /**
@@ -34,7 +34,7 @@ const topLevelSymbolTag = Symbol("top level symbol");
34
34
 
35
35
  /**
36
36
  * @param {ParserState} parserState parser state
37
- * @returns {State} state
37
+ * @returns {State | undefined} state
38
38
  */
39
39
  function getState(parserState) {
40
40
  return parserStateMap.get(parserState);
@@ -235,7 +235,7 @@ exports.onUsage = (state, onUsageCallback) => {
235
235
 
236
236
  /**
237
237
  * @param {ParserState} state parser state
238
- * @param {TopLevelSymbol} symbol the symbol
238
+ * @param {TopLevelSymbol | undefined} symbol the symbol
239
239
  */
240
240
  exports.setTopLevelSymbol = (state, symbol) => {
241
241
  const innerGraphState = getState(state);
@@ -260,7 +260,7 @@ exports.getTopLevelSymbol = state => {
260
260
  /**
261
261
  * @param {JavascriptParser} parser parser
262
262
  * @param {string} name name of variable
263
- * @returns {TopLevelSymbol} symbol
263
+ * @returns {TopLevelSymbol | undefined} symbol
264
264
  */
265
265
  exports.tagTopLevelSymbol = (parser, name) => {
266
266
  const innerGraphState = getState(parser.state);
@@ -36,6 +36,12 @@ const validate = createSchemaValidation(
36
36
  * @property {number} bSize
37
37
  */
38
38
 
39
+ /**
40
+ * @template K, V
41
+ * @param {Map<K, Set<V>>} map map
42
+ * @param {K} key key
43
+ * @param {V} value value
44
+ */
39
45
  const addToSetMap = (map, key, value) => {
40
46
  const set = map.get(key);
41
47
  if (set === undefined) {
@@ -68,7 +74,9 @@ class LimitChunkCountPlugin {
68
74
  },
69
75
  chunks => {
70
76
  const chunkGraph = compilation.chunkGraph;
71
- const maxChunks = options.maxChunks;
77
+ const maxChunks =
78
+ /** @type {LimitChunkCountPluginOptions} */
79
+ (options).maxChunks;
72
80
  if (!maxChunks) return;
73
81
  if (maxChunks < 1) return;
74
82
  if (compilation.chunks.size <= maxChunks) return;
@@ -88,9 +96,17 @@ class LimitChunkCountPlugin {
88
96
  c => c.sizeDiff,
89
97
  (a, b) => b - a,
90
98
  // Layer 2: ordered by smallest combined size
99
+ /**
100
+ * @param {ChunkCombination} c combination
101
+ * @returns {number} integrated size
102
+ */
91
103
  c => c.integratedSize,
92
104
  (a, b) => a - b,
93
105
  // Layer 3: ordered by position difference in orderedChunk (-> to be deterministic)
106
+ /**
107
+ * @param {ChunkCombination} c combination
108
+ * @returns {number} position difference
109
+ */
94
110
  c => c.bIdx - c.aIdx,
95
111
  (a, b) => a - b,
96
112
  // Layer 4: ordered by position in orderedChunk (-> to be deterministic)
@@ -193,14 +209,18 @@ class LimitChunkCountPlugin {
193
209
  // Update all affected combinations
194
210
  // delete all combination with the removed chunk
195
211
  // we will use combinations with the kept chunk instead
196
- for (const combination of combinationsByChunk.get(a)) {
212
+ for (const combination of /** @type {Set<ChunkCombination>} */ (
213
+ combinationsByChunk.get(a)
214
+ )) {
197
215
  if (combination.deleted) continue;
198
216
  combination.deleted = true;
199
217
  combinations.delete(combination);
200
218
  }
201
219
 
202
220
  // Update combinations with the kept chunk with new sizes
203
- for (const combination of combinationsByChunk.get(b)) {
221
+ for (const combination of /** @type {Set<ChunkCombination>} */ (
222
+ combinationsByChunk.get(b)
223
+ )) {
204
224
  if (combination.deleted) continue;
205
225
  if (combination.a === b) {
206
226
  if (!chunkGraph.canChunksBeIntegrated(a, combination.b)) {
@@ -243,7 +263,12 @@ class LimitChunkCountPlugin {
243
263
  finishUpdate();
244
264
  }
245
265
  }
246
- combinationsByChunk.set(a, combinationsByChunk.get(b));
266
+ combinationsByChunk.set(
267
+ a,
268
+ /** @type {Set<ChunkCombination>} */ (
269
+ combinationsByChunk.get(b)
270
+ )
271
+ );
247
272
  combinationsByChunk.delete(b);
248
273
  }
249
274
  }
@@ -39,7 +39,7 @@ const comparator = compareSelect(e => e.name, compareStringsNumeric);
39
39
  /**
40
40
  * @param {boolean} deterministic use deterministic names
41
41
  * @param {ExportsInfo} exportsInfo exports info
42
- * @param {boolean} isNamespace is namespace object
42
+ * @param {boolean | undefined} isNamespace is namespace object
43
43
  * @returns {void}
44
44
  */
45
45
  const mangleExportsInfo = (deterministic, exportsInfo, isNamespace) => {
@@ -9,6 +9,11 @@ const SizeFormatHelpers = require("../SizeFormatHelpers");
9
9
  const WebpackError = require("../WebpackError");
10
10
 
11
11
  class MinMaxSizeWarning extends WebpackError {
12
+ /**
13
+ * @param {string[] | undefined} keys keys
14
+ * @param {number} minSize minimum size
15
+ * @param {number} maxSize maximum size
16
+ */
12
17
  constructor(keys, minSize, maxSize) {
13
18
  let keysMessage = "Fallback cache group";
14
19
  if (keys) {
@@ -40,6 +40,10 @@ const ConcatenatedModule = require("./ConcatenatedModule");
40
40
  * @property {number} added
41
41
  */
42
42
 
43
+ /**
44
+ * @param {string} msg message
45
+ * @returns {string} formatted message
46
+ */
43
47
  const formatBailoutReason = msg => {
44
48
  return "ModuleConcatenation bailout: " + msg;
45
49
  };
@@ -64,8 +68,13 @@ class ModuleConcatenationPlugin {
64
68
  );
65
69
  }
66
70
  const moduleGraph = compilation.moduleGraph;
71
+ /** @type {Map<Module, string | ((requestShortener: RequestShortener) => string)>} */
67
72
  const bailoutReasonMap = new Map();
68
73
 
74
+ /**
75
+ * @param {Module} module the module
76
+ * @param {string | ((requestShortener: RequestShortener) => string)} reason the reason
77
+ */
69
78
  const setBailoutReason = (module, reason) => {
70
79
  setInnerBailoutReason(module, reason);
71
80
  moduleGraph
@@ -77,16 +86,30 @@ class ModuleConcatenationPlugin {
77
86
  );
78
87
  };
79
88
 
89
+ /**
90
+ * @param {Module} module the module
91
+ * @param {string | ((requestShortener: RequestShortener) => string)} reason the reason
92
+ */
80
93
  const setInnerBailoutReason = (module, reason) => {
81
94
  bailoutReasonMap.set(module, reason);
82
95
  };
83
96
 
97
+ /**
98
+ * @param {Module} module the module
99
+ * @param {RequestShortener} requestShortener the request shortener
100
+ * @returns {string | ((requestShortener: RequestShortener) => string) | undefined} the reason
101
+ */
84
102
  const getInnerBailoutReason = (module, requestShortener) => {
85
103
  const reason = bailoutReasonMap.get(module);
86
104
  if (typeof reason === "function") return reason(requestShortener);
87
105
  return reason;
88
106
  };
89
107
 
108
+ /**
109
+ * @param {Module} module the module
110
+ * @param {Module | function(RequestShortener): string} problem the problem
111
+ * @returns {(requestShortener: RequestShortener) => string} the reason
112
+ */
90
113
  const formatBailoutWarning = (module, problem) => requestShortener => {
91
114
  if (typeof problem === "function") {
92
115
  return formatBailoutReason(
@@ -460,7 +483,7 @@ class ModuleConcatenationPlugin {
460
483
  c.module === rootModule ? c.originModule : c.module;
461
484
  const innerConnection =
462
485
  c.dependency instanceof HarmonyImportDependency &&
463
- modules.has(otherModule);
486
+ modules.has(/** @type {Module} */ (otherModule));
464
487
  return !innerConnection;
465
488
  });
466
489
  // add concatenated module to the compilation
@@ -533,7 +556,7 @@ class ModuleConcatenationPlugin {
533
556
  * @param {ChunkGraph} chunkGraph the chunk graph
534
557
  * @param {boolean} avoidMutateOnFailure avoid mutating the config when adding fails
535
558
  * @param {Statistics} statistics gathering metrics
536
- * @returns {Module | function(RequestShortener): string} the problematic module
559
+ * @returns {null | Module | function(RequestShortener): string} the problematic module
537
560
  */
538
561
  _tryToAdd(
539
562
  compilation,
@@ -572,6 +595,10 @@ class ModuleConcatenationPlugin {
572
595
  chunkGraph.getModuleChunksIterable(config.rootModule)
573
596
  ).filter(chunk => !chunkGraph.isModuleInChunk(module, chunk));
574
597
  if (missingChunks.length > 0) {
598
+ /**
599
+ * @param {RequestShortener} requestShortener request shortener
600
+ * @returns {string} problem description
601
+ */
575
602
  const problem = requestShortener => {
576
603
  const missingChunksList = Array.from(
577
604
  new Set(missingChunks.map(chunk => chunk.name || "unnamed chunk(s)"))
@@ -609,6 +636,10 @@ class ModuleConcatenationPlugin {
609
636
  return connection.isActive(runtime);
610
637
  });
611
638
  if (activeNonModulesConnections.length > 0) {
639
+ /**
640
+ * @param {RequestShortener} requestShortener request shortener
641
+ * @returns {string} problem description
642
+ */
612
643
  const problem = requestShortener => {
613
644
  const importingExplanations = new Set(
614
645
  activeNonModulesConnections.map(c => c.explanation).filter(Boolean)
@@ -666,6 +697,10 @@ class ModuleConcatenationPlugin {
666
697
  return false;
667
698
  });
668
699
  if (otherChunkModules.length > 0) {
700
+ /**
701
+ * @param {RequestShortener} requestShortener request shortener
702
+ * @returns {string} problem description
703
+ */
669
704
  const problem = requestShortener => {
670
705
  const names = otherChunkModules
671
706
  .map(m => m.readableIdentifier(requestShortener))
@@ -693,6 +728,10 @@ class ModuleConcatenationPlugin {
693
728
  nonHarmonyConnections.set(originModule, connections);
694
729
  }
695
730
  if (nonHarmonyConnections.size > 0) {
731
+ /**
732
+ * @param {RequestShortener} requestShortener request shortener
733
+ * @returns {string} problem description
734
+ */
696
735
  const problem = requestShortener => {
697
736
  const names = Array.from(nonHarmonyConnections)
698
737
  .map(([originModule, connections]) => {
@@ -753,6 +792,10 @@ class ModuleConcatenationPlugin {
753
792
  }
754
793
  }
755
794
  if (otherRuntimeConnections.length > 0) {
795
+ /**
796
+ * @param {RequestShortener} requestShortener request shortener
797
+ * @returns {string} problem description
798
+ */
756
799
  const problem = requestShortener => {
757
800
  return `Module ${module.readableIdentifier(
758
801
  requestShortener
@@ -831,10 +874,17 @@ class ConcatConfiguration {
831
874
  this.warnings = new Map();
832
875
  }
833
876
 
877
+ /**
878
+ * @param {Module} module the module
879
+ */
834
880
  add(module) {
835
881
  this.modules.add(module);
836
882
  }
837
883
 
884
+ /**
885
+ * @param {Module} module the module
886
+ * @returns {boolean} true, when the module is in the module set
887
+ */
838
888
  has(module) {
839
889
  return this.modules.has(module);
840
890
  }
@@ -843,10 +893,17 @@ class ConcatConfiguration {
843
893
  return this.modules.size === 1;
844
894
  }
845
895
 
896
+ /**
897
+ * @param {Module} module the module
898
+ * @param {Module | function(RequestShortener): string} problem the problem
899
+ */
846
900
  addWarning(module, problem) {
847
901
  this.warnings.set(module, problem);
848
902
  }
849
903
 
904
+ /**
905
+ * @returns {Map<Module, Module | function(RequestShortener): string>} warnings
906
+ */
850
907
  getWarningsSorted() {
851
908
  return new Map(
852
909
  Array.from(this.warnings).sort((a, b) => {