webpack 5.106.1 → 5.107.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.
Files changed (600) hide show
  1. package/README.md +2 -2
  2. package/lib/APIPlugin.js +4 -2
  3. package/lib/AsyncDependenciesBlock.js +3 -0
  4. package/lib/AutomaticPrefetchPlugin.js +6 -1
  5. package/lib/BannerPlugin.js +10 -1
  6. package/lib/Cache.js +27 -5
  7. package/lib/CacheFacade.js +26 -0
  8. package/lib/Chunk.js +46 -0
  9. package/lib/ChunkGraph.js +111 -0
  10. package/lib/ChunkGroup.js +57 -13
  11. package/lib/ChunkTemplate.js +9 -0
  12. package/lib/CleanPlugin.js +14 -1
  13. package/lib/CodeGenerationResults.js +19 -0
  14. package/lib/CompatibilityPlugin.js +23 -8
  15. package/lib/Compilation.js +161 -27
  16. package/lib/Compiler.js +41 -17
  17. package/lib/ConcatenationScope.js +24 -1
  18. package/lib/ConditionalInitFragment.js +6 -0
  19. package/lib/ConstPlugin.js +4 -1
  20. package/lib/ContextExclusionPlugin.js +2 -1
  21. package/lib/ContextModule.js +14 -2
  22. package/lib/ContextModuleFactory.js +10 -0
  23. package/lib/ContextReplacementPlugin.js +4 -1
  24. package/lib/DefinePlugin.js +22 -9
  25. package/lib/DependenciesBlock.js +6 -1
  26. package/lib/Dependency.js +48 -4
  27. package/lib/DependencyTemplate.js +7 -1
  28. package/lib/DependencyTemplates.js +4 -0
  29. package/lib/DotenvPlugin.js +3 -0
  30. package/lib/DynamicEntryPlugin.js +3 -1
  31. package/lib/EntryOptionPlugin.js +3 -0
  32. package/lib/EntryPlugin.js +2 -1
  33. package/lib/Entrypoint.js +4 -0
  34. package/lib/EnvironmentPlugin.js +3 -2
  35. package/lib/ErrorHelpers.js +7 -0
  36. package/lib/EvalDevToolModulePlugin.js +3 -1
  37. package/lib/EvalSourceMapDevToolPlugin.js +11 -10
  38. package/lib/ExportsInfo.js +56 -2
  39. package/lib/ExportsInfoApiPlugin.js +2 -1
  40. package/lib/ExternalModule.js +114 -15
  41. package/lib/ExternalModuleFactoryPlugin.js +15 -0
  42. package/lib/ExternalsPlugin.js +2 -1
  43. package/lib/FileSystemInfo.js +291 -71
  44. package/lib/FlagAllModulesAsUsedPlugin.js +2 -1
  45. package/lib/FlagDependencyExportsPlugin.js +4 -1
  46. package/lib/FlagDependencyUsagePlugin.js +5 -1
  47. package/lib/FlagEntryExportAsUsedPlugin.js +2 -1
  48. package/lib/Generator.js +16 -3
  49. package/lib/HotModuleReplacementPlugin.js +35 -9
  50. package/lib/IgnorePlugin.js +4 -2
  51. package/lib/IgnoreWarningsPlugin.js +2 -1
  52. package/lib/InitFragment.js +10 -0
  53. package/lib/JavascriptMetaInfoPlugin.js +2 -1
  54. package/lib/LibraryTemplatePlugin.js +2 -1
  55. package/lib/LoaderOptionsPlugin.js +3 -1
  56. package/lib/LoaderTargetPlugin.js +2 -1
  57. package/lib/MainTemplate.js +15 -0
  58. package/lib/ManifestPlugin.js +9 -2
  59. package/lib/Module.js +101 -19
  60. package/lib/ModuleFactory.js +6 -1
  61. package/lib/ModuleFilenameHelpers.js +3 -0
  62. package/lib/ModuleGraph.js +66 -0
  63. package/lib/ModuleGraphConnection.js +9 -0
  64. package/lib/ModuleInfoHeaderPlugin.js +5 -0
  65. package/lib/ModuleSourceTypeConstants.js +32 -1
  66. package/lib/ModuleTemplate.js +8 -0
  67. package/lib/ModuleTypeConstants.js +12 -3
  68. package/lib/MultiCompiler.js +30 -2
  69. package/lib/MultiStats.js +8 -0
  70. package/lib/MultiWatching.js +3 -0
  71. package/lib/NoEmitOnErrorsPlugin.js +1 -1
  72. package/lib/NodeStuffPlugin.js +11 -2
  73. package/lib/NormalModule.js +43 -33
  74. package/lib/NormalModuleFactory.js +35 -2
  75. package/lib/NormalModuleReplacementPlugin.js +1 -1
  76. package/lib/NullFactory.js +1 -0
  77. package/lib/OptionsApply.js +1 -0
  78. package/lib/Parser.js +3 -1
  79. package/lib/PlatformPlugin.js +2 -1
  80. package/lib/PrefetchPlugin.js +2 -1
  81. package/lib/ProgressPlugin.js +158 -68
  82. package/lib/ProvidePlugin.js +3 -1
  83. package/lib/RawModule.js +12 -0
  84. package/lib/RecordIdsPlugin.js +8 -0
  85. package/lib/RequestShortener.js +8 -0
  86. package/lib/ResolverFactory.js +5 -0
  87. package/lib/RuntimeGlobals.js +6 -5
  88. package/lib/RuntimeModule.js +22 -7
  89. package/lib/RuntimePlugin.js +13 -0
  90. package/lib/RuntimeTemplate.js +35 -1
  91. package/lib/SelfModuleFactory.js +2 -0
  92. package/lib/SourceMapDevToolModuleOptionsPlugin.js +2 -0
  93. package/lib/SourceMapDevToolPlugin.js +3 -1
  94. package/lib/Stats.js +5 -0
  95. package/lib/Template.js +20 -0
  96. package/lib/TemplatedPathPlugin.js +10 -3
  97. package/lib/UseStrictPlugin.js +2 -1
  98. package/lib/WarnCaseSensitiveModulesPlugin.js +71 -3
  99. package/lib/WarnDeprecatedOptionPlugin.js +2 -2
  100. package/lib/WarnNoModeSetPlugin.js +17 -2
  101. package/lib/WatchIgnorePlugin.js +4 -1
  102. package/lib/Watching.js +16 -3
  103. package/lib/WebpackError.js +3 -74
  104. package/lib/WebpackIsIncludedPlugin.js +3 -1
  105. package/lib/WebpackOptionsApply.js +14 -1
  106. package/lib/WebpackOptionsDefaulter.js +1 -0
  107. package/lib/asset/AssetBytesGenerator.js +12 -2
  108. package/lib/asset/AssetBytesParser.js +1 -0
  109. package/lib/asset/AssetGenerator.js +42 -10
  110. package/lib/asset/AssetModulesPlugin.js +7 -2
  111. package/lib/asset/AssetParser.js +2 -0
  112. package/lib/asset/AssetSourceGenerator.js +12 -2
  113. package/lib/asset/AssetSourceParser.js +1 -0
  114. package/lib/asset/RawDataUrlModule.js +11 -0
  115. package/lib/async-modules/AsyncModuleHelpers.js +1 -0
  116. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -0
  117. package/lib/async-modules/InferAsyncModulesPlugin.js +1 -1
  118. package/lib/buildChunkGraph.js +19 -6
  119. package/lib/cache/AddBuildDependenciesPlugin.js +2 -1
  120. package/lib/cache/AddManagedPathsPlugin.js +2 -1
  121. package/lib/cache/IdleFileCachePlugin.js +2 -1
  122. package/lib/cache/MemoryCachePlugin.js +1 -1
  123. package/lib/cache/MemoryWithGcCachePlugin.js +3 -1
  124. package/lib/cache/PackFileCacheStrategy.js +33 -4
  125. package/lib/cache/ResolverCachePlugin.js +10 -1
  126. package/lib/cache/getLazyHashedEtag.js +4 -0
  127. package/lib/cache/mergeEtags.js +2 -0
  128. package/lib/cli.js +33 -1
  129. package/lib/config/browserslistTargetHandler.js +2 -0
  130. package/lib/config/defaults.js +232 -12
  131. package/lib/config/normalization.js +15 -1
  132. package/lib/config/target.js +11 -0
  133. package/lib/container/ContainerEntryDependency.js +2 -0
  134. package/lib/container/ContainerEntryModule.js +12 -0
  135. package/lib/container/ContainerEntryModuleFactory.js +1 -0
  136. package/lib/container/ContainerExposedDependency.js +4 -0
  137. package/lib/container/ContainerPlugin.js +2 -1
  138. package/lib/container/ContainerReferencePlugin.js +2 -1
  139. package/lib/container/FallbackDependency.js +4 -0
  140. package/lib/container/FallbackItemDependency.js +1 -0
  141. package/lib/container/FallbackModule.js +12 -0
  142. package/lib/container/FallbackModuleFactory.js +1 -0
  143. package/lib/container/ModuleFederationPlugin.js +3 -1
  144. package/lib/container/RemoteModule.js +13 -0
  145. package/lib/container/RemoteRuntimeModule.js +1 -0
  146. package/lib/container/RemoteToExternalDependency.js +1 -0
  147. package/lib/container/options.js +7 -0
  148. package/lib/css/CssGenerator.js +336 -100
  149. package/lib/css/CssInjectStyleRuntimeModule.js +45 -42
  150. package/lib/css/CssLoadingRuntimeModule.js +23 -4
  151. package/lib/{CssModule.js → css/CssModule.js} +21 -15
  152. package/lib/css/CssModulesPlugin.js +235 -89
  153. package/lib/css/CssParser.js +616 -261
  154. package/lib/css/walkCssTokens.js +179 -2
  155. package/lib/debug/ProfilingPlugin.js +19 -1
  156. package/lib/dependencies/AMDDefineDependency.js +7 -0
  157. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +12 -0
  158. package/lib/dependencies/AMDPlugin.js +4 -1
  159. package/lib/dependencies/AMDRequireArrayDependency.js +6 -0
  160. package/lib/dependencies/AMDRequireContextDependency.js +3 -0
  161. package/lib/dependencies/AMDRequireDependenciesBlock.js +1 -0
  162. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +14 -1
  163. package/lib/dependencies/AMDRequireDependency.js +4 -0
  164. package/lib/dependencies/AMDRequireItemDependency.js +1 -0
  165. package/lib/dependencies/AMDRuntimeModules.js +3 -0
  166. package/lib/dependencies/CachedConstDependency.js +6 -1
  167. package/lib/dependencies/CommonJsDependencyHelpers.js +64 -0
  168. package/lib/dependencies/CommonJsExportRequireDependency.js +62 -10
  169. package/lib/dependencies/CommonJsExportsDependency.js +4 -0
  170. package/lib/dependencies/CommonJsExportsParserPlugin.js +9 -1
  171. package/lib/dependencies/CommonJsFullRequireDependency.js +36 -9
  172. package/lib/dependencies/CommonJsImportsParserPlugin.js +24 -3
  173. package/lib/dependencies/CommonJsPlugin.js +4 -1
  174. package/lib/dependencies/CommonJsRequireContextDependency.js +3 -0
  175. package/lib/dependencies/CommonJsRequireDependency.js +70 -4
  176. package/lib/dependencies/CommonJsSelfReferenceDependency.js +5 -0
  177. package/lib/dependencies/ConstDependency.js +6 -1
  178. package/lib/dependencies/ContextDependency.js +9 -2
  179. package/lib/dependencies/ContextDependencyHelpers.js +4 -1
  180. package/lib/dependencies/ContextDependencyTemplateAsId.js +1 -0
  181. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +1 -0
  182. package/lib/dependencies/ContextElementDependency.js +4 -0
  183. package/lib/dependencies/CreateRequireParserPlugin.js +7 -1
  184. package/lib/dependencies/CreateScriptUrlDependency.js +4 -0
  185. package/lib/dependencies/CriticalDependencyWarning.js +2 -1
  186. package/lib/dependencies/CssIcssExportDependency.js +339 -66
  187. package/lib/dependencies/CssIcssImportDependency.js +53 -8
  188. package/lib/dependencies/CssIcssSymbolDependency.js +16 -4
  189. package/lib/dependencies/CssImportDependency.js +12 -0
  190. package/lib/dependencies/CssUrlDependency.js +32 -0
  191. package/lib/dependencies/DelegatedSourceDependency.js +1 -0
  192. package/lib/dependencies/DllEntryDependency.js +3 -0
  193. package/lib/dependencies/DynamicExports.js +5 -0
  194. package/lib/dependencies/EntryDependency.js +1 -0
  195. package/lib/dependencies/ExportsInfoDependency.js +6 -0
  196. package/lib/dependencies/ExternalModuleDependency.js +5 -0
  197. package/lib/dependencies/ExternalModuleInitFragment.js +3 -0
  198. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +4 -0
  199. package/lib/dependencies/HarmonyAcceptDependency.js +6 -0
  200. package/lib/dependencies/HarmonyAcceptImportDependency.js +1 -0
  201. package/lib/dependencies/HarmonyCompatibilityDependency.js +1 -0
  202. package/lib/dependencies/HarmonyDetectionParserPlugin.js +4 -1
  203. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +4 -0
  204. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +10 -7
  205. package/lib/dependencies/HarmonyExportExpressionDependency.js +27 -14
  206. package/lib/dependencies/HarmonyExportHeaderDependency.js +4 -0
  207. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +143 -5
  208. package/lib/dependencies/HarmonyExportInitFragment.js +6 -0
  209. package/lib/dependencies/HarmonyExportSpecifierDependency.js +5 -0
  210. package/lib/dependencies/HarmonyExports.js +2 -0
  211. package/lib/dependencies/HarmonyImportDependency.js +21 -2
  212. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +31 -1
  213. package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -0
  214. package/lib/dependencies/HarmonyImportSpecifierDependency.js +18 -3
  215. package/lib/{HarmonyLinkingError.js → dependencies/HarmonyLinkingError.js} +5 -3
  216. package/lib/dependencies/HarmonyModulesPlugin.js +4 -1
  217. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +1 -0
  218. package/lib/dependencies/HtmlInlineScriptDependency.js +133 -0
  219. package/lib/dependencies/HtmlInlineStyleDependency.js +101 -0
  220. package/lib/dependencies/HtmlScriptSrcDependency.js +318 -0
  221. package/lib/dependencies/HtmlSourceDependency.js +127 -0
  222. package/lib/dependencies/ImportContextDependency.js +4 -0
  223. package/lib/dependencies/ImportDependency.js +5 -0
  224. package/lib/dependencies/ImportEagerDependency.js +2 -0
  225. package/lib/dependencies/ImportMetaContextDependency.js +1 -0
  226. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +4 -1
  227. package/lib/dependencies/ImportMetaContextPlugin.js +2 -1
  228. package/lib/dependencies/ImportMetaHotAcceptDependency.js +1 -0
  229. package/lib/dependencies/ImportMetaHotDeclineDependency.js +1 -0
  230. package/lib/dependencies/ImportMetaPlugin.js +6 -0
  231. package/lib/dependencies/ImportParserPlugin.js +9 -2
  232. package/lib/dependencies/ImportPhase.js +7 -3
  233. package/lib/dependencies/ImportPlugin.js +2 -1
  234. package/lib/dependencies/ImportWeakDependency.js +2 -0
  235. package/lib/dependencies/JsonExportsDependency.js +6 -1
  236. package/lib/dependencies/LoaderDependency.js +2 -0
  237. package/lib/dependencies/LoaderImportDependency.js +2 -0
  238. package/lib/dependencies/LoaderPlugin.js +4 -1
  239. package/lib/dependencies/LocalModule.js +4 -0
  240. package/lib/dependencies/LocalModuleDependency.js +4 -0
  241. package/lib/dependencies/LocalModulesHelpers.js +3 -0
  242. package/lib/dependencies/ModuleDecoratorDependency.js +7 -1
  243. package/lib/dependencies/ModuleDependency.js +7 -0
  244. package/lib/dependencies/ModuleDependencyTemplateAsId.js +1 -0
  245. package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +1 -0
  246. package/lib/dependencies/ModuleHotAcceptDependency.js +1 -0
  247. package/lib/dependencies/ModuleHotDeclineDependency.js +1 -0
  248. package/lib/dependencies/ModuleInitFragmentDependency.js +4 -0
  249. package/lib/dependencies/NullDependency.js +2 -0
  250. package/lib/dependencies/PrefetchDependency.js +1 -0
  251. package/lib/dependencies/ProvidedDependency.js +6 -1
  252. package/lib/dependencies/PureExpressionDependency.js +7 -1
  253. package/lib/dependencies/RequireContextDependency.js +1 -0
  254. package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -0
  255. package/lib/dependencies/RequireContextPlugin.js +2 -1
  256. package/lib/dependencies/RequireEnsureDependenciesBlock.js +1 -0
  257. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +1 -0
  258. package/lib/dependencies/RequireEnsureDependency.js +4 -0
  259. package/lib/dependencies/RequireEnsureItemDependency.js +1 -0
  260. package/lib/dependencies/RequireEnsurePlugin.js +2 -1
  261. package/lib/dependencies/RequireHeaderDependency.js +4 -0
  262. package/lib/dependencies/RequireIncludeDependency.js +2 -0
  263. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +4 -1
  264. package/lib/dependencies/RequireIncludePlugin.js +2 -1
  265. package/lib/{RequireJsStuffPlugin.js → dependencies/RequireJsStuffPlugin.js} +9 -8
  266. package/lib/dependencies/RequireResolveContextDependency.js +3 -0
  267. package/lib/dependencies/RequireResolveDependency.js +1 -0
  268. package/lib/dependencies/RequireResolveHeaderDependency.js +5 -0
  269. package/lib/dependencies/RuntimeRequirementsDependency.js +5 -1
  270. package/lib/dependencies/StaticExportsDependency.js +3 -0
  271. package/lib/dependencies/SystemPlugin.js +5 -2
  272. package/lib/dependencies/SystemRuntimeModule.js +1 -0
  273. package/lib/dependencies/URLContextDependency.js +3 -0
  274. package/lib/dependencies/URLDependency.js +6 -0
  275. package/lib/dependencies/URLPlugin.js +2 -0
  276. package/lib/dependencies/UnsupportedDependency.js +4 -0
  277. package/lib/dependencies/WebAssemblyExportImportedDependency.js +4 -0
  278. package/lib/dependencies/WebAssemblyImportDependency.js +5 -2
  279. package/lib/dependencies/WebpackIsIncludedDependency.js +2 -0
  280. package/lib/dependencies/WorkerDependency.js +6 -1
  281. package/lib/dependencies/WorkerPlugin.js +11 -3
  282. package/lib/dependencies/getFunctionExpression.js +1 -0
  283. package/lib/dependencies/processExportInfo.js +1 -0
  284. package/lib/{DelegatedModule.js → dll/DelegatedModule.js} +44 -31
  285. package/lib/{DelegatedModuleFactoryPlugin.js → dll/DelegatedModuleFactoryPlugin.js} +7 -4
  286. package/lib/{DelegatedPlugin.js → dll/DelegatedPlugin.js} +4 -3
  287. package/lib/{DllEntryPlugin.js → dll/DllEntryPlugin.js} +6 -5
  288. package/lib/{DllModule.js → dll/DllModule.js} +35 -24
  289. package/lib/{DllModuleFactory.js → dll/DllModuleFactory.js} +5 -4
  290. package/lib/{DllPlugin.js → dll/DllPlugin.js} +8 -6
  291. package/lib/{DllReferencePlugin.js → dll/DllReferencePlugin.js} +23 -18
  292. package/lib/{LibManifestPlugin.js → dll/LibManifestPlugin.js} +13 -10
  293. package/lib/electron/ElectronTargetPlugin.js +2 -1
  294. package/lib/{AbstractMethodError.js → errors/AbstractMethodError.js} +10 -1
  295. package/lib/{AsyncDependencyToInitialChunkError.js → errors/AsyncDependencyToInitialChunkError.js} +8 -3
  296. package/lib/errors/BuildCycleError.js +1 -1
  297. package/lib/{ChunkRenderError.js → errors/ChunkRenderError.js} +1 -1
  298. package/lib/{CodeGenerationError.js → errors/CodeGenerationError.js} +1 -1
  299. package/lib/{CommentCompilationWarning.js → errors/CommentCompilationWarning.js} +9 -3
  300. package/lib/{ConcurrentCompilationError.js → errors/ConcurrentCompilationError.js} +4 -2
  301. package/lib/{EnvironmentNotSupportAsyncWarning.js → errors/EnvironmentNotSupportAsyncWarning.js} +4 -4
  302. package/lib/{HookWebpackError.js → errors/HookWebpackError.js} +11 -5
  303. package/lib/{IgnoreErrorModuleFactory.js → errors/IgnoreErrorModuleFactory.js} +6 -4
  304. package/lib/{InvalidDependenciesModuleWarning.js → errors/InvalidDependenciesModuleWarning.js} +4 -3
  305. package/lib/errors/JSONParseError.js +114 -0
  306. package/lib/{ModuleBuildError.js → errors/ModuleBuildError.js} +8 -5
  307. package/lib/{ModuleDependencyError.js → errors/ModuleDependencyError.js} +2 -2
  308. package/lib/{ModuleDependencyWarning.js → errors/ModuleDependencyWarning.js} +5 -4
  309. package/lib/{ModuleError.js → errors/ModuleError.js} +7 -5
  310. package/lib/{ModuleHashingError.js → errors/ModuleHashingError.js} +1 -1
  311. package/lib/{ModuleNotFoundError.js → errors/ModuleNotFoundError.js} +3 -2
  312. package/lib/{ModuleParseError.js → errors/ModuleParseError.js} +11 -6
  313. package/lib/{ModuleRestoreError.js → errors/ModuleRestoreError.js} +2 -1
  314. package/lib/{ModuleStoreError.js → errors/ModuleStoreError.js} +2 -1
  315. package/lib/{ModuleWarning.js → errors/ModuleWarning.js} +8 -5
  316. package/lib/{NodeStuffInWebError.js → errors/NodeStuffInWebError.js} +5 -4
  317. package/lib/errors/NonErrorEmittedError.js +28 -0
  318. package/lib/{UnhandledSchemeError.js → errors/UnhandledSchemeError.js} +8 -2
  319. package/lib/{UnsupportedFeatureWarning.js → errors/UnsupportedFeatureWarning.js} +4 -3
  320. package/lib/errors/WebpackError.js +84 -0
  321. package/lib/esm/ExportWebpackRequireRuntimeModule.js +2 -0
  322. package/lib/esm/ModuleChunkFormatPlugin.js +5 -1
  323. package/lib/esm/ModuleChunkLoadingPlugin.js +3 -1
  324. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +5 -0
  325. package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -0
  326. package/lib/hmr/JavascriptHotModuleReplacementHelper.js +1 -0
  327. package/lib/hmr/LazyCompilationPlugin.js +20 -1
  328. package/lib/hmr/lazyCompilationBackend.js +2 -0
  329. package/lib/html/HtmlGenerator.js +379 -0
  330. package/lib/html/HtmlModulesPlugin.js +433 -0
  331. package/lib/html/HtmlParser.js +1489 -0
  332. package/lib/html/walkHtmlTokens.js +2733 -0
  333. package/lib/ids/ChunkModuleIdRangePlugin.js +3 -1
  334. package/lib/ids/DeterministicChunkIdsPlugin.js +3 -1
  335. package/lib/ids/DeterministicModuleIdsPlugin.js +3 -1
  336. package/lib/ids/HashedModuleIdsPlugin.js +2 -1
  337. package/lib/ids/IdHelpers.js +22 -1
  338. package/lib/ids/NamedChunkIdsPlugin.js +3 -1
  339. package/lib/ids/NamedModuleIdsPlugin.js +3 -1
  340. package/lib/ids/NaturalChunkIdsPlugin.js +1 -1
  341. package/lib/ids/NaturalModuleIdsPlugin.js +1 -1
  342. package/lib/ids/OccurrenceChunkIdsPlugin.js +2 -1
  343. package/lib/ids/OccurrenceModuleIdsPlugin.js +4 -1
  344. package/lib/ids/SyncModuleIdsPlugin.js +3 -1
  345. package/lib/index.js +39 -15
  346. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +1 -1
  347. package/lib/javascript/BasicEvaluatedExpression.js +4 -2
  348. package/lib/javascript/ChunkFormatHelpers.js +2 -1
  349. package/lib/javascript/ChunkHelpers.js +1 -0
  350. package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -1
  351. package/lib/javascript/EnableChunkLoadingPlugin.js +5 -1
  352. package/lib/javascript/JavascriptGenerator.js +10 -0
  353. package/lib/javascript/JavascriptModulesPlugin.js +112 -9
  354. package/lib/javascript/JavascriptParser.js +360 -16
  355. package/lib/javascript/JavascriptParserHelpers.js +7 -1
  356. package/lib/javascript/StartupHelpers.js +5 -0
  357. package/lib/json/JsonData.js +5 -0
  358. package/lib/json/JsonGenerator.js +21 -0
  359. package/lib/json/JsonModulesPlugin.js +1 -1
  360. package/lib/json/JsonParser.js +14 -25
  361. package/lib/library/AbstractLibraryPlugin.js +17 -2
  362. package/lib/library/AmdLibraryPlugin.js +8 -0
  363. package/lib/library/AssignLibraryPlugin.js +16 -0
  364. package/lib/library/EnableLibraryPlugin.js +8 -2
  365. package/lib/library/ExportPropertyLibraryPlugin.js +9 -0
  366. package/lib/{FalseIIFEUmdWarning.js → library/FalseIIFEUmdWarning.js} +1 -1
  367. package/lib/library/JsonpLibraryPlugin.js +8 -0
  368. package/lib/library/ModuleLibraryPlugin.js +86 -1
  369. package/lib/library/SystemLibraryPlugin.js +8 -0
  370. package/lib/library/UmdLibraryPlugin.js +16 -0
  371. package/lib/logging/Logger.js +17 -0
  372. package/lib/logging/createConsoleLogger.js +7 -0
  373. package/lib/logging/runtime.js +2 -0
  374. package/lib/logging/truncateArgs.js +2 -0
  375. package/lib/node/CommonJsChunkLoadingPlugin.js +5 -1
  376. package/lib/node/NodeEnvironmentPlugin.js +7 -3
  377. package/lib/node/NodeSourcePlugin.js +1 -1
  378. package/lib/node/NodeTargetPlugin.js +2 -1
  379. package/lib/node/NodeTemplatePlugin.js +3 -1
  380. package/lib/node/NodeWatchFileSystem.js +2 -0
  381. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +3 -0
  382. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +4 -1
  383. package/lib/node/ReadFileCompileWasmPlugin.js +4 -1
  384. package/lib/node/RequireChunkLoadingRuntimeModule.js +3 -0
  385. package/lib/node/nodeConsole.js +116 -64
  386. package/lib/optimize/AggressiveMergingPlugin.js +3 -1
  387. package/lib/optimize/AggressiveSplittingPlugin.js +6 -1
  388. package/lib/optimize/ConcatenatedModule.js +62 -6
  389. package/lib/optimize/EnsureChunkConditionsPlugin.js +2 -1
  390. package/lib/optimize/FlagIncludedChunksPlugin.js +2 -1
  391. package/lib/optimize/InnerGraph.js +16 -1
  392. package/lib/optimize/InnerGraphPlugin.js +14 -2
  393. package/lib/optimize/LimitChunkCountPlugin.js +9 -0
  394. package/lib/optimize/MangleExportsPlugin.js +5 -1
  395. package/lib/optimize/MergeDuplicateChunksPlugin.js +2 -0
  396. package/lib/optimize/MinChunkSizePlugin.js +2 -1
  397. package/lib/optimize/MinMaxSizeWarning.js +5 -4
  398. package/lib/optimize/ModuleConcatenationPlugin.js +36 -8
  399. package/lib/optimize/RealContentHashPlugin.js +104 -26
  400. package/lib/optimize/RemoveEmptyChunksPlugin.js +2 -1
  401. package/lib/optimize/RemoveParentModulesPlugin.js +3 -1
  402. package/lib/optimize/RuntimeChunkPlugin.js +2 -1
  403. package/lib/optimize/SideEffectsFlagPlugin.js +118 -4
  404. package/lib/optimize/SplitChunksPlugin.js +50 -2
  405. package/lib/performance/AssetsOverSizeLimitWarning.js +3 -2
  406. package/lib/performance/EntrypointsOverSizeLimitWarning.js +3 -2
  407. package/lib/performance/NoAsyncChunksWarning.js +5 -3
  408. package/lib/performance/SizeLimitsPlugin.js +8 -2
  409. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +1 -0
  410. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +6 -0
  411. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +1 -0
  412. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +5 -1
  413. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +1 -0
  414. package/lib/rules/BasicEffectRulePlugin.js +3 -0
  415. package/lib/rules/BasicMatcherRulePlugin.js +3 -0
  416. package/lib/rules/ObjectMatcherRulePlugin.js +3 -0
  417. package/lib/rules/RuleSetCompiler.js +18 -0
  418. package/lib/rules/UseEffectRulePlugin.js +10 -3
  419. package/lib/runtime/AsyncModuleRuntimeModule.js +1 -0
  420. package/lib/runtime/AutoPublicPathRuntimeModule.js +1 -0
  421. package/lib/runtime/BaseUriRuntimeModule.js +1 -0
  422. package/lib/runtime/ChunkNameRuntimeModule.js +1 -0
  423. package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +1 -0
  424. package/lib/runtime/CompatRuntimeModule.js +2 -0
  425. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +1 -0
  426. package/lib/runtime/CreateScriptRuntimeModule.js +1 -0
  427. package/lib/runtime/CreateScriptUrlRuntimeModule.js +1 -0
  428. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +1 -0
  429. package/lib/runtime/EnsureChunkRuntimeModule.js +1 -0
  430. package/lib/runtime/GetChunkFilenameRuntimeModule.js +1 -0
  431. package/lib/runtime/GetFullHashRuntimeModule.js +1 -0
  432. package/lib/runtime/GetMainFilenameRuntimeModule.js +1 -0
  433. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -0
  434. package/lib/runtime/GlobalRuntimeModule.js +1 -0
  435. package/lib/runtime/HasOwnPropertyRuntimeModule.js +1 -0
  436. package/lib/runtime/HelperRuntimeModule.js +5 -0
  437. package/lib/runtime/LoadScriptRuntimeModule.js +1 -0
  438. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +121 -13
  439. package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +1 -0
  440. package/lib/runtime/NonceRuntimeModule.js +1 -0
  441. package/lib/runtime/OnChunksLoadedRuntimeModule.js +1 -0
  442. package/lib/runtime/PublicPathRuntimeModule.js +1 -0
  443. package/lib/runtime/RelativeUrlRuntimeModule.js +1 -0
  444. package/lib/runtime/RuntimeIdRuntimeModule.js +1 -0
  445. package/lib/runtime/SetAnonymousDefaultNameRuntimeModule.js +35 -0
  446. package/lib/runtime/StartupChunkDependenciesPlugin.js +13 -1
  447. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -0
  448. package/lib/runtime/StartupEntrypointRuntimeModule.js +1 -0
  449. package/lib/runtime/SystemContextRuntimeModule.js +1 -0
  450. package/lib/runtime/ToBinaryRuntimeModule.js +1 -0
  451. package/lib/schemes/DataUriPlugin.js +14 -2
  452. package/lib/schemes/FileUriPlugin.js +1 -1
  453. package/lib/schemes/HttpUriPlugin.js +43 -1
  454. package/lib/schemes/VirtualUrlPlugin.js +7 -2
  455. package/lib/serialization/AggregateErrorSerializer.js +2 -0
  456. package/lib/serialization/ArraySerializer.js +2 -0
  457. package/lib/serialization/BinaryMiddleware.js +20 -1
  458. package/lib/serialization/DateObjectSerializer.js +2 -0
  459. package/lib/serialization/ErrorObjectSerializer.js +3 -0
  460. package/lib/serialization/FileMiddleware.js +21 -0
  461. package/lib/serialization/MapObjectSerializer.js +2 -0
  462. package/lib/serialization/NullPrototypeObjectSerializer.js +2 -0
  463. package/lib/serialization/ObjectMiddleware.js +23 -0
  464. package/lib/serialization/PlainObjectSerializer.js +7 -0
  465. package/lib/serialization/RegExpObjectSerializer.js +2 -0
  466. package/lib/serialization/Serializer.js +5 -0
  467. package/lib/serialization/SerializerMiddleware.js +14 -2
  468. package/lib/serialization/SetObjectSerializer.js +2 -0
  469. package/lib/serialization/SingleItemMiddleware.js +3 -0
  470. package/lib/sharing/ConsumeSharedFallbackDependency.js +1 -0
  471. package/lib/sharing/ConsumeSharedModule.js +15 -0
  472. package/lib/sharing/ConsumeSharedPlugin.js +8 -3
  473. package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -4
  474. package/lib/sharing/ProvideForSharedDependency.js +1 -0
  475. package/lib/sharing/ProvideSharedDependency.js +4 -0
  476. package/lib/sharing/ProvideSharedModule.js +12 -1
  477. package/lib/sharing/ProvideSharedModuleFactory.js +1 -0
  478. package/lib/sharing/ProvideSharedPlugin.js +5 -2
  479. package/lib/sharing/SharePlugin.js +2 -1
  480. package/lib/sharing/ShareRuntimeModule.js +1 -0
  481. package/lib/sharing/resolveMatchedConfigs.js +4 -1
  482. package/lib/sharing/utils.js +8 -0
  483. package/lib/stats/DefaultStatsFactoryPlugin.js +58 -3
  484. package/lib/stats/DefaultStatsPresetPlugin.js +12 -2
  485. package/lib/stats/DefaultStatsPrinterPlugin.js +38 -2
  486. package/lib/stats/StatsFactory.js +13 -1
  487. package/lib/stats/StatsPrinter.js +7 -0
  488. package/lib/typescript/TypeScriptPlugin.js +210 -0
  489. package/lib/url/URLParserPlugin.js +8 -2
  490. package/lib/util/AppendOnlyStackedSet.js +15 -0
  491. package/lib/util/ArrayHelpers.js +1 -0
  492. package/lib/util/ArrayQueue.js +10 -5
  493. package/lib/util/AsyncQueue.js +22 -2
  494. package/lib/util/Hash.js +2 -2
  495. package/lib/util/IterableHelpers.js +3 -0
  496. package/lib/util/LazyBucketSortedSet.js +21 -0
  497. package/lib/util/LazySet.js +39 -0
  498. package/lib/util/LocConverter.js +53 -0
  499. package/lib/util/ParallelismFactorCalculator.js +1 -0
  500. package/lib/util/Queue.js +6 -3
  501. package/lib/util/Semaphore.js +14 -1
  502. package/lib/util/SetHelpers.js +3 -0
  503. package/lib/util/SortableSet.js +7 -1
  504. package/lib/util/StackedCacheMap.js +20 -3
  505. package/lib/util/StackedMap.js +45 -0
  506. package/lib/util/StringXor.js +1 -1
  507. package/lib/util/TupleQueue.js +7 -3
  508. package/lib/util/TupleSet.js +13 -0
  509. package/lib/util/URLAbsoluteSpecifier.js +1 -0
  510. package/lib/util/WeakTupleMap.js +33 -0
  511. package/lib/util/binarySearchBounds.js +1 -0
  512. package/lib/util/cleverMerge.js +19 -2
  513. package/lib/util/comparators.js +34 -3
  514. package/lib/util/compileBooleanMatcher.js +9 -0
  515. package/lib/util/concatenate.js +9 -3
  516. package/lib/util/conventions.js +46 -1
  517. package/lib/util/createMappings.js +118 -0
  518. package/lib/util/dataURL.js +1 -0
  519. package/lib/util/deprecation.js +19 -0
  520. package/lib/util/deterministicGrouping.js +20 -0
  521. package/lib/util/extractSourceMap.js +1 -0
  522. package/lib/util/extractUrlAndGlobal.js +1 -0
  523. package/lib/util/findGraphRoots.js +5 -0
  524. package/lib/{formatLocation.js → util/formatLocation.js} +4 -2
  525. package/lib/{SizeFormatHelpers.js → util/formatSize.js} +4 -1
  526. package/lib/util/fs.js +71 -8
  527. package/lib/util/generateDebugId.js +1 -0
  528. package/lib/util/hash/BatchedHash.js +1 -0
  529. package/lib/util/hash/BulkUpdateHash.js +1 -0
  530. package/lib/util/hash/hash-digest.js +8 -0
  531. package/lib/util/hash/md4.js +1 -1
  532. package/lib/util/hash/wasm-hash.js +5 -0
  533. package/lib/util/hash/xxhash64.js +1 -1
  534. package/lib/util/identifier.js +67 -0
  535. package/lib/util/internalSerializables.js +35 -19
  536. package/lib/util/magicComment.js +10 -6
  537. package/lib/util/makeSerializable.js +6 -0
  538. package/lib/util/memoize.js +2 -0
  539. package/lib/util/mimeTypes.js +176 -0
  540. package/lib/util/nonNumericOnlyHash.js +1 -0
  541. package/lib/util/parseJson.js +41 -0
  542. package/lib/util/processAsyncTree.js +8 -0
  543. package/lib/util/property.js +1 -0
  544. package/lib/util/registerExternalSerializer.js +20 -0
  545. package/lib/util/removeBOM.js +1 -0
  546. package/lib/util/runtime.js +32 -0
  547. package/lib/util/semver.js +15 -0
  548. package/lib/util/serialization.js +2 -0
  549. package/lib/util/smartGrouping.js +8 -0
  550. package/lib/util/source.js +23 -0
  551. package/lib/util/topologicalSort.js +69 -0
  552. package/lib/validateSchema.js +1 -0
  553. package/lib/wasm/EnableWasmLoadingPlugin.js +15 -1
  554. package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +1 -0
  555. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +1 -0
  556. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +6 -0
  557. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -0
  558. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +12 -3
  559. package/lib/wasm-async/AsyncWebAssemblyParser.js +2 -1
  560. package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +12 -1
  561. package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +6 -3
  562. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +1 -0
  563. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +2 -2
  564. package/lib/wasm-sync/WebAssemblyGenerator.js +26 -1
  565. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +7 -3
  566. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +4 -0
  567. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +10 -1
  568. package/lib/wasm-sync/WebAssemblyParser.js +2 -0
  569. package/lib/wasm-sync/WebAssemblyUtils.js +2 -0
  570. package/lib/web/FetchCompileAsyncWasmPlugin.js +10 -1
  571. package/lib/web/FetchCompileWasmPlugin.js +13 -1
  572. package/lib/web/JsonpChunkLoadingPlugin.js +11 -1
  573. package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -0
  574. package/lib/web/JsonpTemplatePlugin.js +2 -1
  575. package/lib/webpack.js +13 -1
  576. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +10 -1
  577. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +1 -0
  578. package/lib/webworker/WebWorkerTemplatePlugin.js +1 -1
  579. package/package.json +31 -31
  580. package/schemas/WebpackOptions.check.js +1 -1
  581. package/schemas/WebpackOptions.json +161 -57
  582. package/schemas/plugins/{DllPlugin.check.d.ts → HtmlGeneratorOptions.check.d.ts} +1 -1
  583. package/schemas/plugins/HtmlGeneratorOptions.check.js +6 -0
  584. package/schemas/plugins/HtmlGeneratorOptions.json +3 -0
  585. package/schemas/plugins/ProgressPlugin.check.js +1 -1
  586. package/schemas/plugins/ProgressPlugin.json +22 -0
  587. package/schemas/plugins/{DllReferencePlugin.check.d.ts → css/CssAutoOrModuleParserOptions.check.d.ts} +1 -1
  588. package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +6 -0
  589. package/schemas/plugins/css/CssAutoOrModuleParserOptions.json +3 -0
  590. package/schemas/plugins/dll/DllPlugin.check.d.ts +7 -0
  591. package/schemas/plugins/dll/DllReferencePlugin.check.d.ts +7 -0
  592. package/types.d.ts +5325 -353
  593. package/lib/CaseSensitiveModulesWarning.js +0 -72
  594. package/lib/GraphHelpers.js +0 -46
  595. package/lib/NoModeWarning.js +0 -23
  596. package/lib/css/CssMergeStyleSheetsRuntimeModule.js +0 -56
  597. /package/schemas/plugins/{DllPlugin.check.js → dll/DllPlugin.check.js} +0 -0
  598. /package/schemas/plugins/{DllPlugin.json → dll/DllPlugin.json} +0 -0
  599. /package/schemas/plugins/{DllReferencePlugin.check.js → dll/DllReferencePlugin.check.js} +0 -0
  600. /package/schemas/plugins/{DllReferencePlugin.json → dll/DllReferencePlugin.json} +0 -0
@@ -13,6 +13,7 @@ const Parser = require("../Parser");
13
13
  const StackedMap = require("../util/StackedMap");
14
14
  const binarySearchBounds = require("../util/binarySearchBounds");
15
15
  const {
16
+ CompilerHintNotationRegExp,
16
17
  createMagicCommentContext,
17
18
  webpackCommentRegExp
18
19
  } = require("../util/magicComment");
@@ -94,6 +95,7 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
94
95
  /** @typedef {import("estree").MaybeNamedFunctionDeclaration} MaybeNamedFunctionDeclaration */
95
96
  /** @typedef {import("estree").MaybeNamedClassDeclaration} MaybeNamedClassDeclaration */
96
97
  /**
98
+ * Defines the shared type used by this module.
97
99
  * @template T
98
100
  * @typedef {import("tapable").AsArray<T>} AsArray<T>
99
101
  */
@@ -104,6 +106,7 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
104
106
  /** @typedef {import("../dependencies/HarmonyExportImportedSpecifierDependency").HarmonyStarExportsList} HarmonyStarExportsList */
105
107
 
106
108
  /**
109
+ * Defines the known javascript parser state type used by this module.
107
110
  * @typedef {object} KnownJavascriptParserState
108
111
  * @property {Set<string>=} harmonyNamedExports
109
112
  * @property {HarmonyStarExportsList=} harmonyStarExports
@@ -139,6 +142,7 @@ const LEGACY_ASSERT_ATTRIBUTES = Symbol("assert");
139
142
  const importAssertions = (Parser) =>
140
143
  class extends Parser {
141
144
  /**
145
+ * Parses with clause.
142
146
  * @this {InstanceType<AcornParser>}
143
147
  * @returns {ImportAttribute[]} import attributes
144
148
  */
@@ -204,6 +208,7 @@ let parser = AcornParser.extend(importAssertions);
204
208
  /** @typedef {Record<string, string> & { _isLegacyAssert?: boolean }} ImportAttributes */
205
209
 
206
210
  /**
211
+ * Gets import attributes.
207
212
  * @param {ImportDeclaration | ExportNamedDeclaration | ExportAllDeclaration | ImportExpression} node node with assertions
208
213
  * @returns {ImportAttributes | undefined} import attributes
209
214
  */
@@ -287,6 +292,7 @@ const VariableInfoFlags = Object.freeze({
287
292
 
288
293
  class VariableInfo {
289
294
  /**
295
+ * Creates an instance of VariableInfo.
290
296
  * @param {ScopeInfo} declaredScope scope in which the variable is declared
291
297
  * @param {string | undefined} name which name the variable use, defined name or free name or tagged name
292
298
  * @param {VariableInfoFlagsType} flags how the variable is created
@@ -300,6 +306,7 @@ class VariableInfo {
300
306
  }
301
307
 
302
308
  /**
309
+ * Checks whether this variable info is free.
303
310
  * @returns {boolean} the variable is free or not
304
311
  */
305
312
  isFree() {
@@ -307,6 +314,7 @@ class VariableInfo {
307
314
  }
308
315
 
309
316
  /**
317
+ * Checks whether this variable info is tagged.
310
318
  * @returns {boolean} the variable is tagged by tagVariable or not
311
319
  */
312
320
  isTagged() {
@@ -318,10 +326,12 @@ class VariableInfo {
318
326
  /** @typedef {Literal | string | null | undefined} ImportSource */
319
327
 
320
328
  /**
329
+ * Defines the internal parse options type used by this module.
321
330
  * @typedef {Omit<ParseOptions, "sourceType" | "ecmaVersion"> & { sourceType: "module" | "script" | "auto" }} InternalParseOptions
322
331
  */
323
332
 
324
333
  /**
334
+ * Defines the parse options type used by this module.
325
335
  * @typedef {object} ParseOptions
326
336
  * @property {"module" | "script"} sourceType
327
337
  * @property {EcmaVersion} ecmaVersion
@@ -334,6 +344,7 @@ class VariableInfo {
334
344
  */
335
345
 
336
346
  /**
347
+ * Defines the parse result type used by this module.
337
348
  * @typedef {object} ParseResult
338
349
  * @property {Program} ast
339
350
  * @property {Comment[]} comments
@@ -341,6 +352,7 @@ class VariableInfo {
341
352
  */
342
353
 
343
354
  /**
355
+ * Defines the parse function type used by this module.
344
356
  * @typedef {(code: string, options: ParseOptions) => ParseResult} ParseFunction
345
357
  */
346
358
 
@@ -357,6 +369,7 @@ class VariableInfo {
357
369
  /** @typedef {KnownTagData | Record<string, EXPECTED_ANY>} TagData */
358
370
 
359
371
  /**
372
+ * Defines the tag info type used by this module.
360
373
  * @typedef {object} TagInfo
361
374
  * @property {Tag} tag
362
375
  * @property {TagData=} data
@@ -372,6 +385,7 @@ const SCOPE_INFO_TERMINATED_RETURN = 1;
372
385
  const SCOPE_INFO_TERMINATED_THROW = 2;
373
386
 
374
387
  /**
388
+ * Defines the scope info type used by this module.
375
389
  * @typedef {object} ScopeInfo
376
390
  * @property {StackedMap<string, VariableInfo | ScopeInfo>} definitions
377
391
  * @property {boolean | "arrow"} topLevelScope
@@ -386,6 +400,7 @@ const SCOPE_INFO_TERMINATED_THROW = 2;
386
400
  /** @typedef {[number, number]} Range */
387
401
 
388
402
  /**
403
+ * Defines the destructuring assignment property type used by this module.
389
404
  * @typedef {object} DestructuringAssignmentProperty
390
405
  * @property {string} id
391
406
  * @property {Range} range
@@ -479,8 +494,9 @@ const CLASS_NAME = "JavascriptParser";
479
494
 
480
495
  class JavascriptParser extends Parser {
481
496
  /**
497
+ * Creates an instance of JavascriptParser.
482
498
  * @param {"module" | "script" | "auto"=} sourceType default source type
483
- * @param {{ parse?: ParseFunction }=} options parser options
499
+ * @param {{ parse?: ParseFunction, typescript?: boolean }=} options parser options
484
500
  */
485
501
  constructor(sourceType = "auto", options = {}) {
486
502
  super();
@@ -569,7 +585,7 @@ class JavascriptParser extends Parser {
569
585
  "exportName",
570
586
  "index"
571
587
  ]),
572
- /** @type {SyncBailHook<[VariableDeclarator, Statement], boolean | void>} */
588
+ /** @type {SyncBailHook<[VariableDeclarator, VariableDeclaration], boolean | void>} */
573
589
  preDeclarator: new SyncBailHook(["declarator", "statement"]),
574
590
  /** @type {SyncBailHook<[VariableDeclarator, Statement], boolean | void>} */
575
591
  declarator: new SyncBailHook(["declarator", "statement"]),
@@ -956,6 +972,7 @@ class JavascriptParser extends Parser {
956
972
  (a === true && b === false) || (a === false && b === true);
957
973
 
958
974
  /**
975
+ * Handle template string compare.
959
976
  * @param {BasicEvaluatedExpression} left left
960
977
  * @param {BasicEvaluatedExpression} right right
961
978
  * @param {BasicEvaluatedExpression} res res
@@ -964,6 +981,7 @@ class JavascriptParser extends Parser {
964
981
  */
965
982
  const handleTemplateStringCompare = (left, right, res, eql) => {
966
983
  /**
984
+ * Returns value.
967
985
  * @param {BasicEvaluatedExpression[]} parts parts
968
986
  * @returns {string} value
969
987
  */
@@ -977,6 +995,7 @@ class JavascriptParser extends Parser {
977
995
  return value;
978
996
  };
979
997
  /**
998
+ * Returns value.
980
999
  * @param {BasicEvaluatedExpression[]} parts parts
981
1000
  * @returns {string} value
982
1001
  */
@@ -1460,6 +1479,7 @@ class JavascriptParser extends Parser {
1460
1479
  }
1461
1480
  });
1462
1481
  /**
1482
+ * Tap evaluate with variable info.
1463
1483
  * @param {"Identifier" | "ThisExpression" | "MemberExpression"} exprType expression type name
1464
1484
  * @param {(node: Expression | SpreadElement) => GetInfoResult | undefined} getInfo get info
1465
1485
  * @returns {void}
@@ -1565,8 +1585,8 @@ class JavascriptParser extends Parser {
1565
1585
  )
1566
1586
  );
1567
1587
 
1568
- this.hooks.evaluate.for("CallExpression").tap(CLASS_NAME, (_expr) => {
1569
- const expr = /** @type {CallExpression} */ (_expr);
1588
+ this.hooks.evaluate.for("CallExpression").tap(CLASS_NAME, (expression) => {
1589
+ const expr = /** @type {CallExpression} */ (expression);
1570
1590
  if (
1571
1591
  expr.callee.type === "MemberExpression" &&
1572
1592
  expr.callee.property.type ===
@@ -1687,6 +1707,7 @@ class JavascriptParser extends Parser {
1687
1707
  }
1688
1708
 
1689
1709
  /**
1710
+ * Gets simplified template result.
1690
1711
  * @param {"cooked" | "raw"} kind kind of values to get
1691
1712
  * @param {TemplateLiteral} templateLiteralExpr TemplateLiteral expr
1692
1713
  * @returns {{ quasis: BasicEvaluatedExpression[], parts: BasicEvaluatedExpression[] }} Simplified template
@@ -1959,9 +1980,25 @@ class JavascriptParser extends Parser {
1959
1980
  }
1960
1981
  return this.evaluateExpression(expr.expression);
1961
1982
  });
1983
+ this.hooks.evaluate.for("SequenceExpression").tap(CLASS_NAME, (_expr) => {
1984
+ const expr = /** @type {SequenceExpression} */ (_expr);
1985
+ if (!expr.range) return;
1986
+ let commentsStartPos = /** @type {Range} */ (expr.range)[0];
1987
+ for (let i = 0; i < expr.expressions.length - 1; i++) {
1988
+ const item = expr.expressions[i];
1989
+ if (!item.range) return;
1990
+ if (!this.isPure(item, commentsStartPos)) return;
1991
+ commentsStartPos = /** @type {Range} */ (item.range)[1];
1992
+ }
1993
+ const last = expr.expressions[expr.expressions.length - 1];
1994
+ const evaluated = this.evaluateExpression(last);
1995
+ if (!evaluated.isCompileTimeValue()) return;
1996
+ return evaluated.setRange(/** @type {Range} */ (expr.range));
1997
+ });
1962
1998
  }
1963
1999
 
1964
2000
  /**
2001
+ * Destructuring assignment properties for.
1965
2002
  * @param {Expression} node node
1966
2003
  * @returns {DestructuringAssignmentProperties | undefined} destructured identifiers
1967
2004
  */
@@ -1971,6 +2008,7 @@ class JavascriptParser extends Parser {
1971
2008
  }
1972
2009
 
1973
2010
  /**
2011
+ * Gets rename identifier.
1974
2012
  * @param {Expression | SpreadElement} expr expression
1975
2013
  * @returns {string | VariableInfo | undefined} identifier
1976
2014
  */
@@ -1982,6 +2020,7 @@ class JavascriptParser extends Parser {
1982
2020
  }
1983
2021
 
1984
2022
  /**
2023
+ * Processes the provided classy.
1985
2024
  * @param {ClassExpression | ClassDeclaration | MaybeNamedClassDeclaration} classy a class node
1986
2025
  * @returns {void}
1987
2026
  */
@@ -2166,6 +2205,7 @@ class JavascriptParser extends Parser {
2166
2205
  }
2167
2206
 
2168
2207
  /**
2208
+ * Block pre walk statement.
2169
2209
  * @param {Statement | ModuleDeclaration | MaybeNamedClassDeclaration | MaybeNamedFunctionDeclaration} statement statement
2170
2210
  */
2171
2211
  blockPreWalkStatement(statement) {
@@ -2199,6 +2239,7 @@ class JavascriptParser extends Parser {
2199
2239
  }
2200
2240
 
2201
2241
  /**
2242
+ * Processes the provided statement.
2202
2243
  * @param {Statement | ModuleDeclaration | MaybeNamedFunctionDeclaration | MaybeNamedClassDeclaration} statement statement
2203
2244
  */
2204
2245
  walkStatement(statement) {
@@ -2287,6 +2328,7 @@ class JavascriptParser extends Parser {
2287
2328
 
2288
2329
  // Real Statements
2289
2330
  /**
2331
+ * Pre walk block statement.
2290
2332
  * @param {BlockStatement} statement block statement
2291
2333
  */
2292
2334
  preWalkBlockStatement(statement) {
@@ -2294,6 +2336,7 @@ class JavascriptParser extends Parser {
2294
2336
  }
2295
2337
 
2296
2338
  /**
2339
+ * Walk block statement.
2297
2340
  * @param {BlockStatement | StaticBlock} statement block statement
2298
2341
  */
2299
2342
  walkBlockStatement(statement) {
@@ -2307,6 +2350,7 @@ class JavascriptParser extends Parser {
2307
2350
  }
2308
2351
 
2309
2352
  /**
2353
+ * Walk expression statement.
2310
2354
  * @param {ExpressionStatement} statement expression statement
2311
2355
  */
2312
2356
  walkExpressionStatement(statement) {
@@ -2314,6 +2358,7 @@ class JavascriptParser extends Parser {
2314
2358
  }
2315
2359
 
2316
2360
  /**
2361
+ * Pre walk if statement.
2317
2362
  * @param {IfStatement} statement if statement
2318
2363
  */
2319
2364
  preWalkIfStatement(statement) {
@@ -2324,6 +2369,7 @@ class JavascriptParser extends Parser {
2324
2369
  }
2325
2370
 
2326
2371
  /**
2372
+ * Processes the provided statement.
2327
2373
  * @param {IfStatement} statement if statement
2328
2374
  */
2329
2375
  walkIfStatement(statement) {
@@ -2361,6 +2407,7 @@ class JavascriptParser extends Parser {
2361
2407
  }
2362
2408
 
2363
2409
  /**
2410
+ * Pre walk labeled statement.
2364
2411
  * @param {LabeledStatement} statement with statement
2365
2412
  */
2366
2413
  preWalkLabeledStatement(statement) {
@@ -2368,6 +2415,7 @@ class JavascriptParser extends Parser {
2368
2415
  }
2369
2416
 
2370
2417
  /**
2418
+ * Walk labeled statement.
2371
2419
  * @param {LabeledStatement} statement with statement
2372
2420
  */
2373
2421
  walkLabeledStatement(statement) {
@@ -2382,6 +2430,7 @@ class JavascriptParser extends Parser {
2382
2430
  }
2383
2431
 
2384
2432
  /**
2433
+ * Pre walk with statement.
2385
2434
  * @param {WithStatement} statement with statement
2386
2435
  */
2387
2436
  preWalkWithStatement(statement) {
@@ -2389,6 +2438,7 @@ class JavascriptParser extends Parser {
2389
2438
  }
2390
2439
 
2391
2440
  /**
2441
+ * Walk with statement.
2392
2442
  * @param {WithStatement} statement with statement
2393
2443
  */
2394
2444
  walkWithStatement(statement) {
@@ -2399,6 +2449,7 @@ class JavascriptParser extends Parser {
2399
2449
  }
2400
2450
 
2401
2451
  /**
2452
+ * Pre walk switch statement.
2402
2453
  * @param {SwitchStatement} statement switch statement
2403
2454
  */
2404
2455
  preWalkSwitchStatement(statement) {
@@ -2406,6 +2457,7 @@ class JavascriptParser extends Parser {
2406
2457
  }
2407
2458
 
2408
2459
  /**
2460
+ * Walk switch statement.
2409
2461
  * @param {SwitchStatement} statement switch statement
2410
2462
  */
2411
2463
  walkSwitchStatement(statement) {
@@ -2414,6 +2466,7 @@ class JavascriptParser extends Parser {
2414
2466
  }
2415
2467
 
2416
2468
  /**
2469
+ * Walk terminating statement.
2417
2470
  * @param {ReturnStatement | ThrowStatement} statement return or throw statement
2418
2471
  */
2419
2472
  walkTerminatingStatement(statement) {
@@ -2429,6 +2482,7 @@ class JavascriptParser extends Parser {
2429
2482
  }
2430
2483
 
2431
2484
  /**
2485
+ * Walk return statement.
2432
2486
  * @param {ReturnStatement} statement return statement
2433
2487
  */
2434
2488
  walkReturnStatement(statement) {
@@ -2436,6 +2490,7 @@ class JavascriptParser extends Parser {
2436
2490
  }
2437
2491
 
2438
2492
  /**
2493
+ * Walk throw statement.
2439
2494
  * @param {ThrowStatement} statement return statement
2440
2495
  */
2441
2496
  walkThrowStatement(statement) {
@@ -2443,6 +2498,7 @@ class JavascriptParser extends Parser {
2443
2498
  }
2444
2499
 
2445
2500
  /**
2501
+ * Pre walk try statement.
2446
2502
  * @param {TryStatement} statement try statement
2447
2503
  */
2448
2504
  preWalkTryStatement(statement) {
@@ -2452,6 +2508,7 @@ class JavascriptParser extends Parser {
2452
2508
  }
2453
2509
 
2454
2510
  /**
2511
+ * Walk try statement.
2455
2512
  * @param {TryStatement} statement try statement
2456
2513
  */
2457
2514
  walkTryStatement(statement) {
@@ -2489,6 +2546,7 @@ class JavascriptParser extends Parser {
2489
2546
  }
2490
2547
 
2491
2548
  /**
2549
+ * Pre walk while statement.
2492
2550
  * @param {WhileStatement} statement while statement
2493
2551
  */
2494
2552
  preWalkWhileStatement(statement) {
@@ -2496,6 +2554,7 @@ class JavascriptParser extends Parser {
2496
2554
  }
2497
2555
 
2498
2556
  /**
2557
+ * Walk while statement.
2499
2558
  * @param {WhileStatement} statement while statement
2500
2559
  */
2501
2560
  walkWhileStatement(statement) {
@@ -2506,6 +2565,7 @@ class JavascriptParser extends Parser {
2506
2565
  }
2507
2566
 
2508
2567
  /**
2568
+ * Pre walk do while statement.
2509
2569
  * @param {DoWhileStatement} statement do while statement
2510
2570
  */
2511
2571
  preWalkDoWhileStatement(statement) {
@@ -2513,6 +2573,7 @@ class JavascriptParser extends Parser {
2513
2573
  }
2514
2574
 
2515
2575
  /**
2576
+ * Walk do while statement.
2516
2577
  * @param {DoWhileStatement} statement do while statement
2517
2578
  */
2518
2579
  walkDoWhileStatement(statement) {
@@ -2523,6 +2584,7 @@ class JavascriptParser extends Parser {
2523
2584
  }
2524
2585
 
2525
2586
  /**
2587
+ * Pre walk for statement.
2526
2588
  * @param {ForStatement} statement for statement
2527
2589
  */
2528
2590
  preWalkForStatement(statement) {
@@ -2533,6 +2595,7 @@ class JavascriptParser extends Parser {
2533
2595
  }
2534
2596
 
2535
2597
  /**
2598
+ * Walk for statement.
2536
2599
  * @param {ForStatement} statement for statement
2537
2600
  */
2538
2601
  walkForStatement(statement) {
@@ -2568,6 +2631,7 @@ class JavascriptParser extends Parser {
2568
2631
  }
2569
2632
 
2570
2633
  /**
2634
+ * Pre walk for in statement.
2571
2635
  * @param {ForInStatement} statement for statement
2572
2636
  */
2573
2637
  preWalkForInStatement(statement) {
@@ -2578,6 +2642,7 @@ class JavascriptParser extends Parser {
2578
2642
  }
2579
2643
 
2580
2644
  /**
2645
+ * Walk for in statement.
2581
2646
  * @param {ForInStatement} statement for statement
2582
2647
  */
2583
2648
  walkForInStatement(statement) {
@@ -2606,6 +2671,7 @@ class JavascriptParser extends Parser {
2606
2671
  }
2607
2672
 
2608
2673
  /**
2674
+ * Pre walk for of statement.
2609
2675
  * @param {ForOfStatement} statement statement
2610
2676
  */
2611
2677
  preWalkForOfStatement(statement) {
@@ -2619,6 +2685,7 @@ class JavascriptParser extends Parser {
2619
2685
  }
2620
2686
 
2621
2687
  /**
2688
+ * Walk for of statement.
2622
2689
  * @param {ForOfStatement} statement for statement
2623
2690
  */
2624
2691
  walkForOfStatement(statement) {
@@ -2647,6 +2714,7 @@ class JavascriptParser extends Parser {
2647
2714
  }
2648
2715
 
2649
2716
  /**
2717
+ * Pre walk function declaration.
2650
2718
  * @param {FunctionDeclaration | MaybeNamedFunctionDeclaration} statement function declaration
2651
2719
  */
2652
2720
  preWalkFunctionDeclaration(statement) {
@@ -2656,6 +2724,7 @@ class JavascriptParser extends Parser {
2656
2724
  }
2657
2725
 
2658
2726
  /**
2727
+ * Walk function declaration.
2659
2728
  * @param {FunctionDeclaration | MaybeNamedFunctionDeclaration} statement function declaration
2660
2729
  */
2661
2730
  walkFunctionDeclaration(statement) {
@@ -2678,6 +2747,7 @@ class JavascriptParser extends Parser {
2678
2747
  }
2679
2748
 
2680
2749
  /**
2750
+ * Block pre walk expression statement.
2681
2751
  * @param {ExpressionStatement} statement expression statement
2682
2752
  */
2683
2753
  blockPreWalkExpressionStatement(statement) {
@@ -2689,6 +2759,7 @@ class JavascriptParser extends Parser {
2689
2759
  }
2690
2760
 
2691
2761
  /**
2762
+ * Pre walk assignment expression.
2692
2763
  * @param {AssignmentExpression} expression assignment expression
2693
2764
  */
2694
2765
  preWalkAssignmentExpression(expression) {
@@ -2696,6 +2767,7 @@ class JavascriptParser extends Parser {
2696
2767
  }
2697
2768
 
2698
2769
  /**
2770
+ * Enter destructuring assignment.
2699
2771
  * @param {Pattern} pattern pattern
2700
2772
  * @param {Expression} expression assignment expression
2701
2773
  * @returns {Expression | undefined} destructuring expression
@@ -2737,6 +2809,7 @@ class JavascriptParser extends Parser {
2737
2809
  }
2738
2810
 
2739
2811
  /**
2812
+ * Module pre walk import declaration.
2740
2813
  * @param {ImportDeclaration} statement statement
2741
2814
  */
2742
2815
  modulePreWalkImportDeclaration(statement) {
@@ -2782,6 +2855,7 @@ class JavascriptParser extends Parser {
2782
2855
  }
2783
2856
 
2784
2857
  /**
2858
+ * Processes the provided declaration.
2785
2859
  * @param {Declaration} declaration declaration
2786
2860
  * @param {OnIdent} onIdent on ident callback
2787
2861
  */
@@ -2807,6 +2881,7 @@ class JavascriptParser extends Parser {
2807
2881
  }
2808
2882
 
2809
2883
  /**
2884
+ * Module pre walk export named declaration.
2810
2885
  * @param {ExportNamedDeclaration} statement statement
2811
2886
  */
2812
2887
  modulePreWalkExportNamedDeclaration(statement) {
@@ -2847,6 +2922,7 @@ class JavascriptParser extends Parser {
2847
2922
  }
2848
2923
 
2849
2924
  /**
2925
+ * Block pre walk export named declaration.
2850
2926
  * @param {ExportNamedDeclaration} statement statement
2851
2927
  */
2852
2928
  blockPreWalkExportNamedDeclaration(statement) {
@@ -2898,6 +2974,7 @@ class JavascriptParser extends Parser {
2898
2974
  }
2899
2975
 
2900
2976
  /**
2977
+ * Walk export named declaration.
2901
2978
  * @param {ExportNamedDeclaration} statement the statement
2902
2979
  */
2903
2980
  walkExportNamedDeclaration(statement) {
@@ -2907,6 +2984,7 @@ class JavascriptParser extends Parser {
2907
2984
  }
2908
2985
 
2909
2986
  /**
2987
+ * Block pre walk export default declaration.
2910
2988
  * @param {ExportDefaultDeclaration} statement statement
2911
2989
  */
2912
2990
  blockPreWalkExportDefaultDeclaration(statement) {
@@ -2942,6 +3020,7 @@ class JavascriptParser extends Parser {
2942
3020
  }
2943
3021
 
2944
3022
  /**
3023
+ * Walk export default declaration.
2945
3024
  * @param {ExportDefaultDeclaration} statement statement
2946
3025
  */
2947
3026
  walkExportDefaultDeclaration(statement) {
@@ -2976,6 +3055,7 @@ class JavascriptParser extends Parser {
2976
3055
  }
2977
3056
 
2978
3057
  /**
3058
+ * Module pre walk export all declaration.
2979
3059
  * @param {ExportAllDeclaration} statement statement
2980
3060
  */
2981
3061
  modulePreWalkExportAllDeclaration(statement) {
@@ -2991,6 +3071,7 @@ class JavascriptParser extends Parser {
2991
3071
  }
2992
3072
 
2993
3073
  /**
3074
+ * Pre walk variable declaration.
2994
3075
  * @param {VariableDeclaration} statement variable declaration
2995
3076
  */
2996
3077
  preWalkVariableDeclaration(statement) {
@@ -2999,6 +3080,7 @@ class JavascriptParser extends Parser {
2999
3080
  }
3000
3081
 
3001
3082
  /**
3083
+ * Block pre walk variable declaration.
3002
3084
  * @param {VariableDeclaration} statement variable declaration
3003
3085
  */
3004
3086
  blockPreWalkVariableDeclaration(statement) {
@@ -3014,6 +3096,7 @@ class JavascriptParser extends Parser {
3014
3096
  }
3015
3097
 
3016
3098
  /**
3099
+ * Pre walk variable declaration.
3017
3100
  * @param {VariableDeclaration} statement variable declaration
3018
3101
  * @param {HookMap<SyncBailHook<[Identifier], boolean | void>>} hookMap map of hooks
3019
3102
  */
@@ -3040,6 +3123,7 @@ class JavascriptParser extends Parser {
3040
3123
  }
3041
3124
 
3042
3125
  /**
3126
+ * Pre walk object pattern.
3043
3127
  * @param {ObjectPattern} objectPattern object pattern
3044
3128
  * @returns {DestructuringAssignmentProperties | undefined} set of names or undefined if not all keys are identifiers
3045
3129
  */
@@ -3104,6 +3188,7 @@ class JavascriptParser extends Parser {
3104
3188
  }
3105
3189
 
3106
3190
  /**
3191
+ * Pre walk array pattern.
3107
3192
  * @param {ArrayPattern} arrayPattern array pattern
3108
3193
  * @returns {Set<DestructuringAssignmentProperty> | undefined} set of names or undefined if not all keys are identifiers
3109
3194
  */
@@ -3134,6 +3219,7 @@ class JavascriptParser extends Parser {
3134
3219
  }
3135
3220
 
3136
3221
  /**
3222
+ * Pre walk variable declarator.
3137
3223
  * @param {VariableDeclarator} declarator variable declarator
3138
3224
  */
3139
3225
  preWalkVariableDeclarator(declarator) {
@@ -3143,6 +3229,7 @@ class JavascriptParser extends Parser {
3143
3229
  }
3144
3230
 
3145
3231
  /**
3232
+ * Walk variable declaration.
3146
3233
  * @param {VariableDeclaration} statement variable declaration
3147
3234
  */
3148
3235
  walkVariableDeclaration(statement) {
@@ -3179,6 +3266,7 @@ class JavascriptParser extends Parser {
3179
3266
  }
3180
3267
 
3181
3268
  /**
3269
+ * Block pre walk class declaration.
3182
3270
  * @param {ClassDeclaration | MaybeNamedClassDeclaration} statement class declaration
3183
3271
  */
3184
3272
  blockPreWalkClassDeclaration(statement) {
@@ -3188,6 +3276,7 @@ class JavascriptParser extends Parser {
3188
3276
  }
3189
3277
 
3190
3278
  /**
3279
+ * Walk class declaration.
3191
3280
  * @param {ClassDeclaration | MaybeNamedClassDeclaration} statement class declaration
3192
3281
  */
3193
3282
  walkClassDeclaration(statement) {
@@ -3195,6 +3284,7 @@ class JavascriptParser extends Parser {
3195
3284
  }
3196
3285
 
3197
3286
  /**
3287
+ * Pre walk switch cases.
3198
3288
  * @param {SwitchCase[]} switchCases switch statement
3199
3289
  */
3200
3290
  preWalkSwitchCases(switchCases) {
@@ -3205,6 +3295,7 @@ class JavascriptParser extends Parser {
3205
3295
  }
3206
3296
 
3207
3297
  /**
3298
+ * Processes the provided switch case.
3208
3299
  * @param {SwitchCase[]} switchCases switch statement
3209
3300
  */
3210
3301
  walkSwitchCases(switchCases) {
@@ -3245,6 +3336,7 @@ class JavascriptParser extends Parser {
3245
3336
  }
3246
3337
 
3247
3338
  /**
3339
+ * Pre walk catch clause.
3248
3340
  * @param {CatchClause} catchClause catch clause
3249
3341
  */
3250
3342
  preWalkCatchClause(catchClause) {
@@ -3252,6 +3344,7 @@ class JavascriptParser extends Parser {
3252
3344
  }
3253
3345
 
3254
3346
  /**
3347
+ * Processes the provided catch clause.
3255
3348
  * @param {CatchClause} catchClause catch clause
3256
3349
  */
3257
3350
  walkCatchClause(catchClause) {
@@ -3271,6 +3364,7 @@ class JavascriptParser extends Parser {
3271
3364
  }
3272
3365
 
3273
3366
  /**
3367
+ * Processes the provided pattern.
3274
3368
  * @param {Pattern} pattern pattern
3275
3369
  */
3276
3370
  walkPattern(pattern) {
@@ -3294,6 +3388,7 @@ class JavascriptParser extends Parser {
3294
3388
  }
3295
3389
 
3296
3390
  /**
3391
+ * Walk assignment pattern.
3297
3392
  * @param {AssignmentPattern} pattern assignment pattern
3298
3393
  */
3299
3394
  walkAssignmentPattern(pattern) {
@@ -3302,6 +3397,7 @@ class JavascriptParser extends Parser {
3302
3397
  }
3303
3398
 
3304
3399
  /**
3400
+ * Walk object pattern.
3305
3401
  * @param {ObjectPattern} pattern pattern
3306
3402
  */
3307
3403
  walkObjectPattern(pattern) {
@@ -3318,6 +3414,7 @@ class JavascriptParser extends Parser {
3318
3414
  }
3319
3415
 
3320
3416
  /**
3417
+ * Walk array pattern.
3321
3418
  * @param {ArrayPattern} pattern array pattern
3322
3419
  */
3323
3420
  walkArrayPattern(pattern) {
@@ -3328,6 +3425,7 @@ class JavascriptParser extends Parser {
3328
3425
  }
3329
3426
 
3330
3427
  /**
3428
+ * Processes the provided pattern.
3331
3429
  * @param {RestElement} pattern rest element
3332
3430
  */
3333
3431
  walkRestElement(pattern) {
@@ -3335,6 +3433,7 @@ class JavascriptParser extends Parser {
3335
3433
  }
3336
3434
 
3337
3435
  /**
3436
+ * Processes the provided expression.
3338
3437
  * @param {(Expression | SpreadElement | null)[]} expressions expressions
3339
3438
  */
3340
3439
  walkExpressions(expressions) {
@@ -3346,6 +3445,7 @@ class JavascriptParser extends Parser {
3346
3445
  }
3347
3446
 
3348
3447
  /**
3448
+ * Processes the provided expression.
3349
3449
  * @param {Expression | SpreadElement | PrivateIdentifier | Super} expression expression
3350
3450
  */
3351
3451
  walkExpression(expression) {
@@ -3429,6 +3529,7 @@ class JavascriptParser extends Parser {
3429
3529
  }
3430
3530
 
3431
3531
  /**
3532
+ * Walk await expression.
3432
3533
  * @param {AwaitExpression} expression await expression
3433
3534
  */
3434
3535
  walkAwaitExpression(expression) {
@@ -3439,6 +3540,7 @@ class JavascriptParser extends Parser {
3439
3540
  }
3440
3541
 
3441
3542
  /**
3543
+ * Walk array expression.
3442
3544
  * @param {ArrayExpression} expression array expression
3443
3545
  */
3444
3546
  walkArrayExpression(expression) {
@@ -3448,6 +3550,7 @@ class JavascriptParser extends Parser {
3448
3550
  }
3449
3551
 
3450
3552
  /**
3553
+ * Walk spread element.
3451
3554
  * @param {SpreadElement} expression spread element
3452
3555
  */
3453
3556
  walkSpreadElement(expression) {
@@ -3457,6 +3560,7 @@ class JavascriptParser extends Parser {
3457
3560
  }
3458
3561
 
3459
3562
  /**
3563
+ * Walk object expression.
3460
3564
  * @param {ObjectExpression} expression object expression
3461
3565
  */
3462
3566
  walkObjectExpression(expression) {
@@ -3471,6 +3575,7 @@ class JavascriptParser extends Parser {
3471
3575
  }
3472
3576
 
3473
3577
  /**
3578
+ * Processes the provided prop.
3474
3579
  * @param {Property | SpreadElement} prop property or spread element
3475
3580
  */
3476
3581
  walkProperty(prop) {
@@ -3494,6 +3599,7 @@ class JavascriptParser extends Parser {
3494
3599
  }
3495
3600
 
3496
3601
  /**
3602
+ * Walk function expression.
3497
3603
  * @param {FunctionExpression} expression arrow function expression
3498
3604
  */
3499
3605
  walkFunctionExpression(expression) {
@@ -3523,6 +3629,7 @@ class JavascriptParser extends Parser {
3523
3629
  }
3524
3630
 
3525
3631
  /**
3632
+ * Walk arrow function expression.
3526
3633
  * @param {ArrowFunctionExpression} expression arrow function expression
3527
3634
  */
3528
3635
  walkArrowFunctionExpression(expression) {
@@ -3546,6 +3653,7 @@ class JavascriptParser extends Parser {
3546
3653
  }
3547
3654
 
3548
3655
  /**
3656
+ * Walk sequence expression.
3549
3657
  * @param {SequenceExpression} expression the sequence
3550
3658
  */
3551
3659
  walkSequenceExpression(expression) {
@@ -3584,6 +3692,7 @@ class JavascriptParser extends Parser {
3584
3692
  }
3585
3693
 
3586
3694
  /**
3695
+ * Walk update expression.
3587
3696
  * @param {UpdateExpression} expression the update expression
3588
3697
  */
3589
3698
  walkUpdateExpression(expression) {
@@ -3591,6 +3700,7 @@ class JavascriptParser extends Parser {
3591
3700
  }
3592
3701
 
3593
3702
  /**
3703
+ * Walk unary expression.
3594
3704
  * @param {UnaryExpression} expression the unary expression
3595
3705
  */
3596
3706
  walkUnaryExpression(expression) {
@@ -3614,6 +3724,7 @@ class JavascriptParser extends Parser {
3614
3724
  }
3615
3725
 
3616
3726
  /**
3727
+ * Walk left right expression.
3617
3728
  * @param {LogicalExpression | BinaryExpression} expression the expression
3618
3729
  */
3619
3730
  walkLeftRightExpression(expression) {
@@ -3622,6 +3733,7 @@ class JavascriptParser extends Parser {
3622
3733
  }
3623
3734
 
3624
3735
  /**
3736
+ * Walk binary expression.
3625
3737
  * @param {BinaryExpression} expression the binary expression
3626
3738
  */
3627
3739
  walkBinaryExpression(expression) {
@@ -3631,6 +3743,7 @@ class JavascriptParser extends Parser {
3631
3743
  }
3632
3744
 
3633
3745
  /**
3746
+ * Walk logical expression.
3634
3747
  * @param {LogicalExpression} expression the logical expression
3635
3748
  */
3636
3749
  walkLogicalExpression(expression) {
@@ -3643,6 +3756,7 @@ class JavascriptParser extends Parser {
3643
3756
  }
3644
3757
 
3645
3758
  /**
3759
+ * Walk assignment expression.
3646
3760
  * @param {AssignmentExpression} expression assignment expression
3647
3761
  */
3648
3762
  walkAssignmentExpression(expression) {
@@ -3718,6 +3832,7 @@ class JavascriptParser extends Parser {
3718
3832
  }
3719
3833
 
3720
3834
  /**
3835
+ * Walk conditional expression.
3721
3836
  * @param {ConditionalExpression} expression conditional expression
3722
3837
  */
3723
3838
  walkConditionalExpression(expression) {
@@ -3745,9 +3860,41 @@ class JavascriptParser extends Parser {
3745
3860
  }
3746
3861
 
3747
3862
  /**
3863
+ * Walk new expression.
3748
3864
  * @param {NewExpression} expression new expression
3749
3865
  */
3750
3866
  walkNewExpression(expression) {
3867
+ // TODO: not a webpack bug — `acorn-import-phases` accepts
3868
+ // `new import.defer(...)` / `new import.source(...)` even though
3869
+ // `ImportCall` is a `CallExpression` per spec and is therefore not a
3870
+ // valid `new` operand. Acorn rejects bare `new import(...)` correctly.
3871
+ // Drop this block once the upstream plugin (or acorn itself) reports
3872
+ // the SyntaxError. Parenthesized forms (`new (import.defer(...))`)
3873
+ // produce the same AST shape, so we look at the source between `new`
3874
+ // and the callee (with comments stripped) to keep them valid.
3875
+ if (
3876
+ expression.callee.type === "ImportExpression" &&
3877
+ typeof this.state.source === "string"
3878
+ ) {
3879
+ const newStart = /** @type {Range} */ (expression.range)[0];
3880
+ const calleeStart = /** @type {Range} */ (expression.callee.range)[0];
3881
+ const between = this.state.source
3882
+ .slice(newStart, calleeStart)
3883
+ .replace(/\/\*[\s\S]*?\*\//g, "")
3884
+ .replace(/\/\/[^\n]*/g, "");
3885
+ if (!between.includes("(")) {
3886
+ const err =
3887
+ /** @type {SyntaxError & { loc?: { line: number, column: number } }} */
3888
+ (new SyntaxError("import call cannot be the target of `new`"));
3889
+ if (expression.loc) {
3890
+ err.loc = {
3891
+ line: expression.loc.start.line,
3892
+ column: expression.loc.start.column
3893
+ };
3894
+ }
3895
+ throw err;
3896
+ }
3897
+ }
3751
3898
  const result = this.callHooksForExpression(
3752
3899
  this.hooks.new,
3753
3900
  expression.callee,
@@ -3761,6 +3908,7 @@ class JavascriptParser extends Parser {
3761
3908
  }
3762
3909
 
3763
3910
  /**
3911
+ * Walk yield expression.
3764
3912
  * @param {YieldExpression} expression yield expression
3765
3913
  */
3766
3914
  walkYieldExpression(expression) {
@@ -3770,6 +3918,7 @@ class JavascriptParser extends Parser {
3770
3918
  }
3771
3919
 
3772
3920
  /**
3921
+ * Walk template literal.
3773
3922
  * @param {TemplateLiteral} expression template literal
3774
3923
  */
3775
3924
  walkTemplateLiteral(expression) {
@@ -3779,6 +3928,7 @@ class JavascriptParser extends Parser {
3779
3928
  }
3780
3929
 
3781
3930
  /**
3931
+ * Walk tagged template expression.
3782
3932
  * @param {TaggedTemplateExpression} expression tagged template expression
3783
3933
  */
3784
3934
  walkTaggedTemplateExpression(expression) {
@@ -3793,6 +3943,7 @@ class JavascriptParser extends Parser {
3793
3943
  }
3794
3944
 
3795
3945
  /**
3946
+ * Walk class expression.
3796
3947
  * @param {ClassExpression} expression the class expression
3797
3948
  */
3798
3949
  walkClassExpression(expression) {
@@ -3800,6 +3951,7 @@ class JavascriptParser extends Parser {
3800
3951
  }
3801
3952
 
3802
3953
  /**
3954
+ * Walk chain expression.
3803
3955
  * @param {ChainExpression} expression expression
3804
3956
  */
3805
3957
  walkChainExpression(expression) {
@@ -3815,6 +3967,7 @@ class JavascriptParser extends Parser {
3815
3967
  }
3816
3968
 
3817
3969
  /**
3970
+ * Processes the provided function expression.
3818
3971
  * @private
3819
3972
  * @param {FunctionExpression | ArrowFunctionExpression} functionExpression function expression
3820
3973
  * @param {(Expression | SpreadElement)[]} options options
@@ -3822,6 +3975,7 @@ class JavascriptParser extends Parser {
3822
3975
  */
3823
3976
  _walkIIFE(functionExpression, options, currentThis) {
3824
3977
  /**
3978
+ * Returns var info.
3825
3979
  * @param {Expression | SpreadElement} argOrThis arg or this
3826
3980
  * @returns {string | VariableInfo | undefined} var info
3827
3981
  */
@@ -3890,6 +4044,7 @@ class JavascriptParser extends Parser {
3890
4044
  }
3891
4045
 
3892
4046
  /**
4047
+ * Walk import expression.
3893
4048
  * @param {ImportExpression} expression import expression
3894
4049
  */
3895
4050
  walkImportExpression(expression) {
@@ -3900,10 +4055,12 @@ class JavascriptParser extends Parser {
3900
4055
  }
3901
4056
 
3902
4057
  /**
4058
+ * Walk call expression.
3903
4059
  * @param {CallExpression} expression expression
3904
4060
  */
3905
4061
  walkCallExpression(expression) {
3906
4062
  /**
4063
+ * Checks whether this javascript parser is simple function.
3907
4064
  * @param {FunctionExpression | ArrowFunctionExpression} fn function
3908
4065
  * @returns {boolean} true when simple function
3909
4066
  */
@@ -4019,6 +4176,7 @@ class JavascriptParser extends Parser {
4019
4176
  }
4020
4177
 
4021
4178
  /**
4179
+ * Walk member expression.
4022
4180
  * @param {MemberExpression} expression member expression
4023
4181
  */
4024
4182
  walkMemberExpression(expression) {
@@ -4085,6 +4243,7 @@ class JavascriptParser extends Parser {
4085
4243
  }
4086
4244
 
4087
4245
  /**
4246
+ * Walk member expression with expression name.
4088
4247
  * @template R
4089
4248
  * @param {MemberExpression} expression member expression
4090
4249
  * @param {string} name name
@@ -4102,10 +4261,10 @@ class JavascriptParser extends Parser {
4102
4261
  if (expression.object.type === "MemberExpression") {
4103
4262
  // optimize the case where expression.object is a MemberExpression too.
4104
4263
  // we can keep info here when calling walkMemberExpression directly
4105
- const property =
4106
- /** @type {Identifier} */
4107
- (expression.property).name ||
4108
- `${/** @type {Literal} */ (expression.property).value}`;
4264
+ // Read the property from `members` (already extracted by
4265
+ // extractMemberExpressionChain) since the AST node may be a
4266
+ // TemplateLiteral, which has neither .name nor .value.
4267
+ const property = members[members.length - 1];
4109
4268
  name = name.slice(0, -property.length - 1);
4110
4269
  members.pop();
4111
4270
  const result = this.callHooksForInfo(
@@ -4128,6 +4287,7 @@ class JavascriptParser extends Parser {
4128
4287
  }
4129
4288
 
4130
4289
  /**
4290
+ * Walk this expression.
4131
4291
  * @param {ThisExpression} expression this expression
4132
4292
  */
4133
4293
  walkThisExpression(expression) {
@@ -4135,6 +4295,7 @@ class JavascriptParser extends Parser {
4135
4295
  }
4136
4296
 
4137
4297
  /**
4298
+ * Processes the provided expression.
4138
4299
  * @param {Identifier} expression identifier
4139
4300
  */
4140
4301
  walkIdentifier(expression) {
@@ -4142,6 +4303,7 @@ class JavascriptParser extends Parser {
4142
4303
  }
4143
4304
 
4144
4305
  /**
4306
+ * Walk meta property.
4145
4307
  * @param {MetaProperty} metaProperty meta property
4146
4308
  */
4147
4309
  walkMetaProperty(metaProperty) {
@@ -4149,6 +4311,7 @@ class JavascriptParser extends Parser {
4149
4311
  }
4150
4312
 
4151
4313
  /**
4314
+ * Call hooks for expression.
4152
4315
  * @template T
4153
4316
  * @template R
4154
4317
  * @param {HookMap<SyncBailHook<T, R>>} hookMap hooks the should be called
@@ -4167,6 +4330,7 @@ class JavascriptParser extends Parser {
4167
4330
  }
4168
4331
 
4169
4332
  /**
4333
+ * Call hooks for expression with fallback.
4170
4334
  * @template T
4171
4335
  * @template R
4172
4336
  * @param {HookMap<SyncBailHook<T, R>>} hookMap hooks the should be called
@@ -4201,6 +4365,7 @@ class JavascriptParser extends Parser {
4201
4365
  }
4202
4366
 
4203
4367
  /**
4368
+ * Call hooks for name.
4204
4369
  * @template T
4205
4370
  * @template R
4206
4371
  * @param {HookMap<SyncBailHook<T, R>>} hookMap hooks the should be called
@@ -4219,6 +4384,7 @@ class JavascriptParser extends Parser {
4219
4384
  }
4220
4385
 
4221
4386
  /**
4387
+ * Call hooks for info.
4222
4388
  * @template T
4223
4389
  * @template R
4224
4390
  * @param {HookMap<SyncBailHook<T, R>>} hookMap hooks that should be called
@@ -4237,6 +4403,7 @@ class JavascriptParser extends Parser {
4237
4403
  }
4238
4404
 
4239
4405
  /**
4406
+ * Call hooks for info with fallback.
4240
4407
  * @template T
4241
4408
  * @template R
4242
4409
  * @param {HookMap<SyncBailHook<T, R>>} hookMap hooks the should be called
@@ -4288,6 +4455,7 @@ class JavascriptParser extends Parser {
4288
4455
  }
4289
4456
 
4290
4457
  /**
4458
+ * Call hooks for name with fallback.
4291
4459
  * @template T
4292
4460
  * @template R
4293
4461
  * @param {HookMap<SyncBailHook<T, R>>} hookMap hooks the should be called
@@ -4308,6 +4476,7 @@ class JavascriptParser extends Parser {
4308
4476
  }
4309
4477
 
4310
4478
  /**
4479
+ * Processes the provided param.
4311
4480
  * @deprecated
4312
4481
  * @param {(string | Pattern | Property)[]} params scope params
4313
4482
  * @param {() => void} fn inner function
@@ -4338,6 +4507,7 @@ class JavascriptParser extends Parser {
4338
4507
  }
4339
4508
 
4340
4509
  /**
4510
+ * Processes the provided has thi.
4341
4511
  * @param {boolean} hasThis true, when this is defined
4342
4512
  * @param {Identifier[]} params scope params
4343
4513
  * @param {() => void} fn inner function
@@ -4370,6 +4540,7 @@ class JavascriptParser extends Parser {
4370
4540
  }
4371
4541
 
4372
4542
  /**
4543
+ * Processes the provided has thi.
4373
4544
  * @param {boolean} hasThis true, when this is defined
4374
4545
  * @param {(Pattern | string)[]} params scope params
4375
4546
  * @param {() => void} fn inner function
@@ -4402,6 +4573,7 @@ class JavascriptParser extends Parser {
4402
4573
  }
4403
4574
 
4404
4575
  /**
4576
+ * Processes the provided fn.
4405
4577
  * @param {() => void} fn inner function
4406
4578
  * @param {boolean} inExecutedPath executed state
4407
4579
  * @returns {void}
@@ -4431,6 +4603,7 @@ class JavascriptParser extends Parser {
4431
4603
  }
4432
4604
 
4433
4605
  /**
4606
+ * Processes the provided statement.
4434
4607
  * @param {(Directive | Statement | ModuleDeclaration)[]} statements statements
4435
4608
  */
4436
4609
  detectMode(statements) {
@@ -4457,6 +4630,7 @@ class JavascriptParser extends Parser {
4457
4630
  }
4458
4631
 
4459
4632
  /**
4633
+ * Processes the provided pattern.
4460
4634
  * @param {(string | Pattern | Property)[]} patterns patterns
4461
4635
  * @param {OnIdentString} onIdent on ident callback
4462
4636
  */
@@ -4471,6 +4645,7 @@ class JavascriptParser extends Parser {
4471
4645
  }
4472
4646
 
4473
4647
  /**
4648
+ * Processes the provided pattern.
4474
4649
  * @param {Pattern | Property} pattern pattern
4475
4650
  * @param {OnIdent} onIdent on ident callback
4476
4651
  */
@@ -4505,6 +4680,7 @@ class JavascriptParser extends Parser {
4505
4680
  }
4506
4681
 
4507
4682
  /**
4683
+ * Processes the provided pattern.
4508
4684
  * @param {Identifier} pattern identifier pattern
4509
4685
  * @param {OnIdent} onIdent callback
4510
4686
  */
@@ -4515,6 +4691,7 @@ class JavascriptParser extends Parser {
4515
4691
  }
4516
4692
 
4517
4693
  /**
4694
+ * Enter object pattern.
4518
4695
  * @param {ObjectPattern} pattern object pattern
4519
4696
  * @param {OnIdent} onIdent callback
4520
4697
  */
@@ -4530,6 +4707,7 @@ class JavascriptParser extends Parser {
4530
4707
  }
4531
4708
 
4532
4709
  /**
4710
+ * Enter array pattern.
4533
4711
  * @param {ArrayPattern} pattern object pattern
4534
4712
  * @param {OnIdent} onIdent callback
4535
4713
  */
@@ -4548,6 +4726,7 @@ class JavascriptParser extends Parser {
4548
4726
  }
4549
4727
 
4550
4728
  /**
4729
+ * Enter rest element.
4551
4730
  * @param {RestElement} pattern object pattern
4552
4731
  * @param {OnIdent} onIdent callback
4553
4732
  */
@@ -4556,6 +4735,7 @@ class JavascriptParser extends Parser {
4556
4735
  }
4557
4736
 
4558
4737
  /**
4738
+ * Enter assignment pattern.
4559
4739
  * @param {AssignmentPattern} pattern object pattern
4560
4740
  * @param {OnIdent} onIdent callback
4561
4741
  */
@@ -4564,6 +4744,7 @@ class JavascriptParser extends Parser {
4564
4744
  }
4565
4745
 
4566
4746
  /**
4747
+ * Evaluate expression.
4567
4748
  * @param {Expression | SpreadElement | PrivateIdentifier | Super} expression expression node
4568
4749
  * @returns {BasicEvaluatedExpression} evaluation result
4569
4750
  */
@@ -4588,6 +4769,7 @@ class JavascriptParser extends Parser {
4588
4769
  }
4589
4770
 
4590
4771
  /**
4772
+ * Returns parsed string.
4591
4773
  * @param {Expression} expression expression
4592
4774
  * @returns {string} parsed string
4593
4775
  */
@@ -4612,6 +4794,7 @@ class JavascriptParser extends Parser {
4612
4794
  /** @typedef {{ range?: Range, value: string, code: boolean, conditional: false | CalculatedStringResult[] }} CalculatedStringResult */
4613
4795
 
4614
4796
  /**
4797
+ * Parses calculated string.
4615
4798
  * @param {Expression} expression expression
4616
4799
  * @returns {CalculatedStringResult} result
4617
4800
  */
@@ -4701,6 +4884,7 @@ class JavascriptParser extends Parser {
4701
4884
  }
4702
4885
 
4703
4886
  /**
4887
+ * Parses the provided source and updates the parser state.
4704
4888
  * @param {string | Buffer | PreparsedAst} source the source to parse
4705
4889
  * @param {ParserState} state the parser state
4706
4890
  * @returns {ParserState} the parser state
@@ -4712,6 +4896,9 @@ class JavascriptParser extends Parser {
4712
4896
 
4713
4897
  if (Buffer.isBuffer(source)) {
4714
4898
  source = source.toString("utf8");
4899
+ // Keep `state.source` as a string so downstream walkers can read
4900
+ // the original text without re-decoding the Buffer on every use.
4901
+ state.source = source;
4715
4902
  }
4716
4903
 
4717
4904
  let ast;
@@ -4771,6 +4958,7 @@ class JavascriptParser extends Parser {
4771
4958
  this.destructuringAssignmentProperties = new WeakMap();
4772
4959
  this.detectMode(ast.body);
4773
4960
  this.modulePreWalkStatements(ast.body);
4961
+ this.prevStatement = undefined;
4774
4962
  this.preWalkStatements(ast.body);
4775
4963
  this.prevStatement = undefined;
4776
4964
  this.blockPreWalkStatements(ast.body);
@@ -4789,6 +4977,7 @@ class JavascriptParser extends Parser {
4789
4977
  }
4790
4978
 
4791
4979
  /**
4980
+ * Returns evaluation result.
4792
4981
  * @param {string} source source code
4793
4982
  * @returns {BasicEvaluatedExpression} evaluation result
4794
4983
  */
@@ -4805,6 +4994,7 @@ class JavascriptParser extends Parser {
4805
4994
  }
4806
4995
 
4807
4996
  /**
4997
+ * Checks whether this javascript parser is pure.
4808
4998
  * @param {Expression | Declaration | PrivateIdentifier | MaybeNamedFunctionDeclaration | MaybeNamedClassDeclaration | null | undefined} expr an expression
4809
4999
  * @param {number} commentsStartPos source position from which annotation comments are checked
4810
5000
  * @returns {boolean} true, when the expression is pure
@@ -4815,8 +5005,8 @@ class JavascriptParser extends Parser {
4815
5005
  .for(expr.type)
4816
5006
  .call(expr, commentsStartPos);
4817
5007
  if (typeof result === "boolean") return result;
5008
+ // TODO handle more cases
4818
5009
  switch (expr.type) {
4819
- // TODO handle more cases
4820
5010
  case "ClassDeclaration":
4821
5011
  case "ClassExpression": {
4822
5012
  if (expr.body.type !== "ClassBody") return false;
@@ -4869,9 +5059,15 @@ class JavascriptParser extends Parser {
4869
5059
  });
4870
5060
  }
4871
5061
  case "TemplateLiteral":
4872
- return expr.expressions.every((expr) =>
4873
- this.isPure(expr, /** @type {Range} */ (expr.range)[0])
4874
- );
5062
+ // Thread `commentsStartPos` through the interpolations so a
5063
+ // /*#__PURE__*/ comment that sits inside `${ ... }` (or before
5064
+ // the first interpolation) is part of the scanned range when
5065
+ // the inner expression's purity is evaluated.
5066
+ return expr.expressions.every((e) => {
5067
+ const pureFlag = this.isPure(e, commentsStartPos);
5068
+ commentsStartPos = /** @type {Range} */ (e.range)[1];
5069
+ return pureFlag;
5070
+ });
4875
5071
  case "FunctionDeclaration":
4876
5072
  case "FunctionExpression":
4877
5073
  case "ArrowFunctionExpression":
@@ -4886,6 +5082,78 @@ class JavascriptParser extends Parser {
4886
5082
  this.isPure(decl.init, /** @type {Range} */ (decl.range)[0])
4887
5083
  );
4888
5084
 
5085
+ case "ArrayExpression":
5086
+ return expr.elements.every((element) => {
5087
+ if (element === null) return true;
5088
+ if (element.type === "SpreadElement") return false;
5089
+ const pureFlag = this.isPure(element, commentsStartPos);
5090
+ commentsStartPos = /** @type {Range} */ (element.range)[1];
5091
+ return pureFlag;
5092
+ });
5093
+
5094
+ case "ObjectExpression": {
5095
+ return expr.properties.every((property) => {
5096
+ if (property.type === "SpreadElement") return false;
5097
+
5098
+ if (
5099
+ property.computed &&
5100
+ !this.isPure(property.key, commentsStartPos)
5101
+ ) {
5102
+ return false;
5103
+ }
5104
+
5105
+ const pureFlag = this.isPure(
5106
+ /** @type {Exclude<Property["value"], AssignmentPattern | ObjectPattern | ArrayPattern | RestElement>} */
5107
+ (property.value),
5108
+ /** @type {Range} */ (property.key.range)[1]
5109
+ );
5110
+ commentsStartPos = /** @type {Range} */ (property.range)[1];
5111
+ return pureFlag;
5112
+ });
5113
+ }
5114
+
5115
+ case "ChainExpression":
5116
+ return this.isPure(expr.expression, commentsStartPos);
5117
+
5118
+ case "UnaryExpression":
5119
+ // Safe unary operators — produce their result without invoking
5120
+ // user code on the operand:
5121
+ // - `typeof` returns a type tag and never throws, even for
5122
+ // undeclared identifiers; no coercion.
5123
+ // - `void` evaluates the operand and discards it, returning
5124
+ // `undefined`; pure iff the operand is pure.
5125
+ // - `!` coerces via ToBoolean, which is defined to not call
5126
+ // any user code (objects → true, etc.).
5127
+ // Other operators (`+`, `-`, `~`, `delete`) fall through to
5128
+ // the generic evaluator which can still recognize literal
5129
+ // cases (e.g. `-1`, `+5`).
5130
+ if (
5131
+ expr.operator === "typeof" ||
5132
+ expr.operator === "void" ||
5133
+ expr.operator === "!"
5134
+ ) {
5135
+ return this.isPure(expr.argument, commentsStartPos);
5136
+ }
5137
+ break;
5138
+
5139
+ case "MetaProperty":
5140
+ return true;
5141
+
5142
+ case "BinaryExpression":
5143
+ // Strict (in)equality compares without coercion and never invokes
5144
+ // user code on its operands, so the result is pure iff both sides
5145
+ // are pure. All other binary operators may invoke `valueOf` /
5146
+ // `toString` / `[Symbol.hasInstance]` / Proxy traps and fall through
5147
+ // to the generic evaluator, which can still recognize the cases
5148
+ // where both sides evaluate to known primitive literals.
5149
+ if (expr.operator === "===" || expr.operator === "!==") {
5150
+ return (
5151
+ this.isPure(expr.left, commentsStartPos) &&
5152
+ this.isPure(expr.right, /** @type {Range} */ (expr.left.range)[1])
5153
+ );
5154
+ }
5155
+ break;
5156
+
4889
5157
  case "ConditionalExpression":
4890
5158
  return (
4891
5159
  this.isPure(expr.test, commentsStartPos) &&
@@ -4921,7 +5189,28 @@ class JavascriptParser extends Parser {
4921
5189
  ]).some(
4922
5190
  (comment) =>
4923
5191
  comment.type === "Block" &&
4924
- /^\s*(?:#|@)__PURE__\s*$/.test(comment.value)
5192
+ CompilerHintNotationRegExp.Pure.test(comment.value)
5193
+ );
5194
+ if (!pureFlag) return false;
5195
+ commentsStartPos = /** @type {Range} */ (expr.callee.range)[1];
5196
+ return expr.arguments.every((arg) => {
5197
+ if (arg.type === "SpreadElement") return false;
5198
+ const pureFlag = this.isPure(arg, commentsStartPos);
5199
+ commentsStartPos = /** @type {Range} */ (arg.range)[1];
5200
+ return pureFlag;
5201
+ });
5202
+ }
5203
+
5204
+ case "NewExpression": {
5205
+ const pureFlag =
5206
+ /** @type {Range} */ (expr.range)[0] - commentsStartPos > 12 &&
5207
+ this.getComments([
5208
+ commentsStartPos,
5209
+ /** @type {Range} */ (expr.range)[0]
5210
+ ]).some(
5211
+ (comment) =>
5212
+ comment.type === "Block" &&
5213
+ CompilerHintNotationRegExp.Pure.test(comment.value)
4925
5214
  );
4926
5215
  if (!pureFlag) return false;
4927
5216
  commentsStartPos = /** @type {Range} */ (expr.callee.range)[1];
@@ -4932,18 +5221,40 @@ class JavascriptParser extends Parser {
4932
5221
  return pureFlag;
4933
5222
  });
4934
5223
  }
5224
+
5225
+ case "TaggedTemplateExpression": {
5226
+ const pureFlag =
5227
+ /** @type {Range} */ (expr.range)[0] - commentsStartPos > 12 &&
5228
+ this.getComments([
5229
+ commentsStartPos,
5230
+ /** @type {Range} */ (expr.range)[0]
5231
+ ]).some(
5232
+ (comment) =>
5233
+ comment.type === "Block" &&
5234
+ CompilerHintNotationRegExp.Pure.test(comment.value)
5235
+ );
5236
+ if (!pureFlag) return false;
5237
+ commentsStartPos = /** @type {Range} */ (expr.tag.range)[1];
5238
+ return expr.quasi.expressions.every((e) => {
5239
+ const pureFlag = this.isPure(e, commentsStartPos);
5240
+ commentsStartPos = /** @type {Range} */ (e.range)[1];
5241
+ return pureFlag;
5242
+ });
5243
+ }
4935
5244
  }
4936
5245
  const evaluated = this.evaluateExpression(expr);
4937
5246
  return !evaluated.couldHaveSideEffects();
4938
5247
  }
4939
5248
 
4940
5249
  /**
5250
+ * Returns comments in the range.
4941
5251
  * @param {Range} range range
4942
5252
  * @returns {Comment[]} comments in the range
4943
5253
  */
4944
5254
  getComments(range) {
4945
5255
  const [rangeStart, rangeEnd] = range;
4946
5256
  /**
5257
+ * Returns compared.
4947
5258
  * @param {Comment} comment comment
4948
5259
  * @param {number} needle needle
4949
5260
  * @returns {number} compared
@@ -4966,6 +5277,7 @@ class JavascriptParser extends Parser {
4966
5277
  }
4967
5278
 
4968
5279
  /**
5280
+ * Checks whether this javascript parser is asi position.
4969
5281
  * @param {number} pos source code position
4970
5282
  * @returns {boolean} true when a semicolon has been inserted before this position, false if not
4971
5283
  */
@@ -4996,6 +5308,7 @@ class JavascriptParser extends Parser {
4996
5308
  }
4997
5309
 
4998
5310
  /**
5311
+ * Updates asi position using the provided po.
4999
5312
  * @param {number} pos source code position
5000
5313
  * @returns {void}
5001
5314
  */
@@ -5004,6 +5317,7 @@ class JavascriptParser extends Parser {
5004
5317
  }
5005
5318
 
5006
5319
  /**
5320
+ * Unset asi position.
5007
5321
  * @param {number} pos source code position
5008
5322
  * @returns {void}
5009
5323
  */
@@ -5012,6 +5326,7 @@ class JavascriptParser extends Parser {
5012
5326
  }
5013
5327
 
5014
5328
  /**
5329
+ * Checks whether this javascript parser is statement level expression.
5015
5330
  * @param {Expression} expr expression
5016
5331
  * @returns {boolean} true, when the expression is a statement level expression
5017
5332
  */
@@ -5030,6 +5345,7 @@ class JavascriptParser extends Parser {
5030
5345
  }
5031
5346
 
5032
5347
  /**
5348
+ * Returns tag data.
5033
5349
  * @param {string} name name
5034
5350
  * @param {Tag} tag tag info
5035
5351
  * @returns {TagData | undefined} tag data
@@ -5046,6 +5362,7 @@ class JavascriptParser extends Parser {
5046
5362
  }
5047
5363
 
5048
5364
  /**
5365
+ * Processes the provided name.
5049
5366
  * @param {string} name name
5050
5367
  * @param {Tag} tag tag info
5051
5368
  * @param {TagData=} data data
@@ -5083,6 +5400,7 @@ class JavascriptParser extends Parser {
5083
5400
  }
5084
5401
 
5085
5402
  /**
5403
+ * Processes the provided name.
5086
5404
  * @param {string} name variable name
5087
5405
  */
5088
5406
  defineVariable(name) {
@@ -5098,6 +5416,7 @@ class JavascriptParser extends Parser {
5098
5416
  }
5099
5417
 
5100
5418
  /**
5419
+ * Processes the provided name.
5101
5420
  * @param {string} name variable name
5102
5421
  */
5103
5422
  undefineVariable(name) {
@@ -5105,6 +5424,7 @@ class JavascriptParser extends Parser {
5105
5424
  }
5106
5425
 
5107
5426
  /**
5427
+ * Checks whether this javascript parser is variable defined.
5108
5428
  * @param {string} name variable name
5109
5429
  * @returns {boolean} true, when variable is defined
5110
5430
  */
@@ -5118,6 +5438,7 @@ class JavascriptParser extends Parser {
5118
5438
  }
5119
5439
 
5120
5440
  /**
5441
+ * Gets variable info.
5121
5442
  * @param {string} name variable name
5122
5443
  * @returns {ExportedVariableInfo} info for this variable
5123
5444
  */
@@ -5130,6 +5451,7 @@ class JavascriptParser extends Parser {
5130
5451
  }
5131
5452
 
5132
5453
  /**
5454
+ * Updates variable using the provided name.
5133
5455
  * @param {string} name variable name
5134
5456
  * @param {ExportedVariableInfo} variableInfo new info for this variable
5135
5457
  * @returns {void}
@@ -5155,6 +5477,7 @@ class JavascriptParser extends Parser {
5155
5477
  }
5156
5478
 
5157
5479
  /**
5480
+ * Evaluated variable.
5158
5481
  * @param {TagInfo} tagInfo tag info
5159
5482
  * @returns {VariableInfo} variable info
5160
5483
  */
@@ -5168,6 +5491,7 @@ class JavascriptParser extends Parser {
5168
5491
  }
5169
5492
 
5170
5493
  /**
5494
+ * Parses comment options.
5171
5495
  * @param {Range} range range of the comment
5172
5496
  * @returns {{ options: Record<string, EXPECTED_ANY> | null, errors: (Error & { comment: Comment })[] | null }} result
5173
5497
  */
@@ -5211,6 +5535,7 @@ class JavascriptParser extends Parser {
5211
5535
  }
5212
5536
 
5213
5537
  /**
5538
+ * Extract member expression chain.
5214
5539
  * @param {Expression | Super} expression a member expression
5215
5540
  * @returns {{ members: Members, object: Expression | Super, membersOptionals: MembersOptionals, memberRanges: MemberRanges }} member names (reverse order) and remaining object
5216
5541
  */
@@ -5225,9 +5550,20 @@ class JavascriptParser extends Parser {
5225
5550
  const memberRanges = [];
5226
5551
  while (expr.type === "MemberExpression") {
5227
5552
  if (expr.computed) {
5228
- if (expr.property.type !== "Literal") break;
5229
- members.push(`${expr.property.value}`); // the literal
5230
- memberRanges.push(/** @type {Range} */ (expr.object.range)); // the range of the expression fragment before the literal
5553
+ const prop = expr.property;
5554
+ if (prop.type === "Literal") {
5555
+ members.push(`${prop.value}`); // the literal
5556
+ } else if (
5557
+ prop.type === "TemplateLiteral" &&
5558
+ prop.expressions.length === 0 &&
5559
+ typeof prop.quasis[0].value.cooked === "string"
5560
+ ) {
5561
+ // `[`url`]` is statically a string just like `["url"]`
5562
+ members.push(prop.quasis[0].value.cooked);
5563
+ } else {
5564
+ break;
5565
+ }
5566
+ memberRanges.push(/** @type {Range} */ (expr.object.range)); // the range of the expression fragment before the property
5231
5567
  } else {
5232
5568
  if (expr.property.type !== "Identifier") break;
5233
5569
  members.push(expr.property.name); // the identifier
@@ -5246,6 +5582,7 @@ class JavascriptParser extends Parser {
5246
5582
  }
5247
5583
 
5248
5584
  /**
5585
+ * Gets free info from variable.
5249
5586
  * @param {string} varName variable name
5250
5587
  * @returns {{ name: string, info: VariableInfo | string } | undefined} name of the free variable and variable info for that
5251
5588
  */
@@ -5265,6 +5602,7 @@ class JavascriptParser extends Parser {
5265
5602
  }
5266
5603
 
5267
5604
  /**
5605
+ * Gets name info from variable.
5268
5606
  * @param {string} varName variable name
5269
5607
  * @returns {{ name: string, info: VariableInfo | string } | undefined} name of the free variable and variable info for that
5270
5608
  */
@@ -5287,6 +5625,7 @@ class JavascriptParser extends Parser {
5287
5625
  /** @typedef {{ type: "expression", rootInfo: string | VariableInfo, name: string, getMembers: () => Members, getMembersOptionals: () => MembersOptionals, getMemberRanges: () => MemberRanges }} ExpressionExpressionInfo */
5288
5626
 
5289
5627
  /**
5628
+ * Gets member expression info.
5290
5629
  * @param {Expression | Super} expression a member expression
5291
5630
  * @param {number} allowedTypes which types should be returned, presented in bit mask
5292
5631
  * @returns {CallExpressionInfo | ExpressionExpressionInfo | undefined} expression info
@@ -5344,6 +5683,7 @@ class JavascriptParser extends Parser {
5344
5683
  }
5345
5684
 
5346
5685
  /**
5686
+ * Gets name for expression.
5347
5687
  * @param {Expression} expression an expression
5348
5688
  * @returns {{ name: string, rootInfo: ExportedVariableInfo, getMembers: () => Members } | undefined} name info
5349
5689
  */
@@ -5355,6 +5695,7 @@ class JavascriptParser extends Parser {
5355
5695
  }
5356
5696
 
5357
5697
  /**
5698
+ * Get module parse function.
5358
5699
  * @param {Compilation} compilation compilation
5359
5700
  * @param {Module} module module
5360
5701
  * @returns {ParseFunction | undefined} parser
@@ -5375,6 +5716,7 @@ class JavascriptParser extends Parser {
5375
5716
  }
5376
5717
 
5377
5718
  /**
5719
+ * Returns parse result.
5378
5720
  * @param {string} code source code
5379
5721
  * @param {InternalParseOptions} options parsing options
5380
5722
  * @param {ParseFunction=} customParse custom function to parse
@@ -5390,6 +5732,7 @@ class JavascriptParser extends Parser {
5390
5732
  sourceType: type === "auto" ? "module" : type
5391
5733
  };
5392
5734
  /**
5735
+ * Returns parse result.
5393
5736
  * @param {string} code source code
5394
5737
  * @param {ParseOptions} options parsing options
5395
5738
  * @returns {ParseResult} parse result
@@ -5458,6 +5801,7 @@ class JavascriptParser extends Parser {
5458
5801
  }
5459
5802
 
5460
5803
  /**
5804
+ * Returns parser.
5461
5805
  * @param {((BaseParser: typeof AcornParser) => typeof AcornParser)[]} plugins parser plugin
5462
5806
  * @returns {typeof JavascriptParser} parser
5463
5807
  */