webpack 5.23.0 → 5.24.3

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.

@@ -11,7 +11,7 @@ const HarmonyLinkingError = require("../HarmonyLinkingError");
11
11
  const InitFragment = require("../InitFragment");
12
12
  const RuntimeGlobals = require("../RuntimeGlobals");
13
13
  const Template = require("../Template");
14
- const { first } = require("../util/SetHelpers");
14
+ const { first, combine } = require("../util/SetHelpers");
15
15
  const makeSerializable = require("../util/makeSerializable");
16
16
  const propertyAccess = require("../util/propertyAccess");
17
17
  const HarmonyExportInitFragment = require("./HarmonyExportInitFragment");
@@ -43,14 +43,16 @@ class NormalReexportItem {
43
43
  /**
44
44
  * @param {string} name export name
45
45
  * @param {string[]} ids reexported ids from other module
46
- * @param {ExportInfo=} exportInfo export info from other module
47
- * @param {boolean=} checked true, if it should be checked at runtime if this export exists
46
+ * @param {ExportInfo} exportInfo export info from other module
47
+ * @param {boolean} checked true, if it should be checked at runtime if this export exists
48
+ * @param {boolean} hidden true, if it is hidden behind another active export in the same module
48
49
  */
49
- constructor(name, ids, exportInfo, checked) {
50
+ constructor(name, ids, exportInfo, checked, hidden) {
50
51
  this.name = name;
51
52
  this.ids = ids;
52
53
  this.exportInfo = exportInfo;
53
54
  this.checked = checked;
55
+ this.hidden = hidden;
54
56
  }
55
57
  }
56
58
 
@@ -76,6 +78,10 @@ class ExportMode {
76
78
  /** @type {Set<string> | null} */
77
79
  this.ignored = null;
78
80
 
81
+ // for "dynamic-reexport" | "empty-star":
82
+ /** @type {Set<string> | null} */
83
+ this.hidden = null;
84
+
79
85
  // for "missing":
80
86
  /** @type {string | null} */
81
87
  this.userRequest = null;
@@ -225,7 +231,9 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
225
231
  break;
226
232
  default:
227
233
  mode = new ExportMode("normal-reexport");
228
- mode.items = [new NormalReexportItem(name, ids, exportInfo, false)];
234
+ mode.items = [
235
+ new NormalReexportItem(name, ids, exportInfo, false, false)
236
+ ];
229
237
  break;
230
238
  }
231
239
  } else {
@@ -256,7 +264,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
256
264
 
257
265
  // Star reexporting
258
266
 
259
- const { ignoredExports, exports, checked } = this.getStarReexports(
267
+ const { ignoredExports, exports, checked, hidden } = this.getStarReexports(
260
268
  moduleGraph,
261
269
  runtime,
262
270
  exportsInfo,
@@ -268,12 +276,14 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
268
276
 
269
277
  const mode = new ExportMode("dynamic-reexport");
270
278
  mode.ignored = ignoredExports;
279
+ mode.hidden = hidden;
271
280
 
272
281
  return mode;
273
282
  }
274
283
 
275
284
  if (exports.size === 0) {
276
285
  const mode = new ExportMode("empty-star");
286
+ mode.hidden = hidden;
277
287
 
278
288
  return mode;
279
289
  }
@@ -287,8 +297,21 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
287
297
  exportName,
288
298
  [exportName],
289
299
  exportsInfo.getReadOnlyExportInfo(exportName),
290
- checked.has(exportName)
300
+ checked.has(exportName),
301
+ false
291
302
  )
303
+ ).concat(
304
+ Array.from(
305
+ hidden,
306
+ exportName =>
307
+ new NormalReexportItem(
308
+ exportName,
309
+ [exportName],
310
+ exportsInfo.getReadOnlyExportInfo(exportName),
311
+ false,
312
+ true
313
+ )
314
+ )
292
315
  );
293
316
 
294
317
  return mode;
@@ -299,7 +322,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
299
322
  * @param {RuntimeSpec} runtime the runtime
300
323
  * @param {ExportsInfo} exportsInfo exports info about the current module (optional)
301
324
  * @param {Module} importedModule the imported module (optional)
302
- * @returns {{exports?: Set<string>, checked?: Set<string>, ignoredExports: Set<string>}} information
325
+ * @returns {{exports?: Set<string>, checked?: Set<string>, ignoredExports: Set<string>, hidden: Set<string>}} information
303
326
  */
304
327
  getStarReexports(
305
328
  moduleGraph,
@@ -314,15 +337,16 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
314
337
  const noExtraImports =
315
338
  exportsInfo.otherExportsInfo.getUsed(runtime) === UsageState.Unused;
316
339
 
317
- const ignoredExports = new Set([
318
- "default",
319
- ...this.activeExports,
320
- ...this._discoverActiveExportsFromOtherStarExports(moduleGraph).keys()
321
- ]);
340
+ const ignoredExports = new Set(["default", ...this.activeExports]);
341
+ const hiddenExports = new Set(
342
+ this._discoverActiveExportsFromOtherStarExports(moduleGraph).keys()
343
+ );
344
+ for (const e of ignoredExports) hiddenExports.delete(e);
322
345
 
323
346
  if (!noExtraExports && !noExtraImports) {
324
347
  return {
325
- ignoredExports
348
+ ignoredExports,
349
+ hidden: hiddenExports
326
350
  };
327
351
  }
328
352
 
@@ -330,6 +354,8 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
330
354
  const exports = new Set();
331
355
  /** @type {Set<string>} */
332
356
  const checked = new Set();
357
+ /** @type {Set<string>} */
358
+ const hidden = new Set();
333
359
 
334
360
  if (noExtraImports) {
335
361
  for (const exportInfo of exportsInfo.orderedExports) {
@@ -340,6 +366,10 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
340
366
  name
341
367
  );
342
368
  if (importedExportInfo.provided === false) continue;
369
+ if (hiddenExports.has(name)) {
370
+ hidden.add(name);
371
+ continue;
372
+ }
343
373
  exports.add(name);
344
374
  if (importedExportInfo.provided === true) continue;
345
375
  checked.add(name);
@@ -351,13 +381,17 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
351
381
  if (importedExportInfo.provided === false) continue;
352
382
  const exportInfo = exportsInfo.getReadOnlyExportInfo(name);
353
383
  if (exportInfo.getUsed(runtime) === UsageState.Unused) continue;
384
+ if (hiddenExports.has(name)) {
385
+ hidden.add(name);
386
+ continue;
387
+ }
354
388
  exports.add(name);
355
389
  if (importedExportInfo.provided === true) continue;
356
390
  checked.add(name);
357
391
  }
358
392
  }
359
393
 
360
- return { ignoredExports, exports, checked };
394
+ return { ignoredExports, exports, checked, hidden };
361
395
  }
362
396
 
363
397
  /**
@@ -433,7 +467,8 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
433
467
 
434
468
  case "normal-reexport": {
435
469
  const referencedExports = [];
436
- for (const { ids, exportInfo } of mode.items) {
470
+ for (const { ids, exportInfo, hidden } of mode.items) {
471
+ if (hidden) continue;
437
472
  processExportInfo(runtime, referencedExports, ids, exportInfo, false);
438
473
  }
439
474
  return referencedExports;
@@ -487,22 +522,26 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
487
522
  exports: true,
488
523
  from,
489
524
  canMangle: false,
490
- excludeExports: mode.ignored,
525
+ excludeExports: combine(mode.ignored, mode.hidden),
526
+ hideExports: mode.hidden,
491
527
  dependencies: [from.module]
492
528
  };
493
529
  }
494
530
  case "empty-star":
495
531
  return {
496
532
  exports: [],
533
+ hideExports: mode.hidden,
497
534
  dependencies: [moduleGraph.getModule(this)]
498
535
  };
536
+ // falls through
499
537
  case "normal-reexport": {
500
538
  const from = moduleGraph.getConnection(this);
501
539
  return {
502
540
  exports: Array.from(mode.items, item => ({
503
541
  name: item.name,
504
542
  from,
505
- export: item.ids
543
+ export: item.ids,
544
+ hidden: item.hidden
506
545
  })),
507
546
  dependencies: [from.module]
508
547
  };
@@ -869,7 +908,8 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
869
908
  break;
870
909
 
871
910
  case "normal-reexport":
872
- for (const { name, ids, checked } of mode.items) {
911
+ for (const { name, ids, checked, hidden } of mode.items) {
912
+ if (hidden) continue;
873
913
  if (checked) {
874
914
  initFragments.push(
875
915
  new InitFragment(
@@ -903,7 +943,7 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
903
943
  break;
904
944
 
905
945
  case "dynamic-reexport": {
906
- const ignored = mode.ignored;
946
+ const ignored = combine(mode.ignored, mode.hidden);
907
947
  const modern =
908
948
  runtimeTemplate.supportsConst() &&
909
949
  runtimeTemplate.supportsArrowFunction();
@@ -66,32 +66,43 @@ class OccurrenceModuleIdsPlugin {
66
66
  }
67
67
 
68
68
  /**
69
- * @param {Iterable<ModuleGraphConnection>} connections connections
69
+ * @param {Module} module module
70
70
  * @returns {number} count of occurs
71
71
  */
72
- const countOccursInEntry = connections => {
72
+ const countOccursInEntry = module => {
73
73
  let sum = 0;
74
- for (const c of connections) {
75
- if (!c.isTargetActive(undefined)) continue;
76
- if (!c.originModule) continue;
77
- sum += initialChunkChunkMap.get(c.originModule);
74
+ for (const [
75
+ originModule,
76
+ connections
77
+ ] of moduleGraph.getIncomingConnectionsByOriginModule(module)) {
78
+ if (!originModule) continue;
79
+ if (!connections.some(c => c.isTargetActive(undefined))) continue;
80
+ sum += initialChunkChunkMap.get(originModule);
78
81
  }
79
82
  return sum;
80
83
  };
81
84
 
82
85
  /**
83
- * @param {Iterable<ModuleGraphConnection>} connections connections
86
+ * @param {Module} module module
84
87
  * @returns {number} count of occurs
85
88
  */
86
- const countOccurs = connections => {
89
+ const countOccurs = module => {
87
90
  let sum = 0;
88
- for (const c of connections) {
89
- if (!c.isTargetActive(undefined)) continue;
90
- if (!c.originModule) continue;
91
- if (!c.dependency) continue;
92
- const factor = c.dependency.getNumberOfIdOccurrences();
93
- if (factor === 0) continue;
94
- sum += factor * chunkGraph.getNumberOfModuleChunks(c.originModule);
91
+ for (const [
92
+ originModule,
93
+ connections
94
+ ] of moduleGraph.getIncomingConnectionsByOriginModule(module)) {
95
+ if (!originModule) continue;
96
+ const chunkModules = chunkGraph.getNumberOfModuleChunks(
97
+ originModule
98
+ );
99
+ for (const c of connections) {
100
+ if (!c.isTargetActive(undefined)) continue;
101
+ if (!c.dependency) continue;
102
+ const factor = c.dependency.getNumberOfIdOccurrences();
103
+ if (factor === 0) continue;
104
+ sum += factor * chunkModules;
105
+ }
95
106
  }
96
107
  return sum;
97
108
  };
@@ -99,7 +110,7 @@ class OccurrenceModuleIdsPlugin {
99
110
  if (prioritiseInitial) {
100
111
  for (const m of modulesInOccurrenceOrder) {
101
112
  const result =
102
- countOccursInEntry(moduleGraph.getIncomingConnections(m)) +
113
+ countOccursInEntry(m) +
103
114
  initialChunkChunkMap.get(m) +
104
115
  entryCountMap.get(m);
105
116
  occursInInitialChunksMap.set(m, result);
@@ -108,7 +119,7 @@ class OccurrenceModuleIdsPlugin {
108
119
 
109
120
  for (const m of modules) {
110
121
  const result =
111
- countOccurs(moduleGraph.getIncomingConnections(m)) +
122
+ countOccurs(m) +
112
123
  chunkGraph.getNumberOfModuleChunks(m) +
113
124
  entryCountMap.get(m);
114
125
  occursInAllChunksMap.set(m, result);
package/lib/index.js CHANGED
@@ -27,6 +27,7 @@ const memoize = require("./util/memoize");
27
27
  /** @typedef {import("./Compilation").AssetInfo} AssetInfo */
28
28
  /** @typedef {import("./MultiStats")} MultiStats */
29
29
  /** @typedef {import("./Parser").ParserState} ParserState */
30
+ /** @typedef {import("./Watching")} Watching */
30
31
  /** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsCompilation} StatsCompilation */
31
32
 
32
33
  /**
@@ -901,12 +901,12 @@ class JavascriptModulesPlugin {
901
901
  if (
902
902
  result.allowInlineStartup &&
903
903
  someInIterable(
904
- moduleGraph.getIncomingConnections(entryModule),
905
- c =>
906
- c.originModule &&
907
- c.isTargetActive(chunk.runtime) &&
904
+ moduleGraph.getIncomingConnectionsByOriginModule(entryModule),
905
+ ([originModule, connections]) =>
906
+ originModule &&
907
+ connections.some(c => c.isTargetActive(chunk.runtime)) &&
908
908
  someInIterable(
909
- chunkGraph.getModuleRuntimes(c.originModule),
909
+ chunkGraph.getModuleRuntimes(originModule),
910
910
  runtime =>
911
911
  intersectRuntime(runtime, chunk.runtime) !== undefined
912
912
  )
@@ -98,6 +98,12 @@ class NodeWatchFileSystem {
98
98
  this.watcher.pause();
99
99
  }
100
100
  },
101
+ getAggregatedRemovals: () => {
102
+ return this.watcher && this.watcher.aggregatedRemovals;
103
+ },
104
+ getAggregatedChanges: () => {
105
+ return this.watcher && this.watcher.aggregatedChanges;
106
+ },
101
107
  getFileTimeInfoEntries: () => {
102
108
  if (this.watcher) {
103
109
  return this.watcher.getTimeInfoEntries();
@@ -1239,16 +1239,21 @@ class ConcatenatedModule extends Module {
1239
1239
  for (const identifier of allIdentifiers) {
1240
1240
  const r = identifier.range;
1241
1241
  const path = getPathInAst(info.ast, identifier);
1242
- if (
1243
- path &&
1244
- path.length > 1 &&
1245
- path[1].type === "Property" &&
1246
- path[1].shorthand
1247
- ) {
1248
- source.insert(r[1], `: ${newName}`);
1249
- } else {
1250
- source.replace(r[0], r[1] - 1, newName);
1242
+ if (path && path.length > 1) {
1243
+ const maybeProperty =
1244
+ path[1].type === "AssignmentPattern" &&
1245
+ path[1].left === path[0]
1246
+ ? path[2]
1247
+ : path[1];
1248
+ if (
1249
+ maybeProperty.type === "Property" &&
1250
+ maybeProperty.shorthand
1251
+ ) {
1252
+ source.insert(r[1], `: ${newName}`);
1253
+ continue;
1254
+ }
1251
1255
  }
1256
+ source.replace(r[0], r[1] - 1, newName);
1252
1257
  }
1253
1258
  } else {
1254
1259
  allUsedNames.add(name);