webpack 5.85.0 → 5.88.1

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 (249) hide show
  1. package/README.md +5 -2
  2. package/lib/APIPlugin.js +150 -99
  3. package/lib/AsyncDependenciesBlock.js +3 -3
  4. package/lib/BannerPlugin.js +2 -1
  5. package/lib/CaseSensitiveModulesWarning.js +3 -1
  6. package/lib/Chunk.js +35 -17
  7. package/lib/ChunkGraph.js +4 -4
  8. package/lib/ChunkGroup.js +20 -9
  9. package/lib/CompatibilityPlugin.js +50 -30
  10. package/lib/Compilation.js +2 -1
  11. package/lib/Compiler.js +10 -9
  12. package/lib/ConcatenationScope.js +2 -2
  13. package/lib/ConditionalInitFragment.js +11 -1
  14. package/lib/ConstPlugin.js +73 -32
  15. package/lib/ContextModule.js +8 -3
  16. package/lib/ContextModuleFactory.js +1 -0
  17. package/lib/ContextReplacementPlugin.js +13 -0
  18. package/lib/DelegatedModule.js +15 -3
  19. package/lib/DelegatedModuleFactoryPlugin.js +6 -0
  20. package/lib/DependenciesBlock.js +1 -1
  21. package/lib/Dependency.js +11 -5
  22. package/lib/DependencyTemplates.js +1 -1
  23. package/lib/DllEntryPlugin.js +11 -1
  24. package/lib/DllModule.js +6 -0
  25. package/lib/DllReferencePlugin.js +13 -1
  26. package/lib/Entrypoint.js +1 -1
  27. package/lib/ErrorHelpers.js +1 -0
  28. package/lib/EvalSourceMapDevToolPlugin.js +6 -1
  29. package/lib/ExportsInfo.js +22 -4
  30. package/lib/ExportsInfoApiPlugin.js +14 -5
  31. package/lib/ExternalModule.js +20 -8
  32. package/lib/FileSystemInfo.js +52 -24
  33. package/lib/FlagAllModulesAsUsedPlugin.js +6 -1
  34. package/lib/FlagDependencyUsagePlugin.js +3 -1
  35. package/lib/FlagEntryExportAsUsedPlugin.js +4 -0
  36. package/lib/Generator.js +7 -0
  37. package/lib/HotModuleReplacementPlugin.js +8 -0
  38. package/lib/InitFragment.js +28 -5
  39. package/lib/JavascriptMetaInfoPlugin.js +11 -6
  40. package/lib/LibManifestPlugin.js +20 -4
  41. package/lib/Module.js +14 -3
  42. package/lib/ModuleDependencyError.js +4 -2
  43. package/lib/ModuleDependencyWarning.js +4 -2
  44. package/lib/ModuleGraph.js +31 -24
  45. package/lib/ModuleGraphConnection.js +19 -6
  46. package/lib/ModuleInfoHeaderPlugin.js +9 -2
  47. package/lib/ModuleNotFoundError.js +5 -2
  48. package/lib/ModuleProfile.js +1 -0
  49. package/lib/ModuleRestoreError.js +2 -0
  50. package/lib/ModuleStoreError.js +2 -1
  51. package/lib/ModuleTypeConstants.js +7 -0
  52. package/lib/MultiWatching.js +4 -0
  53. package/lib/NodeStuffPlugin.js +32 -6
  54. package/lib/ProgressPlugin.js +71 -15
  55. package/lib/ProvidePlugin.js +13 -4
  56. package/lib/RawModule.js +3 -1
  57. package/lib/RequireJsStuffPlugin.js +7 -0
  58. package/lib/RuntimeGlobals.js +5 -0
  59. package/lib/RuntimeModule.js +3 -3
  60. package/lib/RuntimePlugin.js +6 -3
  61. package/lib/RuntimeTemplate.js +22 -4
  62. package/lib/SourceMapDevToolModuleOptionsPlugin.js +4 -0
  63. package/lib/SourceMapDevToolPlugin.js +7 -2
  64. package/lib/UseStrictPlugin.js +10 -3
  65. package/lib/Watching.js +62 -25
  66. package/lib/WebpackError.js +6 -5
  67. package/lib/WebpackIsIncludedPlugin.js +6 -4
  68. package/lib/WebpackOptionsApply.js +4 -2
  69. package/lib/WebpackOptionsDefaulter.js +10 -3
  70. package/lib/asset/AssetGenerator.js +2 -1
  71. package/lib/asset/AssetParser.js +11 -6
  72. package/lib/asset/AssetSourceParser.js +8 -3
  73. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -0
  74. package/lib/buildChunkGraph.js +37 -21
  75. package/lib/cache/IdleFileCachePlugin.js +2 -1
  76. package/lib/cache/PackFileCacheStrategy.js +53 -22
  77. package/lib/config/browserslistTargetHandler.js +7 -7
  78. package/lib/config/defaults.js +43 -26
  79. package/lib/container/RemoteRuntimeModule.js +1 -1
  80. package/lib/css/CssExportsGenerator.js +9 -0
  81. package/lib/css/CssGenerator.js +1 -1
  82. package/lib/css/CssLoadingRuntimeModule.js +43 -19
  83. package/lib/css/CssModulesPlugin.js +42 -14
  84. package/lib/css/CssParser.js +22 -0
  85. package/lib/dependencies/AMDDefineDependency.js +34 -4
  86. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +5 -0
  87. package/lib/dependencies/AMDRuntimeModules.js +2 -2
  88. package/lib/dependencies/CommonJsExportsParserPlugin.js +14 -4
  89. package/lib/dependencies/CommonJsImportsParserPlugin.js +169 -59
  90. package/lib/dependencies/CommonJsPlugin.js +13 -8
  91. package/lib/dependencies/CommonJsRequireContextDependency.js +2 -2
  92. package/lib/dependencies/ConstDependency.js +2 -2
  93. package/lib/dependencies/ContextDependency.js +7 -2
  94. package/lib/dependencies/CssImportDependency.js +1 -1
  95. package/lib/dependencies/CssLocalIdentifierDependency.js +5 -0
  96. package/lib/dependencies/CssUrlDependency.js +3 -3
  97. package/lib/dependencies/DllEntryDependency.js +5 -0
  98. package/lib/dependencies/DynamicExports.js +10 -6
  99. package/lib/dependencies/ExportsInfoDependency.js +14 -4
  100. package/lib/dependencies/HarmonyCompatibilityDependency.js +2 -1
  101. package/lib/dependencies/HarmonyDetectionParserPlugin.js +3 -1
  102. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +12 -5
  103. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +2 -0
  104. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +4 -4
  105. package/lib/dependencies/HarmonyExports.js +9 -5
  106. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +40 -27
  107. package/lib/dependencies/HarmonyImportSideEffectDependency.js +1 -2
  108. package/lib/dependencies/HarmonyImportSpecifierDependency.js +31 -21
  109. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -3
  110. package/lib/dependencies/ImportDependency.js +5 -3
  111. package/lib/dependencies/ImportEagerDependency.js +5 -3
  112. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +19 -0
  113. package/lib/dependencies/ImportMetaPlugin.js +31 -15
  114. package/lib/dependencies/ImportParserPlugin.js +62 -25
  115. package/lib/dependencies/ImportWeakDependency.js +5 -3
  116. package/lib/dependencies/JsonExportsDependency.js +1 -1
  117. package/lib/dependencies/ModuleDependency.js +1 -1
  118. package/lib/dependencies/ModuleDependencyTemplateAsId.js +2 -1
  119. package/lib/dependencies/ProvidedDependency.js +4 -1
  120. package/lib/dependencies/RequireContextDependencyParserPlugin.js +13 -5
  121. package/lib/dependencies/RequireEnsureDependenciesBlock.js +5 -2
  122. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +6 -1
  123. package/lib/dependencies/RequireHeaderDependency.js +4 -0
  124. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +26 -5
  125. package/lib/dependencies/RequireResolveHeaderDependency.js +9 -0
  126. package/lib/dependencies/SystemPlugin.js +17 -5
  127. package/lib/dependencies/SystemRuntimeModule.js +1 -1
  128. package/lib/dependencies/URLDependency.js +2 -2
  129. package/lib/dependencies/URLPlugin.js +9 -4
  130. package/lib/dependencies/WebAssemblyImportDependency.js +1 -1
  131. package/lib/dependencies/WorkerPlugin.js +59 -22
  132. package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -1
  133. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -1
  134. package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
  135. package/lib/ids/HashedModuleIdsPlugin.js +1 -1
  136. package/lib/ids/SyncModuleIdsPlugin.js +1 -0
  137. package/lib/javascript/BasicEvaluatedExpression.js +28 -19
  138. package/lib/javascript/CommonJsChunkFormatPlugin.js +6 -2
  139. package/lib/javascript/JavascriptModulesPlugin.js +25 -5
  140. package/lib/javascript/JavascriptParser.js +157 -85
  141. package/lib/javascript/JavascriptParserHelpers.js +37 -15
  142. package/lib/json/JsonData.js +2 -2
  143. package/lib/json/JsonParser.js +25 -12
  144. package/lib/library/AmdLibraryPlugin.js +2 -2
  145. package/lib/library/AssignLibraryPlugin.js +13 -1
  146. package/lib/library/EnableLibraryPlugin.js +4 -0
  147. package/lib/library/SystemLibraryPlugin.js +1 -1
  148. package/lib/library/UmdLibraryPlugin.js +20 -2
  149. package/lib/logging/runtime.js +1 -1
  150. package/lib/logging/truncateArgs.js +4 -0
  151. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +10 -6
  152. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +2 -1
  153. package/lib/node/RequireChunkLoadingRuntimeModule.js +10 -6
  154. package/lib/optimize/AggressiveMergingPlugin.js +8 -0
  155. package/lib/optimize/AggressiveSplittingPlugin.js +9 -2
  156. package/lib/optimize/EnsureChunkConditionsPlugin.js +3 -0
  157. package/lib/optimize/FlagIncludedChunksPlugin.js +11 -5
  158. package/lib/optimize/InnerGraph.js +5 -5
  159. package/lib/optimize/InnerGraphPlugin.js +2 -1
  160. package/lib/optimize/LimitChunkCountPlugin.js +29 -4
  161. package/lib/optimize/MangleExportsPlugin.js +1 -1
  162. package/lib/optimize/MinMaxSizeWarning.js +5 -0
  163. package/lib/optimize/ModuleConcatenationPlugin.js +59 -2
  164. package/lib/optimize/RealContentHashPlugin.js +80 -30
  165. package/lib/optimize/RemoveParentModulesPlugin.js +6 -0
  166. package/lib/optimize/RuntimeChunkPlugin.js +9 -1
  167. package/lib/optimize/SideEffectsFlagPlugin.js +10 -1
  168. package/lib/optimize/SplitChunksPlugin.js +71 -31
  169. package/lib/performance/SizeLimitsPlugin.js +7 -4
  170. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +4 -2
  171. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +3 -1
  172. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +6 -3
  173. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +4 -2
  174. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +4 -2
  175. package/lib/rules/BasicEffectRulePlugin.js +4 -0
  176. package/lib/rules/BasicMatcherRulePlugin.js +5 -0
  177. package/lib/rules/RuleSetCompiler.js +3 -3
  178. package/lib/rules/UseEffectRulePlugin.js +6 -4
  179. package/lib/runtime/AsyncModuleRuntimeModule.js +8 -5
  180. package/lib/runtime/AutoPublicPathRuntimeModule.js +4 -2
  181. package/lib/runtime/BaseUriRuntimeModule.js +3 -3
  182. package/lib/runtime/ChunkNameRuntimeModule.js +1 -1
  183. package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +5 -2
  184. package/lib/runtime/CompatRuntimeModule.js +7 -2
  185. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +5 -2
  186. package/lib/runtime/CreateScriptRuntimeModule.js +4 -2
  187. package/lib/runtime/CreateScriptUrlRuntimeModule.js +4 -2
  188. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +5 -2
  189. package/lib/runtime/EnsureChunkRuntimeModule.js +15 -4
  190. package/lib/runtime/GetChunkFilenameRuntimeModule.js +6 -10
  191. package/lib/runtime/GetFullHashRuntimeModule.js +4 -3
  192. package/lib/runtime/GetMainFilenameRuntimeModule.js +5 -2
  193. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +4 -2
  194. package/lib/runtime/GlobalRuntimeModule.js +1 -1
  195. package/lib/runtime/HasOwnPropertyRuntimeModule.js +5 -2
  196. package/lib/runtime/LoadScriptRuntimeModule.js +64 -48
  197. package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +5 -2
  198. package/lib/runtime/NonceRuntimeModule.js +1 -1
  199. package/lib/runtime/OnChunksLoadedRuntimeModule.js +4 -2
  200. package/lib/runtime/PublicPathRuntimeModule.js +4 -2
  201. package/lib/runtime/RelativeUrlRuntimeModule.js +5 -2
  202. package/lib/runtime/RuntimeIdRuntimeModule.js +6 -2
  203. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +9 -3
  204. package/lib/runtime/StartupEntrypointRuntimeModule.js +3 -2
  205. package/lib/runtime/SystemContextRuntimeModule.js +1 -1
  206. package/lib/serialization/BinaryMiddleware.js +143 -1
  207. package/lib/serialization/ErrorObjectSerializer.js +3 -0
  208. package/lib/serialization/ObjectMiddleware.js +9 -3
  209. package/lib/serialization/types.js +1 -1
  210. package/lib/sharing/ConsumeSharedFallbackDependency.js +3 -0
  211. package/lib/sharing/ConsumeSharedRuntimeModule.js +14 -5
  212. package/lib/sharing/ProvideSharedDependency.js +11 -0
  213. package/lib/sharing/ProvideSharedModule.js +4 -0
  214. package/lib/sharing/ProvideSharedPlugin.js +22 -21
  215. package/lib/sharing/ShareRuntimeModule.js +12 -5
  216. package/lib/sharing/resolveMatchedConfigs.js +1 -1
  217. package/lib/sharing/utils.js +32 -5
  218. package/lib/util/AsyncQueue.js +4 -2
  219. package/lib/util/ParallelismFactorCalculator.js +10 -0
  220. package/lib/util/Semaphore.js +1 -1
  221. package/lib/util/StackedCacheMap.js +1 -1
  222. package/lib/util/URLAbsoluteSpecifier.js +1 -1
  223. package/lib/util/createHash.js +30 -9
  224. package/lib/util/deprecation.js +10 -3
  225. package/lib/util/deterministicGrouping.js +50 -11
  226. package/lib/util/findGraphRoots.js +4 -2
  227. package/lib/util/memoize.js +3 -3
  228. package/lib/util/processAsyncTree.js +7 -1
  229. package/lib/util/registerExternalSerializer.js +1 -1
  230. package/lib/util/runtime.js +84 -21
  231. package/lib/util/semver.js +1 -0
  232. package/lib/util/smartGrouping.js +1 -1
  233. package/lib/validateSchema.js +6 -2
  234. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +6 -2
  235. package/lib/wasm-async/AsyncWebAssemblyParser.js +7 -3
  236. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +14 -7
  237. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +3 -1
  238. package/lib/wasm-sync/WebAssemblyGenerator.js +1 -0
  239. package/lib/wasm-sync/WebAssemblyParser.js +6 -2
  240. package/lib/web/JsonpChunkLoadingRuntimeModule.js +14 -4
  241. package/lib/webpack.js +11 -2
  242. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +15 -16
  243. package/module.d.ts +1 -0
  244. package/package.json +5 -4
  245. package/schemas/WebpackOptions.check.js +1 -1
  246. package/schemas/WebpackOptions.json +52 -6
  247. package/schemas/plugins/css/CssGeneratorOptions.json +1 -1
  248. package/schemas/plugins/css/CssParserOptions.json +1 -1
  249. package/types.d.ts +606 -292
@@ -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
@@ -208,7 +208,7 @@ class Compiler {
208
208
  this.root = this;
209
209
  /** @type {string} */
210
210
  this.outputPath = "";
211
- /** @type {Watching} */
211
+ /** @type {Watching | undefined} */
212
212
  this.watching = undefined;
213
213
 
214
214
  /** @type {OutputFileSystem} */
@@ -230,15 +230,15 @@ class Compiler {
230
230
  /** @type {Set<string | RegExp>} */
231
231
  this.immutablePaths = new Set();
232
232
 
233
- /** @type {ReadonlySet<string>} */
233
+ /** @type {ReadonlySet<string> | undefined} */
234
234
  this.modifiedFiles = undefined;
235
- /** @type {ReadonlySet<string>} */
235
+ /** @type {ReadonlySet<string> | undefined} */
236
236
  this.removedFiles = undefined;
237
- /** @type {ReadonlyMap<string, FileSystemInfoEntry | "ignore" | null>} */
237
+ /** @type {ReadonlyMap<string, FileSystemInfoEntry | "ignore" | null> | undefined} */
238
238
  this.fileTimestamps = undefined;
239
- /** @type {ReadonlyMap<string, FileSystemInfoEntry | "ignore" | null>} */
239
+ /** @type {ReadonlyMap<string, FileSystemInfoEntry | "ignore" | null> | undefined} */
240
240
  this.contextTimestamps = undefined;
241
- /** @type {number} */
241
+ /** @type {number | undefined} */
242
242
  this.fsStartTime = undefined;
243
243
 
244
244
  /** @type {ResolverFactory} */
@@ -1011,8 +1011,7 @@ ${other}`);
1011
1011
  try {
1012
1012
  this.records = parseJson(content.toString("utf-8"));
1013
1013
  } catch (e) {
1014
- e.message = "Cannot parse records: " + e.message;
1015
- return callback(e);
1014
+ return callback(new Error(`Cannot parse records: ${e.message}`));
1016
1015
  }
1017
1016
 
1018
1017
  return callback();
@@ -1074,7 +1073,9 @@ ${other}`);
1074
1073
  childCompiler.root = this.root;
1075
1074
  if (Array.isArray(plugins)) {
1076
1075
  for (const plugin of plugins) {
1077
- plugin.apply(childCompiler);
1076
+ if (plugin) {
1077
+ plugin.apply(childCompiler);
1078
+ }
1078
1079
  }
1079
1080
  }
1080
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,14 +15,26 @@ 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").AssignmentProperty} AssignmentProperty */
19
+ /** @typedef {import("estree").Expression} Expression */
20
+ /** @typedef {import("estree").Identifier} Identifier */
21
+ /** @typedef {import("estree").Pattern} Pattern */
22
+ /** @typedef {import("estree").SourceLocation} SourceLocation */
23
+ /** @typedef {import("estree").Statement} Statement */
24
+ /** @typedef {import("estree").Super} Super */
20
25
  /** @typedef {import("./Compiler")} Compiler */
26
+ /** @typedef {import("./javascript/BasicEvaluatedExpression")} BasicEvaluatedExpression */
27
+ /** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
28
+ /** @typedef {import("./javascript/JavascriptParser").Range} Range */
21
29
 
30
+ /**
31
+ * @param {Set<string>} declarations set of declarations
32
+ * @param {Identifier | Pattern} pattern pattern to collect declarations from
33
+ */
22
34
  const collectDeclaration = (declarations, pattern) => {
23
35
  const stack = [pattern];
24
36
  while (stack.length > 0) {
25
- const node = stack.pop();
37
+ const node = /** @type {Pattern} */ (stack.pop());
26
38
  switch (node.type) {
27
39
  case "Identifier":
28
40
  declarations.add(node.name);
@@ -39,7 +51,7 @@ const collectDeclaration = (declarations, pattern) => {
39
51
  break;
40
52
  case "ObjectPattern":
41
53
  for (const property of node.properties) {
42
- stack.push(property.value);
54
+ stack.push(/** @type {AssignmentProperty} */ (property).value);
43
55
  }
44
56
  break;
45
57
  case "RestElement":
@@ -49,8 +61,14 @@ const collectDeclaration = (declarations, pattern) => {
49
61
  }
50
62
  };
51
63
 
64
+ /**
65
+ * @param {Statement} branch branch to get hoisted declarations from
66
+ * @param {boolean} includeFunctionDeclarations whether to include function declarations
67
+ * @returns {Array<string>} hoisted declarations
68
+ */
52
69
  const getHoistedDeclarations = (branch, includeFunctionDeclarations) => {
53
70
  const declarations = new Set();
71
+ /** @type {Array<TODO | null | undefined>} */
54
72
  const stack = [branch];
55
73
  while (stack.length > 0) {
56
74
  const node = stack.pop();
@@ -98,7 +116,7 @@ const getHoistedDeclarations = (branch, includeFunctionDeclarations) => {
98
116
  break;
99
117
  case "FunctionDeclaration":
100
118
  if (includeFunctionDeclarations) {
101
- collectDeclaration(declarations, node.id);
119
+ collectDeclaration(declarations, /** @type {Identifier} */ (node.id));
102
120
  }
103
121
  break;
104
122
  case "VariableDeclaration":
@@ -136,6 +154,9 @@ class ConstPlugin {
136
154
  new CachedConstDependency.Template()
137
155
  );
138
156
 
157
+ /**
158
+ * @param {JavascriptParser} parser the parser
159
+ */
139
160
  const handler = parser => {
140
161
  parser.hooks.statementIf.tap(PLUGIN_NAME, statement => {
141
162
  if (parser.scope.isAsmJs) return;
@@ -143,8 +164,11 @@ class ConstPlugin {
143
164
  const bool = param.asBool();
144
165
  if (typeof bool === "boolean") {
145
166
  if (!param.couldHaveSideEffects()) {
146
- const dep = new ConstDependency(`${bool}`, param.range);
147
- dep.loc = statement.loc;
167
+ const dep = new ConstDependency(
168
+ `${bool}`,
169
+ /** @type {Range} */ (param.range)
170
+ );
171
+ dep.loc = /** @type {SourceLocation} */ (statement.loc);
148
172
  parser.state.module.addPresentationalDependency(dep);
149
173
  } else {
150
174
  parser.walkExpression(statement.test);
@@ -200,9 +224,9 @@ class ConstPlugin {
200
224
  }
201
225
  const dep = new ConstDependency(
202
226
  replacement,
203
- branchToRemove.range
227
+ /** @type {Range} */ (branchToRemove.range)
204
228
  );
205
- dep.loc = branchToRemove.loc;
229
+ dep.loc = /** @type {SourceLocation} */ (branchToRemove.loc);
206
230
  parser.state.module.addPresentationalDependency(dep);
207
231
  }
208
232
  return bool;
@@ -216,8 +240,11 @@ class ConstPlugin {
216
240
  const bool = param.asBool();
217
241
  if (typeof bool === "boolean") {
218
242
  if (!param.couldHaveSideEffects()) {
219
- const dep = new ConstDependency(` ${bool}`, param.range);
220
- dep.loc = expression.loc;
243
+ const dep = new ConstDependency(
244
+ ` ${bool}`,
245
+ /** @type {Range} */ (param.range)
246
+ );
247
+ dep.loc = /** @type {SourceLocation} */ (expression.loc);
221
248
  parser.state.module.addPresentationalDependency(dep);
222
249
  } else {
223
250
  parser.walkExpression(expression.test);
@@ -236,8 +263,11 @@ class ConstPlugin {
236
263
  const branchToRemove = bool
237
264
  ? expression.alternate
238
265
  : expression.consequent;
239
- const dep = new ConstDependency("0", branchToRemove.range);
240
- dep.loc = branchToRemove.loc;
266
+ const dep = new ConstDependency(
267
+ "0",
268
+ /** @type {Range} */ (branchToRemove.range)
269
+ );
270
+ dep.loc = /** @type {SourceLocation} */ (branchToRemove.loc);
241
271
  parser.state.module.addPresentationalDependency(dep);
242
272
  return bool;
243
273
  }
@@ -313,8 +343,11 @@ class ConstPlugin {
313
343
  //
314
344
  // returnfalse&&'foo'
315
345
  //
316
- const dep = new ConstDependency(` ${bool}`, param.range);
317
- dep.loc = expression.loc;
346
+ const dep = new ConstDependency(
347
+ ` ${bool}`,
348
+ /** @type {Range} */ (param.range)
349
+ );
350
+ dep.loc = /** @type {SourceLocation} */ (expression.loc);
318
351
  parser.state.module.addPresentationalDependency(dep);
319
352
  } else {
320
353
  parser.walkExpression(expression.left);
@@ -322,9 +355,9 @@ class ConstPlugin {
322
355
  if (!keepRight) {
323
356
  const dep = new ConstDependency(
324
357
  "0",
325
- expression.right.range
358
+ /** @type {Range} */ (expression.right.range)
326
359
  );
327
- dep.loc = expression.loc;
360
+ dep.loc = /** @type {SourceLocation} */ (expression.loc);
328
361
  parser.state.module.addPresentationalDependency(dep);
329
362
  }
330
363
  return keepRight;
@@ -363,15 +396,18 @@ class ConstPlugin {
363
396
  //
364
397
  // returnnull??'foo'
365
398
  //
366
- const dep = new ConstDependency(" null", param.range);
367
- dep.loc = expression.loc;
399
+ const dep = new ConstDependency(
400
+ " null",
401
+ /** @type {Range} */ (param.range)
402
+ );
403
+ dep.loc = /** @type {SourceLocation} */ (expression.loc);
368
404
  parser.state.module.addPresentationalDependency(dep);
369
405
  } else {
370
406
  const dep = new ConstDependency(
371
407
  "0",
372
- expression.right.range
408
+ /** @type {Range} */ (expression.right.range)
373
409
  );
374
- dep.loc = expression.loc;
410
+ dep.loc = /** @type {SourceLocation} */ (expression.loc);
375
411
  parser.state.module.addPresentationalDependency(dep);
376
412
  parser.walkExpression(expression.left);
377
413
  }
@@ -382,9 +418,9 @@ class ConstPlugin {
382
418
  }
383
419
  );
384
420
  parser.hooks.optionalChaining.tap(PLUGIN_NAME, expr => {
385
- /** @type {ExpressionNode[]} */
421
+ /** @type {Expression[]} */
386
422
  const optionalExpressionsStack = [];
387
- /** @type {ExpressionNode|SuperNode} */
423
+ /** @type {Expression | Super} */
388
424
  let next = expr.expression;
389
425
 
390
426
  while (
@@ -395,7 +431,7 @@ class ConstPlugin {
395
431
  if (next.optional) {
396
432
  // SuperNode can not be optional
397
433
  optionalExpressionsStack.push(
398
- /** @type {ExpressionNode} */ (next.object)
434
+ /** @type {Expression} */ (next.object)
399
435
  );
400
436
  }
401
437
  next = next.object;
@@ -403,7 +439,7 @@ class ConstPlugin {
403
439
  if (next.optional) {
404
440
  // SuperNode can not be optional
405
441
  optionalExpressionsStack.push(
406
- /** @type {ExpressionNode} */ (next.callee)
442
+ /** @type {Expression} */ (next.callee)
407
443
  );
408
444
  }
409
445
  next = next.callee;
@@ -412,7 +448,9 @@ class ConstPlugin {
412
448
 
413
449
  while (optionalExpressionsStack.length) {
414
450
  const expression = optionalExpressionsStack.pop();
415
- const evaluated = parser.evaluateExpression(expression);
451
+ const evaluated = parser.evaluateExpression(
452
+ /** @type {Expression} */ (expression)
453
+ );
416
454
 
417
455
  if (evaluated.asNullish()) {
418
456
  // ------------------------------------------
@@ -427,8 +465,11 @@ class ConstPlugin {
427
465
  //
428
466
  // ------------------------------------------
429
467
  //
430
- const dep = new ConstDependency(" undefined", expr.range);
431
- dep.loc = expr.loc;
468
+ const dep = new ConstDependency(
469
+ " undefined",
470
+ /** @type {Range} */ (expr.range)
471
+ );
472
+ dep.loc = /** @type {SourceLocation} */ (expr.loc);
432
473
  parser.state.module.addPresentationalDependency(dep);
433
474
  return true;
434
475
  }
@@ -452,10 +493,10 @@ class ConstPlugin {
452
493
  JSON.stringify(
453
494
  cachedParseResource(parser.state.module.resource).query
454
495
  ),
455
- expr.range,
496
+ /** @type {Range} */ (expr.range),
456
497
  "__resourceQuery"
457
498
  );
458
- dep.loc = expr.loc;
499
+ dep.loc = /** @type {SourceLocation} */ (expr.loc);
459
500
  parser.state.module.addPresentationalDependency(dep);
460
501
  return true;
461
502
  });
@@ -478,10 +519,10 @@ class ConstPlugin {
478
519
  JSON.stringify(
479
520
  cachedParseResource(parser.state.module.resource).fragment
480
521
  ),
481
- expr.range,
522
+ /** @type {Range} */ (expr.range),
482
523
  "__resourceFragment"
483
524
  );
484
- dep.loc = expr.loc;
525
+ dep.loc = /** @type {SourceLocation} */ (expr.loc);
485
526
  parser.state.module.addPresentationalDependency(dep);
486
527
  return true;
487
528
  });
@@ -63,7 +63,8 @@ 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
+ * @property {string=} layer
67
68
  */
68
69
 
69
70
  /**
@@ -107,8 +108,9 @@ class ContextModule extends Module {
107
108
  const resourceQuery = (options && options.resourceQuery) || parsed.query;
108
109
  const resourceFragment =
109
110
  (options && options.resourceFragment) || parsed.fragment;
111
+ const layer = options && options.layer;
110
112
 
111
- super(JAVASCRIPT_MODULE_TYPE_DYNAMIC, resource);
113
+ super(JAVASCRIPT_MODULE_TYPE_DYNAMIC, resource, layer);
112
114
  /** @type {ContextModuleOptions} */
113
115
  this.options = {
114
116
  ...options,
@@ -117,7 +119,7 @@ class ContextModule extends Module {
117
119
  resourceFragment
118
120
  };
119
121
  } else {
120
- super(JAVASCRIPT_MODULE_TYPE_DYNAMIC);
122
+ super(JAVASCRIPT_MODULE_TYPE_DYNAMIC, undefined, options.layer);
121
123
  /** @type {ContextModuleOptions} */
122
124
  this.options = {
123
125
  ...options,
@@ -229,6 +231,9 @@ class ContextModule extends Module {
229
231
  } else if (this.options.namespaceObject) {
230
232
  identifier += "|namespace object";
231
233
  }
234
+ if (this.layer) {
235
+ identifier += `|layer: ${this.layer}`;
236
+ }
232
237
 
233
238
  return identifier;
234
239
  }
@@ -95,6 +95,7 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
95
95
  {
96
96
  context: context,
97
97
  dependencies: dependencies,
98
+ layer: data.contextInfo.issuerLayer,
98
99
  resolveOptions,
99
100
  fileDependencies,
100
101
  missingDependencies,
@@ -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(
@@ -7,6 +7,8 @@
7
7
 
8
8
  const DelegatedModule = require("./DelegatedModule");
9
9
 
10
+ /** @typedef {import("./NormalModuleFactory")} NormalModuleFactory */
11
+
10
12
  // options.source
11
13
  // options.type
12
14
  // options.context
@@ -20,6 +22,10 @@ class DelegatedModuleFactoryPlugin {
20
22
  options.extensions = options.extensions || ["", ".js", ".json", ".wasm"];
21
23
  }
22
24
 
25
+ /**
26
+ * @param {NormalModuleFactory} normalModuleFactory the normal module factory
27
+ * @returns {void}
28
+ */
23
29
  apply(normalModuleFactory) {
24
30
  const scope = this.options.scope;
25
31
  if (scope) {
@@ -32,7 +32,7 @@ class DependenciesBlock {
32
32
  this.dependencies = [];
33
33
  /** @type {AsyncDependenciesBlock[]} */
34
34
  this.blocks = [];
35
- /** @type {DependenciesBlock} */
35
+ /** @type {DependenciesBlock | undefined} */
36
36
  this.parent = undefined;
37
37
  }
38
38