webpack 5.86.0 → 5.88.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of webpack might be problematic. Click here for more details.

Files changed (207) hide show
  1. package/README.md +5 -2
  2. package/lib/APIPlugin.js +1 -1
  3. package/lib/AsyncDependenciesBlock.js +3 -3
  4. package/lib/CaseSensitiveModulesWarning.js +3 -1
  5. package/lib/ChunkGraph.js +4 -4
  6. package/lib/ChunkGroup.js +10 -3
  7. package/lib/CompatibilityPlugin.js +50 -30
  8. package/lib/Compilation.js +2 -1
  9. package/lib/Compiler.js +3 -1
  10. package/lib/ConcatenationScope.js +2 -2
  11. package/lib/ConditionalInitFragment.js +11 -1
  12. package/lib/ConstPlugin.js +57 -29
  13. package/lib/ContextModule.js +4 -1
  14. package/lib/ContextReplacementPlugin.js +13 -0
  15. package/lib/DelegatedModule.js +15 -3
  16. package/lib/DelegatedModuleFactoryPlugin.js +6 -0
  17. package/lib/Dependency.js +11 -5
  18. package/lib/DllEntryPlugin.js +11 -1
  19. package/lib/DllReferencePlugin.js +13 -1
  20. package/lib/Entrypoint.js +1 -1
  21. package/lib/ErrorHelpers.js +1 -0
  22. package/lib/EvalSourceMapDevToolPlugin.js +4 -0
  23. package/lib/ExportsInfo.js +17 -3
  24. package/lib/ExportsInfoApiPlugin.js +14 -5
  25. package/lib/ExternalModule.js +5 -0
  26. package/lib/FlagAllModulesAsUsedPlugin.js +6 -1
  27. package/lib/FlagDependencyUsagePlugin.js +3 -1
  28. package/lib/FlagEntryExportAsUsedPlugin.js +4 -0
  29. package/lib/HotModuleReplacementPlugin.js +8 -0
  30. package/lib/InitFragment.js +28 -5
  31. package/lib/JavascriptMetaInfoPlugin.js +11 -6
  32. package/lib/LibManifestPlugin.js +20 -4
  33. package/lib/Module.js +7 -2
  34. package/lib/ModuleDependencyError.js +4 -2
  35. package/lib/ModuleDependencyWarning.js +4 -2
  36. package/lib/ModuleGraph.js +31 -24
  37. package/lib/ModuleGraphConnection.js +19 -6
  38. package/lib/ModuleInfoHeaderPlugin.js +9 -2
  39. package/lib/ModuleNotFoundError.js +5 -2
  40. package/lib/ModuleProfile.js +1 -0
  41. package/lib/ModuleRestoreError.js +2 -0
  42. package/lib/ModuleStoreError.js +2 -1
  43. package/lib/ModuleTypeConstants.js +7 -0
  44. package/lib/MultiWatching.js +4 -0
  45. package/lib/NodeStuffPlugin.js +32 -6
  46. package/lib/ProvidePlugin.js +13 -4
  47. package/lib/RawModule.js +3 -1
  48. package/lib/RequireJsStuffPlugin.js +7 -0
  49. package/lib/RuntimeGlobals.js +5 -0
  50. package/lib/RuntimeModule.js +3 -3
  51. package/lib/RuntimePlugin.js +6 -3
  52. package/lib/RuntimeTemplate.js +22 -4
  53. package/lib/SourceMapDevToolModuleOptionsPlugin.js +4 -0
  54. package/lib/SourceMapDevToolPlugin.js +7 -2
  55. package/lib/UseStrictPlugin.js +10 -3
  56. package/lib/WebpackError.js +6 -5
  57. package/lib/WebpackIsIncludedPlugin.js +6 -4
  58. package/lib/WebpackOptionsApply.js +1 -1
  59. package/lib/WebpackOptionsDefaulter.js +10 -3
  60. package/lib/asset/AssetGenerator.js +2 -1
  61. package/lib/asset/AssetParser.js +11 -6
  62. package/lib/asset/AssetSourceParser.js +8 -3
  63. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -0
  64. package/lib/cache/IdleFileCachePlugin.js +2 -1
  65. package/lib/cache/PackFileCacheStrategy.js +35 -14
  66. package/lib/config/browserslistTargetHandler.js +7 -7
  67. package/lib/config/defaults.js +43 -26
  68. package/lib/container/RemoteRuntimeModule.js +1 -1
  69. package/lib/css/CssLoadingRuntimeModule.js +30 -13
  70. package/lib/css/CssModulesPlugin.js +5 -2
  71. package/lib/css/CssParser.js +22 -0
  72. package/lib/dependencies/AMDDefineDependency.js +34 -4
  73. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +5 -0
  74. package/lib/dependencies/AMDRuntimeModules.js +2 -2
  75. package/lib/dependencies/CommonJsExportsParserPlugin.js +14 -4
  76. package/lib/dependencies/CommonJsImportsParserPlugin.js +169 -59
  77. package/lib/dependencies/CommonJsPlugin.js +13 -8
  78. package/lib/dependencies/CommonJsRequireContextDependency.js +2 -2
  79. package/lib/dependencies/ConstDependency.js +2 -2
  80. package/lib/dependencies/ContextDependency.js +7 -2
  81. package/lib/dependencies/CssImportDependency.js +1 -1
  82. package/lib/dependencies/CssLocalIdentifierDependency.js +5 -0
  83. package/lib/dependencies/CssUrlDependency.js +3 -3
  84. package/lib/dependencies/DllEntryDependency.js +5 -0
  85. package/lib/dependencies/DynamicExports.js +10 -6
  86. package/lib/dependencies/ExportsInfoDependency.js +14 -4
  87. package/lib/dependencies/HarmonyCompatibilityDependency.js +2 -1
  88. package/lib/dependencies/HarmonyDetectionParserPlugin.js +3 -1
  89. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +12 -5
  90. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +2 -0
  91. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +4 -4
  92. package/lib/dependencies/HarmonyExports.js +9 -5
  93. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +32 -17
  94. package/lib/dependencies/HarmonyImportSideEffectDependency.js +1 -2
  95. package/lib/dependencies/HarmonyImportSpecifierDependency.js +19 -9
  96. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -3
  97. package/lib/dependencies/ImportDependency.js +5 -3
  98. package/lib/dependencies/ImportEagerDependency.js +5 -3
  99. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +19 -0
  100. package/lib/dependencies/ImportMetaPlugin.js +31 -15
  101. package/lib/dependencies/ImportParserPlugin.js +62 -25
  102. package/lib/dependencies/ImportWeakDependency.js +5 -3
  103. package/lib/dependencies/ModuleDependency.js +1 -1
  104. package/lib/dependencies/ModuleDependencyTemplateAsId.js +2 -1
  105. package/lib/dependencies/ProvidedDependency.js +4 -1
  106. package/lib/dependencies/RequireContextDependencyParserPlugin.js +13 -5
  107. package/lib/dependencies/RequireEnsureDependenciesBlock.js +5 -2
  108. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +6 -1
  109. package/lib/dependencies/RequireHeaderDependency.js +4 -0
  110. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +26 -5
  111. package/lib/dependencies/RequireResolveHeaderDependency.js +9 -0
  112. package/lib/dependencies/SystemPlugin.js +17 -5
  113. package/lib/dependencies/SystemRuntimeModule.js +1 -1
  114. package/lib/dependencies/URLDependency.js +2 -2
  115. package/lib/dependencies/URLPlugin.js +9 -4
  116. package/lib/dependencies/WebAssemblyImportDependency.js +1 -1
  117. package/lib/dependencies/WorkerPlugin.js +59 -22
  118. package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -1
  119. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -1
  120. package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
  121. package/lib/ids/HashedModuleIdsPlugin.js +1 -1
  122. package/lib/ids/SyncModuleIdsPlugin.js +1 -0
  123. package/lib/javascript/BasicEvaluatedExpression.js +23 -15
  124. package/lib/javascript/CommonJsChunkFormatPlugin.js +6 -2
  125. package/lib/javascript/JavascriptParser.js +135 -63
  126. package/lib/javascript/JavascriptParserHelpers.js +37 -15
  127. package/lib/logging/runtime.js +1 -1
  128. package/lib/logging/truncateArgs.js +4 -0
  129. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +10 -6
  130. package/lib/node/RequireChunkLoadingRuntimeModule.js +10 -6
  131. package/lib/optimize/InnerGraph.js +1 -1
  132. package/lib/optimize/InnerGraphPlugin.js +2 -1
  133. package/lib/performance/SizeLimitsPlugin.js +7 -4
  134. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +4 -2
  135. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +3 -1
  136. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +6 -3
  137. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +4 -2
  138. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +4 -2
  139. package/lib/rules/BasicEffectRulePlugin.js +4 -0
  140. package/lib/rules/BasicMatcherRulePlugin.js +5 -0
  141. package/lib/rules/RuleSetCompiler.js +3 -3
  142. package/lib/rules/UseEffectRulePlugin.js +6 -4
  143. package/lib/runtime/AsyncModuleRuntimeModule.js +8 -5
  144. package/lib/runtime/AutoPublicPathRuntimeModule.js +4 -2
  145. package/lib/runtime/BaseUriRuntimeModule.js +3 -3
  146. package/lib/runtime/ChunkNameRuntimeModule.js +1 -1
  147. package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +5 -2
  148. package/lib/runtime/CompatRuntimeModule.js +7 -2
  149. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +5 -2
  150. package/lib/runtime/CreateScriptRuntimeModule.js +4 -2
  151. package/lib/runtime/CreateScriptUrlRuntimeModule.js +4 -2
  152. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +5 -2
  153. package/lib/runtime/EnsureChunkRuntimeModule.js +15 -4
  154. package/lib/runtime/GetChunkFilenameRuntimeModule.js +6 -10
  155. package/lib/runtime/GetFullHashRuntimeModule.js +4 -3
  156. package/lib/runtime/GetMainFilenameRuntimeModule.js +5 -2
  157. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +4 -2
  158. package/lib/runtime/GlobalRuntimeModule.js +1 -1
  159. package/lib/runtime/HasOwnPropertyRuntimeModule.js +5 -2
  160. package/lib/runtime/LoadScriptRuntimeModule.js +64 -48
  161. package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +5 -2
  162. package/lib/runtime/NonceRuntimeModule.js +1 -1
  163. package/lib/runtime/OnChunksLoadedRuntimeModule.js +4 -2
  164. package/lib/runtime/PublicPathRuntimeModule.js +4 -2
  165. package/lib/runtime/RelativeUrlRuntimeModule.js +5 -2
  166. package/lib/runtime/RuntimeIdRuntimeModule.js +6 -2
  167. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +9 -3
  168. package/lib/runtime/StartupEntrypointRuntimeModule.js +3 -2
  169. package/lib/runtime/SystemContextRuntimeModule.js +1 -1
  170. package/lib/serialization/ObjectMiddleware.js +6 -3
  171. package/lib/sharing/ConsumeSharedFallbackDependency.js +3 -0
  172. package/lib/sharing/ConsumeSharedRuntimeModule.js +14 -5
  173. package/lib/sharing/ProvideSharedDependency.js +11 -0
  174. package/lib/sharing/ProvideSharedModule.js +4 -0
  175. package/lib/sharing/ProvideSharedPlugin.js +22 -21
  176. package/lib/sharing/ShareRuntimeModule.js +12 -5
  177. package/lib/sharing/resolveMatchedConfigs.js +1 -1
  178. package/lib/sharing/utils.js +32 -5
  179. package/lib/util/AsyncQueue.js +4 -2
  180. package/lib/util/ParallelismFactorCalculator.js +10 -0
  181. package/lib/util/Semaphore.js +1 -1
  182. package/lib/util/createHash.js +30 -9
  183. package/lib/util/deprecation.js +10 -3
  184. package/lib/util/deterministicGrouping.js +50 -11
  185. package/lib/util/findGraphRoots.js +4 -2
  186. package/lib/util/memoize.js +3 -3
  187. package/lib/util/processAsyncTree.js +7 -1
  188. package/lib/util/registerExternalSerializer.js +1 -1
  189. package/lib/util/runtime.js +14 -1
  190. package/lib/util/smartGrouping.js +1 -1
  191. package/lib/validateSchema.js +6 -2
  192. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +6 -2
  193. package/lib/wasm-async/AsyncWebAssemblyParser.js +7 -3
  194. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +14 -7
  195. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +3 -1
  196. package/lib/wasm-sync/WebAssemblyGenerator.js +1 -0
  197. package/lib/wasm-sync/WebAssemblyParser.js +6 -2
  198. package/lib/web/JsonpChunkLoadingRuntimeModule.js +14 -4
  199. package/lib/webpack.js +11 -2
  200. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +15 -16
  201. package/module.d.ts +1 -0
  202. package/package.json +5 -4
  203. package/schemas/WebpackOptions.check.js +1 -1
  204. package/schemas/WebpackOptions.json +39 -5
  205. package/schemas/plugins/css/CssGeneratorOptions.json +1 -1
  206. package/schemas/plugins/css/CssParserOptions.json +1 -1
  207. package/types.d.ts +519 -222
package/README.md CHANGED
@@ -232,6 +232,7 @@ or are automatically applied via regex from your webpack configuration.
232
232
  | <a href="https://github.com/webpack-contrib/polymer-webpack-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/polymer.svg"></a> | ![polymer-npm] | ![polymer-size] | Process HTML & CSS with preprocessor of choice and `require()` Web Components like first-class modules |
233
233
  | <a href="https://github.com/TheLarkInn/angular2-template-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/angular-icon-1.svg"></a> | ![angular-npm] | ![angular-size] | Loads and compiles Angular 2 Components |
234
234
  | <a href="https://github.com/riot/webpack-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/riot.svg"></a> | ![riot-npm] | ![riot-size] | Riot official webpack loader |
235
+ | <a href="https://github.com/sveltejs/svelte-loader"><img width="48" height="48" src="https://worldvectorlogo.com/logos/svelte-1.svg"></a> | ![svelte-npm] | ![svelte-size] | Official Svelte loader |
235
236
 
236
237
  [vue-npm]: https://img.shields.io/npm/v/vue-loader.svg
237
238
  [vue-size]: https://packagephobia.com/badge?p=vue-loader
@@ -241,6 +242,8 @@ or are automatically applied via regex from your webpack configuration.
241
242
  [angular-size]: https://packagephobia.com/badge?p=angular2-template-loader
242
243
  [riot-npm]: https://img.shields.io/npm/v/riot-tag-loader.svg
243
244
  [riot-size]: https://packagephobia.com/badge?p=riot-tag-loader
245
+ [svelte-npm]: https://img.shields.io/npm/v/svelte-loader.svg
246
+ [svelte-size]: https://packagephobia.com/badge?p=svelte-loader
244
247
 
245
248
  ### Performance
246
249
 
@@ -714,5 +717,5 @@ src="https://static.monei.net/monei-logo.svg" height="30" alt="MONEI"></a>
714
717
  [builds2-url]: https://dev.azure.com/webpack/webpack/_build/latest?definitionId=3
715
718
  [licenses-url]: https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fwebpack%2Fwebpack?ref=badge_shield
716
719
  [licenses]: https://app.fossa.io/api/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fwebpack%2Fwebpack.svg?type=shield
717
- [cover]: https://img.shields.io/coveralls/webpack/webpack.svg
718
- [cover-url]: https://coveralls.io/r/webpack/webpack/
720
+ [cover]: https://codecov.io/gh/webpack/webpack/branch/master/graph/badge.svg?token=mDP3mQJNnn
721
+ [cover-url]: https://codecov.io/gh/webpack/webpack
package/lib/APIPlugin.js CHANGED
@@ -29,7 +29,7 @@ const GetFullHashRuntimeModule = require("./runtime/GetFullHashRuntimeModule");
29
29
  /**
30
30
  * @param {boolean} module true if ES module
31
31
  * @param {string} importMetaName `import.meta` name
32
- * @returns {Record<string, {expr: string, req: string[], type?: string, assign: boolean}>} replacements
32
+ * @returns {Record<string, {expr: string, req: string[] | null, type?: string, assign: boolean}>} replacements
33
33
  */
34
34
  function getReplacements(module, importMetaName) {
35
35
  return {
@@ -21,9 +21,9 @@ const makeSerializable = require("./util/makeSerializable");
21
21
 
22
22
  class AsyncDependenciesBlock extends DependenciesBlock {
23
23
  /**
24
- * @param {ChunkGroupOptions & { entryOptions?: EntryOptions }} groupOptions options for the group
25
- * @param {DependencyLocation=} loc the line of code
26
- * @param {string=} request the request
24
+ * @param {(ChunkGroupOptions & { entryOptions?: EntryOptions }) | null} groupOptions options for the group
25
+ * @param {(DependencyLocation | null)=} loc the line of code
26
+ * @param {(string | null)=} request the request
27
27
  */
28
28
  constructor(groupOptions, loc, request) {
29
29
  super();
@@ -42,7 +42,9 @@ const createModulesListMessage = (modules, moduleGraph) => {
42
42
 
43
43
  if (validReasons.length > 0) {
44
44
  message += `\n Used by ${validReasons.length} module(s), i. e.`;
45
- message += `\n ${validReasons[0].identifier()}`;
45
+ message += `\n ${
46
+ /** @type {Module[]} */ (validReasons)[0].identifier()
47
+ }`;
46
48
  }
47
49
  return message;
48
50
  })
package/lib/ChunkGraph.js CHANGED
@@ -188,7 +188,7 @@ class ChunkGraphModule {
188
188
  this.entryInChunks = undefined;
189
189
  /** @type {Set<Chunk> | undefined} */
190
190
  this.runtimeInChunks = undefined;
191
- /** @type {RuntimeSpecMap<ModuleHashInfo>} */
191
+ /** @type {RuntimeSpecMap<ModuleHashInfo> | undefined} */
192
192
  this.hashes = undefined;
193
193
  /** @type {string | number} */
194
194
  this.id = null;
@@ -1388,7 +1388,7 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
1388
1388
  */
1389
1389
  hasModuleHashes(module, runtime) {
1390
1390
  const cgm = this._getChunkGraphModule(module);
1391
- const hashes = cgm.hashes;
1391
+ const hashes = /** @type {RuntimeSpecMap<ModuleHashInfo>} */ (cgm.hashes);
1392
1392
  return hashes && hashes.has(runtime);
1393
1393
  }
1394
1394
 
@@ -1399,7 +1399,7 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
1399
1399
  */
1400
1400
  getModuleHash(module, runtime) {
1401
1401
  const cgm = this._getChunkGraphModule(module);
1402
- const hashes = cgm.hashes;
1402
+ const hashes = /** @type {RuntimeSpecMap<ModuleHashInfo>} */ (cgm.hashes);
1403
1403
  return this._getModuleHashInfo(module, hashes, runtime).hash;
1404
1404
  }
1405
1405
 
@@ -1410,7 +1410,7 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
1410
1410
  */
1411
1411
  getRenderedModuleHash(module, runtime) {
1412
1412
  const cgm = this._getChunkGraphModule(module);
1413
- const hashes = cgm.hashes;
1413
+ const hashes = /** @type {RuntimeSpecMap<ModuleHashInfo>} */ (cgm.hashes);
1414
1414
  return this._getModuleHashInfo(module, hashes, runtime).renderedHash;
1415
1415
  }
1416
1416
 
package/lib/ChunkGroup.js CHANGED
@@ -28,6 +28,7 @@ const {
28
28
  * @typedef {Object} RawChunkGroupOptions
29
29
  * @property {number=} preloadOrder
30
30
  * @property {number=} prefetchOrder
31
+ * @property {("low" | "high" | "auto")=} fetchPriority
31
32
  */
32
33
 
33
34
  /** @typedef {RawChunkGroupOptions & { name?: string }} ChunkGroupOptions */
@@ -108,9 +109,15 @@ class ChunkGroup {
108
109
  */
109
110
  addOptions(options) {
110
111
  for (const key of Object.keys(options)) {
111
- if (this.options[key] === undefined) {
112
- this.options[key] = options[key];
113
- } else if (this.options[key] !== options[key]) {
112
+ if (
113
+ this.options[/** @type {keyof ChunkGroupOptions} */ (key)] === undefined
114
+ ) {
115
+ this.options[key] =
116
+ options[/** @type {keyof ChunkGroupOptions} */ (key)];
117
+ } else if (
118
+ this.options[/** @type {keyof ChunkGroupOptions} */ (key)] !==
119
+ options[/** @type {keyof ChunkGroupOptions} */ (key)]
120
+ ) {
114
121
  if (key.endsWith("Order")) {
115
122
  this.options[key] = Math.max(this.options[key], options[key]);
116
123
  } else {
@@ -13,8 +13,11 @@ const {
13
13
  const RuntimeGlobals = require("./RuntimeGlobals");
14
14
  const ConstDependency = require("./dependencies/ConstDependency");
15
15
 
16
+ /** @typedef {import("estree").CallExpression} CallExpression */
16
17
  /** @typedef {import("./Compiler")} Compiler */
18
+ /** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
17
19
  /** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
20
+ /** @typedef {import("./javascript/JavascriptParser").Range} Range */
18
21
 
19
22
  const nestedWebpackIdentifierTag = Symbol("nested webpack identifier");
20
23
  const PLUGIN_NAME = "CompatibilityPlugin";
@@ -43,31 +46,41 @@ class CompatibilityPlugin {
43
46
  )
44
47
  return;
45
48
 
46
- parser.hooks.call.for("require").tap(PLUGIN_NAME, expr => {
47
- // support for browserify style require delegator: "require(o, !0)"
48
- if (expr.arguments.length !== 2) return;
49
- const second = parser.evaluateExpression(expr.arguments[1]);
50
- if (!second.isBoolean()) return;
51
- if (second.asBool() !== true) return;
52
- const dep = new ConstDependency("require", expr.callee.range);
53
- dep.loc = expr.loc;
54
- if (parser.state.current.dependencies.length > 0) {
55
- const last =
56
- parser.state.current.dependencies[
57
- parser.state.current.dependencies.length - 1
58
- ];
59
- if (
60
- last.critical &&
61
- last.options &&
62
- last.options.request === "." &&
63
- last.userRequest === "." &&
64
- last.options.recursive
65
- )
66
- parser.state.current.dependencies.pop();
49
+ parser.hooks.call.for("require").tap(
50
+ PLUGIN_NAME,
51
+ /**
52
+ * @param {CallExpression} expr call expression
53
+ * @returns {boolean | void} true when need to handle
54
+ */
55
+ expr => {
56
+ // support for browserify style require delegator: "require(o, !0)"
57
+ if (expr.arguments.length !== 2) return;
58
+ const second = parser.evaluateExpression(expr.arguments[1]);
59
+ if (!second.isBoolean()) return;
60
+ if (second.asBool() !== true) return;
61
+ const dep = new ConstDependency(
62
+ "require",
63
+ /** @type {Range} */ (expr.callee.range)
64
+ );
65
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
66
+ if (parser.state.current.dependencies.length > 0) {
67
+ const last =
68
+ parser.state.current.dependencies[
69
+ parser.state.current.dependencies.length - 1
70
+ ];
71
+ if (
72
+ last.critical &&
73
+ last.options &&
74
+ last.options.request === "." &&
75
+ last.userRequest === "." &&
76
+ last.options.recursive
77
+ )
78
+ parser.state.current.dependencies.pop();
79
+ }
80
+ parser.state.module.addPresentationalDependency(dep);
81
+ return true;
67
82
  }
68
- parser.state.module.addPresentationalDependency(dep);
69
- return true;
70
- });
83
+ );
71
84
  });
72
85
 
73
86
  /**
@@ -82,7 +95,9 @@ class CompatibilityPlugin {
82
95
  statement.id &&
83
96
  statement.id.name === RuntimeGlobals.require
84
97
  ) {
85
- const newName = `__nested_webpack_require_${statement.range[0]}__`;
98
+ const newName = `__nested_webpack_require_${
99
+ /** @type {Range} */ (statement.range)[0]
100
+ }__`;
86
101
  parser.tagVariable(
87
102
  statement.id.name,
88
103
  nestedWebpackIdentifierTag,
@@ -101,7 +116,9 @@ class CompatibilityPlugin {
101
116
  parser.hooks.pattern
102
117
  .for(RuntimeGlobals.require)
103
118
  .tap(PLUGIN_NAME, pattern => {
104
- const newName = `__nested_webpack_require_${pattern.range[0]}__`;
119
+ const newName = `__nested_webpack_require_${
120
+ /** @type {Range} */ (pattern.range)[0]
121
+ }__`;
105
122
  parser.tagVariable(pattern.name, nestedWebpackIdentifierTag, {
106
123
  name: newName,
107
124
  declaration: {
@@ -135,8 +152,11 @@ class CompatibilityPlugin {
135
152
  parser.state.module.addPresentationalDependency(dep);
136
153
  declaration.updated = true;
137
154
  }
138
- const dep = new ConstDependency(name, expr.range);
139
- dep.loc = expr.loc;
155
+ const dep = new ConstDependency(
156
+ name,
157
+ /** @type {Range} */ (expr.range)
158
+ );
159
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
140
160
  parser.state.module.addPresentationalDependency(dep);
141
161
  return true;
142
162
  });
@@ -145,11 +165,11 @@ class CompatibilityPlugin {
145
165
  parser.hooks.program.tap(PLUGIN_NAME, (program, comments) => {
146
166
  if (comments.length === 0) return;
147
167
  const c = comments[0];
148
- if (c.type === "Line" && c.range[0] === 0) {
168
+ if (c.type === "Line" && /** @type {Range} */ (c.range)[0] === 0) {
149
169
  if (parser.state.source.slice(0, 2).toString() !== "#!") return;
150
170
  // this is a hashbang comment
151
171
  const dep = new ConstDependency("//", 0);
152
- dep.loc = c.loc;
172
+ dep.loc = /** @type {DependencyLocation} */ (c.loc);
153
173
  parser.state.module.addPresentationalDependency(dep);
154
174
  }
155
175
  });
@@ -3208,6 +3208,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3208
3208
  const { chunkGraph, moduleGraph, dependencyTemplates, runtimeTemplate } =
3209
3209
  this;
3210
3210
  const results = this.codeGenerationResults;
3211
+ /** @type {WebpackError[]} */
3211
3212
  const errors = [];
3212
3213
  /** @type {Set<Module> | undefined} */
3213
3214
  let notCodeGeneratedModules = undefined;
@@ -3303,7 +3304,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3303
3304
  * @param {RuntimeTemplate} runtimeTemplate runtimeTemplate
3304
3305
  * @param {WebpackError[]} errors errors
3305
3306
  * @param {CodeGenerationResults} results results
3306
- * @param {function(WebpackError=, boolean=): void} callback callback
3307
+ * @param {function((WebpackError | null)=, boolean=): void} callback callback
3307
3308
  */
3308
3309
  _codeGenerationModule(
3309
3310
  module,
package/lib/Compiler.js CHANGED
@@ -1073,7 +1073,9 @@ ${other}`);
1073
1073
  childCompiler.root = this.root;
1074
1074
  if (Array.isArray(plugins)) {
1075
1075
  for (const plugin of plugins) {
1076
- plugin.apply(childCompiler);
1076
+ if (plugin) {
1077
+ plugin.apply(childCompiler);
1078
+ }
1077
1079
  }
1078
1080
  }
1079
1081
  for (const name in this.hooks) {
@@ -108,7 +108,7 @@ class ConcatenationScope {
108
108
  module,
109
109
  { ids = undefined, call = false, directImport = false, asiSafe = false }
110
110
  ) {
111
- const info = this._modulesMap.get(module);
111
+ const info = /** @type {ModuleInfo} */ (this._modulesMap.get(module));
112
112
  const callFlag = call ? "_call" : "";
113
113
  const directImportFlag = directImport ? "_directImport" : "";
114
114
  const asiSafeFlag = asiSafe
@@ -133,7 +133,7 @@ class ConcatenationScope {
133
133
 
134
134
  /**
135
135
  * @param {string} name the identifier
136
- * @returns {ModuleReferenceOptions & { index: number }} parsed options and index
136
+ * @returns {ModuleReferenceOptions & { index: number } | null} parsed options and index
137
137
  */
138
138
  static matchModuleReference(name) {
139
139
  const match = MODULE_REFERENCE_REGEXP.exec(name);
@@ -14,6 +14,11 @@ const { mergeRuntime } = require("./util/runtime");
14
14
  /** @typedef {import("./Generator").GenerateContext} GenerateContext */
15
15
  /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
16
16
 
17
+ /**
18
+ * @param {string} condition condition
19
+ * @param {string | Source} source source
20
+ * @returns {string | Source} wrapped source
21
+ */
17
22
  const wrapInCondition = (condition, source) => {
18
23
  if (typeof source === "string") {
19
24
  return Template.asString([
@@ -33,13 +38,14 @@ const wrapInCondition = (condition, source) => {
33
38
 
34
39
  /**
35
40
  * @typedef {GenerateContext} Context
41
+ * @extends {InitFragment<Context>}
36
42
  */
37
43
  class ConditionalInitFragment extends InitFragment {
38
44
  /**
39
45
  * @param {string|Source} content the source code that will be included as initialization code
40
46
  * @param {number} stage category of initialization code (contribute to order)
41
47
  * @param {number} position position in the category (contribute to order)
42
- * @param {string} key unique key to avoid emitting the same initialization code twice
48
+ * @param {string | undefined} key unique key to avoid emitting the same initialization code twice
43
49
  * @param {RuntimeSpec | boolean} runtimeCondition in which runtime this fragment should be executed
44
50
  * @param {string|Source=} endContent the source code that will be included at the end of the module
45
51
  */
@@ -89,6 +95,10 @@ class ConditionalInitFragment extends InitFragment {
89
95
  return wrapInCondition(expr, this.endContent);
90
96
  }
91
97
 
98
+ /**
99
+ * @param {ConditionalInitFragment} other fragment to merge with
100
+ * @returns {ConditionalInitFragment} merged fragment
101
+ */
92
102
  merge(other) {
93
103
  if (this.runtimeCondition === true) return this;
94
104
  if (other.runtimeCondition === true) return other;
@@ -15,9 +15,14 @@ const ConstDependency = require("./dependencies/ConstDependency");
15
15
  const { evaluateToString } = require("./javascript/JavascriptParserHelpers");
16
16
  const { parseResource } = require("./util/identifier");
17
17
 
18
- /** @typedef {import("estree").Expression} ExpressionNode */
19
- /** @typedef {import("estree").Super} SuperNode */
18
+ /** @typedef {import("estree").Expression} Expression */
19
+ /** @typedef {import("estree").SourceLocation} SourceLocation */
20
+ /** @typedef {import("estree").Statement} Statement */
21
+ /** @typedef {import("estree").Super} Super */
20
22
  /** @typedef {import("./Compiler")} Compiler */
23
+ /** @typedef {import("./javascript/BasicEvaluatedExpression")} BasicEvaluatedExpression */
24
+ /** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
25
+ /** @typedef {import("./javascript/JavascriptParser").Range} Range */
21
26
 
22
27
  const collectDeclaration = (declarations, pattern) => {
23
28
  const stack = [pattern];
@@ -136,6 +141,9 @@ class ConstPlugin {
136
141
  new CachedConstDependency.Template()
137
142
  );
138
143
 
144
+ /**
145
+ * @param {JavascriptParser} parser the parser
146
+ */
139
147
  const handler = parser => {
140
148
  parser.hooks.statementIf.tap(PLUGIN_NAME, statement => {
141
149
  if (parser.scope.isAsmJs) return;
@@ -143,8 +151,11 @@ class ConstPlugin {
143
151
  const bool = param.asBool();
144
152
  if (typeof bool === "boolean") {
145
153
  if (!param.couldHaveSideEffects()) {
146
- const dep = new ConstDependency(`${bool}`, param.range);
147
- dep.loc = statement.loc;
154
+ const dep = new ConstDependency(
155
+ `${bool}`,
156
+ /** @type {Range} */ (param.range)
157
+ );
158
+ dep.loc = /** @type {SourceLocation} */ (statement.loc);
148
159
  parser.state.module.addPresentationalDependency(dep);
149
160
  } else {
150
161
  parser.walkExpression(statement.test);
@@ -200,9 +211,9 @@ class ConstPlugin {
200
211
  }
201
212
  const dep = new ConstDependency(
202
213
  replacement,
203
- branchToRemove.range
214
+ /** @type {Range} */ (branchToRemove.range)
204
215
  );
205
- dep.loc = branchToRemove.loc;
216
+ dep.loc = /** @type {SourceLocation} */ (branchToRemove.loc);
206
217
  parser.state.module.addPresentationalDependency(dep);
207
218
  }
208
219
  return bool;
@@ -216,8 +227,11 @@ class ConstPlugin {
216
227
  const bool = param.asBool();
217
228
  if (typeof bool === "boolean") {
218
229
  if (!param.couldHaveSideEffects()) {
219
- const dep = new ConstDependency(` ${bool}`, param.range);
220
- dep.loc = expression.loc;
230
+ const dep = new ConstDependency(
231
+ ` ${bool}`,
232
+ /** @type {Range} */ (param.range)
233
+ );
234
+ dep.loc = /** @type {SourceLocation} */ (expression.loc);
221
235
  parser.state.module.addPresentationalDependency(dep);
222
236
  } else {
223
237
  parser.walkExpression(expression.test);
@@ -236,8 +250,11 @@ class ConstPlugin {
236
250
  const branchToRemove = bool
237
251
  ? expression.alternate
238
252
  : expression.consequent;
239
- const dep = new ConstDependency("0", branchToRemove.range);
240
- dep.loc = branchToRemove.loc;
253
+ const dep = new ConstDependency(
254
+ "0",
255
+ /** @type {Range} */ (branchToRemove.range)
256
+ );
257
+ dep.loc = /** @type {SourceLocation} */ (branchToRemove.loc);
241
258
  parser.state.module.addPresentationalDependency(dep);
242
259
  return bool;
243
260
  }
@@ -313,8 +330,11 @@ class ConstPlugin {
313
330
  //
314
331
  // returnfalse&&'foo'
315
332
  //
316
- const dep = new ConstDependency(` ${bool}`, param.range);
317
- dep.loc = expression.loc;
333
+ const dep = new ConstDependency(
334
+ ` ${bool}`,
335
+ /** @type {Range} */ (param.range)
336
+ );
337
+ dep.loc = /** @type {SourceLocation} */ (expression.loc);
318
338
  parser.state.module.addPresentationalDependency(dep);
319
339
  } else {
320
340
  parser.walkExpression(expression.left);
@@ -322,9 +342,9 @@ class ConstPlugin {
322
342
  if (!keepRight) {
323
343
  const dep = new ConstDependency(
324
344
  "0",
325
- expression.right.range
345
+ /** @type {Range} */ (expression.right.range)
326
346
  );
327
- dep.loc = expression.loc;
347
+ dep.loc = /** @type {SourceLocation} */ (expression.loc);
328
348
  parser.state.module.addPresentationalDependency(dep);
329
349
  }
330
350
  return keepRight;
@@ -363,15 +383,18 @@ class ConstPlugin {
363
383
  //
364
384
  // returnnull??'foo'
365
385
  //
366
- const dep = new ConstDependency(" null", param.range);
367
- dep.loc = expression.loc;
386
+ const dep = new ConstDependency(
387
+ " null",
388
+ /** @type {Range} */ (param.range)
389
+ );
390
+ dep.loc = /** @type {SourceLocation} */ (expression.loc);
368
391
  parser.state.module.addPresentationalDependency(dep);
369
392
  } else {
370
393
  const dep = new ConstDependency(
371
394
  "0",
372
- expression.right.range
395
+ /** @type {Range} */ (expression.right.range)
373
396
  );
374
- dep.loc = expression.loc;
397
+ dep.loc = /** @type {SourceLocation} */ (expression.loc);
375
398
  parser.state.module.addPresentationalDependency(dep);
376
399
  parser.walkExpression(expression.left);
377
400
  }
@@ -382,9 +405,9 @@ class ConstPlugin {
382
405
  }
383
406
  );
384
407
  parser.hooks.optionalChaining.tap(PLUGIN_NAME, expr => {
385
- /** @type {ExpressionNode[]} */
408
+ /** @type {Expression[]} */
386
409
  const optionalExpressionsStack = [];
387
- /** @type {ExpressionNode|SuperNode} */
410
+ /** @type {Expression | Super} */
388
411
  let next = expr.expression;
389
412
 
390
413
  while (
@@ -395,7 +418,7 @@ class ConstPlugin {
395
418
  if (next.optional) {
396
419
  // SuperNode can not be optional
397
420
  optionalExpressionsStack.push(
398
- /** @type {ExpressionNode} */ (next.object)
421
+ /** @type {Expression} */ (next.object)
399
422
  );
400
423
  }
401
424
  next = next.object;
@@ -403,7 +426,7 @@ class ConstPlugin {
403
426
  if (next.optional) {
404
427
  // SuperNode can not be optional
405
428
  optionalExpressionsStack.push(
406
- /** @type {ExpressionNode} */ (next.callee)
429
+ /** @type {Expression} */ (next.callee)
407
430
  );
408
431
  }
409
432
  next = next.callee;
@@ -412,7 +435,9 @@ class ConstPlugin {
412
435
 
413
436
  while (optionalExpressionsStack.length) {
414
437
  const expression = optionalExpressionsStack.pop();
415
- const evaluated = parser.evaluateExpression(expression);
438
+ const evaluated = parser.evaluateExpression(
439
+ /** @type {Expression} */ (expression)
440
+ );
416
441
 
417
442
  if (evaluated.asNullish()) {
418
443
  // ------------------------------------------
@@ -427,8 +452,11 @@ class ConstPlugin {
427
452
  //
428
453
  // ------------------------------------------
429
454
  //
430
- const dep = new ConstDependency(" undefined", expr.range);
431
- dep.loc = expr.loc;
455
+ const dep = new ConstDependency(
456
+ " undefined",
457
+ /** @type {Range} */ (expr.range)
458
+ );
459
+ dep.loc = /** @type {SourceLocation} */ (expr.loc);
432
460
  parser.state.module.addPresentationalDependency(dep);
433
461
  return true;
434
462
  }
@@ -452,10 +480,10 @@ class ConstPlugin {
452
480
  JSON.stringify(
453
481
  cachedParseResource(parser.state.module.resource).query
454
482
  ),
455
- expr.range,
483
+ /** @type {Range} */ (expr.range),
456
484
  "__resourceQuery"
457
485
  );
458
- dep.loc = expr.loc;
486
+ dep.loc = /** @type {SourceLocation} */ (expr.loc);
459
487
  parser.state.module.addPresentationalDependency(dep);
460
488
  return true;
461
489
  });
@@ -478,10 +506,10 @@ class ConstPlugin {
478
506
  JSON.stringify(
479
507
  cachedParseResource(parser.state.module.resource).fragment
480
508
  ),
481
- expr.range,
509
+ /** @type {Range} */ (expr.range),
482
510
  "__resourceFragment"
483
511
  );
484
- dep.loc = expr.loc;
512
+ dep.loc = /** @type {SourceLocation} */ (expr.loc);
485
513
  parser.state.module.addPresentationalDependency(dep);
486
514
  return true;
487
515
  });
@@ -63,7 +63,7 @@ const makeSerializable = require("./util/makeSerializable");
63
63
  * @property {RawChunkGroupOptions=} groupOptions
64
64
  * @property {string=} typePrefix
65
65
  * @property {string=} category
66
- * @property {string[][]=} referencedExports exports referenced from modules (won't be mangled)
66
+ * @property {(string[][] | null)=} referencedExports exports referenced from modules (won't be mangled)
67
67
  * @property {string=} layer
68
68
  */
69
69
 
@@ -231,6 +231,9 @@ class ContextModule extends Module {
231
231
  } else if (this.options.namespaceObject) {
232
232
  identifier += "|namespace object";
233
233
  }
234
+ if (this.layer) {
235
+ identifier += `|layer: ${this.layer}`;
236
+ }
234
237
 
235
238
  return identifier;
236
239
  }
@@ -8,7 +8,15 @@
8
8
  const ContextElementDependency = require("./dependencies/ContextElementDependency");
9
9
  const { join } = require("./util/fs");
10
10
 
11
+ /** @typedef {import("./Compiler")} Compiler */
12
+
11
13
  class ContextReplacementPlugin {
14
+ /**
15
+ * @param {RegExp} resourceRegExp A regular expression that determines which files will be selected
16
+ * @param {TODO=} newContentResource A new resource to replace the match
17
+ * @param {TODO=} newContentRecursive If true, all subdirectories are searched for matches
18
+ * @param {TODO=} newContentRegExp A regular expression that determines which files will be selected
19
+ */
12
20
  constructor(
13
21
  resourceRegExp,
14
22
  newContentResource,
@@ -49,6 +57,11 @@ class ContextReplacementPlugin {
49
57
  }
50
58
  }
51
59
 
60
+ /**
61
+ * Apply the plugin
62
+ * @param {Compiler} compiler the compiler instance
63
+ * @returns {void}
64
+ */
52
65
  apply(compiler) {
53
66
  const resourceRegExp = this.resourceRegExp;
54
67
  const newContentCallback = this.newContentCallback;
@@ -42,6 +42,13 @@ const RUNTIME_REQUIREMENTS = new Set([
42
42
  ]);
43
43
 
44
44
  class DelegatedModule extends Module {
45
+ /**
46
+ * @param {string} sourceRequest source request
47
+ * @param {TODO} data data
48
+ * @param {"require" | "object"} type type
49
+ * @param {string} userRequest user request
50
+ * @param {string | Module} originalRequest original request
51
+ */
45
52
  constructor(sourceRequest, data, type, userRequest, originalRequest) {
46
53
  super(JAVASCRIPT_MODULE_TYPE_DYNAMIC, null);
47
54
 
@@ -51,7 +58,7 @@ class DelegatedModule extends Module {
51
58
  this.delegationType = type;
52
59
  this.userRequest = userRequest;
53
60
  this.originalRequest = originalRequest;
54
- /** @type {ManifestModuleData} */
61
+ /** @type {ManifestModuleData | undefined} */
55
62
  this.delegateData = data;
56
63
 
57
64
  // Build info
@@ -110,7 +117,8 @@ class DelegatedModule extends Module {
110
117
  * @returns {void}
111
118
  */
112
119
  build(options, compilation, resolver, fs, callback) {
113
- this.buildMeta = { ...this.delegateData.buildMeta };
120
+ const delegateData = /** @type {ManifestModuleData} */ (this.delegateData);
121
+ this.buildMeta = { ...delegateData.buildMeta };
114
122
  this.buildInfo = {};
115
123
  this.dependencies.length = 0;
116
124
  this.delegatedSourceDependency = new DelegatedSourceDependency(
@@ -118,7 +126,7 @@ class DelegatedModule extends Module {
118
126
  );
119
127
  this.addDependency(this.delegatedSourceDependency);
120
128
  this.addDependency(
121
- new StaticExportsDependency(this.delegateData.exports || true, false)
129
+ new StaticExportsDependency(delegateData.exports || true, false)
122
130
  );
123
131
  callback();
124
132
  }
@@ -202,6 +210,10 @@ class DelegatedModule extends Module {
202
210
  super.serialize(context);
203
211
  }
204
212
 
213
+ /**
214
+ * @param {ObjectDeserializerContext} context context\
215
+ * @returns {DelegatedModule} DelegatedModule
216
+ */
205
217
  static deserialize(context) {
206
218
  const { read } = context;
207
219
  const obj = new DelegatedModule(