webpack 5.90.3 → 5.92.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 (257) hide show
  1. package/README.md +5 -5
  2. package/bin/webpack.js +6 -3
  3. package/lib/APIPlugin.js +14 -6
  4. package/lib/AutomaticPrefetchPlugin.js +1 -1
  5. package/lib/BannerPlugin.js +3 -1
  6. package/lib/Cache.js +8 -2
  7. package/lib/CacheFacade.js +3 -3
  8. package/lib/Chunk.js +7 -4
  9. package/lib/ChunkGraph.js +52 -25
  10. package/lib/ChunkGroup.js +23 -17
  11. package/lib/CleanPlugin.js +8 -6
  12. package/lib/Compilation.js +295 -120
  13. package/lib/Compiler.js +223 -87
  14. package/lib/ConcatenationScope.js +3 -3
  15. package/lib/ConditionalInitFragment.js +4 -5
  16. package/lib/ContextModule.js +95 -41
  17. package/lib/ContextModuleFactory.js +4 -2
  18. package/lib/ContextReplacementPlugin.js +3 -2
  19. package/lib/DefinePlugin.js +18 -6
  20. package/lib/Dependency.js +12 -10
  21. package/lib/DependencyTemplate.js +17 -7
  22. package/lib/DllModule.js +1 -0
  23. package/lib/DllReferencePlugin.js +7 -3
  24. package/lib/EntryOptionPlugin.js +4 -1
  25. package/lib/EntryPlugin.js +6 -1
  26. package/lib/Entrypoint.js +1 -1
  27. package/lib/EvalDevToolModulePlugin.js +11 -0
  28. package/lib/ExportsInfo.js +23 -8
  29. package/lib/ExternalModule.js +160 -35
  30. package/lib/ExternalModuleFactoryPlugin.js +37 -2
  31. package/lib/FileSystemInfo.js +69 -42
  32. package/lib/FlagDependencyExportsPlugin.js +21 -7
  33. package/lib/Generator.js +4 -4
  34. package/lib/HookWebpackError.js +2 -2
  35. package/lib/HotModuleReplacementPlugin.js +108 -45
  36. package/lib/IgnorePlugin.js +4 -1
  37. package/lib/InitFragment.js +5 -3
  38. package/lib/LibManifestPlugin.js +17 -9
  39. package/lib/Module.js +41 -14
  40. package/lib/ModuleFactory.js +3 -3
  41. package/lib/ModuleFilenameHelpers.js +30 -17
  42. package/lib/ModuleGraph.js +60 -31
  43. package/lib/ModuleGraphConnection.js +2 -1
  44. package/lib/MultiCompiler.js +62 -9
  45. package/lib/NodeStuffPlugin.js +14 -3
  46. package/lib/NormalModule.js +13 -13
  47. package/lib/NormalModuleFactory.js +18 -9
  48. package/lib/NormalModuleReplacementPlugin.js +5 -1
  49. package/lib/Parser.js +1 -1
  50. package/lib/PlatformPlugin.js +39 -0
  51. package/lib/ProgressPlugin.js +1 -1
  52. package/lib/ProvidePlugin.js +3 -1
  53. package/lib/RawModule.js +2 -1
  54. package/lib/RecordIdsPlugin.js +4 -4
  55. package/lib/ResolverFactory.js +6 -4
  56. package/lib/RuntimeModule.js +4 -4
  57. package/lib/RuntimePlugin.js +1 -0
  58. package/lib/RuntimeTemplate.js +124 -52
  59. package/lib/SourceMapDevToolPlugin.js +4 -1
  60. package/lib/Stats.js +11 -4
  61. package/lib/Template.js +5 -5
  62. package/lib/TemplatedPathPlugin.js +48 -7
  63. package/lib/Watching.js +67 -60
  64. package/lib/WebpackError.js +6 -6
  65. package/lib/WebpackOptionsApply.js +18 -5
  66. package/lib/asset/AssetGenerator.js +15 -0
  67. package/lib/asset/RawDataUrlModule.js +3 -1
  68. package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
  69. package/lib/buildChunkGraph.js +120 -67
  70. package/lib/cache/IdleFileCachePlugin.js +8 -3
  71. package/lib/cache/MemoryCachePlugin.js +1 -1
  72. package/lib/cache/MemoryWithGcCachePlugin.js +6 -2
  73. package/lib/cache/PackFileCacheStrategy.js +51 -18
  74. package/lib/cache/ResolverCachePlugin.js +22 -14
  75. package/lib/cache/getLazyHashedEtag.js +2 -2
  76. package/lib/cli.js +5 -5
  77. package/lib/config/browserslistTargetHandler.js +7 -1
  78. package/lib/config/defaults.js +108 -34
  79. package/lib/config/normalization.js +3 -1
  80. package/lib/config/target.js +18 -11
  81. package/lib/container/ContainerEntryDependency.js +2 -1
  82. package/lib/container/ContainerEntryModule.js +4 -2
  83. package/lib/container/ContainerPlugin.js +14 -10
  84. package/lib/container/FallbackModule.js +1 -1
  85. package/lib/container/RemoteRuntimeModule.js +12 -3
  86. package/lib/css/CssExportsGenerator.js +68 -25
  87. package/lib/css/CssGenerator.js +34 -6
  88. package/lib/css/CssLoadingRuntimeModule.js +217 -98
  89. package/lib/css/CssModulesPlugin.js +238 -107
  90. package/lib/css/CssParser.js +24 -15
  91. package/lib/css/walkCssTokens.js +1 -1
  92. package/lib/debug/ProfilingPlugin.js +28 -3
  93. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +9 -5
  94. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +4 -1
  95. package/lib/dependencies/CommonJsDependencyHelpers.js +2 -1
  96. package/lib/dependencies/CommonJsExportRequireDependency.js +33 -18
  97. package/lib/dependencies/CommonJsExportsDependency.js +13 -5
  98. package/lib/dependencies/CommonJsExportsParserPlugin.js +20 -15
  99. package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -2
  100. package/lib/dependencies/ContextDependencyHelpers.js +49 -29
  101. package/lib/dependencies/ContextElementDependency.js +8 -1
  102. package/lib/dependencies/CssExportDependency.js +2 -2
  103. package/lib/dependencies/CssLocalIdentifierDependency.js +71 -9
  104. package/lib/dependencies/CssUrlDependency.js +10 -7
  105. package/lib/dependencies/ExportsInfoDependency.js +5 -4
  106. package/lib/dependencies/ExternalModuleDependency.js +4 -2
  107. package/lib/dependencies/ExternalModuleInitFragment.js +5 -3
  108. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +4 -4
  109. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +43 -23
  110. package/lib/dependencies/HarmonyExportHeaderDependency.js +1 -1
  111. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +73 -32
  112. package/lib/dependencies/HarmonyExportInitFragment.js +10 -2
  113. package/lib/dependencies/HarmonyImportDependency.js +28 -12
  114. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +70 -19
  115. package/lib/dependencies/HarmonyImportSideEffectDependency.js +7 -6
  116. package/lib/dependencies/HarmonyImportSpecifierDependency.js +47 -35
  117. package/lib/dependencies/ImportDependency.js +9 -2
  118. package/lib/dependencies/ImportEagerDependency.js +4 -2
  119. package/lib/dependencies/ImportMetaContextDependency.js +7 -0
  120. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +25 -14
  121. package/lib/dependencies/ImportMetaPlugin.js +1 -1
  122. package/lib/dependencies/ImportParserPlugin.js +15 -5
  123. package/lib/dependencies/ImportWeakDependency.js +4 -2
  124. package/lib/dependencies/LoaderDependency.js +2 -1
  125. package/lib/dependencies/LoaderImportDependency.js +2 -1
  126. package/lib/dependencies/LoaderPlugin.js +2 -2
  127. package/lib/dependencies/ModuleDependency.js +4 -5
  128. package/lib/dependencies/PureExpressionDependency.js +64 -47
  129. package/lib/dependencies/RequireContextPlugin.js +1 -1
  130. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +26 -14
  131. package/lib/dependencies/RequireEnsureDependency.js +1 -1
  132. package/lib/dependencies/URLDependency.js +7 -4
  133. package/lib/dependencies/WorkerDependency.js +1 -1
  134. package/lib/dependencies/WorkerPlugin.js +2 -1
  135. package/lib/dependencies/getFunctionExpression.js +3 -1
  136. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +92 -3
  137. package/lib/hmr/LazyCompilationPlugin.js +2 -2
  138. package/lib/ids/ChunkModuleIdRangePlugin.js +1 -1
  139. package/lib/ids/DeterministicChunkIdsPlugin.js +1 -1
  140. package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
  141. package/lib/ids/IdHelpers.js +6 -6
  142. package/lib/ids/NamedChunkIdsPlugin.js +1 -1
  143. package/lib/ids/NamedModuleIdsPlugin.js +1 -1
  144. package/lib/ids/SyncModuleIdsPlugin.js +2 -2
  145. package/lib/index.js +11 -0
  146. package/lib/javascript/BasicEvaluatedExpression.js +2 -2
  147. package/lib/javascript/ChunkHelpers.js +2 -2
  148. package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -1
  149. package/lib/javascript/JavascriptGenerator.js +0 -1
  150. package/lib/javascript/JavascriptModulesPlugin.js +174 -17
  151. package/lib/javascript/JavascriptParser.js +204 -71
  152. package/lib/javascript/JavascriptParserHelpers.js +1 -1
  153. package/lib/javascript/StartupHelpers.js +22 -5
  154. package/lib/library/AbstractLibraryPlugin.js +2 -2
  155. package/lib/library/AmdLibraryPlugin.js +2 -2
  156. package/lib/library/AssignLibraryPlugin.js +3 -3
  157. package/lib/library/ExportPropertyLibraryPlugin.js +2 -2
  158. package/lib/library/JsonpLibraryPlugin.js +2 -2
  159. package/lib/library/ModuleLibraryPlugin.js +2 -2
  160. package/lib/library/SystemLibraryPlugin.js +2 -2
  161. package/lib/library/UmdLibraryPlugin.js +33 -12
  162. package/lib/logging/Logger.js +27 -2
  163. package/lib/logging/createConsoleLogger.js +13 -9
  164. package/lib/node/CommonJsChunkLoadingPlugin.js +2 -1
  165. package/lib/node/NodeEnvironmentPlugin.js +14 -8
  166. package/lib/node/NodeTemplatePlugin.js +1 -1
  167. package/lib/node/NodeWatchFileSystem.js +37 -26
  168. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -1
  169. package/lib/node/ReadFileCompileWasmPlugin.js +1 -1
  170. package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -1
  171. package/lib/node/nodeConsole.js +24 -1
  172. package/lib/optimize/AggressiveMergingPlugin.js +1 -1
  173. package/lib/optimize/AggressiveSplittingPlugin.js +1 -0
  174. package/lib/optimize/ConcatenatedModule.js +140 -121
  175. package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -1
  176. package/lib/optimize/InnerGraph.js +8 -3
  177. package/lib/optimize/InnerGraphPlugin.js +36 -13
  178. package/lib/optimize/LimitChunkCountPlugin.js +1 -2
  179. package/lib/optimize/ModuleConcatenationPlugin.js +13 -3
  180. package/lib/optimize/RealContentHashPlugin.js +3 -3
  181. package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
  182. package/lib/optimize/RuntimeChunkPlugin.js +6 -1
  183. package/lib/optimize/SideEffectsFlagPlugin.js +48 -17
  184. package/lib/optimize/SplitChunksPlugin.js +10 -10
  185. package/lib/performance/SizeLimitsPlugin.js +13 -2
  186. package/lib/rules/ObjectMatcherRulePlugin.js +15 -1
  187. package/lib/rules/RuleSetCompiler.js +9 -7
  188. package/lib/runtime/EnsureChunkRuntimeModule.js +2 -1
  189. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +2 -1
  190. package/lib/runtime/LoadScriptRuntimeModule.js +1 -1
  191. package/lib/runtime/StartupChunkDependenciesPlugin.js +1 -1
  192. package/lib/schemes/HttpUriPlugin.js +1 -1
  193. package/lib/serialization/BinaryMiddleware.js +4 -4
  194. package/lib/serialization/FileMiddleware.js +4 -3
  195. package/lib/serialization/NullPrototypeObjectSerializer.js +2 -2
  196. package/lib/serialization/ObjectMiddleware.js +8 -5
  197. package/lib/serialization/PlainObjectSerializer.js +2 -2
  198. package/lib/serialization/Serializer.js +19 -0
  199. package/lib/serialization/SerializerMiddleware.js +2 -2
  200. package/lib/serialization/SingleItemMiddleware.js +2 -2
  201. package/lib/serialization/types.js +1 -1
  202. package/lib/sharing/ConsumeSharedModule.js +2 -2
  203. package/lib/sharing/ConsumeSharedPlugin.js +17 -3
  204. package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -2
  205. package/lib/sharing/ProvideSharedPlugin.js +13 -6
  206. package/lib/sharing/resolveMatchedConfigs.js +3 -3
  207. package/lib/sharing/utils.js +13 -6
  208. package/lib/stats/DefaultStatsFactoryPlugin.js +20 -20
  209. package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
  210. package/lib/stats/StatsFactory.js +2 -2
  211. package/lib/stats/StatsPrinter.js +6 -6
  212. package/lib/util/ArrayQueue.js +14 -21
  213. package/lib/util/AsyncQueue.js +1 -1
  214. package/lib/util/Queue.js +8 -2
  215. package/lib/util/SortableSet.js +16 -4
  216. package/lib/util/StackedCacheMap.js +26 -0
  217. package/lib/util/TupleQueue.js +8 -2
  218. package/lib/util/WeakTupleMap.js +57 -13
  219. package/lib/util/binarySearchBounds.js +1 -1
  220. package/lib/util/cleverMerge.js +26 -13
  221. package/lib/util/comparators.js +37 -15
  222. package/lib/util/conventions.js +129 -0
  223. package/lib/util/createHash.js +3 -5
  224. package/lib/util/deprecation.js +3 -3
  225. package/lib/util/deterministicGrouping.js +2 -2
  226. package/lib/util/findGraphRoots.js +1 -1
  227. package/lib/util/fs.js +383 -69
  228. package/lib/util/hash/BatchedHash.js +3 -0
  229. package/lib/util/hash/xxhash64.js +2 -2
  230. package/lib/util/identifier.js +5 -5
  231. package/lib/util/mergeScope.js +79 -0
  232. package/lib/util/runtime.js +2 -17
  233. package/lib/util/semver.js +3 -0
  234. package/lib/util/smartGrouping.js +3 -3
  235. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +4 -2
  236. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -1
  237. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -2
  238. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -3
  239. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +16 -7
  240. package/lib/wasm-sync/WebAssemblyGenerator.js +40 -19
  241. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +1 -1
  242. package/lib/wasm-sync/WebAssemblyParser.js +7 -4
  243. package/lib/wasm-sync/WebAssemblyUtils.js +2 -1
  244. package/lib/web/FetchCompileWasmPlugin.js +1 -1
  245. package/lib/web/JsonpChunkLoadingRuntimeModule.js +3 -2
  246. package/lib/webpack.js +19 -6
  247. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +2 -1
  248. package/package.json +40 -39
  249. package/schemas/WebpackOptions.check.js +1 -1
  250. package/schemas/WebpackOptions.json +97 -8
  251. package/schemas/plugins/BannerPlugin.check.js +1 -1
  252. package/schemas/plugins/BannerPlugin.json +5 -1
  253. package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
  254. package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
  255. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
  256. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
  257. package/types.d.ts +1826 -639
@@ -8,12 +8,13 @@
8
8
  const RuntimeGlobals = require("../RuntimeGlobals");
9
9
 
10
10
  /** @typedef {import("../Module")} Module */
11
+ /** @typedef {import("../Module").RuntimeRequirements} RuntimeRequirements */
11
12
  /** @typedef {"exports" | "module.exports" | "this" | "Object.defineProperty(exports)" | "Object.defineProperty(module.exports)" | "Object.defineProperty(this)"} CommonJSDependencyBaseKeywords */
12
13
 
13
14
  /**
14
15
  * @param {CommonJSDependencyBaseKeywords} depBase commonjs dependency base
15
16
  * @param {Module} module module
16
- * @param {Set<string>} runtimeRequirements runtime requirements
17
+ * @param {RuntimeRequirements} runtimeRequirements runtime requirements
17
18
  * @returns {[string, string]} type and base
18
19
  */
19
20
  exports.handleDependencyBase = (depBase, module, runtimeRequirements) => {
@@ -20,6 +20,8 @@ const processExportInfo = require("./processExportInfo");
20
20
  /** @typedef {import("../Dependency").ReferencedExport} ReferencedExport */
21
21
  /** @typedef {import("../Dependency").TRANSITIVE} TRANSITIVE */
22
22
  /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
23
+ /** @typedef {import("../ExportsInfo")} ExportsInfo */
24
+ /** @typedef {import("../ExportsInfo").ExportInfo} ExportInfo */
23
25
  /** @typedef {import("../Module")} Module */
24
26
  /** @typedef {import("../ModuleGraph")} ModuleGraph */
25
27
  /** @typedef {import("../javascript/JavascriptParser").Range} Range */
@@ -35,7 +37,7 @@ const EMPTY_OBJECT = {};
35
37
  class CommonJsExportRequireDependency extends ModuleDependency {
36
38
  /**
37
39
  * @param {Range} range range
38
- * @param {Range} valueRange value range
40
+ * @param {Range | null} valueRange value range
39
41
  * @param {CommonJSDependencyBaseKeywords} base base
40
42
  * @param {string[]} names names
41
43
  * @param {string} request request
@@ -69,7 +71,9 @@ class CommonJsExportRequireDependency extends ModuleDependency {
69
71
  * @returns {string[]} the imported id
70
72
  */
71
73
  getIds(moduleGraph) {
72
- return moduleGraph.getMeta(this)[idsSymbol] || this.ids;
74
+ return (
75
+ /** @type {TODO} */ (moduleGraph.getMeta(this))[idsSymbol] || this.ids
76
+ );
73
77
  }
74
78
 
75
79
  /**
@@ -78,7 +82,7 @@ class CommonJsExportRequireDependency extends ModuleDependency {
78
82
  * @returns {void}
79
83
  */
80
84
  setIds(moduleGraph, ids) {
81
- moduleGraph.getMeta(this)[idsSymbol] = ids;
85
+ /** @type {TODO} */ (moduleGraph.getMeta(this))[idsSymbol] = ids;
82
86
  }
83
87
 
84
88
  /**
@@ -102,11 +106,14 @@ class CommonJsExportRequireDependency extends ModuleDependency {
102
106
  }
103
107
  };
104
108
  if (this.resultUsed) return getFullResult();
109
+ /** @type {ExportsInfo | undefined} */
105
110
  let exportsInfo = moduleGraph.getExportsInfo(
106
- moduleGraph.getParentModule(this)
111
+ /** @type {Module} */ (moduleGraph.getParentModule(this))
107
112
  );
108
113
  for (const name of this.names) {
109
- const exportInfo = exportsInfo.getReadOnlyExportInfo(name);
114
+ const exportInfo = /** @type {ExportInfo} */ (
115
+ exportsInfo.getReadOnlyExportInfo(name)
116
+ );
110
117
  const used = exportInfo.getUsed(runtime);
111
118
  if (used === UsageState.Unused) return Dependency.NO_EXPORTS_REFERENCED;
112
119
  if (used !== UsageState.OnlyPropertiesUsed) return getFullResult();
@@ -182,14 +189,17 @@ class CommonJsExportRequireDependency extends ModuleDependency {
182
189
  );
183
190
  if (reexportInfo) {
184
191
  return {
185
- exports: Array.from(reexportInfo.exports, name => {
186
- return {
187
- name,
188
- from,
189
- export: ids.concat(name),
190
- canMangle: !(name in EMPTY_OBJECT) && false
191
- };
192
- }),
192
+ exports: Array.from(
193
+ /** @type {TODO} */ (reexportInfo).exports,
194
+ name => {
195
+ return {
196
+ name,
197
+ from,
198
+ export: ids.concat(name),
199
+ canMangle: !(name in EMPTY_OBJECT) && false
200
+ };
201
+ }
202
+ ),
193
203
  // TODO handle deep reexports
194
204
  dependencies: [from.module]
195
205
  };
@@ -208,19 +218,21 @@ class CommonJsExportRequireDependency extends ModuleDependency {
208
218
  * @param {ModuleGraph} moduleGraph the module graph
209
219
  * @param {RuntimeSpec} runtime the runtime
210
220
  * @param {Module} importedModule the imported module (optional)
211
- * @returns {{exports?: Set<string>, checked?: Set<string>}} information
221
+ * @returns {{exports?: Set<string>, checked?: Set<string>} | undefined} information
212
222
  */
213
223
  getStarReexports(
214
224
  moduleGraph,
215
225
  runtime,
216
- importedModule = moduleGraph.getModule(this)
226
+ importedModule = /** @type {Module} */ (moduleGraph.getModule(this))
217
227
  ) {
228
+ /** @type {ExportsInfo | undefined} */
218
229
  let importedExportsInfo = moduleGraph.getExportsInfo(importedModule);
219
230
  const ids = this.getIds(moduleGraph);
220
231
  if (ids.length > 0)
221
232
  importedExportsInfo = importedExportsInfo.getNestedExportsInfo(ids);
233
+ /** @type {ExportsInfo | undefined} */
222
234
  let exportsInfo = moduleGraph.getExportsInfo(
223
- moduleGraph.getParentModule(this)
235
+ /** @type {Module} */ (moduleGraph.getParentModule(this))
224
236
  );
225
237
  if (this.names.length > 0)
226
238
  exportsInfo = exportsInfo.getNestedExportsInfo(this.names);
@@ -245,7 +257,8 @@ class CommonJsExportRequireDependency extends ModuleDependency {
245
257
  const checked = new Set();
246
258
 
247
259
  if (noExtraImports) {
248
- for (const exportInfo of exportsInfo.orderedExports) {
260
+ for (const exportInfo of /** @type {ExportsInfo} */ (exportsInfo)
261
+ .orderedExports) {
249
262
  const name = exportInfo.name;
250
263
  if (exportInfo.getUsed(runtime) === UsageState.Unused) continue;
251
264
  if (name === "__esModule" && isNamespaceImport) {
@@ -263,7 +276,9 @@ class CommonJsExportRequireDependency extends ModuleDependency {
263
276
  }
264
277
  }
265
278
  } else if (noExtraExports) {
266
- for (const importedExportInfo of importedExportsInfo.orderedExports) {
279
+ for (const importedExportInfo of /** @type {ExportsInfo} */ (
280
+ importedExportsInfo
281
+ ).orderedExports) {
267
282
  const name = importedExportInfo.name;
268
283
  if (importedExportInfo.provided === false) continue;
269
284
  if (exportsInfo) {
@@ -26,7 +26,7 @@ const EMPTY_OBJECT = {};
26
26
  class CommonJsExportsDependency extends NullDependency {
27
27
  /**
28
28
  * @param {Range} range range
29
- * @param {Range} valueRange value range
29
+ * @param {Range | null} valueRange value range
30
30
  * @param {CommonJSDependencyBaseKeywords} base base
31
31
  * @param {string[]} names names
32
32
  */
@@ -154,20 +154,28 @@ CommonJsExportsDependency.Template = class CommonJsExportsDependencyTemplate ext
154
154
  );
155
155
  source.replace(
156
156
  dep.range[0],
157
- dep.valueRange[0] - 1,
157
+ /** @type {Range} */ (dep.valueRange)[0] - 1,
158
158
  "__webpack_unused_export__ = ("
159
159
  );
160
- source.replace(dep.valueRange[1], dep.range[1] - 1, ")");
160
+ source.replace(
161
+ /** @type {Range} */ (dep.valueRange)[1],
162
+ dep.range[1] - 1,
163
+ ")"
164
+ );
161
165
  return;
162
166
  }
163
167
  source.replace(
164
168
  dep.range[0],
165
- dep.valueRange[0] - 1,
169
+ /** @type {Range} */ (dep.valueRange)[0] - 1,
166
170
  `Object.defineProperty(${base}${propertyAccess(
167
171
  used.slice(0, -1)
168
172
  )}, ${JSON.stringify(used[used.length - 1])}, (`
169
173
  );
170
- source.replace(dep.valueRange[1], dep.range[1] - 1, "))");
174
+ source.replace(
175
+ /** @type {Range} */ (dep.valueRange)[1],
176
+ dep.range[1] - 1,
177
+ "))"
178
+ );
171
179
  return;
172
180
  }
173
181
  }
@@ -20,11 +20,12 @@ const ModuleDecoratorDependency = require("./ModuleDecoratorDependency");
20
20
  /** @typedef {import("estree").CallExpression} CallExpression */
21
21
  /** @typedef {import("estree").Expression} Expression */
22
22
  /** @typedef {import("estree").Super} Super */
23
-
23
+ /** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
24
24
  /** @typedef {import("../ModuleGraph")} ModuleGraph */
25
25
  /** @typedef {import("../NormalModule")} NormalModule */
26
26
  /** @typedef {import("../javascript/BasicEvaluatedExpression")} BasicEvaluatedExpression */
27
27
  /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
28
+ /** @typedef {import("../javascript/JavascriptParser").Range} Range */
28
29
  /** @typedef {import("./CommonJsDependencyHelpers").CommonJSDependencyBaseKeywords} CommonJSDependencyBaseKeywords */
29
30
 
30
31
  /**
@@ -190,7 +191,7 @@ class CommonJsExportsParserPlugin {
190
191
  * @param {AssignmentExpression} expr expression
191
192
  * @param {CommonJSDependencyBaseKeywords} base commonjs base keywords
192
193
  * @param {string[]} members members of the export
193
- * @returns {boolean} true, when the expression was handled
194
+ * @returns {boolean | undefined} true, when the expression was handled
194
195
  */
195
196
  const handleAssignExport = (expr, base, members) => {
196
197
  if (HarmonyExports.isEnabled(parser.state)) return;
@@ -205,15 +206,15 @@ class CommonJsExportsParserPlugin {
205
206
  // It's possible to reexport __esModule, so we must convert to a dynamic module
206
207
  if (members.length === 0) DynamicExports.setDynamic(parser.state);
207
208
  const dep = new CommonJsExportRequireDependency(
208
- expr.range,
209
+ /** @type {Range} */ (expr.range),
209
210
  null,
210
211
  base,
211
212
  members,
212
- requireCall.argument.string,
213
+ /** @type {string} */ (requireCall.argument.string),
213
214
  requireCall.ids,
214
215
  !parser.isStatementLevelExpression(expr)
215
216
  );
216
- dep.loc = expr.loc;
217
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
217
218
  dep.optional = !!parser.scope.inTry;
218
219
  parser.state.module.addDependency(dep);
219
220
  return true;
@@ -228,12 +229,12 @@ class CommonJsExportsParserPlugin {
228
229
  expr.right
229
230
  );
230
231
  const dep = new CommonJsExportsDependency(
231
- expr.left.range,
232
+ /** @type {Range} */ (expr.left.range),
232
233
  null,
233
234
  base,
234
235
  remainingMembers
235
236
  );
236
- dep.loc = expr.loc;
237
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
237
238
  parser.state.module.addDependency(dep);
238
239
  parser.walkExpression(expr.right);
239
240
  return true;
@@ -284,12 +285,12 @@ class CommonJsExportsParserPlugin {
284
285
  getValueOfPropertyDescription(descArg)
285
286
  );
286
287
  const dep = new CommonJsExportsDependency(
287
- expr.range,
288
- expr.arguments[2].range,
288
+ /** @type {Range} */ (expr.range),
289
+ /** @type {Range} */ (expr.arguments[2].range),
289
290
  `Object.defineProperty(${exportsArg.identifier})`,
290
291
  [property]
291
292
  );
292
- dep.loc = expr.loc;
293
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
293
294
  parser.state.module.addDependency(dep);
294
295
 
295
296
  parser.walkExpression(expr.arguments[2]);
@@ -308,24 +309,28 @@ class CommonJsExportsParserPlugin {
308
309
  const handleAccessExport = (expr, base, members, call = undefined) => {
309
310
  if (HarmonyExports.isEnabled(parser.state)) return;
310
311
  if (members.length === 0) {
311
- bailout(`${base} is used directly at ${formatLocation(expr.loc)}`);
312
+ bailout(
313
+ `${base} is used directly at ${formatLocation(
314
+ /** @type {DependencyLocation} */ (expr.loc)
315
+ )}`
316
+ );
312
317
  }
313
318
  if (call && members.length === 1) {
314
319
  bailoutHint(
315
320
  `${base}${propertyAccess(
316
321
  members
317
322
  )}(...) prevents optimization as ${base} is passed as call context at ${formatLocation(
318
- expr.loc
323
+ /** @type {DependencyLocation} */ (expr.loc)
319
324
  )}`
320
325
  );
321
326
  }
322
327
  const dep = new CommonJsSelfReferenceDependency(
323
- expr.range,
328
+ /** @type {Range} */ (expr.range),
324
329
  base,
325
330
  members,
326
331
  !!call
327
332
  );
328
- dep.loc = expr.loc;
333
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
329
334
  parser.state.module.addDependency(dep);
330
335
  if (call) {
331
336
  parser.walkExpressions(call.arguments);
@@ -398,7 +403,7 @@ class CommonJsExportsParserPlugin {
398
403
  : RuntimeGlobals.nodeModuleDecorator,
399
404
  !isHarmony
400
405
  );
401
- dep.loc = expr.loc;
406
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
402
407
  parser.state.module.addDependency(dep);
403
408
  return true;
404
409
  });
@@ -344,7 +344,6 @@ class CommonJsImportsParserPlugin {
344
344
  );
345
345
  dep.loc = /** @type {DependencyLocation} */ (expr.loc);
346
346
  parser.state.module.addPresentationalDependency(dep);
347
- return true;
348
347
  } else {
349
348
  const result = processRequireItem(expr, param);
350
349
  if (result === undefined) {
@@ -356,8 +355,8 @@ class CommonJsImportsParserPlugin {
356
355
  dep.loc = /** @type {DependencyLocation} */ (expr.loc);
357
356
  parser.state.module.addPresentationalDependency(dep);
358
357
  }
359
- return true;
360
358
  }
359
+ return true;
361
360
  };
362
361
  parser.hooks.call
363
362
  .for("require")
@@ -10,8 +10,10 @@ const { parseResource } = require("../util/identifier");
10
10
  /** @typedef {import("estree").Node} EsTreeNode */
11
11
  /** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
12
12
  /** @typedef {import("../../declarations/WebpackOptions").ModuleOptionsNormalized} ModuleOptions */
13
+ /** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
13
14
  /** @typedef {import("../javascript/BasicEvaluatedExpression")} BasicEvaluatedExpression */
14
15
  /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
16
+ /** @typedef {import("../javascript/JavascriptParser").Range} Range */
15
17
  /** @typedef {import("./ContextDependency")} ContextDependency */
16
18
  /** @typedef {import("./ContextDependency").ContextDependencyOptions} ContextDependencyOptions */
17
19
 
@@ -24,6 +26,10 @@ const quoteMeta = str => {
24
26
  return str.replace(/[-[\]\\/{}()*+?.^$|]/g, "\\$&");
25
27
  };
26
28
 
29
+ /**
30
+ * @param {string} prefix prefix
31
+ * @returns {{prefix: string, context: string}} result
32
+ */
27
33
  const splitContextFromPrefix = prefix => {
28
34
  const idx = prefix.lastIndexOf("/");
29
35
  let context = ".";
@@ -38,7 +44,6 @@ const splitContextFromPrefix = prefix => {
38
44
  };
39
45
 
40
46
  /** @typedef {Partial<Omit<ContextDependencyOptions, "resource">>} PartialContextDependencyOptions */
41
- /** @typedef {import("../javascript/JavascriptParser").Range} Range */
42
47
  /** @typedef {{ new(options: ContextDependencyOptions, range: Range, valueRange: [number, number], ...args: any[]): ContextDependency }} ContextDependencyConstructor */
43
48
 
44
49
  /**
@@ -63,13 +68,13 @@ exports.create = (
63
68
  ...depArgs
64
69
  ) => {
65
70
  if (param.isTemplateString()) {
66
- let prefixRaw = param.quasis[0].string;
71
+ const quasis = /** @type {BasicEvaluatedExpression[]} */ (param.quasis);
72
+ let prefixRaw = /** @type {string} */ (quasis[0].string);
67
73
  let postfixRaw =
68
- param.quasis.length > 1
69
- ? param.quasis[param.quasis.length - 1].string
70
- : "";
74
+ /** @type {string} */
75
+ (quasis.length > 1 ? quasis[quasis.length - 1].string : "");
71
76
 
72
- const valueRange = param.range;
77
+ const valueRange = /** @type {Range} */ (param.range);
73
78
  const { context, prefix } = splitContextFromPrefix(prefixRaw);
74
79
  const {
75
80
  path: postfix,
@@ -79,11 +84,15 @@ exports.create = (
79
84
 
80
85
  // When there are more than two quasis, the generated RegExp can be more precise
81
86
  // We join the quasis with the expression regexp
82
- const innerQuasis = param.quasis.slice(1, param.quasis.length - 1);
87
+ const innerQuasis = quasis.slice(1, quasis.length - 1);
83
88
  const innerRegExp =
84
- options.wrappedContextRegExp.source +
89
+ /** @type {RegExp} */ (options.wrappedContextRegExp).source +
85
90
  innerQuasis
86
- .map(q => quoteMeta(q.string) + options.wrappedContextRegExp.source)
91
+ .map(
92
+ q =>
93
+ quoteMeta(/** @type {string} */ (q.string)) +
94
+ /** @type {RegExp} */ (options.wrappedContextRegExp).source
95
+ )
87
96
  .join("");
88
97
 
89
98
  // Example: `./context/pre${e}inner${e}inner2${e}post?query#frag`
@@ -101,7 +110,7 @@ exports.create = (
101
110
  const dep = new Dep(
102
111
  {
103
112
  request: context + query + fragment,
104
- recursive: options.wrappedContextRecursive,
113
+ recursive: /** @type {boolean} */ (options.wrappedContextRecursive),
105
114
  regExp,
106
115
  mode: "sync",
107
116
  ...contextOptions
@@ -110,14 +119,17 @@ exports.create = (
110
119
  valueRange,
111
120
  ...depArgs
112
121
  );
113
- dep.loc = expr.loc;
122
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
123
+
124
+ /** @type {{ value: string, range: Range }[]} */
114
125
  const replaces = [];
126
+ const parts = /** @type {BasicEvaluatedExpression[]} */ (param.parts);
115
127
 
116
- param.parts.forEach((part, i) => {
128
+ parts.forEach((part, i) => {
117
129
  if (i % 2 === 0) {
118
130
  // Quasis or merged quasi
119
- let range = part.range;
120
- let value = part.string;
131
+ let range = /** @type {Range} */ (part.range);
132
+ let value = /** @type {string} */ (part.string);
121
133
  if (param.templateStringKind === "cooked") {
122
134
  value = JSON.stringify(value);
123
135
  value = value.slice(1, value.length - 1);
@@ -125,14 +137,20 @@ exports.create = (
125
137
  if (i === 0) {
126
138
  // prefix
127
139
  value = prefix;
128
- range = [param.range[0], part.range[1]];
140
+ range = [
141
+ /** @type {Range} */ (param.range)[0],
142
+ /** @type {Range} */ (part.range)[1]
143
+ ];
129
144
  value =
130
145
  (param.templateStringKind === "cooked" ? "`" : "String.raw`") +
131
146
  value;
132
- } else if (i === param.parts.length - 1) {
147
+ } else if (i === parts.length - 1) {
133
148
  // postfix
134
149
  value = postfix;
135
- range = [part.range[0], param.range[1]];
150
+ range = [
151
+ /** @type {Range} */ (part.range)[0],
152
+ /** @type {Range} */ (param.range)[1]
153
+ ];
136
154
  value = value + "`";
137
155
  } else if (
138
156
  part.expression &&
@@ -163,14 +181,16 @@ exports.create = (
163
181
  (param.postfix && param.postfix.isString()))
164
182
  ) {
165
183
  let prefixRaw =
166
- param.prefix && param.prefix.isString() ? param.prefix.string : "";
184
+ /** @type {string} */
185
+ (param.prefix && param.prefix.isString() ? param.prefix.string : "");
167
186
  let postfixRaw =
168
- param.postfix && param.postfix.isString() ? param.postfix.string : "";
187
+ /** @type {string} */
188
+ (param.postfix && param.postfix.isString() ? param.postfix.string : "");
169
189
  const prefixRange =
170
190
  param.prefix && param.prefix.isString() ? param.prefix.range : null;
171
191
  const postfixRange =
172
192
  param.postfix && param.postfix.isString() ? param.postfix.range : null;
173
- const valueRange = param.range;
193
+ const valueRange = /** @type {Range} */ (param.range);
174
194
  const { context, prefix } = splitContextFromPrefix(prefixRaw);
175
195
  const {
176
196
  path: postfix,
@@ -178,14 +198,14 @@ exports.create = (
178
198
  fragment
179
199
  } = parseResource(postfixRaw, parser);
180
200
  const regExp = new RegExp(
181
- `^${quoteMeta(prefix)}${options.wrappedContextRegExp.source}${quoteMeta(
182
- postfix
183
- )}$`
201
+ `^${quoteMeta(prefix)}${
202
+ /** @type {RegExp} */ (options.wrappedContextRegExp).source
203
+ }${quoteMeta(postfix)}$`
184
204
  );
185
205
  const dep = new Dep(
186
206
  {
187
207
  request: context + query + fragment,
188
- recursive: options.wrappedContextRecursive,
208
+ recursive: /** @type {boolean} */ (options.wrappedContextRecursive),
189
209
  regExp,
190
210
  mode: "sync",
191
211
  ...contextOptions
@@ -194,7 +214,7 @@ exports.create = (
194
214
  valueRange,
195
215
  ...depArgs
196
216
  );
197
- dep.loc = expr.loc;
217
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
198
218
  const replaces = [];
199
219
  if (prefixRange) {
200
220
  replaces.push({
@@ -223,17 +243,17 @@ exports.create = (
223
243
  } else {
224
244
  const dep = new Dep(
225
245
  {
226
- request: options.exprContextRequest,
227
- recursive: options.exprContextRecursive,
246
+ request: /** @type {string} */ (options.exprContextRequest),
247
+ recursive: /** @type {boolean} */ (options.exprContextRecursive),
228
248
  regExp: /** @type {RegExp} */ (options.exprContextRegExp),
229
249
  mode: "sync",
230
250
  ...contextOptions
231
251
  },
232
252
  range,
233
- param.range,
253
+ /** @type {Range} */ (param.range),
234
254
  ...depArgs
235
255
  );
236
- dep.loc = expr.loc;
256
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
237
257
  dep.critical =
238
258
  options.exprContextCritical &&
239
259
  "the request of a dependency is an expression";
@@ -11,6 +11,7 @@ const ModuleDependency = require("./ModuleDependency");
11
11
 
12
12
  /** @typedef {import("../Dependency").ReferencedExport} ReferencedExport */
13
13
  /** @typedef {import("../ModuleGraph")} ModuleGraph */
14
+ /** @typedef {import("../javascript/JavascriptParser").ImportAttributes} ImportAttributes */
14
15
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
15
16
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
16
17
  /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
@@ -23,6 +24,7 @@ class ContextElementDependency extends ModuleDependency {
23
24
  * @param {string} category category
24
25
  * @param {string[][]=} referencedExports referenced exports
25
26
  * @param {string=} context context
27
+ * @param {ImportAttributes=} attributes import assertions
26
28
  */
27
29
  constructor(
28
30
  request,
@@ -30,7 +32,8 @@ class ContextElementDependency extends ModuleDependency {
30
32
  typePrefix,
31
33
  category,
32
34
  referencedExports,
33
- context
35
+ context,
36
+ attributes
34
37
  ) {
35
38
  super(request);
36
39
  this.referencedExports = referencedExports;
@@ -41,6 +44,8 @@ class ContextElementDependency extends ModuleDependency {
41
44
  if (userRequest) {
42
45
  this.userRequest = userRequest;
43
46
  }
47
+
48
+ this.assertions = attributes;
44
49
  }
45
50
 
46
51
  get type() {
@@ -78,6 +83,7 @@ class ContextElementDependency extends ModuleDependency {
78
83
  write(this._typePrefix);
79
84
  write(this._category);
80
85
  write(this.referencedExports);
86
+ write(this.assertions);
81
87
  super.serialize(context);
82
88
  }
83
89
 
@@ -89,6 +95,7 @@ class ContextElementDependency extends ModuleDependency {
89
95
  this._typePrefix = read();
90
96
  this._category = read();
91
97
  this.referencedExports = read();
98
+ this.assertions = read();
92
99
  super.deserialize(context);
93
100
  }
94
101
  }
@@ -79,9 +79,9 @@ CssExportDependency.Template = class CssExportDependencyTemplate extends (
79
79
  * @param {DependencyTemplateContext} templateContext the context object
80
80
  * @returns {void}
81
81
  */
82
- apply(dependency, source, { cssExports }) {
82
+ apply(dependency, source, { cssExportsData }) {
83
83
  const dep = /** @type {CssExportDependency} */ (dependency);
84
- cssExports.set(dep.name, dep.value);
84
+ cssExportsData.exports.set(dep.name, dep.value);
85
85
  }
86
86
  };
87
87