webpack 5.101.1 → 5.101.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.
package/lib/ChunkGraph.js CHANGED
@@ -1242,7 +1242,7 @@ class ChunkGraph {
1242
1242
  * @param {Chunk} chunk the chunk
1243
1243
  * @returns {Iterable<Chunk>} iterable of chunks and include chunks from children entrypoints
1244
1244
  */
1245
- getChunkEntryDependOnChunksIterable(chunk) {
1245
+ getRuntimeChunkDependentChunksIterable(chunk) {
1246
1246
  /** @type {Set<Chunk>} */
1247
1247
  const set = new Set();
1248
1248
 
@@ -1259,7 +1259,7 @@ class ChunkGraph {
1259
1259
 
1260
1260
  let hasChildrenEntrypoint = false;
1261
1261
  for (const child of current.childrenIterable) {
1262
- if (child.isInitial()) {
1262
+ if (child instanceof Entrypoint && child.dependOn(current)) {
1263
1263
  hasChildrenEntrypoint = true;
1264
1264
  queue.push(/** @type {Entrypoint} */ (child));
1265
1265
  }
@@ -1277,6 +1277,18 @@ class ChunkGraph {
1277
1277
  }
1278
1278
  }
1279
1279
  }
1280
+
1281
+ for (const entrypoint of entrypoints) {
1282
+ const entrypointChunk = entrypoint.getEntrypointChunk();
1283
+ const cgc = this._getChunkGraphChunk(entrypointChunk);
1284
+ for (const chunkGroup of cgc.entryModules.values()) {
1285
+ for (const c of chunkGroup.chunks) {
1286
+ if (c !== chunk && c !== entrypointChunk && !c.hasRuntime()) {
1287
+ set.add(c);
1288
+ }
1289
+ }
1290
+ }
1291
+ }
1280
1292
  return set;
1281
1293
  }
1282
1294
 
@@ -32,7 +32,8 @@ const ErrorHelpers = require("./ErrorHelpers");
32
32
  const FileSystemInfo = require("./FileSystemInfo");
33
33
  const {
34
34
  connectChunkGroupAndChunk,
35
- connectChunkGroupParentAndChild
35
+ connectChunkGroupParentAndChild,
36
+ connectEntrypointAndDependOn
36
37
  } = require("./GraphHelpers");
37
38
  const {
38
39
  makeWebpackError,
@@ -3207,7 +3208,6 @@ Remove the 'runtime' option from the entrypoint.`);
3207
3208
  const referencedChunks = entry
3208
3209
  .getEntrypointChunk()
3209
3210
  .getAllReferencedChunks();
3210
- const dependOnEntries = [];
3211
3211
  for (const dep of dependOn) {
3212
3212
  const dependency = this.entrypoints.get(dep);
3213
3213
  if (!dependency) {
@@ -3225,9 +3225,7 @@ Remove the 'runtime' option from the entrypoint.`);
3225
3225
  entry.setRuntimeChunk(entryChunk);
3226
3226
  continue outer;
3227
3227
  }
3228
- dependOnEntries.push(dependency);
3229
- }
3230
- for (const dependency of dependOnEntries) {
3228
+ connectEntrypointAndDependOn(entry, dependency);
3231
3229
  connectChunkGroupParentAndChild(dependency, entry);
3232
3230
  }
3233
3231
  } else if (runtime) {
@@ -3278,26 +3276,6 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3278
3276
  }
3279
3277
  this.hooks.afterOptimizeChunks.call(this.chunks, this.chunkGroups);
3280
3278
 
3281
- for (const [
3282
- name,
3283
- {
3284
- options: { dependOn }
3285
- }
3286
- ] of this.entries) {
3287
- if (dependOn) {
3288
- const entry = /** @type {Entrypoint} */ (this.entrypoints.get(name));
3289
- for (const dep of dependOn) {
3290
- const depEntry = /** @type {Entrypoint} */ (
3291
- this.entrypoints.get(dep)
3292
- );
3293
- const runtimeChunk = depEntry.getRuntimeChunk();
3294
- if (runtimeChunk) {
3295
- runtimeChunk.addGroup(entry);
3296
- }
3297
- }
3298
- }
3299
- }
3300
-
3301
3279
  this.hooks.optimizeTree.callAsync(this.chunks, this.modules, (err) => {
3302
3280
  if (err) {
3303
3281
  return finalCallback(
package/lib/Entrypoint.js CHANGED
@@ -6,6 +6,7 @@
6
6
  "use strict";
7
7
 
8
8
  const ChunkGroup = require("./ChunkGroup");
9
+ const SortableSet = require("./util/SortableSet");
9
10
 
10
11
  /** @typedef {import("../declarations/WebpackOptions").EntryDescriptionNormalized} EntryDescription */
11
12
  /** @typedef {import("./Chunk")} Chunk */
@@ -38,6 +39,8 @@ class Entrypoint extends ChunkGroup {
38
39
  this._entrypointChunk = undefined;
39
40
  /** @type {boolean} */
40
41
  this._initial = initial;
42
+ /** @type {SortableSet<Entrypoint>} */
43
+ this._dependOn = new SortableSet();
41
44
  }
42
45
 
43
46
  /**
@@ -96,6 +99,22 @@ class Entrypoint extends ChunkGroup {
96
99
  if (this._entrypointChunk === oldChunk) this._entrypointChunk = newChunk;
97
100
  return super.replaceChunk(oldChunk, newChunk);
98
101
  }
102
+
103
+ /**
104
+ * @param {Entrypoint} entrypoint the entrypoint
105
+ * @returns {void}
106
+ */
107
+ addDependOn(entrypoint) {
108
+ this._dependOn.add(entrypoint);
109
+ }
110
+
111
+ /**
112
+ * @param {Entrypoint} entrypoint the entrypoint
113
+ * @returns {boolean} true if the entrypoint is in the dependOn set
114
+ */
115
+ dependOn(entrypoint) {
116
+ return this._dependOn.has(entrypoint);
117
+ }
99
118
  }
100
119
 
101
120
  module.exports = Entrypoint;
@@ -10,6 +10,7 @@
10
10
  /** @typedef {import("./ChunkGroup")} ChunkGroup */
11
11
  /** @typedef {import("./DependenciesBlock")} DependenciesBlock */
12
12
  /** @typedef {import("./Module")} Module */
13
+ /** @typedef {import(".").Entrypoint} Entrypoint */
13
14
 
14
15
  /**
15
16
  * @param {ChunkGroup} chunkGroup the ChunkGroup to connect
@@ -33,6 +34,16 @@ const connectChunkGroupParentAndChild = (parent, child) => {
33
34
  }
34
35
  };
35
36
 
37
+ /**
38
+ * @param {Entrypoint} entrypoint the entrypoint
39
+ * @param {Entrypoint} dependOnEntrypoint the dependOnEntrypoint
40
+ * @returns {void}
41
+ */
42
+ const connectEntrypointAndDependOn = (entrypoint, dependOnEntrypoint) => {
43
+ entrypoint.addDependOn(dependOnEntrypoint);
44
+ };
45
+
36
46
  module.exports.connectChunkGroupAndChunk = connectChunkGroupAndChunk;
37
47
  module.exports.connectChunkGroupParentAndChild =
38
48
  connectChunkGroupParentAndChild;
49
+ module.exports.connectEntrypointAndDependOn = connectEntrypointAndDependOn;
@@ -54,8 +54,7 @@ class JavascriptMetaInfoPlugin {
54
54
  topLevelDeclarations = buildInfo.topLevelDeclarations = new Set();
55
55
  }
56
56
  for (const name of parser.scope.definitions.asSet()) {
57
- const freeInfo = parser.getFreeInfoFromVariable(name);
58
- if (freeInfo === undefined) {
57
+ if (parser.isVariableDefined(name)) {
59
58
  topLevelDeclarations.add(name);
60
59
  }
61
60
  }
@@ -258,17 +258,42 @@ const getImportAttributes = (node) => {
258
258
  return result;
259
259
  };
260
260
 
261
+ /** @typedef {typeof VariableInfoFlags.Evaluated | typeof VariableInfoFlags.Free | typeof VariableInfoFlags.Normal | typeof VariableInfoFlags.Tagged} VariableInfoFlagsType */
262
+
263
+ const VariableInfoFlags = Object.freeze({
264
+ Evaluated: 0b000,
265
+ Free: 0b001,
266
+ Normal: 0b010,
267
+ Tagged: 0b100
268
+ });
269
+
261
270
  class VariableInfo {
262
271
  /**
263
272
  * @param {ScopeInfo} declaredScope scope in which the variable is declared
264
- * @param {string | true | undefined} freeName which free name the variable aliases, or true when none
273
+ * @param {string | undefined} name which name the variable use, defined name or free name or tagged name
274
+ * @param {VariableInfoFlagsType} flags how the variable is created
265
275
  * @param {TagInfo | undefined} tagInfo info about tags
266
276
  */
267
- constructor(declaredScope, freeName, tagInfo) {
277
+ constructor(declaredScope, name, flags, tagInfo) {
268
278
  this.declaredScope = declaredScope;
269
- this.freeName = freeName;
279
+ this.name = name;
280
+ this.flags = flags;
270
281
  this.tagInfo = tagInfo;
271
282
  }
283
+
284
+ /**
285
+ * @returns {boolean} the variable is free or not
286
+ */
287
+ isFree() {
288
+ return (this.flags & VariableInfoFlags.Free) > 0;
289
+ }
290
+
291
+ /**
292
+ * @returns {boolean} the variable is tagged by tagVariable or not
293
+ */
294
+ isTagged() {
295
+ return (this.flags & VariableInfoFlags.Tagged) > 0;
296
+ }
272
297
  }
273
298
 
274
299
  /** @typedef {string | ScopeInfo | VariableInfo} ExportedVariableInfo */
@@ -1426,7 +1451,7 @@ class JavascriptParser extends Parser {
1426
1451
  const info = this.getVariableInfo(/** @type {Identifier} */ (expr).name);
1427
1452
  if (
1428
1453
  typeof info === "string" ||
1429
- (info instanceof VariableInfo && typeof info.freeName === "string")
1454
+ (info instanceof VariableInfo && (info.isFree() || info.isTagged()))
1430
1455
  ) {
1431
1456
  return {
1432
1457
  name: info,
@@ -1441,7 +1466,7 @@ class JavascriptParser extends Parser {
1441
1466
  const info = this.getVariableInfo("this");
1442
1467
  if (
1443
1468
  typeof info === "string" ||
1444
- (info instanceof VariableInfo && typeof info.freeName === "string")
1469
+ (info instanceof VariableInfo && (info.isFree() || info.isTagged()))
1445
1470
  ) {
1446
1471
  return {
1447
1472
  name: info,
@@ -1930,6 +1955,32 @@ class JavascriptParser extends Parser {
1930
1955
  }
1931
1956
  }
1932
1957
 
1958
+ /**
1959
+ * Module pre walking iterates the scope for import entries
1960
+ * @param {(Statement | ModuleDeclaration)[]} statements statements
1961
+ */
1962
+ modulePreWalkStatements(statements) {
1963
+ for (let index = 0, len = statements.length; index < len; index++) {
1964
+ const statement = statements[index];
1965
+ /** @type {StatementPath} */
1966
+ (this.statementPath).push(statement);
1967
+ switch (statement.type) {
1968
+ case "ImportDeclaration":
1969
+ this.modulePreWalkImportDeclaration(statement);
1970
+ break;
1971
+ case "ExportAllDeclaration":
1972
+ this.modulePreWalkExportAllDeclaration(statement);
1973
+ break;
1974
+ case "ExportNamedDeclaration":
1975
+ this.modulePreWalkExportNamedDeclaration(statement);
1976
+ break;
1977
+ }
1978
+ this.prevStatement =
1979
+ /** @type {StatementPath} */
1980
+ (this.statementPath).pop();
1981
+ }
1982
+ }
1983
+
1933
1984
  /**
1934
1985
  * Pre walking iterates the scope for variable declarations
1935
1986
  * @param {(Statement | ModuleDeclaration)[]} statements statements
@@ -2050,12 +2101,6 @@ class JavascriptParser extends Parser {
2050
2101
  return;
2051
2102
  }
2052
2103
  switch (statement.type) {
2053
- case "ImportDeclaration":
2054
- this.blockPreWalkImportDeclaration(statement);
2055
- break;
2056
- case "ExportAllDeclaration":
2057
- this.blockPreWalkExportAllDeclaration(statement);
2058
- break;
2059
2104
  case "ExportDefaultDeclaration":
2060
2105
  this.blockPreWalkExportDefaultDeclaration(statement);
2061
2106
  break;
@@ -2595,7 +2640,7 @@ class JavascriptParser extends Parser {
2595
2640
  /**
2596
2641
  * @param {ImportDeclaration} statement statement
2597
2642
  */
2598
- blockPreWalkImportDeclaration(statement) {
2643
+ modulePreWalkImportDeclaration(statement) {
2599
2644
  const source = /** @type {ImportSource} */ (statement.source.value);
2600
2645
  this.hooks.import.call(statement, source);
2601
2646
  for (const specifier of statement.specifiers) {
@@ -2665,14 +2710,49 @@ class JavascriptParser extends Parser {
2665
2710
  /**
2666
2711
  * @param {ExportNamedDeclaration} statement statement
2667
2712
  */
2668
- blockPreWalkExportNamedDeclaration(statement) {
2669
- let source;
2670
- if (statement.source) {
2671
- source = /** @type {ImportSource} */ (statement.source.value);
2672
- this.hooks.exportImport.call(statement, source);
2673
- } else {
2674
- this.hooks.export.call(statement);
2713
+ modulePreWalkExportNamedDeclaration(statement) {
2714
+ if (!statement.source) return;
2715
+ const source = /** @type {ImportSource} */ (statement.source.value);
2716
+ this.hooks.exportImport.call(statement, source);
2717
+ if (statement.specifiers) {
2718
+ for (
2719
+ let specifierIndex = 0;
2720
+ specifierIndex < statement.specifiers.length;
2721
+ specifierIndex++
2722
+ ) {
2723
+ const specifier = statement.specifiers[specifierIndex];
2724
+ switch (specifier.type) {
2725
+ case "ExportSpecifier": {
2726
+ const localName =
2727
+ /** @type {Identifier} */ (specifier.local).name ||
2728
+ /** @type {string} */ (
2729
+ /** @type {Literal} */ (specifier.local).value
2730
+ );
2731
+ const name =
2732
+ /** @type {Identifier} */
2733
+ (specifier.exported).name ||
2734
+ /** @type {string} */
2735
+ (/** @type {Literal} */ (specifier.exported).value);
2736
+ this.hooks.exportImportSpecifier.call(
2737
+ statement,
2738
+ source,
2739
+ localName,
2740
+ name,
2741
+ specifierIndex
2742
+ );
2743
+ break;
2744
+ }
2745
+ }
2746
+ }
2675
2747
  }
2748
+ }
2749
+
2750
+ /**
2751
+ * @param {ExportNamedDeclaration} statement statement
2752
+ */
2753
+ blockPreWalkExportNamedDeclaration(statement) {
2754
+ if (statement.source) return;
2755
+ this.hooks.export.call(statement);
2676
2756
  if (
2677
2757
  statement.declaration &&
2678
2758
  !this.hooks.exportDeclaration.call(statement, statement.declaration)
@@ -2705,22 +2785,12 @@ class JavascriptParser extends Parser {
2705
2785
  (specifier.exported).name ||
2706
2786
  /** @type {string} */
2707
2787
  (/** @type {Literal} */ (specifier.exported).value);
2708
- if (source) {
2709
- this.hooks.exportImportSpecifier.call(
2710
- statement,
2711
- source,
2712
- localName,
2713
- name,
2714
- specifierIndex
2715
- );
2716
- } else {
2717
- this.hooks.exportSpecifier.call(
2718
- statement,
2719
- localName,
2720
- name,
2721
- specifierIndex
2722
- );
2723
- }
2788
+ this.hooks.exportSpecifier.call(
2789
+ statement,
2790
+ localName,
2791
+ name,
2792
+ specifierIndex
2793
+ );
2724
2794
  break;
2725
2795
  }
2726
2796
  }
@@ -2812,7 +2882,7 @@ class JavascriptParser extends Parser {
2812
2882
  /**
2813
2883
  * @param {ExportAllDeclaration} statement statement
2814
2884
  */
2815
- blockPreWalkExportAllDeclaration(statement) {
2885
+ modulePreWalkExportAllDeclaration(statement) {
2816
2886
  const source = /** @type {ImportSource} */ (statement.source.value);
2817
2887
  const name = statement.exported
2818
2888
  ? /** @type {Identifier} */
@@ -4053,13 +4123,13 @@ class JavascriptParser extends Parser {
4053
4123
  }
4054
4124
  tagInfo = tagInfo.next;
4055
4125
  }
4056
- if (info.freeName === true) {
4126
+ if (!info.isFree() && !info.isTagged()) {
4057
4127
  if (defined !== undefined) {
4058
4128
  return defined();
4059
4129
  }
4060
4130
  return;
4061
4131
  }
4062
- name = info.freeName;
4132
+ name = info.name;
4063
4133
  }
4064
4134
  const hook = hookMap.get(name);
4065
4135
  if (hook !== undefined) {
@@ -4543,6 +4613,7 @@ class JavascriptParser extends Parser {
4543
4613
  if (this.hooks.program.call(ast, comments) === undefined) {
4544
4614
  this.destructuringAssignmentProperties = new WeakMap();
4545
4615
  this.detectMode(ast.body);
4616
+ this.modulePreWalkStatements(ast.body);
4546
4617
  this.preWalkStatements(ast.body);
4547
4618
  this.prevStatement = undefined;
4548
4619
  this.blockPreWalkStatements(ast.body);
@@ -4818,25 +4889,31 @@ class JavascriptParser extends Parser {
4818
4889
  * @param {string} name name
4819
4890
  * @param {Tag} tag tag info
4820
4891
  * @param {TagData=} data data
4892
+ * @param {VariableInfoFlagsType=} flags flags
4821
4893
  */
4822
- tagVariable(name, tag, data) {
4894
+ tagVariable(name, tag, data, flags = VariableInfoFlags.Tagged) {
4823
4895
  const oldInfo = this.scope.definitions.get(name);
4824
4896
  /** @type {VariableInfo} */
4825
4897
  let newInfo;
4826
4898
  if (oldInfo === undefined) {
4827
- newInfo = new VariableInfo(this.scope, name, {
4899
+ newInfo = new VariableInfo(this.scope, name, flags, {
4828
4900
  tag,
4829
4901
  data,
4830
4902
  next: undefined
4831
4903
  });
4832
4904
  } else if (oldInfo instanceof VariableInfo) {
4833
- newInfo = new VariableInfo(oldInfo.declaredScope, oldInfo.freeName, {
4834
- tag,
4835
- data,
4836
- next: oldInfo.tagInfo
4837
- });
4905
+ newInfo = new VariableInfo(
4906
+ oldInfo.declaredScope,
4907
+ oldInfo.name,
4908
+ /** @type {VariableInfoFlagsType} */ (oldInfo.flags | flags),
4909
+ {
4910
+ tag,
4911
+ data,
4912
+ next: oldInfo.tagInfo
4913
+ }
4914
+ );
4838
4915
  } else {
4839
- newInfo = new VariableInfo(oldInfo, true, {
4916
+ newInfo = new VariableInfo(oldInfo, name, flags, {
4840
4917
  tag,
4841
4918
  data,
4842
4919
  next: undefined
@@ -4875,7 +4952,7 @@ class JavascriptParser extends Parser {
4875
4952
  const info = this.scope.definitions.get(name);
4876
4953
  if (info === undefined) return false;
4877
4954
  if (info instanceof VariableInfo) {
4878
- return info.freeName === true;
4955
+ return !info.isFree();
4879
4956
  }
4880
4957
  return true;
4881
4958
  }
@@ -4904,7 +4981,12 @@ class JavascriptParser extends Parser {
4904
4981
  } else {
4905
4982
  this.scope.definitions.set(
4906
4983
  name,
4907
- new VariableInfo(this.scope, variableInfo, undefined)
4984
+ new VariableInfo(
4985
+ this.scope,
4986
+ variableInfo,
4987
+ VariableInfoFlags.Free,
4988
+ undefined
4989
+ )
4908
4990
  );
4909
4991
  }
4910
4992
  } else {
@@ -4917,7 +4999,12 @@ class JavascriptParser extends Parser {
4917
4999
  * @returns {VariableInfo} variable info
4918
5000
  */
4919
5001
  evaluatedVariable(tagInfo) {
4920
- return new VariableInfo(this.scope, undefined, tagInfo);
5002
+ return new VariableInfo(
5003
+ this.scope,
5004
+ undefined,
5005
+ VariableInfoFlags.Evaluated,
5006
+ tagInfo
5007
+ );
4921
5008
  }
4922
5009
 
4923
5010
  /**
@@ -5002,9 +5089,27 @@ class JavascriptParser extends Parser {
5002
5089
  getFreeInfoFromVariable(varName) {
5003
5090
  const info = this.getVariableInfo(varName);
5004
5091
  let name;
5005
- if (info instanceof VariableInfo) {
5006
- name = info.freeName;
5007
- if (typeof name !== "string") return;
5092
+ if (info instanceof VariableInfo && info.name) {
5093
+ if (!info.isFree()) return;
5094
+ name = info.name;
5095
+ } else if (typeof info !== "string") {
5096
+ return;
5097
+ } else {
5098
+ name = info;
5099
+ }
5100
+ return { info, name };
5101
+ }
5102
+
5103
+ /**
5104
+ * @param {string} varName variable name
5105
+ * @returns {{name: string, info: VariableInfo | string} | undefined} name of the free variable and variable info for that
5106
+ */
5107
+ getNameInfoFromVariable(varName) {
5108
+ const info = this.getVariableInfo(varName);
5109
+ let name;
5110
+ if (info instanceof VariableInfo && info.name) {
5111
+ if (!info.isFree() && !info.isTagged()) return;
5112
+ name = info.name;
5008
5113
  } else if (typeof info !== "string") {
5009
5114
  return;
5010
5115
  } else {
@@ -5035,7 +5140,7 @@ class JavascriptParser extends Parser {
5035
5140
  }
5036
5141
  const rootName = getRootName(callee);
5037
5142
  if (!rootName) return;
5038
- const result = this.getFreeInfoFromVariable(rootName);
5143
+ const result = this.getNameInfoFromVariable(rootName);
5039
5144
  if (!result) return;
5040
5145
  const { info: rootInfo, name: resolvedRoot } = result;
5041
5146
  const calleeName = objectAndMembersToName(resolvedRoot, rootMembers);
@@ -5058,7 +5163,7 @@ class JavascriptParser extends Parser {
5058
5163
  const rootName = getRootName(object);
5059
5164
  if (!rootName) return;
5060
5165
 
5061
- const result = this.getFreeInfoFromVariable(rootName);
5166
+ const result = this.getNameInfoFromVariable(rootName);
5062
5167
  if (!result) return;
5063
5168
  const { info: rootInfo, name: resolvedRoot } = result;
5064
5169
  return {
@@ -5151,4 +5256,5 @@ module.exports.ALLOWED_MEMBER_TYPES_CALL_EXPRESSION =
5151
5256
  module.exports.ALLOWED_MEMBER_TYPES_EXPRESSION =
5152
5257
  ALLOWED_MEMBER_TYPES_EXPRESSION;
5153
5258
  module.exports.VariableInfo = VariableInfo;
5259
+ module.exports.VariableInfoFlags = VariableInfoFlags;
5154
5260
  module.exports.getImportAttributes = getImportAttributes;
@@ -242,7 +242,6 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
242
242
  { factory, inlinedInIIFE },
243
243
  libraryContext
244
244
  ) {
245
- const result = new ConcatSource(source);
246
245
  // Re-add `factoryExportsBinding` to the source
247
246
  // when the module is rendered as a factory or treated as an inlined (startup) module but wrapped in an IIFE
248
247
  if (
@@ -250,9 +249,9 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
250
249
  module.buildMeta &&
251
250
  module.buildMeta.factoryExportsBinding
252
251
  ) {
253
- result.add(module.buildMeta.factoryExportsBinding);
252
+ return new ConcatSource(module.buildMeta.factoryExportsBinding, source);
254
253
  }
255
- return result;
254
+ return source;
256
255
  }
257
256
  }
258
257
 
@@ -1722,6 +1722,7 @@ class ConcatenatedModule extends Module {
1722
1722
 
1723
1723
  if (onDemandExportsGeneration.call(this)) {
1724
1724
  /** @type {BuildMeta} */ (this.buildMeta).factoryExportsBinding =
1725
+ "\n// EXPORTS\n" +
1725
1726
  `${RuntimeGlobals.definePropertyGetters}(${
1726
1727
  this.exportsArgument
1727
1728
  }, {${definitions.join(",")}\n});\n`;
@@ -6,6 +6,7 @@
6
6
  "use strict";
7
7
 
8
8
  const { UsageState } = require("../ExportsInfo");
9
+ const JavascriptParser = require("../javascript/JavascriptParser");
9
10
 
10
11
  /** @typedef {import("estree").Node} AnyNode */
11
12
  /** @typedef {import("../Dependency")} Dependency */
@@ -15,7 +16,6 @@ const { UsageState } = require("../ExportsInfo");
15
16
  /** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
16
17
  /** @typedef {import("../ModuleGraphConnection").ConnectionState} ConnectionState */
17
18
  /** @typedef {import("../Parser").ParserState} ParserState */
18
- /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
19
19
  /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
20
20
 
21
21
  /** @typedef {Map<TopLevelSymbol | null, Set<string | TopLevelSymbol> | true | undefined>} InnerGraph */
@@ -348,7 +348,12 @@ module.exports.tagTopLevelSymbol = (parser, name) => {
348
348
  }
349
349
 
350
350
  const fn = new TopLevelSymbol(name);
351
- parser.tagVariable(name, topLevelSymbolTag, fn);
351
+ parser.tagVariable(
352
+ name,
353
+ topLevelSymbolTag,
354
+ fn,
355
+ JavascriptParser.VariableInfoFlags.Normal
356
+ );
352
357
  return fn;
353
358
  };
354
359
 
@@ -101,16 +101,12 @@ class GetChunkFilenameRuntimeModule extends RuntimeModule {
101
101
  .getTreeRuntimeRequirements(chunk)
102
102
  .has(RuntimeGlobals.ensureChunkIncludeEntries);
103
103
  if (includeEntries) {
104
- includedChunksMessages.push("sibling chunks for the entrypoint");
105
- for (const c of chunkGraph.getChunkEntryDependentChunksIterable(
104
+ includedChunksMessages.push("chunks that the entrypoint depends on");
105
+ for (const c of chunkGraph.getRuntimeChunkDependentChunksIterable(
106
106
  chunk
107
107
  )) {
108
108
  addChunk(c);
109
109
  }
110
- includedChunksMessages.push("chunks that the entrypoint depends on");
111
- for (const c of chunkGraph.getChunkEntryDependOnChunksIterable(chunk)) {
112
- addChunk(c);
113
- }
114
110
  }
115
111
  }
116
112
  for (const entrypoint of chunk.getAllReferencedAsyncEntrypoints()) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpack",
3
- "version": "5.101.1",
3
+ "version": "5.101.2",
4
4
  "description": "Packs ECMAScript/CommonJs/AMD modules for the browser. Allows you to split your codebase into multiple bundles, which can be loaded on demand. Supports loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.",
5
5
  "homepage": "https://github.com/webpack/webpack",
6
6
  "bugs": "https://github.com/webpack/webpack/issues",
package/types.d.ts CHANGED
@@ -1373,7 +1373,7 @@ declare class ChunkGraph {
1373
1373
  getNumberOfRuntimeModules(chunk: Chunk): number;
1374
1374
  getChunkEntryModulesIterable(chunk: Chunk): Iterable<Module>;
1375
1375
  getChunkEntryDependentChunksIterable(chunk: Chunk): Iterable<Chunk>;
1376
- getChunkEntryDependOnChunksIterable(chunk: Chunk): Iterable<Chunk>;
1376
+ getRuntimeChunkDependentChunksIterable(chunk: Chunk): Iterable<Chunk>;
1377
1377
  hasChunkEntryDependentChunks(chunk: Chunk): boolean;
1378
1378
  getChunkRuntimeModulesIterable(chunk: Chunk): Iterable<RuntimeModule>;
1379
1379
  getChunkRuntimeModulesInOrder(chunk: Chunk): RuntimeModule[];
@@ -4534,6 +4534,8 @@ declare abstract class Entrypoint extends ChunkGroup {
4534
4534
  * (or at least the execution of them)
4535
4535
  */
4536
4536
  getEntrypointChunk(): Chunk;
4537
+ addDependOn(entrypoint: Entrypoint): void;
4538
+ dependOn(entrypoint: Entrypoint): boolean;
4537
4539
  }
4538
4540
  type EnumValue =
4539
4541
  | null
@@ -7054,6 +7056,40 @@ declare class JavascriptParser extends ParserClass {
7054
7056
  classy: ClassExpression | ClassDeclaration | MaybeNamedClassDeclaration
7055
7057
  ): void;
7056
7058
 
7059
+ /**
7060
+ * Module pre walking iterates the scope for import entries
7061
+ */
7062
+ modulePreWalkStatements(
7063
+ statements: (
7064
+ | ImportDeclarationJavascriptParser
7065
+ | ExportNamedDeclarationJavascriptParser
7066
+ | ExportAllDeclarationJavascriptParser
7067
+ | FunctionDeclaration
7068
+ | VariableDeclaration
7069
+ | ClassDeclaration
7070
+ | ExpressionStatement
7071
+ | BlockStatement
7072
+ | StaticBlock
7073
+ | EmptyStatement
7074
+ | DebuggerStatement
7075
+ | WithStatement
7076
+ | ReturnStatement
7077
+ | LabeledStatement
7078
+ | BreakStatement
7079
+ | ContinueStatement
7080
+ | IfStatement
7081
+ | SwitchStatement
7082
+ | ThrowStatement
7083
+ | TryStatement
7084
+ | WhileStatement
7085
+ | DoWhileStatement
7086
+ | ForStatement
7087
+ | ForInStatement
7088
+ | ForOfStatement
7089
+ | ExportDefaultDeclaration
7090
+ )[]
7091
+ ): void;
7092
+
7057
7093
  /**
7058
7094
  * Pre walking iterates the scope for variable declarations
7059
7095
  */
@@ -7293,13 +7329,16 @@ declare class JavascriptParser extends ParserClass {
7293
7329
  ): void;
7294
7330
  blockPreWalkExpressionStatement(statement: ExpressionStatement): void;
7295
7331
  preWalkAssignmentExpression(expression: AssignmentExpression): void;
7296
- blockPreWalkImportDeclaration(
7332
+ modulePreWalkImportDeclaration(
7297
7333
  statement: ImportDeclarationJavascriptParser
7298
7334
  ): void;
7299
7335
  enterDeclaration(
7300
7336
  declaration: Declaration,
7301
7337
  onIdent: (ident: string, identifier: Identifier) => void
7302
7338
  ): void;
7339
+ modulePreWalkExportNamedDeclaration(
7340
+ statement: ExportNamedDeclarationJavascriptParser
7341
+ ): void;
7303
7342
  blockPreWalkExportNamedDeclaration(
7304
7343
  statement: ExportNamedDeclarationJavascriptParser
7305
7344
  ): void;
@@ -7310,7 +7349,7 @@ declare class JavascriptParser extends ParserClass {
7310
7349
  statement: ExportDefaultDeclaration
7311
7350
  ): void;
7312
7351
  walkExportDefaultDeclaration(statement: ExportDefaultDeclaration): void;
7313
- blockPreWalkExportAllDeclaration(
7352
+ modulePreWalkExportAllDeclaration(
7314
7353
  statement: ExportAllDeclarationJavascriptParser
7315
7354
  ): void;
7316
7355
  preWalkVariableDeclaration(statement: VariableDeclaration): void;
@@ -7716,7 +7755,12 @@ declare class JavascriptParser extends ParserClass {
7716
7755
  unsetAsiPosition(pos: number): void;
7717
7756
  isStatementLevelExpression(expr: Expression): boolean;
7718
7757
  getTagData(name: string, tag: symbol): undefined | TagData;
7719
- tagVariable(name: string, tag: symbol, data?: TagData): void;
7758
+ tagVariable(
7759
+ name: string,
7760
+ tag: symbol,
7761
+ data?: TagData,
7762
+ flags?: 0 | 1 | 2 | 4
7763
+ ): void;
7720
7764
  defineVariable(name: string): void;
7721
7765
  undefineVariable(name: string): void;
7722
7766
  isVariableDefined(name: string): boolean;
@@ -7794,6 +7838,9 @@ declare class JavascriptParser extends ParserClass {
7794
7838
  getFreeInfoFromVariable(
7795
7839
  varName: string
7796
7840
  ): undefined | { name: string; info: string | VariableInfo };
7841
+ getNameInfoFromVariable(
7842
+ varName: string
7843
+ ): undefined | { name: string; info: string | VariableInfo };
7797
7844
  getMemberExpressionInfo(
7798
7845
  expression:
7799
7846
  | ImportExpressionImport
@@ -7842,6 +7889,12 @@ declare class JavascriptParser extends ParserClass {
7842
7889
  static ALLOWED_MEMBER_TYPES_CALL_EXPRESSION: 1;
7843
7890
  static ALLOWED_MEMBER_TYPES_EXPRESSION: 2;
7844
7891
  static VariableInfo: typeof VariableInfo;
7892
+ static VariableInfoFlags: Readonly<{
7893
+ Evaluated: 0;
7894
+ Free: 1;
7895
+ Normal: 2;
7896
+ Tagged: 4;
7897
+ }>;
7845
7898
  static getImportAttributes: (
7846
7899
  node:
7847
7900
  | ImportDeclarationJavascriptParser
@@ -16949,13 +17002,18 @@ declare interface Values {
16949
17002
  declare class VariableInfo {
16950
17003
  constructor(
16951
17004
  declaredScope: ScopeInfo,
16952
- freeName?: string | true,
17005
+ name: undefined | string,
17006
+ flags: VariableInfoFlagsType,
16953
17007
  tagInfo?: TagInfo
16954
17008
  );
16955
17009
  declaredScope: ScopeInfo;
16956
- freeName?: string | true;
17010
+ name?: string;
17011
+ flags: VariableInfoFlagsType;
16957
17012
  tagInfo?: TagInfo;
17013
+ isFree(): boolean;
17014
+ isTagged(): boolean;
16958
17015
  }
17016
+ type VariableInfoFlagsType = 0 | 1 | 2 | 4;
16959
17017
  declare interface VirtualModuleConfig {
16960
17018
  /**
16961
17019
  * - The module type