webpack 5.108.4 → 5.109.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.
Files changed (186) hide show
  1. package/lib/APIPlugin.js +48 -29
  2. package/lib/CacheFacade.js +8 -0
  3. package/lib/ChunkGroup.js +1 -0
  4. package/lib/CompatibilityPlugin.js +31 -29
  5. package/lib/Compilation.js +49 -4
  6. package/lib/ConstPlugin.js +11 -11
  7. package/lib/ContextModule.js +239 -6
  8. package/lib/ContextModuleFactory.js +139 -14
  9. package/lib/DefinePlugin.js +396 -101
  10. package/lib/Entrypoint.js +1 -1
  11. package/lib/ExportsInfoApiPlugin.js +2 -2
  12. package/lib/ExternalModule.js +107 -5
  13. package/lib/ExternalModuleFactoryPlugin.js +20 -1
  14. package/lib/FileSystemInfo.js +130 -74
  15. package/lib/HotModuleReplacementPlugin.js +18 -15
  16. package/lib/Module.js +3 -0
  17. package/lib/ModuleFilenameHelpers.js +2 -2
  18. package/lib/ModuleTypeConstants.js +8 -1
  19. package/lib/MultiCompiler.js +13 -2
  20. package/lib/MultiWatching.js +1 -0
  21. package/lib/NodeStuffPlugin.js +51 -33
  22. package/lib/NormalModule.js +169 -401
  23. package/lib/NormalModuleFactory.js +76 -2
  24. package/lib/ProgressPlugin.js +211 -119
  25. package/lib/ProvidePlugin.js +2 -2
  26. package/lib/RuntimeGlobals.js +47 -0
  27. package/lib/RuntimePlugin.js +33 -0
  28. package/lib/RuntimeTemplate.js +304 -16
  29. package/lib/UseStrictPlugin.js +1 -1
  30. package/lib/WebpackIsIncludedPlugin.js +1 -1
  31. package/lib/WebpackOptionsApply.js +24 -19
  32. package/lib/asset/AssetGenerator.js +110 -28
  33. package/lib/asset/AssetModulesPlugin.js +92 -2
  34. package/lib/asset/WebManifestGenerator.js +164 -0
  35. package/lib/asset/WebManifestParser.js +130 -0
  36. package/lib/async-modules/AwaitDependenciesInitFragment.js +14 -4
  37. package/lib/async-modules/isGeneratorLowered.js +26 -0
  38. package/lib/cache/PackFileCacheStrategy.js +9 -3
  39. package/lib/config/browserslistTargetHandler.js +40 -0
  40. package/lib/config/defaults.js +219 -29
  41. package/lib/config/normalization.js +26 -0
  42. package/lib/config/target.js +9 -1
  43. package/lib/css/CssGenerator.js +40 -31
  44. package/lib/css/CssLoadingRuntimeModule.js +5 -1
  45. package/lib/css/CssModulesPlugin.js +13 -0
  46. package/lib/css/CssParser.js +594 -263
  47. package/lib/css/syntax.js +875 -462
  48. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -6
  49. package/lib/dependencies/AMDPlugin.js +2 -2
  50. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +13 -13
  51. package/lib/dependencies/CommonJsDependencyHelpers.js +39 -0
  52. package/lib/dependencies/CommonJsExportsDependency.js +47 -2
  53. package/lib/dependencies/CommonJsExportsParserPlugin.js +10 -10
  54. package/lib/dependencies/CommonJsImportsParserPlugin.js +18 -18
  55. package/lib/dependencies/CommonJsPlugin.js +2 -2
  56. package/lib/dependencies/CommonJsRequireDependency.js +26 -1
  57. package/lib/dependencies/CommonJsSelfReferenceDependency.js +32 -1
  58. package/lib/dependencies/ContextDependencyHelpers.js +3 -3
  59. package/lib/dependencies/CreateRequireParserPlugin.js +6 -6
  60. package/lib/dependencies/CssIcssExportDependency.js +162 -71
  61. package/lib/dependencies/CssUrlDependency.js +35 -4
  62. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +2 -2
  63. package/lib/dependencies/HarmonyCompatibilityDependency.js +32 -14
  64. package/lib/dependencies/HarmonyDetectionParserPlugin.js +43 -13
  65. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +7 -19
  66. package/lib/dependencies/HarmonyImportDependency.js +12 -1
  67. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +11 -11
  68. package/lib/dependencies/HarmonyModulesPlugin.js +6 -0
  69. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +1 -1
  70. package/lib/dependencies/HtmlEntryDependency.js +797 -172
  71. package/lib/dependencies/HtmlSourceDependency.js +26 -0
  72. package/lib/dependencies/ImportDependency.js +43 -1
  73. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +31 -18
  74. package/lib/dependencies/ImportMetaContextPlugin.js +38 -7
  75. package/lib/dependencies/ImportMetaGlobDependency.js +81 -0
  76. package/lib/dependencies/ImportMetaGlobDependencyParserPlugin.js +78 -0
  77. package/lib/dependencies/ImportMetaGlobHelpers.js +660 -0
  78. package/lib/dependencies/ImportMetaPlugin.js +532 -180
  79. package/lib/dependencies/ImportMetaResolveDependency.js +90 -0
  80. package/lib/dependencies/ImportParserPlugin.js +80 -17
  81. package/lib/dependencies/ImportPhase.js +10 -8
  82. package/lib/dependencies/LoaderPlugin.js +5 -1
  83. package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -1
  84. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +3 -6
  85. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +4 -11
  86. package/lib/dependencies/SystemPlugin.js +2 -4
  87. package/lib/dependencies/TopLevelAwaitDependency.js +93 -0
  88. package/lib/dependencies/URLDependency.js +141 -21
  89. package/lib/dependencies/{WorkerPlugin.js → WorkerAndWorkletPlugin.js} +324 -112
  90. package/lib/dependencies/WorkerDependency.js +86 -18
  91. package/lib/dependencies/WorkletDependency.js +278 -0
  92. package/lib/dll/DelegatedModuleFactoryPlugin.js +19 -0
  93. package/lib/errors/EnvironmentNotSupportAsyncWarning.js +1 -1
  94. package/lib/errors/LoaderLoadingError.js +20 -0
  95. package/lib/errors/ModuleParseError.js +39 -22
  96. package/lib/errors/NodeStuffInWebError.js +1 -1
  97. package/lib/esm/ModuleChunkFormatPlugin.js +47 -14
  98. package/lib/esm/ModuleChunkLoadingPlugin.js +8 -1
  99. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +29 -1
  100. package/lib/hmr/lazyCompilationBackend.js +32 -8
  101. package/lib/html/HtmlGenerator.js +887 -15
  102. package/lib/html/HtmlModule.js +2 -2
  103. package/lib/html/HtmlModulesPlugin.js +610 -166
  104. package/lib/html/HtmlParser.js +603 -247
  105. package/lib/html/favicon.svg +1 -0
  106. package/lib/html/syntax.js +1264 -661
  107. package/lib/ids/IdHelpers.js +1 -1
  108. package/lib/index.js +6 -0
  109. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +4 -5
  110. package/lib/javascript/BasicEvaluatedExpression.js +366 -48
  111. package/lib/javascript/JavascriptGenerator.js +197 -49
  112. package/lib/javascript/JavascriptModulesPlugin.js +178 -24
  113. package/lib/javascript/JavascriptParser.js +701 -355
  114. package/lib/javascript/JavascriptParserHelpers.js +3 -6
  115. package/lib/javascript/syntax.js +4380 -0
  116. package/lib/library/ModuleLibraryPlugin.js +38 -1
  117. package/lib/loaders/LoaderRunner.js +714 -0
  118. package/lib/loaders/loadLoader.js +100 -0
  119. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +19 -0
  120. package/lib/node/ReadFileCompileWasmPlugin.js +14 -0
  121. package/lib/optimize/ConcatenatedModule.js +120 -16
  122. package/lib/optimize/FlagIncludedChunksPlugin.js +13 -3
  123. package/lib/optimize/InnerGraphPlugin.js +50 -30
  124. package/lib/optimize/ModuleConcatenationPlugin.js +69 -3
  125. package/lib/optimize/SideEffectsFlagPlugin.js +86 -43
  126. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +15 -0
  127. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +24 -13
  128. package/lib/prefetch/ResourceHintPlugin.js +663 -0
  129. package/lib/prefetch/ResourceHintRuntimeModule.js +149 -0
  130. package/lib/prefetch/StartupAssetHintRuntimeModule.js +210 -0
  131. package/lib/prefetch/parseResourceHintOptions.js +103 -0
  132. package/lib/rules/RuleSetCompiler.js +114 -0
  133. package/lib/runtime/AsyncModuleGeneratorRuntimeModule.js +56 -0
  134. package/lib/runtime/AsyncModuleRuntimeModule.js +24 -8
  135. package/lib/runtime/AutoPublicPathRuntimeModule.js +7 -1
  136. package/lib/runtime/CommonJsWrapRuntimeModule.js +37 -0
  137. package/lib/runtime/GetWorkletBootstrapRuntimeModule.js +59 -0
  138. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +204 -8
  139. package/lib/runtime/SetAnonymousDefaultNameRuntimeModule.js +4 -1
  140. package/lib/schemes/HttpUriPlugin.js +40 -1
  141. package/lib/schemes/VirtualUrlPlugin.js +1 -2
  142. package/lib/serialization/FileMiddleware.js +29 -3
  143. package/lib/stats/DefaultStatsFactoryPlugin.js +32 -3
  144. package/lib/stats/DefaultStatsPresetPlugin.js +2 -0
  145. package/lib/stats/DefaultStatsPrinterPlugin.js +12 -2
  146. package/lib/stats/StatsFactory.js +15 -8
  147. package/lib/url/URLParserPlugin.js +66 -13
  148. package/lib/util/AsyncQueue.js +122 -72
  149. package/lib/util/SetHelpers.js +1 -1
  150. package/lib/util/StackedMap.js +122 -48
  151. package/lib/util/binarySearchBounds.js +2 -2
  152. package/lib/util/concatenate.js +40 -14
  153. package/lib/util/createHooksRegistry.js +13 -5
  154. package/lib/util/dataURL.js +2 -2
  155. package/lib/util/deterministicGrouping.js +7 -5
  156. package/lib/util/formatSize.js +6 -2
  157. package/lib/util/globUtils.js +710 -0
  158. package/lib/util/identifier.js +23 -6
  159. package/lib/util/implicitTypeLoaderFallback.js +62 -0
  160. package/lib/util/internalSerializables.js +88 -71
  161. package/lib/util/magicComment.js +121 -25
  162. package/lib/util/numberHash.js +2 -2
  163. package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +24 -18
  164. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +33 -22
  165. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +79 -16
  166. package/lib/web/FetchCompileAsyncWasmPlugin.js +19 -0
  167. package/lib/web/FetchCompileWasmPlugin.js +14 -0
  168. package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -0
  169. package/lib/webpack.js +65 -0
  170. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +3 -0
  171. package/module.d.ts +21 -0
  172. package/package.json +13 -12
  173. package/schemas/WebpackOptions.check.js +1 -1
  174. package/schemas/WebpackOptions.json +759 -36
  175. package/schemas/plugins/HtmlParserOptions.check.js +1 -1
  176. package/schemas/plugins/ProgressPlugin.check.js +1 -1
  177. package/schemas/plugins/ProgressPlugin.json +17 -1
  178. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  179. package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
  180. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  181. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  182. package/schemas/plugins/container/ModuleFederationPlugin.json +1 -0
  183. package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +1 -1
  184. package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
  185. package/schemas/plugins/css/CssParserOptions.check.js +1 -1
  186. package/types.d.ts +1213 -96
package/lib/APIPlugin.js CHANGED
@@ -31,9 +31,22 @@ const GetFullHashRuntimeModule = require("./runtime/GetFullHashRuntimeModule");
31
31
  /** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
32
32
  /** @typedef {import("./Module").BuildInfo} BuildInfo */
33
33
  /** @typedef {import("./javascript/JavascriptModule").JavascriptModuleBuildInfo} JavascriptModuleBuildInfo */
34
+ /** @typedef {import("./Compilation")} Compilation */
34
35
  /** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
35
36
  /** @typedef {import("./javascript/JavascriptParser").Range} Range */
36
37
 
38
+ // Compilations where a module reassigns `__webpack_public_path__` at runtime.
39
+ // A baked analyzable specifier can't reflect that, so those forms fall back.
40
+ /** @type {WeakSet<Compilation>} */
41
+ const runtimePublicPathOverride = new WeakSet();
42
+
43
+ /**
44
+ * @param {Compilation} compilation compilation
45
+ * @returns {boolean} true when a module reassigns `__webpack_public_path__` at runtime
46
+ */
47
+ const usesRuntimePublicPathOverride = (compilation) =>
48
+ runtimePublicPathOverride.has(compilation);
49
+
37
50
  /**
38
51
  * Returns the replacement definitions used for webpack API identifiers.
39
52
  * @returns {Record<string, { expr: string, req: string[] | null, type?: string, assign: boolean }>} replacements
@@ -225,27 +238,28 @@ class APIPlugin {
225
238
  }
226
239
  });
227
240
 
228
- parser.hooks.preStatement.tap(PLUGIN_NAME, (statement) => {
229
- if (parser.scope.topLevelScope === true) {
230
- if (
231
- statement.type === "FunctionDeclaration" &&
232
- statement.id &&
233
- statement.id.name === "module"
234
- ) {
235
- /** @type {BuildInfo} */
236
- (parser.state.module.buildInfo).moduleArgument =
237
- "__webpack_module__";
238
- } else if (
239
- statement.type === "ClassDeclaration" &&
240
- statement.id &&
241
- statement.id.name === "module"
242
- ) {
243
- /** @type {BuildInfo} */
244
- (parser.state.module.buildInfo).moduleArgument =
245
- "__webpack_module__";
246
- }
241
+ /**
242
+ * @param {import("estree").Statement | import("estree").ModuleDeclaration | import("estree").MaybeNamedFunctionDeclaration | import("estree").MaybeNamedClassDeclaration} statement statement
243
+ */
244
+ const moduleDeclarationHandler = (statement) => {
245
+ if (
246
+ parser.scope.topLevelScope === true &&
247
+ (statement.type === "FunctionDeclaration" ||
248
+ statement.type === "ClassDeclaration") &&
249
+ statement.id &&
250
+ statement.id.name === "module"
251
+ ) {
252
+ /** @type {BuildInfo} */
253
+ (parser.state.module.buildInfo).moduleArgument =
254
+ "__webpack_module__";
247
255
  }
248
- });
256
+ };
257
+ parser.hooks.preStatementByType
258
+ .for("FunctionDeclaration")
259
+ .tap(PLUGIN_NAME, moduleDeclarationHandler);
260
+ parser.hooks.preStatementByType
261
+ .for("ClassDeclaration")
262
+ .tap(PLUGIN_NAME, moduleDeclarationHandler);
249
263
 
250
264
  for (const key of Object.keys(REPLACEMENTS)) {
251
265
  const info = REPLACEMENTS[key];
@@ -260,9 +274,7 @@ class APIPlugin {
260
274
  const warning = new WebpackError(
261
275
  `${PLUGIN_NAME}\n__non_webpack_require__ is only allowed in target node`
262
276
  );
263
- warning.loc = /** @type {DependencyLocation} */ (
264
- expression.loc
265
- );
277
+ warning.loc = parser.getLocation(expression);
266
278
  warning.module = parser.state.module;
267
279
  compilation.warnings.push(warning);
268
280
  }
@@ -273,9 +285,15 @@ class APIPlugin {
273
285
  if (info.assign === false) {
274
286
  parser.hooks.assign.for(key).tap(PLUGIN_NAME, (expr) => {
275
287
  const err = new WebpackError(`${key} must not be assigned`);
276
- err.loc = /** @type {DependencyLocation} */ (expr.loc);
288
+ err.loc = parser.getLocation(expr);
277
289
  throw err;
278
290
  });
291
+ } else if (key === "__webpack_public_path__") {
292
+ // Flag the runtime override (still let the default handler emit
293
+ // `__webpack_require__.p = …`); returning nothing keeps that path.
294
+ parser.hooks.assign.for(key).tap(PLUGIN_NAME, () => {
295
+ runtimePublicPathOverride.add(compilation);
296
+ });
279
297
  }
280
298
  if (info.type) {
281
299
  parser.hooks.evaluateTypeof
@@ -291,7 +309,7 @@ class APIPlugin {
291
309
  JSON.stringify(parser.state.module.layer),
292
310
  /** @type {Range} */ (expr.range)
293
311
  );
294
- dep.loc = /** @type {DependencyLocation} */ (expr.loc);
312
+ dep.loc = parser.getLocation(expr);
295
313
  parser.state.module.addPresentationalDependency(dep);
296
314
  return true;
297
315
  });
@@ -326,7 +344,7 @@ class APIPlugin {
326
344
  const dep = new RuntimeRequirementsDependency([
327
345
  RuntimeGlobals.moduleId
328
346
  ]);
329
- dep.loc = /** @type {DependencyLocation} */ (expr.loc);
347
+ dep.loc = parser.getLocation(expr);
330
348
  parser.state.module.addPresentationalDependency(dep);
331
349
  } else {
332
350
  const initDep = new ModuleInitFragmentDependency(
@@ -340,7 +358,7 @@ class APIPlugin {
340
358
  /** @type {Range} */ (expr.range),
341
359
  []
342
360
  );
343
- dep.loc = /** @type {DependencyLocation} */ (expr.loc);
361
+ dep.loc = parser.getLocation(expr);
344
362
  parser.state.module.addPresentationalDependency(dep);
345
363
  }
346
364
  return true;
@@ -357,7 +375,7 @@ class APIPlugin {
357
375
  const dep = new RuntimeRequirementsDependency([
358
376
  RuntimeGlobals.module
359
377
  ]);
360
- dep.loc = /** @type {DependencyLocation} */ (expr.loc);
378
+ dep.loc = parser.getLocation(expr);
361
379
  parser.state.module.addPresentationalDependency(dep);
362
380
  } else {
363
381
  const initDep = new ModuleInitFragmentDependency(
@@ -371,7 +389,7 @@ class APIPlugin {
371
389
  /** @type {Range} */ (expr.range),
372
390
  []
373
391
  );
374
- dep.loc = /** @type {DependencyLocation} */ (expr.loc);
392
+ dep.loc = parser.getLocation(expr);
375
393
  parser.state.module.addPresentationalDependency(dep);
376
394
  }
377
395
  return true;
@@ -396,3 +414,4 @@ class APIPlugin {
396
414
  }
397
415
 
398
416
  module.exports = APIPlugin;
417
+ module.exports.usesRuntimePublicPathOverride = usesRuntimePublicPathOverride;
@@ -227,6 +227,14 @@ class CacheFacade {
227
227
  this._hashFunction = hashFunction;
228
228
  }
229
229
 
230
+ /**
231
+ * Returns whether a cache backend is active.
232
+ * @returns {boolean} true, when get or store can have an effect
233
+ */
234
+ isEnabled() {
235
+ return this._cache.hooks.get.isUsed() || this._cache.hooks.store.isUsed();
236
+ }
237
+
230
238
  /**
231
239
  * Returns child cache.
232
240
  * @param {string} name the child cache name#
package/lib/ChunkGroup.js CHANGED
@@ -30,6 +30,7 @@ const {
30
30
  * @typedef {object} RawChunkGroupOptions
31
31
  * @property {number=} preloadOrder
32
32
  * @property {number=} prefetchOrder
33
+ * @property {number=} cssPreloadOrder preload only the chunk's CSS (`as="style"`), not its JS
33
34
  * @property {("low" | "high" | "auto")=} fetchPriority
34
35
  */
35
36
 
@@ -89,7 +89,7 @@ class CompatibilityPlugin {
89
89
  "require",
90
90
  /** @type {Range} */ (expr.callee.range)
91
91
  );
92
- dep.loc = /** @type {DependencyLocation} */ (expr.loc);
92
+ dep.loc = parser.getLocation(expr);
93
93
  if (parser.state.current.dependencies.length > 0) {
94
94
  const last =
95
95
  /** @type {ContextDependency} */
@@ -122,31 +122,33 @@ class CompatibilityPlugin {
122
122
  */
123
123
  const handler = (parser) => {
124
124
  // Handle nested requires
125
- parser.hooks.preStatement.tap(PLUGIN_NAME, (statement) => {
126
- if (
127
- statement.type === "FunctionDeclaration" &&
128
- statement.id &&
129
- statement.id.name === RuntimeGlobals.require
130
- ) {
131
- const newName = `__nested_webpack_require_${
132
- /** @type {Range} */
133
- (statement.range)[0]
134
- }__`;
135
- parser.tagVariable(
136
- statement.id.name,
137
- nestedWebpackIdentifierTag,
138
- {
139
- name: newName,
140
- declaration: {
141
- updated: false,
142
- loc: /** @type {DependencyLocation} */ (statement.id.loc),
143
- range: /** @type {Range} */ (statement.id.range)
125
+ parser.hooks.preStatementByType
126
+ .for("FunctionDeclaration")
127
+ .tap(PLUGIN_NAME, (statement) => {
128
+ if (
129
+ statement.type === "FunctionDeclaration" &&
130
+ statement.id &&
131
+ statement.id.name === RuntimeGlobals.require
132
+ ) {
133
+ const newName = `__nested_webpack_require_${
134
+ /** @type {Range} */
135
+ (statement.range)[0]
136
+ }__`;
137
+ parser.tagVariable(
138
+ statement.id.name,
139
+ nestedWebpackIdentifierTag,
140
+ {
141
+ name: newName,
142
+ declaration: {
143
+ updated: false,
144
+ loc: parser.getLocation(statement.id),
145
+ range: /** @type {Range} */ (statement.id.range)
146
+ }
144
147
  }
145
- }
146
- );
147
- return true;
148
- }
149
- });
148
+ );
149
+ return true;
150
+ }
151
+ });
150
152
  parser.hooks.pattern
151
153
  .for(RuntimeGlobals.require)
152
154
  .tap(PLUGIN_NAME, (pattern) => {
@@ -157,7 +159,7 @@ class CompatibilityPlugin {
157
159
  name: newName,
158
160
  declaration: {
159
161
  updated: false,
160
- loc: /** @type {DependencyLocation} */ (pattern.loc),
162
+ loc: parser.getLocation(pattern),
161
163
  range: /** @type {Range} */ (pattern.range)
162
164
  }
163
165
  });
@@ -173,7 +175,7 @@ class CompatibilityPlugin {
173
175
  name: newName,
174
176
  declaration: {
175
177
  updated: false,
176
- loc: /** @type {DependencyLocation} */ (pattern.loc),
178
+ loc: parser.getLocation(pattern),
177
179
  range: /** @type {Range} */ (pattern.range)
178
180
  }
179
181
  });
@@ -218,7 +220,7 @@ class CompatibilityPlugin {
218
220
  name,
219
221
  /** @type {Range} */ (expr.range)
220
222
  );
221
- dep.loc = /** @type {DependencyLocation} */ (expr.loc);
223
+ dep.loc = parser.getLocation(expr);
222
224
  parser.state.module.addPresentationalDependency(dep);
223
225
  return true;
224
226
  });
@@ -231,7 +233,7 @@ class CompatibilityPlugin {
231
233
  if (parser.state.source.slice(0, 2).toString() !== "#!") return;
232
234
  // this is a hashbang comment
233
235
  const dep = new ConstDependency("//", 0);
234
- dep.loc = /** @type {DependencyLocation} */ (c.loc);
236
+ dep.loc = parser.getLocation(c);
235
237
  parser.state.module.addPresentationalDependency(dep);
236
238
  }
237
239
  });
@@ -251,6 +251,7 @@ const { isSourceEqual } = require("./util/source");
251
251
  * @typedef {object} ExecuteModuleResult
252
252
  * @property {ExecuteModuleExports} exports
253
253
  * @property {boolean} cacheable
254
+ * @property {string[]} notCacheableReasons reasons why the executed modules are not cacheable
254
255
  * @property {ExecuteModuleAssets} assets
255
256
  * @property {FileSystemDependencies} fileDependencies
256
257
  * @property {FileSystemDependencies} contextDependencies
@@ -4084,6 +4085,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4084
4085
  * @param {WebpackError[]} errors errors
4085
4086
  * @param {CodeGenerationResults} results results
4086
4087
  * @param {(err?: WebpackError | null, result?: boolean) => void} callback callback
4088
+ * @returns {void}
4087
4089
  */
4088
4090
  _codeGenerationModule(
4089
4091
  module,
@@ -4099,6 +4101,39 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4099
4101
  callback
4100
4102
  ) {
4101
4103
  let codeGenerated = false;
4104
+ // without a cache backend, skip building the cache keys — the module
4105
+ // identifier strings are large (concatenated modules join all inner ids)
4106
+ if (!this._codeGenerationCache.isEnabled()) {
4107
+ /** @type {CodeGenerationResult} */
4108
+ let result;
4109
+ try {
4110
+ codeGenerated = true;
4111
+ this.codeGeneratedModules.add(module);
4112
+ result = module.codeGeneration({
4113
+ chunkGraph,
4114
+ moduleGraph,
4115
+ dependencyTemplates,
4116
+ runtimeTemplate,
4117
+ runtime,
4118
+ runtimes,
4119
+ codeGenerationResults: results,
4120
+ compilation: this
4121
+ });
4122
+ } catch (err) {
4123
+ errors.push(
4124
+ new CodeGenerationError(module, /** @type {Error} */ (err))
4125
+ );
4126
+ result = {
4127
+ sources: new Map(),
4128
+ runtimeRequirements: null,
4129
+ data: undefined
4130
+ };
4131
+ }
4132
+ for (const runtime of runtimes) {
4133
+ results.add(module, runtime, result);
4134
+ }
4135
+ return callback(null, codeGenerated);
4136
+ }
4102
4137
  const cache = new MultiItemCache(
4103
4138
  runtimes.map((runtime) =>
4104
4139
  this._codeGenerationCache.getItemCache(
@@ -5990,6 +6025,8 @@ This prevents using hashes of each other and should be avoided.`);
5990
6025
  const assets = new Map();
5991
6026
 
5992
6027
  let cacheable = true;
6028
+ /** @type {ExecuteModuleResult["notCacheableReasons"]} */
6029
+ const notCacheableReasons = [];
5993
6030
 
5994
6031
  /** @type {ExecuteModuleContext} */
5995
6032
  const context = {
@@ -6025,11 +6062,18 @@ This prevents using hashes of each other and should be avoided.`);
6025
6062
  missingDependencies,
6026
6063
  buildDependencies
6027
6064
  );
6028
- if (
6029
- /** @type {BuildInfo} */ (module.buildInfo).cacheable ===
6030
- false
6031
- ) {
6065
+ const buildInfo = /** @type {BuildInfo} */ (
6066
+ module.buildInfo
6067
+ );
6068
+ if (buildInfo.cacheable === false) {
6032
6069
  cacheable = false;
6070
+ if (buildInfo.notCacheableReasons) {
6071
+ for (const reason of buildInfo.notCacheableReasons) {
6072
+ if (!notCacheableReasons.includes(reason)) {
6073
+ notCacheableReasons.push(reason);
6074
+ }
6075
+ }
6076
+ }
6033
6077
  }
6034
6078
  if (module.buildInfo && module.buildInfo.assets) {
6035
6079
  const { assets: moduleAssets, assetsInfo } =
@@ -6181,6 +6225,7 @@ This prevents using hashes of each other and should be avoided.`);
6181
6225
  exports,
6182
6226
  assets,
6183
6227
  cacheable,
6228
+ notCacheableReasons,
6184
6229
  fileDependencies,
6185
6230
  contextDependencies,
6186
6231
  missingDependencies,
@@ -175,7 +175,7 @@ class ConstPlugin {
175
175
  `${bool}`,
176
176
  /** @type {Range} */ (param.range)
177
177
  );
178
- dep.loc = /** @type {SourceLocation} */ (statement.loc);
178
+ dep.loc = parser.getLocation(statement);
179
179
  parser.state.module.addPresentationalDependency(dep);
180
180
  } else {
181
181
  parser.walkExpression(statement.test);
@@ -212,7 +212,7 @@ class ConstPlugin {
212
212
  ` ${bool}`,
213
213
  /** @type {Range} */ (param.range)
214
214
  );
215
- dep.loc = /** @type {SourceLocation} */ (expression.loc);
215
+ dep.loc = parser.getLocation(expression);
216
216
  parser.state.module.addPresentationalDependency(dep);
217
217
  } else {
218
218
  parser.walkExpression(expression.test);
@@ -235,7 +235,7 @@ class ConstPlugin {
235
235
  "0",
236
236
  /** @type {Range} */ (branchToRemove.range)
237
237
  );
238
- dep.loc = /** @type {SourceLocation} */ (branchToRemove.loc);
238
+ dep.loc = parser.getLocation(branchToRemove);
239
239
  parser.state.module.addPresentationalDependency(dep);
240
240
  return bool;
241
241
  }
@@ -315,7 +315,7 @@ class ConstPlugin {
315
315
  ` ${bool}`,
316
316
  /** @type {Range} */ (param.range)
317
317
  );
318
- dep.loc = /** @type {SourceLocation} */ (expression.loc);
318
+ dep.loc = parser.getLocation(expression);
319
319
  parser.state.module.addPresentationalDependency(dep);
320
320
  } else {
321
321
  parser.walkExpression(expression.left);
@@ -325,7 +325,7 @@ class ConstPlugin {
325
325
  "0",
326
326
  /** @type {Range} */ (expression.right.range)
327
327
  );
328
- dep.loc = /** @type {SourceLocation} */ (expression.loc);
328
+ dep.loc = parser.getLocation(expression);
329
329
  parser.state.module.addPresentationalDependency(dep);
330
330
  }
331
331
  return keepRight;
@@ -368,14 +368,14 @@ class ConstPlugin {
368
368
  " null",
369
369
  /** @type {Range} */ (param.range)
370
370
  );
371
- dep.loc = /** @type {SourceLocation} */ (expression.loc);
371
+ dep.loc = parser.getLocation(expression);
372
372
  parser.state.module.addPresentationalDependency(dep);
373
373
  } else {
374
374
  const dep = new ConstDependency(
375
375
  "0",
376
376
  /** @type {Range} */ (expression.right.range)
377
377
  );
378
- dep.loc = /** @type {SourceLocation} */ (expression.loc);
378
+ dep.loc = parser.getLocation(expression);
379
379
  parser.state.module.addPresentationalDependency(dep);
380
380
  parser.walkExpression(expression.left);
381
381
  }
@@ -437,7 +437,7 @@ class ConstPlugin {
437
437
  " undefined",
438
438
  /** @type {Range} */ (expr.range)
439
439
  );
440
- dep.loc = /** @type {SourceLocation} */ (expr.loc);
440
+ dep.loc = parser.getLocation(expr);
441
441
  parser.state.module.addPresentationalDependency(dep);
442
442
  return true;
443
443
  }
@@ -464,7 +464,7 @@ class ConstPlugin {
464
464
  /** @type {Range} */ (expr.range),
465
465
  "__resourceQuery"
466
466
  );
467
- dep.loc = /** @type {SourceLocation} */ (expr.loc);
467
+ dep.loc = parser.getLocation(expr);
468
468
  parser.state.module.addPresentationalDependency(dep);
469
469
  return true;
470
470
  });
@@ -490,7 +490,7 @@ class ConstPlugin {
490
490
  /** @type {Range} */ (expr.range),
491
491
  "__resourceFragment"
492
492
  );
493
- dep.loc = /** @type {SourceLocation} */ (expr.loc);
493
+ dep.loc = parser.getLocation(expr);
494
494
  parser.state.module.addPresentationalDependency(dep);
495
495
  return true;
496
496
  });
@@ -562,7 +562,7 @@ class ConstPlugin {
562
562
  `// removed by dead control flow\n${replacement}`,
563
563
  /** @type {Range} */ (statement.range)
564
564
  );
565
- dep.loc = /** @type {SourceLocation} */ (statement.loc);
565
+ dep.loc = parser.getLocation(statement);
566
566
  parser.state.module.addPresentationalDependency(dep);
567
567
  }
568
568
  }