webpack 5.112.0 → 5.112.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (263) hide show
  1. package/bin/webpack.js +13 -7
  2. package/lib/Compilation.js +198 -61
  3. package/lib/Compiler.js +12 -25
  4. package/lib/asset/AssetBytesGenerator.js +14 -6
  5. package/lib/asset/AssetBytesParser.js +10 -8
  6. package/lib/asset/AssetGenerator.js +36 -48
  7. package/lib/asset/AssetModule.js +11 -0
  8. package/lib/asset/AssetModulesPlugin.js +5 -4
  9. package/lib/asset/AssetParser.js +8 -8
  10. package/lib/asset/AssetSourceGenerator.js +16 -8
  11. package/lib/asset/AssetSourceParser.js +10 -8
  12. package/lib/asset/WebManifestGenerator.js +11 -6
  13. package/lib/asset/WebManifestParser.js +3 -3
  14. package/lib/async-modules/AsyncModuleHelpers.js +8 -2
  15. package/lib/async-modules/InferAsyncModulesPlugin.js +7 -2
  16. package/lib/cache/CacheFacade.js +1 -1
  17. package/lib/cache/PackFileCacheStrategy.js +6 -10
  18. package/lib/cache/ResolverCachePlugin.js +58 -8
  19. package/lib/config/WebpackOptionsApply.js +8 -28
  20. package/lib/config/cli.js +9 -6
  21. package/lib/config/defaults.js +24 -13
  22. package/lib/config/getClaimedAssetTypes.js +2 -2
  23. package/lib/config/target.js +1 -1
  24. package/lib/context/ContextModule.js +1 -1
  25. package/lib/context/ContextModuleFactory.js +1 -1
  26. package/lib/context/ContextReplacementPlugin.js +3 -9
  27. package/lib/css/CssGenerator.js +40 -47
  28. package/lib/css/CssModule.js +10 -0
  29. package/lib/css/CssModulesPlugin.js +13 -6
  30. package/lib/css/CssParser.js +33 -32
  31. package/lib/css/conventions.js +1 -1
  32. package/lib/css/data.js +224 -219
  33. package/lib/css/syntax-parser.js +1312 -312
  34. package/lib/css/syntax-printer.js +1142 -1025
  35. package/lib/debug/ProfilingPlugin.js +65 -43
  36. package/lib/define/DefinePlugin.js +10 -15
  37. package/lib/define/DotenvPlugin.js +10 -6
  38. package/lib/define/EnvironmentPlugin.js +4 -2
  39. package/lib/dependencies/amd/AMDDefineDependencyParserPlugin.js +1 -2
  40. package/lib/dependencies/amd/AMDRequireDependenciesBlockParserPlugin.js +4 -1
  41. package/lib/dependencies/commonjs/CommonJsExportRequireDependency.js +1 -4
  42. package/lib/dependencies/commonjs/CommonJsExportsParserPlugin.js +18 -33
  43. package/lib/dependencies/commonjs/CommonJsImportsParserPlugin.js +1 -3
  44. package/lib/dependencies/commonjs/CommonJsObjectExportDependency.js +4 -4
  45. package/lib/dependencies/commonjs/CommonJsPlugin.js +2 -5
  46. package/lib/dependencies/commonjs/RequireEnsureDependenciesBlockParserPlugin.js +4 -1
  47. package/lib/dependencies/context/ImportMetaContextDependencyParserPlugin.js +1 -2
  48. package/lib/dependencies/context/ImportMetaGlobDependencyParserPlugin.js +4 -7
  49. package/lib/dependencies/context/ImportMetaGlobHelpers.js +8 -10
  50. package/lib/dependencies/core/CachedConstDependency.js +9 -6
  51. package/lib/dependencies/css/CssIcssExportDependency.js +6 -7
  52. package/lib/dependencies/css/CssIcssImportDependency.js +1 -3
  53. package/lib/dependencies/css/CssUrlDependency.js +2 -6
  54. package/lib/dependencies/esm/ESMDetectionParserPlugin.js +2 -4
  55. package/lib/dependencies/esm/ESMExportExpressionDependency.js +2 -2
  56. package/lib/dependencies/esm/ESMExportImportedSpecifierDependency.js +16 -18
  57. package/lib/dependencies/esm/ESMExportSpecifierDependency.js +20 -3
  58. package/lib/dependencies/esm/ESMExports.js +2 -10
  59. package/lib/dependencies/esm/ESMImportDependency.js +17 -2
  60. package/lib/dependencies/esm/ESMImportDependencyParserPlugin.js +6 -17
  61. package/lib/dependencies/esm/ESMImportGuard.js +11 -23
  62. package/lib/dependencies/esm/ESMImportSideEffectDependency.js +1 -1
  63. package/lib/dependencies/esm/ESMImportSpecifierDependency.js +4 -1
  64. package/lib/dependencies/esm/ESMLiveExportDependency.js +311 -0
  65. package/lib/dependencies/esm/ESMLiveExportParserPlugin.js +862 -0
  66. package/lib/dependencies/esm/ESMModulesPlugin.js +1 -3
  67. package/lib/dependencies/esm/TopLevelAwaitDependency.js +1 -8
  68. package/lib/dependencies/helpers/DynamicExports.js +4 -6
  69. package/lib/dependencies/html/HtmlEntryDependency.js +5 -14
  70. package/lib/dependencies/html/HtmlInlineHtmlDependency.js +1 -4
  71. package/lib/dependencies/html/HtmlInlineScriptDependency.js +2 -6
  72. package/lib/dependencies/html/HtmlInlineStyleDependency.js +1 -4
  73. package/lib/dependencies/import/ImportParserPlugin.js +3 -6
  74. package/lib/dependencies/import-meta/ImportMetaPlugin.js +4 -6
  75. package/lib/dependencies/url/URLParserPlugin.js +1 -1
  76. package/lib/dependencies/worker/WorkerAndWorkletPlugin.js +51 -20
  77. package/lib/devtool/ModuleFilenameHelpers.js +1 -1
  78. package/lib/devtool/SourceMapDevToolPlugin.js +1 -1
  79. package/lib/dll/DelegatedModule.js +3 -3
  80. package/lib/dll/DllModule.js +3 -1
  81. package/lib/dll/DllReferencePlugin.js +1 -4
  82. package/lib/errors/AbstractMethodError.js +1 -1
  83. package/lib/errors/ErrorHelpers.js +2 -1
  84. package/lib/errors/HookWebpackError.js +2 -1
  85. package/lib/errors/JSONParseError.js +4 -4
  86. package/lib/errors/WebpackError.js +3 -2
  87. package/lib/esm/ModuleChunkFormatPlugin.js +36 -1
  88. package/lib/externals/ExternalModule.js +12 -9
  89. package/lib/externals/ExternalModuleFactoryPlugin.js +1 -2
  90. package/lib/externals/ExternalsPlugin.js +1 -1
  91. package/lib/fs/FileSystemInfo.js +4 -4
  92. package/lib/graph/AsyncDependenciesBlock.js +1 -1
  93. package/lib/graph/ChunkGraph.js +5 -0
  94. package/lib/graph/Dependency.js +8 -2
  95. package/lib/graph/ExportsInfo.js +1 -1
  96. package/lib/graph/ModuleGraph.js +14 -3
  97. package/lib/graph/buildChunkGraph.js +17 -19
  98. package/lib/graph/findGraphRoots.js +1 -1
  99. package/lib/hmr/HotModuleReplacement.runtime.js +10 -9
  100. package/lib/hmr/HotModuleReplacementPlugin.js +5 -11
  101. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +16 -19
  102. package/lib/hmr/LazyCompilationPlugin.js +1 -7
  103. package/lib/html/HtmlGenerator.js +25 -17
  104. package/lib/html/HtmlModule.js +11 -1
  105. package/lib/html/HtmlModulesPlugin.js +12 -11
  106. package/lib/html/HtmlParser.js +10 -9
  107. package/lib/html/builtinEmbeddedRenderer.js +31 -33
  108. package/lib/html/data.js +42 -21
  109. package/lib/html/htmlMinify.js +4 -1
  110. package/lib/html/syntax-parser.js +34 -35
  111. package/lib/html/syntax-printer.js +2 -3
  112. package/lib/html/xmlMinify.js +4 -1
  113. package/lib/ids/HashedModuleIdsPlugin.js +1 -1
  114. package/lib/index.js +13 -12
  115. package/lib/javascript/APIPlugin.js +7 -13
  116. package/lib/javascript/BasicEvaluatedExpression.js +5 -5
  117. package/lib/javascript/CommonJsChunkFormatPlugin.js +2 -7
  118. package/lib/javascript/ConstPlugin.js +1 -1
  119. package/lib/javascript/JavascriptGenerator.js +16 -11
  120. package/lib/javascript/JavascriptMetaInfoPlugin.js +3 -15
  121. package/lib/javascript/JavascriptModule.js +10 -0
  122. package/lib/javascript/JavascriptModulesPlugin.js +2 -4
  123. package/lib/javascript/JavascriptParser.js +99 -11
  124. package/lib/javascript/ScopeAnalyzer.js +183 -107
  125. package/lib/javascript/UseStrictPlugin.js +2 -5
  126. package/lib/javascript/jsMinify.js +1 -1
  127. package/lib/javascript/regexp.js +2 -2
  128. package/lib/javascript/syntax-parser.js +2114 -1506
  129. package/lib/javascript/syntax-printer-data.js +167 -1
  130. package/lib/javascript/syntax-printer.js +9554 -2782
  131. package/lib/json/JsonGenerator.js +15 -7
  132. package/lib/json/JsonModule.js +11 -0
  133. package/lib/json/JsonParser.js +7 -6
  134. package/lib/library/AssignLibraryPlugin.js +1 -1
  135. package/lib/library/JsonpLibraryPlugin.js +1 -1
  136. package/lib/library/ModuleLibraryPlugin.js +399 -23
  137. package/lib/loaders/LoaderRunner.js +76 -38
  138. package/lib/loaders/loadLoader.js +16 -10
  139. package/lib/module/Generator.js +17 -9
  140. package/lib/module/Module.js +2 -2
  141. package/lib/module/NormalModule.js +7 -5
  142. package/lib/module/NormalModuleFactory.js +11 -17
  143. package/lib/module/Parser.js +9 -2
  144. package/lib/module/extractSourceMap.js +69 -18
  145. package/lib/module/findCaseMismatch.js +2 -2
  146. package/lib/node/ExternalModuleInitFragment.js +2 -2
  147. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +4 -12
  148. package/lib/node/ReadFileCompileWasmPlugin.js +2 -6
  149. package/lib/node/nodeConsole.js +4 -3
  150. package/lib/optimize/CircularModulesPlugin.js +1 -1
  151. package/lib/optimize/ConcatenatedModule.js +4 -8
  152. package/lib/optimize/FlagDependencyExportsPlugin.js +6 -11
  153. package/lib/optimize/FlagDependencyUsagePlugin.js +28 -3
  154. package/lib/optimize/InlineExports.js +4 -7
  155. package/lib/optimize/LazyBarrels.js +41 -5
  156. package/lib/optimize/ModuleConcatenationPlugin.js +8 -10
  157. package/lib/optimize/RealContentHashPlugin.js +2 -6
  158. package/lib/optimize/SideEffectsFlagPlugin.js +7 -21
  159. package/lib/optimize/SplitChunksPlugin.js +11 -24
  160. package/lib/optimize/TupleQueue.js +1 -1
  161. package/lib/output/CleanPlugin.js +3 -1
  162. package/lib/output/CopyPlugin.js +3 -4
  163. package/lib/performance/EvalUsagePlugin.js +1 -3
  164. package/lib/performance/HotspotsPlugin.js +33 -9
  165. package/lib/performance/PureAnnotationsPlugin.js +16 -10
  166. package/lib/performance/TopLevelThisPlugin.js +17 -9
  167. package/lib/prefetch/ResourceHintPlugin.js +1 -1
  168. package/lib/provide/ProvidedDependency.js +36 -4
  169. package/lib/rules/BasicEffectRulePlugin.js +1 -1
  170. package/lib/rules/RuleSetCompiler.js +15 -5
  171. package/lib/rules/UseEffectRulePlugin.js +1 -3
  172. package/lib/runtime/AsyncModuleRuntimeModule.js +7 -1
  173. package/lib/runtime/GetChunkFilenameRuntimeModule.js +1 -5
  174. package/lib/runtime/RuntimeGlobals.js +6 -0
  175. package/lib/runtime/RuntimePlugin.js +2 -0
  176. package/lib/schemes/HttpUriPlugin.js +1 -2
  177. package/lib/schemes/VirtualUrlPlugin.js +3 -1
  178. package/lib/serialization/AggregateErrorSerializer.js +3 -3
  179. package/lib/serialization/BinaryMiddleware.js +4 -1
  180. package/lib/serialization/ErrorObjectSerializer.js +2 -5
  181. package/lib/serialization/ObjectMiddleware.js +17 -15
  182. package/lib/serialization/PlainObjectSerializer.js +3 -7
  183. package/lib/serialization/Serializer.js +21 -11
  184. package/lib/serialization/SerializerMiddleware.js +8 -6
  185. package/lib/stats/DefaultStatsFactoryPlugin.js +35 -35
  186. package/lib/stats/DefaultStatsPresetPlugin.js +2 -6
  187. package/lib/stats/DefaultStatsPrinterPlugin.js +12 -11
  188. package/lib/stats/StatsFactory.js +194 -24
  189. package/lib/stats/StatsPrinter.js +126 -13
  190. package/lib/template/DependencyTemplate.js +1 -1
  191. package/lib/template/RuntimeTemplate.js +13 -32
  192. package/lib/template/Template.js +1 -1
  193. package/lib/util/SourceProcessor.js +146 -29
  194. package/lib/util/WeakTupleMap.js +10 -4
  195. package/lib/util/cleverMerge.js +61 -33
  196. package/lib/util/comparators.js +9 -5
  197. package/lib/util/dataURL.js +2 -0
  198. package/lib/util/deprecation.js +4 -3
  199. package/lib/util/globUtils.js +1 -4
  200. package/lib/util/internalSerializables.js +2 -0
  201. package/lib/util/makeSerializable.js +6 -4
  202. package/lib/util/memoize.js +1 -1
  203. package/lib/util/parseJson.js +2 -2
  204. package/lib/util/serialization.js +31 -27
  205. package/lib/wasm/AsyncWasmModule.js +12 -2
  206. package/lib/wasm/AsyncWebAssemblyGenerator.js +12 -4
  207. package/lib/wasm/AsyncWebAssemblyJavascriptGenerator.js +13 -5
  208. package/lib/wasm/AsyncWebAssemblyParser.js +7 -5
  209. package/lib/wasm/UniversalCompileAsyncWasmPlugin.js +2 -6
  210. package/lib/wasm-sync/SyncWasmModule.js +16 -1
  211. package/lib/wasm-sync/WebAssemblyGenerator.js +15 -10
  212. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +13 -5
  213. package/lib/wasm-sync/WebAssemblyParser.js +10 -12
  214. package/lib/web/FetchCompileAsyncWasmPlugin.js +4 -12
  215. package/lib/web/FetchCompileWasmPlugin.js +2 -6
  216. package/package.json +18 -19
  217. package/schemas/WebpackOptions.check.js +3 -3
  218. package/schemas/WebpackOptions.json +2 -2
  219. package/schemas/plugins/BannerPlugin.check.js +3 -3
  220. package/schemas/plugins/HtmlGeneratorOptions.check.js +3 -3
  221. package/schemas/plugins/HtmlParserOptions.check.js +3 -3
  222. package/schemas/plugins/IgnorePlugin.check.js +3 -3
  223. package/schemas/plugins/LoaderOptionsPlugin.check.js +3 -3
  224. package/schemas/plugins/ManifestPlugin.check.js +3 -3
  225. package/schemas/plugins/ProgressPlugin.check.js +3 -3
  226. package/schemas/plugins/SSRManifestPlugin.check.js +3 -3
  227. package/schemas/plugins/SourceMapDevToolPlugin.check.js +3 -3
  228. package/schemas/plugins/WatchIgnorePlugin.check.js +3 -3
  229. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +3 -3
  230. package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.js +3 -3
  231. package/schemas/plugins/asset/AssetParserOptions.check.js +3 -3
  232. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +3 -3
  233. package/schemas/plugins/container/ContainerPlugin.check.js +3 -3
  234. package/schemas/plugins/container/ContainerReferencePlugin.check.js +3 -3
  235. package/schemas/plugins/container/ExternalsType.check.js +3 -3
  236. package/schemas/plugins/container/ModuleFederationPlugin.check.js +3 -3
  237. package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +3 -3
  238. package/schemas/plugins/css/CssGeneratorOptions.check.js +3 -3
  239. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +3 -3
  240. package/schemas/plugins/css/CssModuleParserOptions.check.js +3 -3
  241. package/schemas/plugins/css/CssParserOptions.check.js +3 -3
  242. package/schemas/plugins/debug/ProfilingPlugin.check.js +3 -3
  243. package/schemas/plugins/define/DotenvPluginOptions.check.js +7 -0
  244. package/schemas/plugins/define/DotenvPluginOptions.json +3 -0
  245. package/schemas/plugins/dll/DllPlugin.check.js +3 -3
  246. package/schemas/plugins/dll/DllReferencePlugin.check.js +3 -3
  247. package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +3 -3
  248. package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.js +3 -3
  249. package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.js +3 -3
  250. package/schemas/plugins/json/JsonModulesPluginGenerator.check.js +3 -3
  251. package/schemas/plugins/json/JsonModulesPluginParser.check.js +3 -3
  252. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +3 -3
  253. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +3 -3
  254. package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.js +3 -3
  255. package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +3 -3
  256. package/schemas/plugins/output/CleanOptions.check.js +7 -0
  257. package/schemas/plugins/output/CleanOptions.json +3 -0
  258. package/schemas/plugins/schemes/HttpUriPlugin.check.js +3 -3
  259. package/schemas/plugins/schemes/VirtualUrlPlugin.check.js +3 -3
  260. package/schemas/plugins/sharing/ConsumeSharedPlugin.check.js +3 -3
  261. package/schemas/plugins/sharing/ProvideSharedPlugin.check.js +3 -3
  262. package/schemas/plugins/sharing/SharePlugin.check.js +3 -3
  263. package/types.d.ts +1482 -358
@@ -21,25 +21,37 @@ const LOADER_TIMING = Symbol("loader timing");
21
21
 
22
22
  /** @typedef {string | { loader: string, options?: LoaderItem["options"], ident?: string | null, type?: string | null, fragment?: string }} LoaderItemInput */
23
23
 
24
+ /**
25
+ * What a loader hands on: content (`null` for a resource without a path),
26
+ * source map and additional data.
27
+ * @typedef {[(string | Buffer | null)?, (string | RawSourceMap | null)?, AdditionalData?]} LoaderResultArgs
28
+ */
29
+
30
+ /**
31
+ * @template C
32
+ * @typedef {(loaderContext: C, resource: string, callback: (err: Error | null, ...args: LoaderResultArgs) => void) => void} ProcessResource
33
+ */
34
+
24
35
  /**
25
36
  * @typedef {object} ProcessOptions
26
- * @property {Buffer | null} resourceBuffer the raw resource buffer
27
- * @property {(loaderContext: EXPECTED_ANY, resource: string, callback: (err: Error | null, ...args: EXPECTED_ANY[]) => void) => void} processResource read and process the resource
37
+ * @property {string | Buffer | null | undefined} resourceBuffer the resource as read, a string when a `readResource` tap answered one
38
+ * @property {ProcessResource<LoaderContext>} processResource read and process the resource
28
39
  */
29
40
 
30
41
  /**
42
+ * @template C
31
43
  * @typedef {object} RunLoaderOptions
32
44
  * @property {string=} resource the resource (with query and fragment)
33
45
  * @property {LoaderItemInput[]=} loaders the loaders to run
34
- * @property {EXPECTED_ANY=} context the loader context to augment and pass to loaders
35
- * @property {ProcessOptions["processResource"]=} processResource custom resource reader/processor
46
+ * @property {C=} context the loader context to augment and pass to loaders
47
+ * @property {ProcessResource<C>=} processResource custom resource reader/processor
36
48
  * @property {((path: string, callback: (err: Error | null, result?: Buffer) => void) => void)=} readResource custom file reader
37
49
  */
38
50
 
39
51
  /**
40
52
  * @typedef {object} RunLoaderResult
41
- * @property {EXPECTED_ANY=} result the loader pipeline result
42
- * @property {Buffer | null=} resourceBuffer the raw resource buffer
53
+ * @property {LoaderResultArgs=} result the loader pipeline result
54
+ * @property {(string | Buffer | null)=} resourceBuffer the resource as read, a string when a `readResource` tap answered one
43
55
  * @property {boolean} cacheable whether the request is cacheable
44
56
  * @property {string[]} notCacheableReasons reasons why the request is not cacheable (e.g. paths of loaders that marked it)
45
57
  * @property {string[]} fileDependencies file dependencies
@@ -47,11 +59,13 @@ const LOADER_TIMING = Symbol("loader timing");
47
59
  * @property {string[]} missingDependencies missing dependencies
48
60
  */
49
61
 
50
- /** @typedef {(...args: EXPECTED_ANY[]) => void} LoaderCallback */
62
+ /** @typedef {(err?: Error | null, ...args: LoaderResultArgs) => void} LoaderCallback */
63
+
64
+ /** @typedef {{ then: (onFulfilled: (content: string | Buffer) => void, onRejected: LoaderCallback) => void }} LoaderThenable */
51
65
 
52
66
  /**
53
67
  * @typedef {object} AdditionalDataKnown
54
- * @property {PreparsedAst} webpackAST the AST webpack should parse instead of the source
68
+ * @property {PreparsedAst=} webpackAST the AST webpack should parse instead of the source
55
69
  */
56
70
 
57
71
  /** @typedef {AdditionalDataKnown & Record<string, EXPECTED_ANY>} AdditionalData */
@@ -66,17 +80,25 @@ const LOADER_TIMING = Symbol("loader timing");
66
80
  */
67
81
 
68
82
  /**
83
+ * What a loader keeps between its pitch and normal phase. Open by default: a
84
+ * loader stores whatever it likes, and reads it back without narrowing.
85
+ * @typedef {{ [key: string]: EXPECTED_ANY }} LoaderData
86
+ */
87
+
88
+ /**
89
+ * @template [OptionsType=LoaderOptions]
90
+ * @template [DataType=LoaderData]
69
91
  * @typedef {object} LoaderEntry
70
92
  * @property {string} request
71
93
  * @property {string} path
72
94
  * @property {string} query
73
95
  * @property {string} fragment
74
- * @property {Record<string, EXPECTED_ANY> | string | undefined} options
96
+ * @property {string | null | undefined | OptionsType} options
75
97
  * @property {string} ident
76
- * @property {LoaderDefinitionFunction<EXPECTED_ANY> | RawLoaderDefinitionFunction<EXPECTED_ANY> | undefined} normal
77
- * @property {PitchLoaderDefinitionFunction<EXPECTED_ANY> | undefined} pitch
98
+ * @property {LoaderDefinitionFunction<OptionsType> | RawLoaderDefinitionFunction<OptionsType> | undefined} normal
99
+ * @property {PitchLoaderDefinitionFunction<OptionsType> | undefined} pitch
78
100
  * @property {boolean | undefined} raw
79
- * @property {Record<string, EXPECTED_ANY> | undefined} data
101
+ * @property {DataType | undefined} data
80
102
  * @property {boolean} pitchExecuted
81
103
  * @property {boolean} normalExecuted
82
104
  * @property {("commonjs" | "module")=} type
@@ -86,7 +108,8 @@ const LOADER_TIMING = Symbol("loader timing");
86
108
  * The members the runner never lets a loader assign. They carry no
87
109
  * documentation, so a type literal loses nothing and keeps `readonly`
88
110
  * @template OptionsType
89
- * @typedef {{ readonly currentRequest: string, readonly data: EXPECTED_ANY, readonly previousRequest: string, readonly query: string | OptionsType, readonly remainingRequest: string, readonly request: string }} LoaderRunnerReadonlyContext
111
+ * @template [DataType=LoaderData]
112
+ * @typedef {{ readonly currentRequest: string, readonly data: DataType, readonly previousRequest: string, readonly query: string | OptionsType, readonly remainingRequest: string, readonly request: string }} LoaderRunnerReadonlyContext
90
113
  */
91
114
 
92
115
  /**
@@ -134,13 +157,14 @@ const LOADER_TIMING = Symbol("loader timing");
134
157
  /**
135
158
  * The properties are added by https://github.com/webpack/loader-runner
136
159
  * @template OptionsType
137
- * @typedef {LoaderRunnerMutableContext<OptionsType> & LoaderRunnerReadonlyContext<OptionsType>} LoaderRunnerLoaderContext
160
+ * @template [DataType=LoaderData]
161
+ * @typedef {LoaderRunnerMutableContext<OptionsType> & LoaderRunnerReadonlyContext<OptionsType, DataType>} LoaderRunnerLoaderContext
138
162
  */
139
163
 
140
164
  /**
141
165
  * @template [OptionsType={}]
142
166
  * @template [ContextAdditions={}]
143
- * @typedef {(this: import("../module/NormalModule").LoaderContext<OptionsType> & ContextAdditions, remainingRequest: string, previousRequest: string, data: Record<string, EXPECTED_ANY>) => string | Buffer | Promise<string | Buffer> | void} PitchLoaderDefinitionFunction
167
+ * @typedef {(this: import("../module/NormalModule").LoaderContext<OptionsType> & ContextAdditions, remainingRequest: string, previousRequest: string, data: LoaderData) => string | Buffer | Promise<string | Buffer> | void} PitchLoaderDefinitionFunction
144
168
  */
145
169
 
146
170
  /**
@@ -181,9 +205,13 @@ const LOADER_TIMING = Symbol("loader timing");
181
205
  * `LoaderRunnerLoaderContext` shape (not re-declared here), with only the fields
182
206
  * the runner assigns internally before a loader runs widened to their mutable
183
207
  * form (nullable `context`/`callback`/`async`, `LoaderObject` loaders).
184
- * @typedef {Omit<LoaderRunnerLoaderContext<EXPECTED_ANY>, "context" | "callback" | "async" | "loaders"> & { context: string | null, callback: LoaderCallback | null, async: (() => LoaderCallback | undefined) | null, loaders: LoaderObject[] }} LoaderContext
208
+ * @typedef {Omit<LoaderRunnerLoaderContext<LoaderOptions>, "context" | "callback" | "async" | "loaders"> & { context: string | null, callback: LoaderCallback | null, async: (() => LoaderCallback | undefined) | null, loaders: LoaderObject[] }} LoaderContext
185
209
  */
186
210
 
211
+ /** @typedef {NonNullable<Exclude<LoaderItem["options"], string>>} LoaderOptions */
212
+
213
+ /** @typedef {[string, string, NonNullable<LoaderObject["data"]>]} PitchArgs */
214
+
187
215
  const HASH_ESCAPE_REGEXP = /#/g;
188
216
 
189
217
  // UTF-8 encoding of the BOM: EF BB BF
@@ -258,19 +286,19 @@ class LoaderObject {
258
286
  this.query = "";
259
287
  /** @type {string} */
260
288
  this.fragment = "";
261
- /** @type {string | { [key: string]: EXPECTED_ANY } | null=} */
289
+ /** @type {LoaderItem["options"]} */
262
290
  this.options = null;
263
291
  /** @type {string | null=} */
264
292
  this.ident = null;
265
293
  /** @type {(string | null)=} */
266
294
  this.type = undefined;
267
- /** @type {LoaderDefinitionFunction<EXPECTED_ANY> | RawLoaderDefinitionFunction<EXPECTED_ANY> | null=} */
295
+ /** @type {LoaderDefinitionFunction<LoaderOptions> | RawLoaderDefinitionFunction<LoaderOptions> | null=} */
268
296
  this.normal = null;
269
- /** @type {PitchLoaderDefinitionFunction<EXPECTED_ANY> | null=} */
297
+ /** @type {PitchLoaderDefinitionFunction<LoaderOptions> | null=} */
270
298
  this.pitch = null;
271
299
  /** @type {boolean | null=} */
272
300
  this.raw = null;
273
- /** @type {Record<string, EXPECTED_ANY> | null=} */
301
+ /** @type {LoaderData | null=} */
274
302
  this.data = null;
275
303
  this.pitchExecuted = false;
276
304
  this.normalExecuted = false;
@@ -340,9 +368,9 @@ const REQUEST_DESCRIPTOR = {
340
368
  };
341
369
 
342
370
  /**
343
- * @param {LoaderDefinitionFunction<EXPECTED_ANY> | RawLoaderDefinitionFunction<EXPECTED_ANY> | PitchLoaderDefinitionFunction<EXPECTED_ANY>} fn the loader function
371
+ * @param {NonNullable<LoaderObject["normal"] | LoaderObject["pitch"]>} fn the loader function
344
372
  * @param {LoaderContext} context the loader context
345
- * @param {EXPECTED_ANY[]} args arguments
373
+ * @param {LoaderResultArgs | PitchArgs} args arguments
346
374
  * @param {LoaderCallback} callback callback
347
375
  * @returns {void}
348
376
  */
@@ -353,7 +381,7 @@ function runSyncOrAsync(fn, context, args, callback) {
353
381
  let reportedError = false;
354
382
 
355
383
  /**
356
- * @param {...EXPECTED_ANY} callbackArgs callback args
384
+ * @param {Parameters<LoaderCallback>} callbackArgs callback args
357
385
  * @returns {void}
358
386
  */
359
387
  function innerCallback(...callbackArgs) {
@@ -387,7 +415,7 @@ function runSyncOrAsync(fn, context, args, callback) {
387
415
 
388
416
  // The runner types its context more loosely than a loader's `this`.
389
417
  const loader =
390
- /** @type {(this: LoaderContext, ...args: EXPECTED_ANY[]) => EXPECTED_ANY} */ (
418
+ /** @type {(this: LoaderContext, ...args: LoaderResultArgs | PitchArgs) => ReturnType<LoaderDefinitionFunction>} */ (
391
419
  fn
392
420
  );
393
421
  const timing =
@@ -408,13 +436,13 @@ function runSyncOrAsync(fn, context, args, callback) {
408
436
  if (
409
437
  result &&
410
438
  typeof result === "object" &&
411
- typeof result.then === "function"
439
+ typeof (/** @type {LoaderThenable} */ (result).then) === "function"
412
440
  ) {
413
- return result.then((/** @type {EXPECTED_ANY} */ r) => {
441
+ return /** @type {LoaderThenable} */ (result).then((r) => {
414
442
  callback(null, r);
415
443
  }, callback);
416
444
  }
417
- return callback(null, result);
445
+ return callback(null, /** @type {string | Buffer} */ (result));
418
446
  }
419
447
  } catch (err) {
420
448
  if (isError) throw err;
@@ -436,7 +464,7 @@ function runSyncOrAsync(fn, context, args, callback) {
436
464
  }
437
465
 
438
466
  /**
439
- * @param {EXPECTED_ANY[]} args arguments
467
+ * @param {LoaderResultArgs} args arguments
440
468
  * @param {boolean | null=} raw whether the loader wants a Buffer
441
469
  * @param {boolean=} fromLoader whether args came from a loader rather than the resource
442
470
  * @returns {void}
@@ -461,8 +489,8 @@ function convertArgs(args, raw, fromLoader) {
461
489
  /**
462
490
  * @param {ProcessOptions} options process options
463
491
  * @param {LoaderContext} loaderContext the loader context
464
- * @param {EXPECTED_ANY[]} args arguments
465
- * @param {(err: Error | null, args?: EXPECTED_ANY[]) => void} callback callback
492
+ * @param {LoaderResultArgs} args arguments
493
+ * @param {(err: Error | null, args?: LoaderResultArgs) => void} callback callback
466
494
  * @param {boolean=} fromLoader whether args came from a loader rather than the resource
467
495
  * @returns {void}
468
496
  */
@@ -504,7 +532,7 @@ function iterateNormalLoaders(
504
532
  /**
505
533
  * @param {ProcessOptions} options process options
506
534
  * @param {LoaderContext} loaderContext the loader context
507
- * @param {(err: Error | null, args?: EXPECTED_ANY[]) => void} callback callback
535
+ * @param {(err: Error | null, args?: LoaderResultArgs) => void} callback callback
508
536
  * @returns {void}
509
537
  */
510
538
  function processResource(options, loaderContext, callback) {
@@ -522,14 +550,19 @@ function processResource(options, loaderContext, callback) {
522
550
 
523
551
  options.resourceBuffer = args[0];
524
552
 
525
- iterateNormalLoaders(options, loaderContext, args, callback);
553
+ iterateNormalLoaders(
554
+ options,
555
+ loaderContext,
556
+ /** @type {LoaderResultArgs} */ (args),
557
+ callback
558
+ );
526
559
  });
527
560
  }
528
561
 
529
562
  /**
530
563
  * @param {ProcessOptions} options process options
531
564
  * @param {LoaderContext} loaderContext the loader context
532
- * @param {(err: Error | null, args?: EXPECTED_ANY[]) => void} callback callback
565
+ * @param {(err: Error | null, args?: LoaderResultArgs) => void} callback callback
533
566
  * @returns {void}
534
567
  */
535
568
  function iteratePitchingLoaders(options, loaderContext, callback) {
@@ -713,7 +746,8 @@ function createLoaderContext(base) {
713
746
  * Marks the request as not cacheable with the given reasons instead of
714
747
  * attributing the currently running loader (used by the host when the cause
715
748
  * lives outside the loader, e.g. in a child compilation of `importModule`).
716
- * @param {LoaderRunnerLoaderContext<EXPECTED_ANY>} loaderContext loader context
749
+ * @template OptionsType
750
+ * @param {LoaderRunnerLoaderContext<OptionsType>} loaderContext loader context
717
751
  * @param {string[]} reasons reasons why the request is not cacheable
718
752
  * @returns {void}
719
753
  */
@@ -815,7 +849,8 @@ const ACCESSORS = {
815
849
  };
816
850
 
817
851
  /**
818
- * @param {RunLoaderOptions} options run options
852
+ * @template [C=LoaderContext]
853
+ * @param {RunLoaderOptions<C>} options run options
819
854
  * @param {(err: Error | null, result: RunLoaderResult) => void} callback callback
820
855
  * @returns {void}
821
856
  */
@@ -826,7 +861,9 @@ module.exports.runLoaders = function runLoaders(options, callback) {
826
861
  // host hook such as `beforeLoaders` can pre-add dependencies or mark the
827
862
  // request non-cacheable before the run; a caller re-running on the same context
828
863
  // should `clearDependencies()` first, to avoid accumulating stale ones.
829
- const provided = options.context;
864
+ const provided =
865
+ /** @type {{ [LOADER_STATE]?: LoaderState } | undefined} */
866
+ (options.context);
830
867
  const loaderContext =
831
868
  provided && provided[LOADER_STATE]
832
869
  ? /** @type {LoaderContext} */ (provided)
@@ -851,8 +888,9 @@ module.exports.runLoaders = function runLoaders(options, callback) {
851
888
  );
852
889
 
853
890
  const processResourceFn =
854
- options.processResource ||
855
- /** @type {(readResource: NonNullable<RunLoaderOptions["readResource"]>, context: LoaderContext, res: string, cb: (err: Error | null, result?: Buffer) => void) => void} */
891
+ /** @type {ProcessResource<LoaderContext> | undefined} */
892
+ (options.processResource) ||
893
+ /** @type {(readResource: NonNullable<RunLoaderOptions<C>["readResource"]>, context: LoaderContext, res: string, cb: (err: Error | null, result?: Buffer) => void) => void} */
856
894
  (
857
895
  (readResource, context, res, cb) => {
858
896
  context.addDependency(res);
@@ -12,18 +12,27 @@ const getLoaderLoadingError = memoize(() =>
12
12
  require("../errors/LoaderLoadingError")
13
13
  );
14
14
 
15
- /** @import { LoaderObject } from "./LoaderRunner" */
15
+ /**
16
+ * @import {
17
+ * LoaderDefinition,
18
+ * LoaderModule,
19
+ * LoaderObject,
20
+ * RawLoaderDefinition
21
+ * } from "./LoaderRunner"
22
+ */
23
+
24
+ /** @typedef {LoaderDefinition | RawLoaderDefinition | LoaderModule} LoadedLoader */
16
25
 
17
26
  /**
18
27
  * Lazily-compiled dynamic `import()`. Built on first use so this file still
19
28
  * parses on Node versions without native `import()` (<13.2), then reused.
20
- * @type {((url: URL) => Promise<EXPECTED_ANY>) | undefined}
29
+ * @type {((url: URL) => Promise<LoadedLoader>) | undefined}
21
30
  */
22
31
  let importModule;
23
32
 
24
33
  /**
25
34
  * @param {LoaderObject} loader the loader to load into
26
- * @param {EXPECTED_ANY} module the loaded module
35
+ * @param {LoadedLoader} module the loaded module
27
36
  * @param {(err?: Error) => void} callback callback
28
37
  * @returns {void}
29
38
  */
@@ -66,17 +75,14 @@ function loadLoader(loader, callback) {
66
75
  // loadable on Node versions that can't parse it (<13.2).
67
76
  // eslint-disable-next-line no-eval
68
77
  const dynamicImport = eval("(url) => import(url)");
69
- importModule = /** @type {(url: URL) => Promise<EXPECTED_ANY>} */ (
78
+ importModule = /** @type {(url: URL) => Promise<LoadedLoader>} */ (
70
79
  dynamicImport
71
80
  );
72
81
  }
73
82
 
74
- importModule(pathToFileURL(loader.path)).then(
75
- (/** @type {EXPECTED_ANY} */ module) => {
76
- handleResult(loader, module, callback);
77
- },
78
- callback
79
- );
83
+ importModule(pathToFileURL(loader.path)).then((module) => {
84
+ handleResult(loader, module, callback);
85
+ }, callback);
80
86
  } catch (err) {
81
87
  callback(/** @type {Error} */ (err));
82
88
  }
@@ -56,8 +56,9 @@ const { JAVASCRIPT_TYPE } = require("./ModuleSourceTypeConstants");
56
56
 
57
57
  /**
58
58
  * Represents the generator runtime component.
59
+ * @template {NormalModule} [TModule=NormalModule]
59
60
  * @typedef {object} UpdateHashContext
60
- * @property {NormalModule} module the module
61
+ * @property {TModule} module the module
61
62
  * @property {ChunkGraph} chunkGraph
62
63
  * @property {RuntimeSpec} runtime
63
64
  * @property {RuntimeTemplate=} runtimeTemplate
@@ -67,6 +68,9 @@ const getModuleParseError = memoize(() =>
67
68
  require("../errors/ModuleParseError")
68
69
  );
69
70
 
71
+ /**
72
+ * @template {NormalModule} [TModule=NormalModule] the module class this generator generates
73
+ */
70
74
  class Generator {
71
75
  /**
72
76
  * Returns generator by type.
@@ -115,7 +119,7 @@ class Generator {
115
119
  /**
116
120
  * Returns the source types available for this module.
117
121
  * @abstract
118
- * @param {NormalModule} module fresh module
122
+ * @param {TModule} module fresh module
119
123
  * @returns {SourceTypes} available types (do not mutate)
120
124
  */
121
125
  getTypes(module) {
@@ -135,7 +139,7 @@ class Generator {
135
139
  /**
136
140
  * Returns the estimated size for the requested source type.
137
141
  * @abstract
138
- * @param {NormalModule} module the module
142
+ * @param {TModule} module the module
139
143
  * @param {SourceType=} type source type
140
144
  * @returns {number} estimate size of the module
141
145
  */
@@ -149,7 +153,7 @@ class Generator {
149
153
  /**
150
154
  * Generates generated code for this runtime module.
151
155
  * @abstract
152
- * @param {NormalModule} module module for which the code should be generated
156
+ * @param {TModule} module module for which the code should be generated
153
157
  * @param {GenerateContext} generateContext context for generate
154
158
  * @returns {Source | null} generated code
155
159
  */
@@ -164,7 +168,7 @@ class Generator {
164
168
 
165
169
  /**
166
170
  * Returns the reason this module cannot be concatenated, when one exists.
167
- * @param {NormalModule} module module for which the bailout reason should be determined
171
+ * @param {TModule} module module for which the bailout reason should be determined
168
172
  * @param {ConcatenationBailoutReasonContext} context context
169
173
  * @returns {string | undefined} reason why this module can't be concatenated, undefined when it can be concatenated
170
174
  */
@@ -175,7 +179,7 @@ class Generator {
175
179
  /**
176
180
  * Updates the hash with the data contributed by this instance.
177
181
  * @param {Hash} hash hash that will be modified
178
- * @param {UpdateHashContext} updateHashContext context for updating hash
182
+ * @param {UpdateHashContext<TModule>} updateHashContext context for updating hash
179
183
  */
180
184
  updateHash(hash, { module, runtime }) {
181
185
  // no nothing
@@ -200,6 +204,10 @@ function generateError(error, module, generateContext) {
200
204
  return generator.generateError(error, module, generateContext);
201
205
  }
202
206
 
207
+ /**
208
+ * @template {NormalModule} [TModule=NormalModule] the module class this generator generates
209
+ * @extends {Generator<TModule>}
210
+ */
203
211
  class ByTypeGenerator extends Generator {
204
212
  /**
205
213
  * Creates an instance of ByTypeGenerator.
@@ -216,7 +224,7 @@ class ByTypeGenerator extends Generator {
216
224
 
217
225
  /**
218
226
  * Returns the source types available for this module.
219
- * @param {NormalModule} module fresh module
227
+ * @param {TModule} module fresh module
220
228
  * @returns {SourceTypes} available types (do not mutate)
221
229
  */
222
230
  getTypes(module) {
@@ -225,7 +233,7 @@ class ByTypeGenerator extends Generator {
225
233
 
226
234
  /**
227
235
  * Returns the estimated size for the requested source type.
228
- * @param {NormalModule} module the module
236
+ * @param {TModule} module the module
229
237
  * @param {SourceType=} type source type
230
238
  * @returns {number} estimate size of the module
231
239
  */
@@ -237,7 +245,7 @@ class ByTypeGenerator extends Generator {
237
245
 
238
246
  /**
239
247
  * Generates generated code for this runtime module.
240
- * @param {NormalModule} module module for which the code should be generated
248
+ * @param {TModule} module module for which the code should be generated
241
249
  * @param {GenerateContext} generateContext context for generate
242
250
  * @returns {Source | null} generated code
243
251
  */
@@ -136,7 +136,7 @@ const {
136
136
  * @typedef {object} AllCodeGenerationSchemas
137
137
  * @property {Set<string>} topLevelDeclarations top level declarations for javascript modules
138
138
  * @property {Set<string>} freeNames free identifier names in the rendered source for javascript modules
139
- * @property {InitFragment<EXPECTED_ANY>[]} chunkInitFragments chunk init fragments for javascript modules
139
+ * @property {InitFragment<import("../javascript/JavascriptModulesPlugin").ChunkRenderContext>[]} chunkInitFragments chunk init fragments for javascript modules
140
140
  * @property {string} externalReexport native external reexport source and attributes
141
141
  * @property {string} exportsSource export definitions left out of a javascript module's source on demand (see `KnownMeta.onDemandExports`), to be placed before its body where it is wrapped
142
142
  * @property {string} exportsBindingSource export definitions left out on demand that read the module's own declarations, to be placed after its body where it is wrapped
@@ -1536,7 +1536,7 @@ Object.defineProperty(Module.prototype, "used", {
1536
1536
  },
1537
1537
  /**
1538
1538
  * Updates used using the provided value.
1539
- * @param {EXPECTED_ANY} value value
1539
+ * @param {never} value value
1540
1540
  */
1541
1541
  set(value) {
1542
1542
  throw new Error(
@@ -203,6 +203,7 @@ const DEPRECATED_PARSER_STATE_ALIASES = {
203
203
  * } from "./NormalModuleFactory"
204
204
  */
205
205
  /** @import Parser, { ParserState, PreparsedAst } from "./Parser" */
206
+ /** @import { LoaderData, LoaderResultArgs } from "../loaders/LoaderRunner" */
206
207
  /**
207
208
  * @typedef {InstanceType<typeof import("../dependencies/esm/ESMExportImportedSpecifierDependency").ESMStarExportsList>} ESMStarExportsList
208
209
  */
@@ -290,7 +291,8 @@ const DEPRECATED_PARSER_STATE_ALIASES = {
290
291
 
291
292
  /**
292
293
  * @template T
293
- * @typedef {NormalModuleLoaderContext<T> & import("../loaders/LoaderRunner").LoaderRunnerLoaderContext<T> & import("../loaders/LoaderPlugin").LoaderPluginLoaderContext & import("../hmr/HotModuleReplacementPlugin").HotModuleReplacementPluginLoaderContext} LoaderContext
294
+ * @template [DataType=LoaderData]
295
+ * @typedef {NormalModuleLoaderContext<T> & import("../loaders/LoaderRunner").LoaderRunnerLoaderContext<T, DataType> & import("../loaders/LoaderPlugin").LoaderPluginLoaderContext & import("../hmr/HotModuleReplacementPlugin").HotModuleReplacementPluginLoaderContext} LoaderContext
294
296
  */
295
297
 
296
298
  /** @typedef {(content: string) => boolean} NoParseFn */
@@ -1163,7 +1165,7 @@ class NormalModule extends Module {
1163
1165
  /** @type {NormalModuleLoaderContext<T>} */
1164
1166
  const loaderContext = {
1165
1167
  version: 2,
1166
- /** @type {LoaderContext<EXPECTED_ANY>["getOptions"]} */
1168
+ /** @type {LoaderContext<T>["getOptions"]} */
1167
1169
  getOptions: (/** @type {Schema=} */ schema = undefined) => {
1168
1170
  const loader = this.getCurrentLoader(
1169
1171
  /** @type {AnyLoaderContext} */
@@ -1411,7 +1413,7 @@ class NormalModule extends Module {
1411
1413
 
1412
1414
  /**
1413
1415
  * @param {Error | null} err err
1414
- * @param {(Result | null)=} result_ result
1416
+ * @param {(LoaderResultArgs | null)=} result_ result
1415
1417
  * @returns {void}
1416
1418
  */
1417
1419
  const processResult = (err, result_) => {
@@ -1523,7 +1525,7 @@ class NormalModule extends Module {
1523
1525
  /**
1524
1526
  * @param {AnyLoaderContext} loaderContext the loader context
1525
1527
  * @param {string} resourcePath the resource Path
1526
- * @param {(err: Error | null, result?: string | Buffer, sourceMap?: Result[1]) => void} callback callback
1528
+ * @param {(err: Error | null, ...args: LoaderResultArgs) => void} callback callback
1527
1529
  * @returns {Promise<void>}
1528
1530
  */
1529
1531
  processResource: async (loaderContext, resourcePath, callback) => {
@@ -1607,7 +1609,7 @@ class NormalModule extends Module {
1607
1609
  loaderContext._compiler =
1608
1610
  loaderContext._module =
1609
1611
  loaderContext.fs =
1610
- /** @type {EXPECTED_ANY} */
1612
+ /** @type {never} */
1611
1613
  (undefined);
1612
1614
 
1613
1615
  if (!result) {
@@ -579,26 +579,28 @@ const ruleSetCompiler = new RuleSetCompiler([
579
579
  */
580
580
  /* eslint-enable jsdoc/type-formatting */
581
581
 
582
+ /** @typedef {[string, Parser<never>, ParserOptions, Generator<never>, GeneratorOptions]} ParserAndGeneratorTuple */
583
+
582
584
  /**
583
585
  * Defines the extract tuple elements type used by this module.
584
- * @template {unknown[]} T
586
+ * @template {ParserAndGeneratorTuple} T
585
587
  * @template {number[]} I
586
588
  * @typedef {{ [K in keyof I]: K extends keyof I ? I[K] extends keyof T ? T[I[K]] : never : never }} ExtractTupleElements
587
589
  */
588
590
 
589
591
  /**
590
592
  * Represents the normal module factory runtime component.
591
- * @template {unknown[]} T
593
+ * @template {ParserAndGeneratorTuple[]} T
592
594
  * @template {number[]} A
593
595
  * @template [R=void]
594
- * @typedef {T extends [infer Head extends [string, ...unknown[]], ...infer Tail extends [string, ...unknown[]][]] ? Record<Head[0], SyncBailHook<ExtractTupleElements<Head, A>, R extends number ? Head[R] : R>> & RecordFactoryFromTuple<Tail, A, R> : unknown } RecordFactoryFromTuple
596
+ * @typedef {T extends [infer Head extends ParserAndGeneratorTuple] ? Record<Head[0], SyncBailHook<ExtractTupleElements<Head, A>, R extends number ? Head[R] : R>> : T extends [infer Head extends ParserAndGeneratorTuple, ...infer Tail extends ParserAndGeneratorTuple[]] ? Record<Head[0], SyncBailHook<ExtractTupleElements<Head, A>, R extends number ? Head[R] : R>> & RecordFactoryFromTuple<Tail, A, R> : never } RecordFactoryFromTuple
595
597
  */
596
598
 
597
599
  /**
598
600
  * Maps each tuple in `T` to a record from its `[0]` key to its `[I]` value.
599
- * @template {unknown[]} T
601
+ * @template {ParserAndGeneratorTuple[]} T
600
602
  * @template {number} I
601
- * @typedef {T extends [infer Head extends [string, ...unknown[]], ...infer Tail extends [string, ...unknown[]][]] ? Record<Head[0], I extends keyof Head ? Head[I] : never> & TupleToTypeMap<Tail, I> : unknown } TupleToTypeMap
603
+ * @typedef {T extends [infer Head extends ParserAndGeneratorTuple] ? Record<Head[0], I extends keyof Head ? Head[I] : never> : T extends [infer Head extends ParserAndGeneratorTuple, ...infer Tail extends ParserAndGeneratorTuple[]] ? Record<Head[0], I extends keyof Head ? Head[I] : never> & TupleToTypeMap<Tail, I> : never } TupleToTypeMap
602
604
  */
603
605
 
604
606
  /** @typedef {TupleToTypeMap<ParsersAndGeneratorsByTypes, 1>} ParserByType */
@@ -1604,12 +1606,8 @@ ${difference}`);
1604
1606
  );
1605
1607
  this.fs.readdir(directory, (err, entries) => {
1606
1608
  if (!err && entries) {
1607
- return suggest(
1608
- prefix,
1609
- requestedName,
1610
- /** @type {string[]} */ (entries),
1611
- false,
1612
- () => next(index + 1)
1609
+ return suggest(prefix, requestedName, entries, false, () =>
1610
+ next(index + 1)
1613
1611
  );
1614
1612
  }
1615
1613
  // The directory is missing, so only a directory the request spells
@@ -1624,12 +1622,8 @@ ${difference}`);
1624
1622
  if (fixedPrefix === undefined) return next(index + 1);
1625
1623
  this.fs.readdir(mismatch.path, (realError, realEntries) => {
1626
1624
  if (realError || !realEntries) return next(index + 1);
1627
- suggest(
1628
- fixedPrefix,
1629
- requestedName,
1630
- /** @type {string[]} */ (realEntries),
1631
- true,
1632
- () => next(index + 1)
1625
+ suggest(fixedPrefix, requestedName, realEntries, true, () =>
1626
+ next(index + 1)
1633
1627
  );
1634
1628
  });
1635
1629
  });
@@ -17,16 +17,23 @@
17
17
 
18
18
  /**
19
19
  * Defines the parser state base type used by this module.
20
+ * @template {NormalModule} [TModule=NormalModule]
20
21
  * @typedef {object} ParserStateBase
21
22
  * @property {string | Buffer} source
22
23
  * @property {NormalModule} current
23
- * @property {NormalModule} module
24
+ * @property {TModule} module the module being parsed
24
25
  * @property {Compilation} compilation
25
26
  * @property {WebpackOptions} options
26
27
  */
27
28
 
28
- /** @typedef {ParserStateBase & Record<string, EXPECTED_ANY>} ParserState */
29
+ /**
30
+ * @template {NormalModule} [TModule=NormalModule]
31
+ * @typedef {ParserStateBase<TModule> & Record<string, EXPECTED_ANY>} ParserState
32
+ */
29
33
 
34
+ /**
35
+ * @template {NormalModule} [TModule=NormalModule] the module class this parser parses
36
+ */
30
37
  class Parser {
31
38
  /* istanbul ignore next */
32
39
  /**