webpack 5.101.0 → 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.
@@ -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;
@@ -19,6 +19,8 @@ const JavascriptModulesPlugin = require("../javascript/JavascriptModulesPlugin")
19
19
  /** @typedef {import("../Module")} Module */
20
20
  /** @typedef {import("../javascript/JavascriptModulesPlugin").RenderContext} RenderContext */
21
21
  /** @typedef {import("../javascript/JavascriptModulesPlugin").StartupRenderContext} StartupRenderContext */
22
+ /** @typedef {import("../javascript/JavascriptModulesPlugin").ChunkRenderContext} ChunkRenderContext */
23
+ /** @typedef {import("../javascript/JavascriptModulesPlugin").ModuleRenderContext} ModuleRenderContext */
22
24
  /** @typedef {import("../util/Hash")} Hash */
23
25
 
24
26
  const COMMON_LIBRARY_NAME_MESSAGE =
@@ -173,6 +175,20 @@ class AbstractLibraryPlugin {
173
175
  });
174
176
  }
175
177
 
178
+ if (
179
+ this.renderModuleContent !==
180
+ AbstractLibraryPlugin.prototype.renderModuleContent
181
+ ) {
182
+ hooks.renderModuleContent.tap(
183
+ _pluginName,
184
+ (source, module, renderContext) =>
185
+ this.renderModuleContent(source, module, renderContext, {
186
+ compilation,
187
+ chunkGraph: compilation.chunkGraph
188
+ })
189
+ );
190
+ }
191
+
176
192
  if (
177
193
  this.renderStartup !== AbstractLibraryPlugin.prototype.renderStartup
178
194
  ) {
@@ -288,6 +304,17 @@ class AbstractLibraryPlugin {
288
304
  return source;
289
305
  }
290
306
 
307
+ /**
308
+ * @param {Source} source source
309
+ * @param {Module} module module
310
+ * @param {ModuleRenderContext} renderContext render context
311
+ * @param {Omit<LibraryContext<T>, 'options'>} libraryContext context
312
+ * @returns {Source} source with library export
313
+ */
314
+ renderModuleContent(source, module, renderContext, libraryContext) {
315
+ return source;
316
+ }
317
+
291
318
  /**
292
319
  * @param {Chunk} chunk the chunk
293
320
  * @param {Hash} hash hash
@@ -8,7 +8,7 @@
8
8
  const { ConcatSource } = require("webpack-sources");
9
9
  const RuntimeGlobals = require("../RuntimeGlobals");
10
10
  const Template = require("../Template");
11
- const JavascriptModulesPlugin = require("../javascript/JavascriptModulesPlugin");
11
+ const CommonJsSelfReferenceDependency = require("../dependencies/CommonJsSelfReferenceDependency");
12
12
  const ConcatenatedModule = require("../optimize/ConcatenatedModule");
13
13
  const propertyAccess = require("../util/propertyAccess");
14
14
  const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
@@ -22,6 +22,7 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
22
22
  /** @typedef {import("../Module")} Module */
23
23
  /** @typedef {import("../Module").BuildMeta} BuildMeta */
24
24
  /** @typedef {import("../javascript/JavascriptModulesPlugin").StartupRenderContext} StartupRenderContext */
25
+ /** @typedef {import("../javascript/JavascriptModulesPlugin").ModuleRenderContext} ModuleRenderContext */
25
26
  /** @typedef {import("../util/Hash")} Hash */
26
27
 
27
28
  /**
@@ -66,37 +67,9 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
66
67
  super.apply(compiler);
67
68
 
68
69
  compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
69
- const { exportsDefinitions } =
70
+ const { onDemandExportsGeneration } =
70
71
  ConcatenatedModule.getCompilationHooks(compilation);
71
- exportsDefinitions.tap(PLUGIN_NAME, (definitions, module) => {
72
- const bailout = JavascriptModulesPlugin.getCompilationHooks(
73
- compilation
74
- ).inlineInRuntimeBailout.call(module, {});
75
- if (bailout) return false;
76
- // If we have connections not all modules were concatenated, so we need the wrapper
77
- const connections =
78
- compilation.moduleGraph.getIncomingConnections(module);
79
-
80
- for (const connection of connections) {
81
- if (connection.originModule) {
82
- return false;
83
- }
84
- }
85
-
86
- // Runtime and splitting chunks now requires the wrapper too
87
- for (const chunk of compilation.chunkGraph.getModuleChunksIterable(
88
- module
89
- )) {
90
- if (
91
- !chunk.hasRuntime() ||
92
- compilation.chunkGraph.getNumberOfEntryModules(chunk) > 1
93
- ) {
94
- return false;
95
- }
96
- }
97
-
98
- return true;
99
- });
72
+ onDemandExportsGeneration.tap(PLUGIN_NAME, (_module) => true);
100
73
  });
101
74
  }
102
75
 
@@ -128,10 +101,21 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
128
101
  renderStartup(
129
102
  source,
130
103
  module,
131
- { moduleGraph, chunk, codeGenerationResults },
104
+ { moduleGraph, chunk, codeGenerationResults, inlined, inlinedInIIFE },
132
105
  { options, compilation }
133
106
  ) {
134
107
  const result = new ConcatSource(source);
108
+
109
+ if (!module.buildMeta || !module.buildMeta.exportsType) {
110
+ for (const dependency of module.dependencies) {
111
+ if (dependency instanceof CommonJsSelfReferenceDependency) {
112
+ result.add(`export { ${RuntimeGlobals.exports} as default }`);
113
+ break;
114
+ }
115
+ }
116
+ return result;
117
+ }
118
+
135
119
  const exportsInfo = options.export
136
120
  ? [
137
121
  moduleGraph.getExportInfo(
@@ -141,8 +125,11 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
141
125
  ]
142
126
  : moduleGraph.getExportsInfo(module).orderedExports;
143
127
  const definitions =
144
- /** @type {BuildMeta} */
145
- (module.buildMeta).exportsFinalName || {};
128
+ inlined && !inlinedInIIFE
129
+ ? (module.buildMeta &&
130
+ /** @type {GenerationMeta} */ module.buildMeta.exportsFinalName) ||
131
+ {}
132
+ : {};
146
133
  /** @type {string[]} */
147
134
  const shortHandedExports = [];
148
135
  /** @type {[string, string][]} */
@@ -241,6 +228,31 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
241
228
 
242
229
  return result;
243
230
  }
231
+
232
+ /**
233
+ * @param {Source} source source
234
+ * @param {Module} module module
235
+ * @param {ModuleRenderContext} renderContext render context
236
+ * @param {Omit<LibraryContext<T>, 'options'>} libraryContext context
237
+ * @returns {Source} source with library export
238
+ */
239
+ renderModuleContent(
240
+ source,
241
+ module,
242
+ { factory, inlinedInIIFE },
243
+ libraryContext
244
+ ) {
245
+ // Re-add `factoryExportsBinding` to the source
246
+ // when the module is rendered as a factory or treated as an inlined (startup) module but wrapped in an IIFE
247
+ if (
248
+ (inlinedInIIFE || factory) &&
249
+ module.buildMeta &&
250
+ module.buildMeta.factoryExportsBinding
251
+ ) {
252
+ return new ConcatSource(module.buildMeta.factoryExportsBinding, source);
253
+ }
254
+ return source;
255
+ }
244
256
  }
245
257
 
246
258
  module.exports = ModuleLibraryPlugin;
@@ -158,11 +158,16 @@ class RequireChunkLoadingRuntimeModule extends RuntimeModule {
158
158
  ? "if(true) { // all chunks have JS"
159
159
  : `if(${hasJsMatcher("chunkId")}) {`,
160
160
  Template.indent([
161
- `installChunk(require(${JSON.stringify(
161
+ // The require function loads and runs a chunk. When the chunk is being run,
162
+ // it can call __webpack_require__.C to directly complete installed.
163
+ `var installedChunk = require(${JSON.stringify(
162
164
  rootOutputDir
163
165
  )} + ${
164
166
  RuntimeGlobals.getChunkScriptFilename
165
- }(chunkId)));`
167
+ }(chunkId));`,
168
+ "if (!installedChunks[chunkId]) {",
169
+ Template.indent(["installChunk(installedChunk);"]),
170
+ "}"
166
171
  ]),
167
172
  "} else installedChunks[chunkId] = 1;",
168
173
  ""
@@ -668,7 +668,7 @@ const getFinalName = (
668
668
 
669
669
  /**
670
670
  * @typedef {object} ConcatenateModuleHooks
671
- * @property {SyncBailHook<[Record<string, string>, ConcatenatedModule], boolean | void>} exportsDefinitions
671
+ * @property {SyncBailHook<[ConcatenatedModule], boolean>} onDemandExportsGeneration
672
672
  * @property {SyncBailHook<[Partial<ConcatenatedModuleInfo>, ConcatenatedModuleInfo], boolean | void>} concatenatedModuleInfo
673
673
  */
674
674
 
@@ -716,7 +716,7 @@ class ConcatenatedModule extends Module {
716
716
  let hooks = compilationHooksMap.get(compilation);
717
717
  if (hooks === undefined) {
718
718
  hooks = {
719
- exportsDefinitions: new SyncBailHook(["definitions", "module"]),
719
+ onDemandExportsGeneration: new SyncBailHook(["module"]),
720
720
  concatenatedModuleInfo: new SyncBailHook([
721
721
  "updatedInfo",
722
722
  "concatenatedModuleInfo"
@@ -1692,11 +1692,6 @@ class ConcatenatedModule extends Module {
1692
1692
 
1693
1693
  // define exports
1694
1694
  if (exportsMap.size > 0) {
1695
- const { exportsDefinitions } = ConcatenatedModule.getCompilationHooks(
1696
- /** @type {Compilation} */
1697
- (this.compilation)
1698
- );
1699
-
1700
1695
  const definitions = [];
1701
1696
  for (const [key, value] of exportsMap) {
1702
1697
  definitions.push(
@@ -1706,34 +1701,40 @@ class ConcatenatedModule extends Module {
1706
1701
  );
1707
1702
  }
1708
1703
 
1709
- const shouldSkipRenderDefinitions = exportsDefinitions.call(
1710
- exportsFinalName,
1711
- this
1712
- );
1704
+ const { onDemandExportsGeneration } =
1705
+ ConcatenatedModule.getCompilationHooks(
1706
+ /** @type {Compilation} */
1707
+ (this.compilation)
1708
+ );
1713
1709
 
1714
- if (!shouldSkipRenderDefinitions) {
1715
- runtimeRequirements.add(RuntimeGlobals.exports);
1716
- runtimeRequirements.add(RuntimeGlobals.definePropertyGetters);
1710
+ runtimeRequirements.add(RuntimeGlobals.exports);
1711
+ runtimeRequirements.add(RuntimeGlobals.definePropertyGetters);
1717
1712
 
1718
- if (shouldAddHarmonyFlag) {
1719
- result.add("// ESM COMPAT FLAG\n");
1720
- result.add(
1721
- runtimeTemplate.defineEsModuleFlagStatement({
1722
- exportsArgument: this.exportsArgument,
1723
- runtimeRequirements
1724
- })
1725
- );
1726
- }
1713
+ if (shouldAddHarmonyFlag) {
1714
+ result.add("// ESM COMPAT FLAG\n");
1715
+ result.add(
1716
+ runtimeTemplate.defineEsModuleFlagStatement({
1717
+ exportsArgument: this.exportsArgument,
1718
+ runtimeRequirements
1719
+ })
1720
+ );
1721
+ }
1727
1722
 
1723
+ if (onDemandExportsGeneration.call(this)) {
1724
+ /** @type {BuildMeta} */ (this.buildMeta).factoryExportsBinding =
1725
+ "\n// EXPORTS\n" +
1726
+ `${RuntimeGlobals.definePropertyGetters}(${
1727
+ this.exportsArgument
1728
+ }, {${definitions.join(",")}\n});\n`;
1729
+ /** @type {BuildMeta} */ (this.buildMeta).exportsFinalName =
1730
+ exportsFinalName;
1731
+ } else {
1728
1732
  result.add("\n// EXPORTS\n");
1729
1733
  result.add(
1730
1734
  `${RuntimeGlobals.definePropertyGetters}(${
1731
1735
  this.exportsArgument
1732
1736
  }, {${definitions.join(",")}\n});\n`
1733
1737
  );
1734
- } else {
1735
- /** @type {BuildMeta} */
1736
- (this.buildMeta).exportsFinalName = exportsFinalName;
1737
1738
  }
1738
1739
  }
1739
1740
 
@@ -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,8 +101,8 @@ 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);