webpack 5.104.1 → 5.105.4

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 (333) hide show
  1. package/README.md +2 -2
  2. package/bin/webpack.js +6 -3
  3. package/lib/APIPlugin.js +85 -15
  4. package/lib/AbstractMethodError.js +1 -0
  5. package/lib/AsyncDependenciesBlock.js +17 -2
  6. package/lib/AsyncDependencyToInitialChunkError.js +3 -0
  7. package/lib/AutomaticPrefetchPlugin.js +1 -1
  8. package/lib/BannerPlugin.js +5 -1
  9. package/lib/CacheFacade.js +2 -2
  10. package/lib/CaseSensitiveModulesWarning.js +1 -0
  11. package/lib/Chunk.js +9 -5
  12. package/lib/ChunkGraph.js +30 -9
  13. package/lib/ChunkGroup.js +6 -3
  14. package/lib/ChunkRenderError.js +9 -2
  15. package/lib/CleanPlugin.js +5 -1
  16. package/lib/CodeGenerationError.js +7 -1
  17. package/lib/CodeGenerationResults.js +10 -3
  18. package/lib/CommentCompilationWarning.js +2 -1
  19. package/lib/Compilation.js +294 -244
  20. package/lib/Compiler.js +4 -3
  21. package/lib/ConcatenationScope.js +2 -1
  22. package/lib/ConcurrentCompilationError.js +3 -3
  23. package/lib/ContextModule.js +255 -112
  24. package/lib/ContextModuleFactory.js +14 -2
  25. package/lib/DefinePlugin.js +15 -8
  26. package/lib/DelegatedModule.js +6 -0
  27. package/lib/DelegatedModuleFactoryPlugin.js +2 -0
  28. package/lib/Dependency.js +7 -2
  29. package/lib/DependencyTemplates.js +3 -2
  30. package/lib/DllModule.js +2 -0
  31. package/lib/DllReferencePlugin.js +1 -0
  32. package/lib/DotenvPlugin.js +11 -5
  33. package/lib/DynamicEntryPlugin.js +8 -1
  34. package/lib/EnvironmentNotSupportAsyncWarning.js +2 -0
  35. package/lib/EvalDevToolModulePlugin.js +3 -0
  36. package/lib/EvalSourceMapDevToolPlugin.js +25 -14
  37. package/lib/ExportsInfo.js +8 -34
  38. package/lib/ExternalModule.js +18 -2
  39. package/lib/ExternalModuleFactoryPlugin.js +9 -2
  40. package/lib/ExternalsPlugin.js +2 -1
  41. package/lib/FalseIIFEUmdWarning.js +1 -0
  42. package/lib/FileSystemInfo.js +49 -25
  43. package/lib/FlagDependencyExportsPlugin.js +8 -1
  44. package/lib/FlagDependencyUsagePlugin.js +9 -7
  45. package/lib/HarmonyLinkingError.js +1 -0
  46. package/lib/HookWebpackError.js +2 -0
  47. package/lib/HotModuleReplacementPlugin.js +16 -2
  48. package/lib/IgnoreWarningsPlugin.js +5 -2
  49. package/lib/InitFragment.js +1 -0
  50. package/lib/InvalidDependenciesModuleWarning.js +1 -0
  51. package/lib/LibManifestPlugin.js +1 -0
  52. package/lib/ManifestPlugin.js +8 -1
  53. package/lib/Module.js +51 -8
  54. package/lib/ModuleBuildError.js +3 -1
  55. package/lib/ModuleDependencyError.js +1 -0
  56. package/lib/ModuleDependencyWarning.js +1 -0
  57. package/lib/ModuleError.js +4 -1
  58. package/lib/ModuleFilenameHelpers.js +4 -2
  59. package/lib/ModuleGraph.js +3 -0
  60. package/lib/ModuleGraphConnection.js +10 -10
  61. package/lib/ModuleHashingError.js +2 -0
  62. package/lib/ModuleInfoHeaderPlugin.js +6 -1
  63. package/lib/ModuleNotFoundError.js +1 -0
  64. package/lib/ModuleParseError.js +5 -1
  65. package/lib/ModuleProfile.js +1 -1
  66. package/lib/ModuleRestoreError.js +2 -0
  67. package/lib/ModuleSourceTypeConstants.js +1 -11
  68. package/lib/ModuleStoreError.js +2 -0
  69. package/lib/ModuleWarning.js +3 -1
  70. package/lib/MultiCompiler.js +11 -7
  71. package/lib/MultiStats.js +5 -5
  72. package/lib/MultiWatching.js +2 -2
  73. package/lib/NoModeWarning.js +1 -0
  74. package/lib/NodeStuffInWebError.js +1 -0
  75. package/lib/NormalModule.js +28 -5
  76. package/lib/NormalModuleFactory.js +20 -4
  77. package/lib/OptionsApply.js +3 -1
  78. package/lib/ProgressPlugin.js +4 -0
  79. package/lib/RawModule.js +2 -0
  80. package/lib/RuntimeModule.js +28 -1
  81. package/lib/RuntimePlugin.js +7 -9
  82. package/lib/RuntimeTemplate.js +14 -7
  83. package/lib/SourceMapDevToolModuleOptionsPlugin.js +1 -0
  84. package/lib/SourceMapDevToolPlugin.js +40 -25
  85. package/lib/Stats.js +3 -2
  86. package/lib/Template.js +10 -5
  87. package/lib/TemplatedPathPlugin.js +4 -2
  88. package/lib/UnhandledSchemeError.js +1 -0
  89. package/lib/UnsupportedFeatureWarning.js +3 -0
  90. package/lib/WarnDeprecatedOptionPlugin.js +1 -0
  91. package/lib/WatchIgnorePlugin.js +1 -1
  92. package/lib/Watching.js +5 -0
  93. package/lib/WebpackError.js +4 -0
  94. package/lib/WebpackOptionsApply.js +74 -44
  95. package/lib/asset/AssetBytesGenerator.js +1 -0
  96. package/lib/asset/AssetGenerator.js +18 -3
  97. package/lib/asset/AssetModulesPlugin.js +48 -2
  98. package/lib/asset/AssetParser.js +4 -0
  99. package/lib/asset/AssetSourceGenerator.js +1 -0
  100. package/lib/asset/RawDataUrlModule.js +9 -1
  101. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -1
  102. package/lib/buildChunkGraph.js +31 -2
  103. package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
  104. package/lib/cache/PackFileCacheStrategy.js +41 -8
  105. package/lib/cache/getLazyHashedEtag.js +13 -4
  106. package/lib/cache/mergeEtags.js +3 -1
  107. package/lib/cli.js +3 -1
  108. package/lib/config/defaults.js +65 -44
  109. package/lib/config/normalization.js +96 -0
  110. package/lib/container/ContainerEntryDependency.js +3 -0
  111. package/lib/container/ContainerEntryModule.js +7 -0
  112. package/lib/container/ContainerExposedDependency.js +1 -0
  113. package/lib/container/FallbackDependency.js +1 -0
  114. package/lib/container/FallbackItemDependency.js +1 -0
  115. package/lib/container/FallbackModule.js +4 -0
  116. package/lib/container/HoistContainerReferencesPlugin.js +6 -0
  117. package/lib/container/ModuleFederationPlugin.js +1 -1
  118. package/lib/container/RemoteModule.js +42 -1
  119. package/lib/css/CssGenerator.js +38 -4
  120. package/lib/css/CssModulesPlugin.js +33 -30
  121. package/lib/css/CssParser.js +12 -9
  122. package/lib/debug/ProfilingPlugin.js +1 -0
  123. package/lib/dependencies/AMDDefineDependency.js +3 -1
  124. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -0
  125. package/lib/dependencies/AMDPlugin.js +1 -1
  126. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +7 -1
  127. package/lib/dependencies/CachedConstDependency.js +1 -0
  128. package/lib/dependencies/CommonJsDependencyHelpers.js +2 -0
  129. package/lib/dependencies/CommonJsExportRequireDependency.js +5 -0
  130. package/lib/dependencies/CommonJsFullRequireDependency.js +2 -0
  131. package/lib/dependencies/CommonJsImportsParserPlugin.js +315 -506
  132. package/lib/dependencies/CommonJsRequireContextDependency.js +2 -2
  133. package/lib/dependencies/CommonJsSelfReferenceDependency.js +1 -0
  134. package/lib/dependencies/ConstDependency.js +1 -0
  135. package/lib/dependencies/ContextDependencyHelpers.js +11 -4
  136. package/lib/dependencies/ContextElementDependency.js +1 -0
  137. package/lib/dependencies/CreateRequireParserPlugin.js +356 -0
  138. package/lib/dependencies/CriticalDependencyWarning.js +1 -0
  139. package/lib/dependencies/CssIcssExportDependency.js +7 -4
  140. package/lib/dependencies/CssIcssSymbolDependency.js +1 -0
  141. package/lib/dependencies/CssUrlDependency.js +2 -3
  142. package/lib/dependencies/ExternalModuleInitFragment.js +4 -1
  143. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +0 -9
  144. package/lib/dependencies/HarmonyAcceptDependency.js +3 -0
  145. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +3 -1
  146. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +4 -8
  147. package/lib/dependencies/HarmonyExportExpressionDependency.js +4 -0
  148. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +8 -1
  149. package/lib/dependencies/HarmonyExportInitFragment.js +17 -3
  150. package/lib/dependencies/HarmonyExportSpecifierDependency.js +4 -0
  151. package/lib/dependencies/HarmonyImportDependency.js +31 -1
  152. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +217 -49
  153. package/lib/dependencies/HarmonyImportSideEffectDependency.js +11 -5
  154. package/lib/dependencies/HarmonyImportSpecifierDependency.js +22 -3
  155. package/lib/dependencies/HarmonyModulesPlugin.js +4 -0
  156. package/lib/dependencies/ImportDependency.js +1 -0
  157. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -0
  158. package/lib/dependencies/ImportMetaPlugin.js +53 -11
  159. package/lib/dependencies/ImportParserPlugin.js +8 -23
  160. package/lib/dependencies/ImportPhase.js +4 -0
  161. package/lib/dependencies/LoaderPlugin.js +3 -0
  162. package/lib/dependencies/ModuleDecoratorDependency.js +1 -0
  163. package/lib/dependencies/ModuleDependency.js +1 -0
  164. package/lib/dependencies/ModuleInitFragmentDependency.js +87 -0
  165. package/lib/dependencies/ProvidedDependency.js +1 -0
  166. package/lib/dependencies/RequireContextPlugin.js +1 -0
  167. package/lib/dependencies/RequireEnsureDependenciesBlock.js +1 -1
  168. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +7 -2
  169. package/lib/dependencies/RuntimeRequirementsDependency.js +1 -0
  170. package/lib/dependencies/WorkerDependency.js +9 -3
  171. package/lib/dependencies/WorkerPlugin.js +1 -0
  172. package/lib/dependencies/getFunctionExpression.js +3 -1
  173. package/lib/electron/ElectronTargetPlugin.js +3 -1
  174. package/lib/errors/BuildCycleError.js +4 -1
  175. package/lib/esm/ModuleChunkFormatPlugin.js +6 -4
  176. package/lib/esm/ModuleChunkLoadingPlugin.js +1 -0
  177. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -0
  178. package/lib/hmr/LazyCompilationPlugin.js +5 -0
  179. package/lib/hmr/lazyCompilationBackend.js +3 -2
  180. package/lib/ids/ChunkModuleIdRangePlugin.js +9 -7
  181. package/lib/ids/DeterministicChunkIdsPlugin.js +1 -0
  182. package/lib/ids/DeterministicModuleIdsPlugin.js +1 -0
  183. package/lib/ids/HashedModuleIdsPlugin.js +3 -8
  184. package/lib/ids/IdHelpers.js +10 -8
  185. package/lib/ids/NamedChunkIdsPlugin.js +7 -5
  186. package/lib/ids/NamedModuleIdsPlugin.js +1 -0
  187. package/lib/ids/OccurrenceChunkIdsPlugin.js +2 -2
  188. package/lib/ids/OccurrenceModuleIdsPlugin.js +18 -10
  189. package/lib/ids/SyncModuleIdsPlugin.js +30 -20
  190. package/lib/javascript/BasicEvaluatedExpression.js +1 -0
  191. package/lib/javascript/EnableChunkLoadingPlugin.js +5 -2
  192. package/lib/javascript/JavascriptModulesPlugin.js +104 -30
  193. package/lib/javascript/JavascriptParser.js +48 -15
  194. package/lib/json/JsonGenerator.js +1 -0
  195. package/lib/json/JsonParser.js +9 -2
  196. package/lib/library/AbstractLibraryPlugin.js +4 -1
  197. package/lib/library/AmdLibraryPlugin.js +2 -1
  198. package/lib/library/AssignLibraryPlugin.js +6 -2
  199. package/lib/library/EnableLibraryPlugin.js +1 -0
  200. package/lib/library/ExportPropertyLibraryPlugin.js +1 -1
  201. package/lib/library/JsonpLibraryPlugin.js +1 -1
  202. package/lib/library/ModuleLibraryPlugin.js +130 -13
  203. package/lib/library/SystemLibraryPlugin.js +4 -1
  204. package/lib/library/UmdLibraryPlugin.js +4 -3
  205. package/lib/logging/Logger.js +9 -5
  206. package/lib/logging/createConsoleLogger.js +4 -0
  207. package/lib/logging/truncateArgs.js +1 -1
  208. package/lib/node/CommonJsChunkLoadingPlugin.js +6 -4
  209. package/lib/node/NodeEnvironmentPlugin.js +1 -0
  210. package/lib/node/NodeTargetPlugin.js +10 -1
  211. package/lib/node/NodeTemplatePlugin.js +1 -0
  212. package/lib/node/NodeWatchFileSystem.js +6 -0
  213. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +1 -0
  214. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +1 -0
  215. package/lib/node/ReadFileCompileWasmPlugin.js +1 -0
  216. package/lib/node/RequireChunkLoadingRuntimeModule.js +1 -0
  217. package/lib/node/nodeConsole.js +18 -1
  218. package/lib/optimize/AggressiveMergingPlugin.js +2 -1
  219. package/lib/optimize/AggressiveSplittingPlugin.js +15 -6
  220. package/lib/optimize/ConcatenatedModule.js +36 -19
  221. package/lib/optimize/FlagIncludedChunksPlugin.js +11 -1
  222. package/lib/optimize/InnerGraph.js +5 -3
  223. package/lib/optimize/InnerGraphPlugin.js +25 -25
  224. package/lib/optimize/LimitChunkCountPlugin.js +3 -2
  225. package/lib/optimize/MangleExportsPlugin.js +14 -2
  226. package/lib/optimize/MergeDuplicateChunksPlugin.js +5 -1
  227. package/lib/optimize/MinChunkSizePlugin.js +5 -2
  228. package/lib/optimize/ModuleConcatenationPlugin.js +23 -5
  229. package/lib/optimize/RealContentHashPlugin.js +37 -27
  230. package/lib/optimize/RemoveParentModulesPlugin.js +12 -3
  231. package/lib/optimize/RuntimeChunkPlugin.js +3 -5
  232. package/lib/optimize/SideEffectsFlagPlugin.js +3 -0
  233. package/lib/optimize/SplitChunksPlugin.js +23 -5
  234. package/lib/performance/AssetsOverSizeLimitWarning.js +7 -2
  235. package/lib/performance/EntrypointsOverSizeLimitWarning.js +7 -2
  236. package/lib/performance/NoAsyncChunksWarning.js +1 -0
  237. package/lib/performance/SizeLimitsPlugin.js +7 -6
  238. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +2 -0
  239. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +3 -1
  240. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +1 -0
  241. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +1 -0
  242. package/lib/rules/BasicEffectRulePlugin.js +2 -0
  243. package/lib/rules/BasicMatcherRulePlugin.js +3 -0
  244. package/lib/rules/ObjectMatcherRulePlugin.js +5 -1
  245. package/lib/rules/RuleSetCompiler.js +6 -0
  246. package/lib/runtime/AsyncModuleRuntimeModule.js +1 -0
  247. package/lib/runtime/ChunkNameRuntimeModule.js +1 -0
  248. package/lib/runtime/CompatRuntimeModule.js +1 -0
  249. package/lib/runtime/EnsureChunkRuntimeModule.js +1 -0
  250. package/lib/runtime/GetChunkFilenameRuntimeModule.js +5 -0
  251. package/lib/runtime/GetFullHashRuntimeModule.js +1 -0
  252. package/lib/runtime/GetMainFilenameRuntimeModule.js +2 -0
  253. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -0
  254. package/lib/runtime/LoadScriptRuntimeModule.js +2 -0
  255. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +16 -32
  256. package/lib/runtime/PublicPathRuntimeModule.js +1 -0
  257. package/lib/runtime/StartupChunkDependenciesPlugin.js +2 -0
  258. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -0
  259. package/lib/runtime/StartupEntrypointRuntimeModule.js +1 -0
  260. package/lib/runtime/ToBinaryRuntimeModule.js +14 -6
  261. package/lib/schemes/HttpUriPlugin.js +39 -20
  262. package/lib/schemes/VirtualUrlPlugin.js +28 -2
  263. package/lib/serialization/BinaryMiddleware.js +4 -0
  264. package/lib/serialization/FileMiddleware.js +9 -4
  265. package/lib/serialization/ObjectMiddleware.js +34 -11
  266. package/lib/serialization/PlainObjectSerializer.js +2 -0
  267. package/lib/sharing/ConsumeSharedModule.js +78 -1
  268. package/lib/sharing/ConsumeSharedPlugin.js +5 -4
  269. package/lib/sharing/ProvideSharedModule.js +4 -0
  270. package/lib/sharing/ProvideSharedPlugin.js +24 -25
  271. package/lib/sharing/resolveMatchedConfigs.js +2 -2
  272. package/lib/sharing/utils.js +8 -6
  273. package/lib/stats/DefaultStatsFactoryPlugin.js +20 -12
  274. package/lib/stats/DefaultStatsPrinterPlugin.js +6 -5
  275. package/lib/stats/StatsFactory.js +2 -2
  276. package/lib/url/URLParserPlugin.js +5 -3
  277. package/lib/util/AppendOnlyStackedSet.js +78 -0
  278. package/lib/util/Hash.js +1 -0
  279. package/lib/util/IterableHelpers.js +1 -0
  280. package/lib/util/LazyBucketSortedSet.js +1 -0
  281. package/lib/util/LazySet.js +1 -0
  282. package/lib/util/ParallelismFactorCalculator.js +1 -0
  283. package/lib/util/SortableSet.js +1 -0
  284. package/lib/util/StringXor.js +1 -0
  285. package/lib/util/binarySearchBounds.js +15 -8
  286. package/lib/util/chainedImports.js +1 -1
  287. package/lib/util/cleverMerge.js +6 -1
  288. package/lib/util/comparators.js +21 -1
  289. package/lib/util/compileBooleanMatcher.js +3 -3
  290. package/lib/util/concatenate.js +3 -2
  291. package/lib/util/conventions.js +3 -2
  292. package/lib/util/deterministicGrouping.js +13 -1
  293. package/lib/util/extractSourceMap.js +12 -13
  294. package/lib/util/findGraphRoots.js +79 -109
  295. package/lib/util/fs.js +15 -19
  296. package/lib/util/hash/BatchedHash.js +4 -0
  297. package/lib/util/hash/BulkUpdateHash.js +8 -1
  298. package/lib/util/hash/hash-digest.js +1 -0
  299. package/lib/util/hash/wasm-hash.js +18 -2
  300. package/lib/util/identifier.js +7 -2
  301. package/lib/util/magicComment.js +1 -1
  302. package/lib/util/propertyName.js +1 -1
  303. package/lib/util/registerExternalSerializer.js +1 -0
  304. package/lib/util/runtime.js +15 -1
  305. package/lib/util/semver.js +1 -0
  306. package/lib/util/serialization.js +2 -2
  307. package/lib/wasm/EnableWasmLoadingPlugin.js +2 -0
  308. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +11 -3
  309. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -0
  310. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -2
  311. package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +5 -1
  312. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +3 -0
  313. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +2 -0
  314. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +7 -3
  315. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +2 -2
  316. package/lib/wasm-sync/WebAssemblyParser.js +3 -1
  317. package/lib/web/FetchCompileWasmPlugin.js +1 -0
  318. package/lib/web/JsonpChunkLoadingPlugin.js +1 -0
  319. package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -0
  320. package/lib/webpack.js +16 -4
  321. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +1 -0
  322. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +2 -0
  323. package/package.json +40 -40
  324. package/schemas/WebpackOptions.check.js +1 -1
  325. package/schemas/WebpackOptions.json +121 -55
  326. package/schemas/plugins/BannerPlugin.json +2 -2
  327. package/schemas/plugins/IgnorePlugin.json +1 -1
  328. package/schemas/plugins/ManifestPlugin.json +3 -3
  329. package/schemas/plugins/ProgressPlugin.json +1 -1
  330. package/schemas/plugins/SourceMapDevToolPlugin.json +2 -2
  331. package/schemas/plugins/schemes/HttpUriPlugin.json +1 -1
  332. package/schemas/plugins/schemes/VirtualUrlPlugin.json +3 -3
  333. package/types.d.ts +677 -230
@@ -18,8 +18,8 @@ class CommonJsRequireContextDependency extends ContextDependency {
18
18
  /**
19
19
  * @param {ContextDependencyOptions} options options for the context module
20
20
  * @param {Range} range location in source code
21
- * @param {Range | undefined} valueRange location of the require call
22
- * @param {boolean | string} inShorthand true or name
21
+ * @param {Range=} valueRange location of the require call
22
+ * @param {boolean | string=} inShorthand true or name
23
23
  * @param {string=} context context
24
24
  */
25
25
  constructor(options, range, valueRange, inShorthand, context) {
@@ -118,6 +118,7 @@ CommonJsSelfReferenceDependency.Template = class CommonJsSelfReferenceDependency
118
118
  );
119
119
  }
120
120
 
121
+ /** @type {string} */
121
122
  let base;
122
123
  switch (dep.base) {
123
124
  case "exports":
@@ -33,6 +33,7 @@ class ConstDependency extends NullDependency {
33
33
  this.runtimeRequirements = runtimeRequirements
34
34
  ? new Set(runtimeRequirements)
35
35
  : null;
36
+ /** @type {undefined | string} */
36
37
  this._hashUpdate = undefined;
37
38
  }
38
39
 
@@ -26,7 +26,7 @@ const quoteMeta = (str) => str.replace(/[-[\]\\/{}()*+?.^$|]/g, "\\$&");
26
26
 
27
27
  /**
28
28
  * @param {string} prefix prefix
29
- * @returns {{prefix: string, context: string}} result
29
+ * @returns {{ prefix: string, context: string }} result
30
30
  */
31
31
  const splitContextFromPrefix = (prefix) => {
32
32
  const idx = prefix.lastIndexOf("/");
@@ -42,17 +42,23 @@ const splitContextFromPrefix = (prefix) => {
42
42
  };
43
43
 
44
44
  /** @typedef {Partial<Omit<ContextDependencyOptions, "resource">>} PartialContextDependencyOptions */
45
- /** @typedef {{ new(options: ContextDependencyOptions, range: Range, valueRange: Range, ...args: EXPECTED_ANY[]): ContextDependency }} ContextDependencyConstructor */
45
+ /** @typedef {{ new (options: ContextDependencyOptions, range: Range, valueRange: Range, ...args: EXPECTED_ANY[]): ContextDependency }} ContextDependencyConstructor */
46
46
 
47
47
  /**
48
- * @param {ContextDependencyConstructor} Dep the Dependency class
48
+ * @template T
49
+ * @typedef {T extends new (options: ContextDependencyOptions, range: Range, valueRange: Range, ...remains: infer R) => EXPECTED_ANY ? R : []} GetAdditionalDepArgs
50
+ */
51
+
52
+ /**
53
+ * @template {ContextDependencyConstructor} T
54
+ * @param {T} Dep the Dependency class
49
55
  * @param {Range} range source range
50
56
  * @param {BasicEvaluatedExpression} param context param
51
57
  * @param {Expression} expr expr
52
58
  * @param {Pick<JavascriptParserOptions, `${"expr" | "wrapped"}Context${"Critical" | "Recursive" | "RegExp"}` | "exprContextRequest">} options options for context creation
53
59
  * @param {PartialContextDependencyOptions} contextOptions options for the ContextModule
54
60
  * @param {JavascriptParser} parser the parser
55
- * @param {...EXPECTED_ANY} depArgs depArgs
61
+ * @param {GetAdditionalDepArgs<T>} depArgs depArgs
56
62
  * @returns {ContextDependency} the created Dependency
57
63
  */
58
64
  module.exports.create = (
@@ -216,6 +222,7 @@ module.exports.create = (
216
222
  ...depArgs
217
223
  );
218
224
  dep.loc = /** @type {DependencyLocation} */ (expr.loc);
225
+ /** @type {Replaces} */
219
226
  const replaces = [];
220
227
  if (prefixRange) {
221
228
  replaces.push({
@@ -82,6 +82,7 @@ class ContextElementDependency extends ModuleDependency {
82
82
  */
83
83
  getReferencedExports(moduleGraph, runtime) {
84
84
  if (!this.referencedExports) return Dependency.EXPORTS_OBJECT_REFERENCED;
85
+ /** @type {ReferencedExports} */
85
86
  const refs = [];
86
87
  for (const referencedExport of this.referencedExports) {
87
88
  if (
@@ -0,0 +1,356 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+
6
+ "use strict";
7
+
8
+ const { fileURLToPath } = require("url");
9
+ const WebpackError = require("../WebpackError");
10
+ const BasicEvaluatedExpression = require("../javascript/BasicEvaluatedExpression");
11
+ const { VariableInfo } = require("../javascript/JavascriptParser");
12
+ const {
13
+ evaluateToString,
14
+ expressionIsUnsupported,
15
+ toConstantDependency
16
+ } = require("../javascript/JavascriptParserHelpers");
17
+ const CommonJsImportsParserPlugin = require("./CommonJsImportsParserPlugin");
18
+ const ConstDependency = require("./ConstDependency");
19
+
20
+ /** @typedef {import("estree").CallExpression} CallExpression */
21
+ /** @typedef {import("estree").Expression} Expression */
22
+ /** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
23
+ /** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
24
+ /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
25
+ /** @typedef {import("../javascript/JavascriptParser").ImportSource} ImportSource */
26
+ /** @typedef {import("../javascript/JavascriptParser").Range} Range */
27
+
28
+ /**
29
+ * @typedef {object} CommonJsImportSettings
30
+ * @property {string=} name
31
+ * @property {string} context
32
+ */
33
+
34
+ const createRequireSpecifierTag = Symbol("createRequire");
35
+ const createdRequireIdentifierTag = Symbol("createRequire()");
36
+
37
+ const PLUGIN_NAME = "CreateRequireParserPlugin";
38
+
39
+ const {
40
+ createProcessResolveHandler,
41
+ createRequireAsExpressionHandler,
42
+ createRequireCacheDependency,
43
+ createRequireHandler
44
+ } = CommonJsImportsParserPlugin;
45
+
46
+ class CreateRequireParserPlugin {
47
+ /**
48
+ * @param {JavascriptParserOptions} options parser options
49
+ */
50
+ constructor(options) {
51
+ this.options = options;
52
+ }
53
+
54
+ /**
55
+ * @param {JavascriptParser} parser the parser
56
+ * @returns {void}
57
+ */
58
+ apply(parser) {
59
+ const options = this.options;
60
+ if (!options.createRequire) return;
61
+
62
+ const getContext = () => {
63
+ if (parser.currentTagData) {
64
+ const { context } =
65
+ /** @type {CommonJsImportSettings} */
66
+ (parser.currentTagData);
67
+ return context;
68
+ }
69
+ };
70
+
71
+ /**
72
+ * @param {string | symbol} tag tag
73
+ */
74
+ const tapRequireExpressionTag = (tag) => {
75
+ parser.hooks.typeof
76
+ .for(tag)
77
+ .tap(
78
+ PLUGIN_NAME,
79
+ toConstantDependency(parser, JSON.stringify("function"))
80
+ );
81
+ parser.hooks.evaluateTypeof
82
+ .for(tag)
83
+ .tap(PLUGIN_NAME, evaluateToString("function"));
84
+ };
85
+
86
+ /**
87
+ * @param {Expression} expr expression
88
+ * @returns {boolean} true when set undefined
89
+ */
90
+ const defineUndefined = (expr) => {
91
+ const dep = new ConstDependency(
92
+ "undefined",
93
+ /** @type {Range} */ (expr.range)
94
+ );
95
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
96
+ parser.state.module.addPresentationalDependency(dep);
97
+ return false;
98
+ };
99
+
100
+ const requireCache = createRequireCacheDependency(parser);
101
+ const requireAsExpressionHandler = createRequireAsExpressionHandler(
102
+ parser,
103
+ options,
104
+ getContext
105
+ );
106
+ const createRequireCallHandler = createRequireHandler(
107
+ parser,
108
+ options,
109
+ getContext
110
+ );
111
+ const processResolve = createProcessResolveHandler(
112
+ parser,
113
+ options,
114
+ getContext
115
+ );
116
+
117
+ /** @type {ImportSource[]} */
118
+ let moduleNames = [];
119
+ /** @type {string | undefined} */
120
+ let specifierName;
121
+
122
+ if (options.createRequire === true) {
123
+ moduleNames = ["module", "node:module"];
124
+ specifierName = "createRequire";
125
+ } else if (typeof options.createRequire === "string") {
126
+ /** @type {undefined | string} */
127
+ let parsedModuleName;
128
+ const match = /^(.*) from (.*)$/.exec(options.createRequire);
129
+ if (match) {
130
+ [, specifierName, parsedModuleName] = match;
131
+ }
132
+ if (!specifierName || !parsedModuleName) {
133
+ const err = new WebpackError(
134
+ `Parsing javascript parser option "createRequire" failed, got ${JSON.stringify(
135
+ options.createRequire
136
+ )}`
137
+ );
138
+ err.details =
139
+ 'Expected string in format "createRequire from module", where "createRequire" is specifier name and "module" name of the module';
140
+ throw err;
141
+ }
142
+ moduleNames = [parsedModuleName];
143
+ } else {
144
+ return;
145
+ }
146
+
147
+ /**
148
+ * @param {CallExpression} expr call expression
149
+ * @returns {string | void} context
150
+ */
151
+ const parseCreateRequireArguments = (expr) => {
152
+ const args = expr.arguments;
153
+ if (args.length !== 1) {
154
+ const err = new WebpackError(
155
+ "module.createRequire supports only one argument."
156
+ );
157
+ err.loc = /** @type {DependencyLocation} */ (expr.loc);
158
+ parser.state.module.addWarning(err);
159
+ return;
160
+ }
161
+ const arg = args[0];
162
+ const evaluated = parser.evaluateExpression(arg);
163
+ if (!evaluated.isString()) {
164
+ const err = new WebpackError(
165
+ "module.createRequire failed parsing argument."
166
+ );
167
+ err.loc = /** @type {DependencyLocation} */ (arg.loc);
168
+ parser.state.module.addWarning(err);
169
+ return;
170
+ }
171
+ const ctx = /** @type {string} */ (evaluated.string).startsWith("file://")
172
+ ? fileURLToPath(/** @type {string} */ (evaluated.string))
173
+ : /** @type {string} */ (evaluated.string);
174
+ // argument always should be a filename
175
+ return ctx.slice(0, ctx.lastIndexOf(ctx.startsWith("/") ? "/" : "\\"));
176
+ };
177
+
178
+ tapRequireExpressionTag(createdRequireIdentifierTag);
179
+ tapRequireExpressionTag(createRequireSpecifierTag);
180
+
181
+ parser.hooks.evaluateCallExpression
182
+ .for(createRequireSpecifierTag)
183
+ .tap(PLUGIN_NAME, (expr) => {
184
+ const context = parseCreateRequireArguments(expr);
185
+ if (context === undefined) return;
186
+ const ident = parser.evaluatedVariable({
187
+ tag: createdRequireIdentifierTag,
188
+ data: { context },
189
+ next: undefined
190
+ });
191
+
192
+ return new BasicEvaluatedExpression()
193
+ .setIdentifier(ident, ident, () => [])
194
+ .setSideEffects(false)
195
+ .setRange(/** @type {Range} */ (expr.range));
196
+ });
197
+
198
+ parser.hooks.unhandledExpressionMemberChain
199
+ .for(createdRequireIdentifierTag)
200
+ .tap(PLUGIN_NAME, (expr, members) =>
201
+ expressionIsUnsupported(
202
+ parser,
203
+ `createRequire().${members.join(".")} is not supported by webpack.`
204
+ )(expr)
205
+ );
206
+ parser.hooks.canRename
207
+ .for(createdRequireIdentifierTag)
208
+ .tap(PLUGIN_NAME, () => true);
209
+ parser.hooks.canRename
210
+ .for(createRequireSpecifierTag)
211
+ .tap(PLUGIN_NAME, () => true);
212
+ parser.hooks.rename
213
+ .for(createRequireSpecifierTag)
214
+ .tap(PLUGIN_NAME, defineUndefined);
215
+ parser.hooks.expression
216
+ .for(createdRequireIdentifierTag)
217
+ .tap(PLUGIN_NAME, requireAsExpressionHandler);
218
+ parser.hooks.call
219
+ .for(createdRequireIdentifierTag)
220
+ .tap(PLUGIN_NAME, createRequireCallHandler(false));
221
+
222
+ parser.hooks.import.tap(
223
+ {
224
+ name: PLUGIN_NAME,
225
+ stage: -10
226
+ },
227
+ (statement, source) => {
228
+ if (
229
+ !moduleNames.includes(source) ||
230
+ statement.specifiers.length !== 1 ||
231
+ statement.specifiers[0].type !== "ImportSpecifier" ||
232
+ statement.specifiers[0].imported.type !== "Identifier" ||
233
+ statement.specifiers[0].imported.name !== specifierName
234
+ ) {
235
+ return;
236
+ }
237
+ // clear for 'import { createRequire as x } from "module"'
238
+ // if any other specifier was used import module
239
+ const clearDep = new ConstDependency(
240
+ parser.isAsiPosition(/** @type {Range} */ (statement.range)[0])
241
+ ? ";"
242
+ : "",
243
+ /** @type {Range} */ (statement.range)
244
+ );
245
+ clearDep.loc = /** @type {DependencyLocation} */ (statement.loc);
246
+ parser.state.module.addPresentationalDependency(clearDep);
247
+ parser.unsetAsiPosition(/** @type {Range} */ (statement.range)[1]);
248
+ return true;
249
+ }
250
+ );
251
+ parser.hooks.importSpecifier.tap(
252
+ {
253
+ name: PLUGIN_NAME,
254
+ stage: -10
255
+ },
256
+ (statement, source, id, name) => {
257
+ if (!moduleNames.includes(source) || id !== specifierName) return;
258
+ parser.tagVariable(name, createRequireSpecifierTag);
259
+ return true;
260
+ }
261
+ );
262
+ parser.hooks.preDeclarator.tap(PLUGIN_NAME, (declarator) => {
263
+ if (
264
+ declarator.id.type !== "Identifier" ||
265
+ !declarator.init ||
266
+ declarator.init.type !== "CallExpression" ||
267
+ declarator.init.callee.type !== "Identifier"
268
+ ) {
269
+ return;
270
+ }
271
+ const variableInfo = parser.getVariableInfo(declarator.init.callee.name);
272
+ if (
273
+ variableInfo instanceof VariableInfo &&
274
+ variableInfo.tagInfo &&
275
+ variableInfo.tagInfo.tag === createRequireSpecifierTag
276
+ ) {
277
+ const context = parseCreateRequireArguments(declarator.init);
278
+ if (context === undefined) return;
279
+ parser.tagVariable(declarator.id.name, createdRequireIdentifierTag, {
280
+ name: declarator.id.name,
281
+ context
282
+ });
283
+ return true;
284
+ }
285
+ });
286
+
287
+ parser.hooks.memberChainOfCallMemberChain
288
+ .for(createRequireSpecifierTag)
289
+ .tap(PLUGIN_NAME, (expr, calleeMembers, callExpr, members) => {
290
+ if (
291
+ calleeMembers.length !== 0 ||
292
+ members.length !== 1 ||
293
+ members[0] !== "cache"
294
+ ) {
295
+ return;
296
+ }
297
+ // createRequire().cache
298
+ const context = parseCreateRequireArguments(callExpr);
299
+ if (context === undefined) return;
300
+ return requireCache(expr);
301
+ });
302
+ parser.hooks.callMemberChainOfCallMemberChain
303
+ .for(createRequireSpecifierTag)
304
+ .tap(PLUGIN_NAME, (expr, calleeMembers, innerCallExpression, members) => {
305
+ if (
306
+ calleeMembers.length !== 0 ||
307
+ members.length !== 1 ||
308
+ members[0] !== "resolve"
309
+ ) {
310
+ return;
311
+ }
312
+ // createRequire().resolve()
313
+ return processResolve(expr, false);
314
+ });
315
+ parser.hooks.expressionMemberChain
316
+ .for(createdRequireIdentifierTag)
317
+ .tap(PLUGIN_NAME, (expr, members) => {
318
+ // require.cache
319
+ if (members.length === 1 && members[0] === "cache") {
320
+ return requireCache(expr);
321
+ }
322
+ });
323
+ parser.hooks.callMemberChain
324
+ .for(createdRequireIdentifierTag)
325
+ .tap(PLUGIN_NAME, (expr, members) => {
326
+ // require.resolve()
327
+ if (members.length === 1 && members[0] === "resolve") {
328
+ return processResolve(expr, false);
329
+ }
330
+ });
331
+ parser.hooks.expression
332
+ .for(createRequireSpecifierTag)
333
+ .tap(PLUGIN_NAME, (expr) => {
334
+ const clearDep = new ConstDependency(
335
+ "/* createRequire */ undefined",
336
+ /** @type {Range} */ (expr.range)
337
+ );
338
+ clearDep.loc = /** @type {DependencyLocation} */ (expr.loc);
339
+ parser.state.module.addPresentationalDependency(clearDep);
340
+ return true;
341
+ });
342
+ parser.hooks.call
343
+ .for(createRequireSpecifierTag)
344
+ .tap(PLUGIN_NAME, (expr) => {
345
+ const clearDep = new ConstDependency(
346
+ "/* createRequire() */ undefined",
347
+ /** @type {Range} */ (expr.range)
348
+ );
349
+ clearDep.loc = /** @type {DependencyLocation} */ (expr.loc);
350
+ parser.state.module.addPresentationalDependency(clearDep);
351
+ return true;
352
+ });
353
+ }
354
+ }
355
+
356
+ module.exports = CreateRequireParserPlugin;
@@ -15,6 +15,7 @@ class CriticalDependencyWarning extends WebpackError {
15
15
  constructor(message) {
16
16
  super();
17
17
 
18
+ /** @type {string} */
18
19
  this.name = "CriticalDependencyWarning";
19
20
  this.message = `Critical dependency: ${message}`;
20
21
  }
@@ -37,6 +37,8 @@ const getCssParser = memoize(() => require("../css/CssParser"));
37
37
  /** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
38
38
  /** @typedef {import("../css/CssParser").Range} Range */
39
39
 
40
+ /** @typedef {(name: string) => string} ExportsConventionFn */
41
+
40
42
  /**
41
43
  * @param {string} local css local
42
44
  * @param {CssModule} module module
@@ -60,7 +62,7 @@ const getLocalIdent = (local, module, chunkGraph, runtimeTemplate) => {
60
62
 
61
63
  let localIdentHash = "";
62
64
 
63
- if (/\[(fullhash|hash)\]/.test(localIdentName)) {
65
+ if (/\[(?:fullhash|hash)\]/.test(localIdentName)) {
64
66
  const hashSalt = generator.options.localIdentHashSalt;
65
67
  const hashDigest =
66
68
  /** @type {string} */
@@ -113,8 +115,8 @@ const getLocalIdent = (local, module, chunkGraph, runtimeTemplate) => {
113
115
  if (typeof id !== "string") return id;
114
116
 
115
117
  return id
116
- .replace(/^([.-]|[^a-zA-Z0-9_-])+/, "")
117
- .replace(/[^a-zA-Z0-9_-]+/g, "_");
118
+ .replace(/^([.-]|[^a-z0-9_-])+/i, "")
119
+ .replace(/[^a-z0-9_-]+/gi, "_");
118
120
  },
119
121
  filename: relativeResourcePath,
120
122
  hash: localIdentHash,
@@ -135,7 +137,7 @@ const getLocalIdent = (local, module, chunkGraph, runtimeTemplate) => {
135
137
  }
136
138
 
137
139
  // Protect the first character from unsupported values
138
- return localIdent.replace(/^((-?[0-9])|--)/, "_$1");
140
+ return localIdent.replace(/^((-?\d)|--)/, "_$1");
139
141
  };
140
142
 
141
143
  // 0 - replace, 1 - replace, 2 - append, 2 - once
@@ -170,6 +172,7 @@ class CssIcssExportDependency extends NullDependency {
170
172
  this.interpolate = interpolate;
171
173
  this.exportMode = exportMode;
172
174
  this.exportType = exportType;
175
+ /** @type {undefined | string} */
173
176
  this._hashUpdate = undefined;
174
177
  }
175
178
 
@@ -36,6 +36,7 @@ class CssIcssSymbolDependency extends NullDependency {
36
36
  this.symbol = symbol;
37
37
  this.range = range;
38
38
  this.isReference = isReference;
39
+ /** @type {undefined | string} */
39
40
  this._hashUpdate = undefined;
40
41
  }
41
42
 
@@ -16,6 +16,7 @@ const ModuleDependency = require("./ModuleDependency");
16
16
  /** @typedef {import("../DependencyTemplate").CssDependencyTemplateContext} DependencyTemplateContext */
17
17
  /** @typedef {import("../Module")} Module */
18
18
  /** @typedef {import("../Module").CodeGenerationResult} CodeGenerationResult */
19
+ /** @typedef {import("../Module").CodeGenerationResultData} CodeGenerationResultData */
19
20
  /** @typedef {import("../javascript/JavascriptParser").Range} Range */
20
21
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
21
22
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
@@ -173,9 +174,7 @@ CssUrlDependency.Template = class CssUrlDependencyTemplate extends (
173
174
  return "data:,";
174
175
  }
175
176
  const codeGen = codeGenerationResults.get(module, runtime);
176
- const data =
177
- /** @type {NonNullable<CodeGenerationResult["data"]>} */
178
- (codeGen.data);
177
+ const data = codeGen.data;
179
178
  if (!data) return "data:,";
180
179
  const url = data.get("url");
181
180
  if (!url || !url["css-url"]) return "data:,";
@@ -13,7 +13,8 @@ const makeSerializable = require("../util/makeSerializable");
13
13
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
14
14
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
15
15
  /** @typedef {{ name: string, value?: string }[]} ArrayImportSpecifiers */
16
- /** @typedef {Map<string, Set<string>>} ImportSpecifiers */
16
+ /** @typedef {Set<string>} ImportSpecifier */
17
+ /** @typedef {Map<string, ImportSpecifier>} ImportSpecifiers */
17
18
 
18
19
  /**
19
20
  * @extends {InitFragment<GenerateContext>}
@@ -38,6 +39,7 @@ class ExternalModuleInitFragment extends InitFragment {
38
39
  for (const { name, value } of specifiers) {
39
40
  let specifiers = this.specifiers.get(name);
40
41
  if (!specifiers) {
42
+ /** @type {ImportSpecifier} */
41
43
  specifiers = new Set();
42
44
  this.specifiers.set(name, specifiers);
43
45
  }
@@ -77,6 +79,7 @@ class ExternalModuleInitFragment extends InitFragment {
77
79
  * @returns {string | Source | undefined} the source code that will be included as initialization code
78
80
  */
79
81
  getContent({ runtimeRequirements }) {
82
+ /** @type {string[]} */
80
83
  const namedImports = [];
81
84
 
82
85
  for (const [name, specifiers] of this.specifiers) {
@@ -31,15 +31,6 @@ class ExternalModuleInitFragmentDependency extends NullDependency {
31
31
  this.default = defaultImport;
32
32
  }
33
33
 
34
- /**
35
- * @returns {string} hash update
36
- */
37
- _createHashUpdate() {
38
- return `${this.importedModule}${JSON.stringify(this.specifiers)}${
39
- this.default || "null"
40
- }`;
41
- }
42
-
43
34
  /**
44
35
  * @param {ObjectSerializerContext} context context
45
36
  */
@@ -114,8 +114,11 @@ HarmonyAcceptDependency.Template = class HarmonyAcceptDependencyTemplate extends
114
114
  * @returns {HarmonyImportDependency[]} array of related harmony import dependencies
115
115
  */
116
116
  const getHarmonyImportDependencies = (dependency) => {
117
+ /** @type {HarmonyImportDependency[]} */
117
118
  const result = [];
119
+ /** @type {HarmonyImportDependency | null} */
118
120
  let deferDependency = null;
121
+ /** @type {HarmonyImportDependency | null} */
119
122
  let noDeferredDependency = null;
120
123
 
121
124
  for (const d of module.dependencies) {
@@ -6,6 +6,7 @@
6
6
  "use strict";
7
7
 
8
8
  const makeSerializable = require("../util/makeSerializable");
9
+ const { ExportPresenceModes } = require("./HarmonyImportDependency");
9
10
  const HarmonyImportSpecifierDependency = require("./HarmonyImportSpecifierDependency");
10
11
  const { ImportPhase } = require("./ImportPhase");
11
12
 
@@ -44,7 +45,7 @@ class HarmonyEvaluatedImportSpecifierDependency extends HarmonyImportSpecifierDe
44
45
  ids,
45
46
  name,
46
47
  range,
47
- false,
48
+ ExportPresenceModes.NONE,
48
49
  ImportPhase.Evaluation,
49
50
  attributes,
50
51
  []
@@ -103,6 +104,7 @@ HarmonyEvaluatedImportSpecifierDependency.Template = class HarmonyEvaluatedImpor
103
104
  );
104
105
  const ids = dep.getIds(moduleGraph);
105
106
 
107
+ /** @type {boolean | undefined | null} */
106
108
  let value;
107
109
 
108
110
  const exportsType =
@@ -39,14 +39,10 @@ module.exports = class HarmonyExportDependencyParserPlugin {
39
39
  */
40
40
  constructor(options) {
41
41
  this.options = options;
42
- this.exportPresenceMode =
43
- options.reexportExportsPresence !== undefined
44
- ? ExportPresenceModes.fromUserOption(options.reexportExportsPresence)
45
- : options.exportsPresence !== undefined
46
- ? ExportPresenceModes.fromUserOption(options.exportsPresence)
47
- : options.strictExportPresence
48
- ? ExportPresenceModes.ERROR
49
- : ExportPresenceModes.AUTO;
42
+ this.exportPresenceMode = ExportPresenceModes.resolveFromOptions(
43
+ options.reexportExportsPresence,
44
+ options
45
+ );
50
46
  }
51
47
 
52
48
  /**
@@ -21,6 +21,7 @@ const NullDependency = require("./NullDependency");
21
21
  /** @typedef {import("../javascript/JavascriptParser").Range} Range */
22
22
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
23
23
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
24
+ /** @typedef {import("./HarmonyExportInitFragment").ExportMap} ExportMap */
24
25
 
25
26
  class HarmonyExportExpressionDependency extends NullDependency {
26
27
  /**
@@ -120,6 +121,7 @@ HarmonyExportExpressionDependency.Template = class HarmonyExportDependencyTempla
120
121
  const { declarationId } = dep;
121
122
  const exportsName = module.exportsArgument;
122
123
  if (declarationId) {
124
+ /** @type {string} */
123
125
  let name;
124
126
  if (typeof declarationId === "string") {
125
127
  name = declarationId;
@@ -139,6 +141,7 @@ HarmonyExportExpressionDependency.Template = class HarmonyExportDependencyTempla
139
141
  .getExportsInfo(module)
140
142
  .getUsedName("default", runtime);
141
143
  if (used) {
144
+ /** @type {ExportMap} */
142
145
  const map = new Map();
143
146
  map.set(used, `/* export default binding */ ${name}`);
144
147
  initFragments.push(new HarmonyExportInitFragment(exportsName, map));
@@ -164,6 +167,7 @@ HarmonyExportExpressionDependency.Template = class HarmonyExportDependencyTempla
164
167
  .getUsedName("default", runtime);
165
168
  if (used) {
166
169
  runtimeRequirements.add(RuntimeGlobals.exports);
170
+ /** @type {ExportMap} */
167
171
  const map = new Map();
168
172
  map.set(used, name);
169
173
  initFragments.push(new HarmonyExportInitFragment(exportsName, map));