webpack 5.99.9 → 5.100.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 (306) hide show
  1. package/bin/webpack.js +8 -2
  2. package/hot/log.js +15 -15
  3. package/hot/poll.js +1 -0
  4. package/lib/APIPlugin.js +3 -3
  5. package/lib/AbstractMethodError.js +1 -0
  6. package/lib/AutomaticPrefetchPlugin.js +1 -0
  7. package/lib/BannerPlugin.js +1 -1
  8. package/lib/CaseSensitiveModulesWarning.js +4 -4
  9. package/lib/Chunk.js +6 -6
  10. package/lib/ChunkGraph.js +37 -31
  11. package/lib/ChunkGroup.js +4 -4
  12. package/lib/ChunkTemplate.js +1 -1
  13. package/lib/CleanPlugin.js +94 -17
  14. package/lib/CodeGenerationResults.js +1 -1
  15. package/lib/CompatibilityPlugin.js +5 -2
  16. package/lib/Compilation.js +67 -45
  17. package/lib/Compiler.js +46 -16
  18. package/lib/ConcatenationScope.js +15 -6
  19. package/lib/ConstPlugin.js +5 -3
  20. package/lib/ContextModule.js +16 -12
  21. package/lib/ContextModuleFactory.js +4 -3
  22. package/lib/ContextReplacementPlugin.js +4 -2
  23. package/lib/CssModule.js +2 -2
  24. package/lib/DefinePlugin.js +111 -3
  25. package/lib/DelegatedModuleFactoryPlugin.js +18 -18
  26. package/lib/Dependency.js +6 -1
  27. package/lib/DependencyTemplate.js +1 -0
  28. package/lib/DllEntryPlugin.js +3 -1
  29. package/lib/DllPlugin.js +4 -3
  30. package/lib/DllReferencePlugin.js +2 -2
  31. package/lib/DynamicEntryPlugin.js +1 -1
  32. package/lib/EntryOptionPlugin.js +5 -0
  33. package/lib/ErrorHelpers.js +4 -4
  34. package/lib/EvalDevToolModulePlugin.js +3 -3
  35. package/lib/EvalSourceMapDevToolPlugin.js +7 -7
  36. package/lib/ExportsInfo.js +48 -39
  37. package/lib/ExternalModule.js +15 -11
  38. package/lib/ExternalModuleFactoryPlugin.js +5 -2
  39. package/lib/FileSystemInfo.js +51 -36
  40. package/lib/FlagDependencyExportsPlugin.js +14 -7
  41. package/lib/FlagDependencyUsagePlugin.js +1 -1
  42. package/lib/Generator.js +14 -1
  43. package/lib/HookWebpackError.js +1 -0
  44. package/lib/HotModuleReplacementPlugin.js +77 -50
  45. package/lib/IgnorePlugin.js +1 -1
  46. package/lib/InvalidDependenciesModuleWarning.js +1 -1
  47. package/lib/JavascriptMetaInfoPlugin.js +0 -1
  48. package/lib/LibManifestPlugin.js +4 -2
  49. package/lib/LoaderOptionsPlugin.js +6 -4
  50. package/lib/MainTemplate.js +2 -2
  51. package/lib/Module.js +21 -6
  52. package/lib/ModuleFactory.js +1 -0
  53. package/lib/ModuleGraph.js +24 -2
  54. package/lib/ModuleGraphConnection.js +5 -5
  55. package/lib/ModuleInfoHeaderPlugin.js +2 -1
  56. package/lib/ModuleParseError.js +1 -0
  57. package/lib/ModuleSourceTypesConstants.js +12 -12
  58. package/lib/ModuleTemplate.js +1 -1
  59. package/lib/ModuleTypeConstants.js +21 -21
  60. package/lib/MultiCompiler.js +6 -6
  61. package/lib/NormalModule.js +31 -44
  62. package/lib/NormalModuleFactory.js +29 -19
  63. package/lib/NormalModuleReplacementPlugin.js +1 -1
  64. package/lib/NullFactory.js +1 -0
  65. package/lib/OptimizationStages.js +1 -1
  66. package/lib/Parser.js +1 -0
  67. package/lib/ProgressPlugin.js +12 -5
  68. package/lib/ProvidePlugin.js +5 -1
  69. package/lib/RecordIdsPlugin.js +3 -3
  70. package/lib/RuntimeGlobals.js +175 -155
  71. package/lib/RuntimeModule.js +1 -0
  72. package/lib/RuntimePlugin.js +33 -7
  73. package/lib/RuntimeTemplate.js +111 -11
  74. package/lib/SourceMapDevToolModuleOptionsPlugin.js +15 -25
  75. package/lib/SourceMapDevToolPlugin.js +19 -17
  76. package/lib/Template.js +2 -2
  77. package/lib/TemplatedPathPlugin.js +1 -1
  78. package/lib/WarnDeprecatedOptionPlugin.js +7 -8
  79. package/lib/WatchIgnorePlugin.js +4 -3
  80. package/lib/WebpackIsIncludedPlugin.js +2 -1
  81. package/lib/WebpackOptionsApply.js +115 -27
  82. package/lib/asset/AssetGenerator.js +15 -11
  83. package/lib/asset/AssetModulesPlugin.js +19 -17
  84. package/lib/asset/AssetSourceGenerator.js +4 -4
  85. package/lib/asset/RawDataUrlModule.js +4 -2
  86. package/lib/async-modules/AwaitDependenciesInitFragment.js +1 -1
  87. package/lib/buildChunkGraph.js +6 -3
  88. package/lib/cache/AddBuildDependenciesPlugin.js +5 -6
  89. package/lib/cache/IdleFileCachePlugin.js +7 -4
  90. package/lib/cache/MemoryCachePlugin.js +1 -0
  91. package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
  92. package/lib/cache/PackFileCacheStrategy.js +26 -20
  93. package/lib/cache/ResolverCachePlugin.js +16 -8
  94. package/lib/cli.js +15 -10
  95. package/lib/config/browserslistTargetHandler.js +3 -3
  96. package/lib/config/defaults.js +25 -17
  97. package/lib/config/normalization.js +2 -1
  98. package/lib/config/target.js +6 -5
  99. package/lib/container/ContainerPlugin.js +1 -1
  100. package/lib/container/ContainerReferencePlugin.js +1 -1
  101. package/lib/container/FallbackModule.js +2 -1
  102. package/lib/container/HoistContainerReferencesPlugin.js +1 -1
  103. package/lib/container/ModuleFederationPlugin.js +2 -2
  104. package/lib/container/RemoteModule.js +1 -1
  105. package/lib/css/CssGenerator.js +9 -6
  106. package/lib/css/CssModulesPlugin.js +44 -31
  107. package/lib/css/CssParser.js +6 -4
  108. package/lib/css/walkCssTokens.js +33 -37
  109. package/lib/debug/ProfilingPlugin.js +6 -6
  110. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +8 -8
  111. package/lib/dependencies/AMDPlugin.js +12 -8
  112. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +28 -26
  113. package/lib/dependencies/CachedConstDependency.js +1 -5
  114. package/lib/dependencies/CommonJsExportRequireDependency.js +6 -4
  115. package/lib/dependencies/CommonJsExportsParserPlugin.js +22 -25
  116. package/lib/dependencies/CommonJsFullRequireDependency.js +1 -9
  117. package/lib/dependencies/CommonJsImportsParserPlugin.js +100 -114
  118. package/lib/dependencies/CommonJsPlugin.js +15 -16
  119. package/lib/dependencies/ContextDependencyHelpers.js +2 -1
  120. package/lib/dependencies/ContextDependencyTemplateAsId.js +1 -0
  121. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +1 -0
  122. package/lib/dependencies/CssIcssExportDependency.js +1 -1
  123. package/lib/dependencies/CssLocalIdentifierDependency.js +2 -2
  124. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +2 -1
  125. package/lib/dependencies/DynamicExports.js +9 -9
  126. package/lib/dependencies/ExportsInfoDependency.js +1 -1
  127. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +122 -101
  128. package/lib/dependencies/HarmonyExportExpressionDependency.js +1 -1
  129. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +95 -19
  130. package/lib/dependencies/HarmonyExportInitFragment.js +1 -1
  131. package/lib/dependencies/HarmonyImportDependency.js +11 -5
  132. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +238 -162
  133. package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -1
  134. package/lib/dependencies/HarmonyImportSpecifierDependency.js +20 -9
  135. package/lib/dependencies/HarmonyModulesPlugin.js +23 -12
  136. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -0
  137. package/lib/dependencies/ImportMetaContextPlugin.js +2 -1
  138. package/lib/dependencies/ImportMetaPlugin.js +2 -2
  139. package/lib/dependencies/ImportParserPlugin.js +40 -9
  140. package/lib/dependencies/ImportPlugin.js +3 -1
  141. package/lib/dependencies/LoaderPlugin.js +1 -0
  142. package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +1 -0
  143. package/lib/dependencies/RequireContextPlugin.js +3 -1
  144. package/lib/dependencies/RequireEnsurePlugin.js +6 -6
  145. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +33 -34
  146. package/lib/dependencies/RequireIncludePlugin.js +1 -0
  147. package/lib/dependencies/RuntimeRequirementsDependency.js +1 -1
  148. package/lib/dependencies/SystemPlugin.js +1 -1
  149. package/lib/dependencies/URLContextDependency.js +65 -0
  150. package/lib/dependencies/URLPlugin.js +17 -157
  151. package/lib/dependencies/WorkerPlugin.js +23 -10
  152. package/lib/dependencies/processExportInfo.js +2 -1
  153. package/lib/esm/ModuleChunkFormatPlugin.js +269 -185
  154. package/lib/esm/ModuleChunkLoadingPlugin.js +39 -1
  155. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +70 -3
  156. package/lib/hmr/HotModuleReplacement.runtime.js +0 -1
  157. package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
  158. package/lib/hmr/JavascriptHotModuleReplacementHelper.js +37 -0
  159. package/lib/hmr/LazyCompilationPlugin.js +4 -2
  160. package/lib/hmr/lazyCompilationBackend.js +4 -2
  161. package/lib/ids/ChunkModuleIdRangePlugin.js +6 -3
  162. package/lib/ids/DeterministicChunkIdsPlugin.js +30 -35
  163. package/lib/ids/DeterministicModuleIdsPlugin.js +4 -3
  164. package/lib/ids/HashedModuleIdsPlugin.js +5 -4
  165. package/lib/ids/IdHelpers.js +21 -17
  166. package/lib/ids/NamedChunkIdsPlugin.js +5 -5
  167. package/lib/ids/NamedModuleIdsPlugin.js +4 -4
  168. package/lib/ids/NaturalChunkIdsPlugin.js +2 -1
  169. package/lib/ids/NaturalModuleIdsPlugin.js +1 -1
  170. package/lib/ids/OccurrenceChunkIdsPlugin.js +3 -2
  171. package/lib/ids/OccurrenceModuleIdsPlugin.js +1 -1
  172. package/lib/ids/SyncModuleIdsPlugin.js +1 -1
  173. package/lib/index.js +13 -3
  174. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +113 -119
  175. package/lib/javascript/BasicEvaluatedExpression.js +2 -1
  176. package/lib/javascript/ChunkHelpers.js +1 -0
  177. package/lib/javascript/CommonJsChunkFormatPlugin.js +121 -136
  178. package/lib/javascript/EnableChunkLoadingPlugin.js +6 -3
  179. package/lib/javascript/JavascriptGenerator.js +14 -2
  180. package/lib/javascript/JavascriptModulesPlugin.js +68 -27
  181. package/lib/javascript/JavascriptParser.js +117 -76
  182. package/lib/javascript/JavascriptParserHelpers.js +41 -41
  183. package/lib/javascript/StartupHelpers.js +17 -17
  184. package/lib/json/JsonGenerator.js +4 -2
  185. package/lib/json/JsonModulesPlugin.js +2 -2
  186. package/lib/json/JsonParser.js +1 -1
  187. package/lib/library/AbstractLibraryPlugin.js +6 -2
  188. package/lib/library/AssignLibraryPlugin.js +21 -6
  189. package/lib/library/EnableLibraryPlugin.js +23 -3
  190. package/lib/library/UmdLibraryPlugin.js +15 -6
  191. package/lib/logging/createConsoleLogger.js +3 -3
  192. package/lib/logging/runtime.js +9 -9
  193. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +4 -22
  194. package/lib/node/RequireChunkLoadingRuntimeModule.js +4 -22
  195. package/lib/node/nodeConsole.js +4 -2
  196. package/lib/optimize/AggressiveMergingPlugin.js +45 -46
  197. package/lib/optimize/AggressiveSplittingPlugin.js +13 -12
  198. package/lib/optimize/ConcatenatedModule.js +227 -57
  199. package/lib/optimize/EnsureChunkConditionsPlugin.js +58 -58
  200. package/lib/optimize/FlagIncludedChunksPlugin.js +3 -1
  201. package/lib/optimize/InnerGraph.js +115 -112
  202. package/lib/optimize/InnerGraphPlugin.js +2 -2
  203. package/lib/optimize/LimitChunkCountPlugin.js +4 -2
  204. package/lib/optimize/MangleExportsPlugin.js +4 -3
  205. package/lib/optimize/MergeDuplicateChunksPlugin.js +80 -81
  206. package/lib/optimize/MinChunkSizePlugin.js +6 -3
  207. package/lib/optimize/ModuleConcatenationPlugin.js +31 -22
  208. package/lib/optimize/RealContentHashPlugin.js +26 -20
  209. package/lib/optimize/RemoveEmptyChunksPlugin.js +2 -1
  210. package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
  211. package/lib/optimize/SideEffectsFlagPlugin.js +3 -2
  212. package/lib/optimize/SplitChunksPlugin.js +16 -13
  213. package/lib/rules/BasicEffectRulePlugin.js +4 -2
  214. package/lib/rules/BasicMatcherRulePlugin.js +3 -1
  215. package/lib/rules/ObjectMatcherRulePlugin.js +3 -1
  216. package/lib/rules/RuleSetCompiler.js +6 -3
  217. package/lib/rules/UseEffectRulePlugin.js +3 -1
  218. package/lib/runtime/AsyncModuleRuntimeModule.js +64 -9
  219. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +1 -1
  220. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +214 -0
  221. package/lib/runtime/RuntimeIdRuntimeModule.js +2 -1
  222. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +8 -7
  223. package/lib/schemes/FileUriPlugin.js +1 -1
  224. package/lib/schemes/HttpUriPlugin.js +27 -19
  225. package/lib/schemes/VirtualUrlPlugin.js +222 -0
  226. package/lib/serialization/AggregateErrorSerializer.js +1 -1
  227. package/lib/serialization/BinaryMiddleware.js +5 -4
  228. package/lib/serialization/FileMiddleware.js +7 -4
  229. package/lib/serialization/ObjectMiddleware.js +14 -8
  230. package/lib/serialization/Serializer.js +5 -3
  231. package/lib/serialization/SerializerMiddleware.js +2 -0
  232. package/lib/sharing/ConsumeSharedModule.js +1 -1
  233. package/lib/sharing/ConsumeSharedPlugin.js +3 -3
  234. package/lib/sharing/ConsumeSharedRuntimeModule.js +2 -2
  235. package/lib/sharing/ProvideSharedModule.js +1 -1
  236. package/lib/sharing/ProvideSharedPlugin.js +3 -2
  237. package/lib/sharing/SharePlugin.js +2 -1
  238. package/lib/sharing/ShareRuntimeModule.js +3 -5
  239. package/lib/sharing/utils.js +34 -34
  240. package/lib/stats/DefaultStatsFactoryPlugin.js +49 -46
  241. package/lib/stats/DefaultStatsPresetPlugin.js +4 -2
  242. package/lib/stats/DefaultStatsPrinterPlugin.js +15 -9
  243. package/lib/stats/StatsFactory.js +4 -2
  244. package/lib/stats/StatsPrinter.js +3 -2
  245. package/lib/url/URLParserPlugin.js +266 -0
  246. package/lib/util/ArrayQueue.js +1 -1
  247. package/lib/util/AsyncQueue.js +1 -1
  248. package/lib/util/Hash.js +2 -0
  249. package/lib/util/IterableHelpers.js +1 -1
  250. package/lib/util/LazyBucketSortedSet.js +2 -1
  251. package/lib/util/LazySet.js +11 -6
  252. package/lib/util/ParallelismFactorCalculator.js +1 -1
  253. package/lib/util/SetHelpers.js +3 -3
  254. package/lib/util/SortableSet.js +2 -2
  255. package/lib/util/StackedCacheMap.js +3 -1
  256. package/lib/util/StackedMap.js +2 -2
  257. package/lib/util/StringXor.js +1 -0
  258. package/lib/util/TupleSet.js +1 -0
  259. package/lib/util/URLAbsoluteSpecifier.js +1 -1
  260. package/lib/util/cleverMerge.js +12 -8
  261. package/lib/util/comparators.js +154 -127
  262. package/lib/util/compileBooleanMatcher.js +8 -3
  263. package/lib/util/concatenate.js +8 -7
  264. package/lib/util/conventions.js +72 -73
  265. package/lib/util/create-schema-validation.js +2 -1
  266. package/lib/util/createHash.js +10 -4
  267. package/lib/util/deprecation.js +69 -66
  268. package/lib/util/deterministicGrouping.js +4 -2
  269. package/lib/util/extractUrlAndGlobal.js +1 -1
  270. package/lib/util/findGraphRoots.js +2 -2
  271. package/lib/util/fs.js +30 -23
  272. package/lib/util/hash/md4.js +2 -2
  273. package/lib/util/hash/wasm-hash.js +4 -2
  274. package/lib/util/identifier.js +13 -12
  275. package/lib/util/internalSerializables.js +2 -0
  276. package/lib/util/magicComment.js +5 -5
  277. package/lib/util/processAsyncTree.js +1 -1
  278. package/lib/util/propertyAccess.js +1 -1
  279. package/lib/util/propertyName.js +1 -1
  280. package/lib/util/registerExternalSerializer.js +1 -2
  281. package/lib/util/removeBOM.js +1 -1
  282. package/lib/util/runtime.js +29 -21
  283. package/lib/util/semver.js +1 -1
  284. package/lib/util/serialization.js +3 -0
  285. package/lib/util/source.js +3 -2
  286. package/lib/validateSchema.js +1 -0
  287. package/lib/wasm/EnableWasmLoadingPlugin.js +6 -3
  288. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -1
  289. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +46 -49
  290. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +2 -2
  291. package/lib/wasm-sync/WebAssemblyGenerator.js +2 -3
  292. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +3 -2
  293. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +3 -0
  294. package/lib/wasm-sync/WebAssemblyUtils.js +1 -1
  295. package/lib/web/JsonpChunkLoadingRuntimeModule.js +4 -22
  296. package/lib/webpack.js +4 -5
  297. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +1 -0
  298. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +6 -24
  299. package/lib/webworker/WebWorkerTemplatePlugin.js +1 -0
  300. package/package.json +119 -113
  301. package/schemas/WebpackOptions.check.js +1 -1
  302. package/schemas/WebpackOptions.json +17 -0
  303. package/schemas/plugins/schemes/VirtualUrlPlugin.check.d.ts +7 -0
  304. package/schemas/plugins/schemes/VirtualUrlPlugin.check.js +6 -0
  305. package/schemas/plugins/schemes/VirtualUrlPlugin.json +77 -0
  306. package/types.d.ts +1230 -360
@@ -5,15 +5,16 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- const { Parser: AcornParser, tokTypes } = require("acorn");
9
- const { SyncBailHook, HookMap } = require("tapable");
10
8
  const vm = require("vm");
9
+ const { Parser: AcornParser, tokTypes } = require("acorn");
10
+ const acornImportPhases = require("acorn-import-phases");
11
+ const { HookMap, SyncBailHook } = require("tapable");
11
12
  const Parser = require("../Parser");
12
13
  const StackedMap = require("../util/StackedMap");
13
14
  const binarySearchBounds = require("../util/binarySearchBounds");
14
15
  const {
15
- webpackCommentRegExp,
16
- createMagicCommentContext
16
+ createMagicCommentContext,
17
+ webpackCommentRegExp
17
18
  } = require("../util/magicComment");
18
19
  const memoize = require("../util/memoize");
19
20
  const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
@@ -83,6 +84,7 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
83
84
  /** @typedef {import("estree").Statement} Statement */
84
85
  /** @typedef {import("estree").ExportDefaultDeclaration} ExportDefaultDeclaration */
85
86
  /** @typedef {import("estree").Super} Super */
87
+ /** @typedef {import("estree").ImportSpecifier} ImportSpecifier */
86
88
  /** @typedef {import("estree").TaggedTemplateExpression} TaggedTemplateExpression */
87
89
  /** @typedef {import("estree").TemplateLiteral} TemplateLiteral */
88
90
  /** @typedef {import("estree").AssignmentProperty} AssignmentProperty */
@@ -102,10 +104,10 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
102
104
 
103
105
  // TODO remove cast when @types/estree has been updated to import assertions
104
106
  /** @typedef {import("estree").BaseNode & { type: "ImportAttribute", key: Identifier | Literal, value: Literal }} ImportAttribute */
105
- /** @typedef {import("estree").ImportDeclaration & { attributes?: Array<ImportAttribute> }} ImportDeclaration */
107
+ /** @typedef {import("estree").ImportDeclaration & { attributes?: Array<ImportAttribute>, phase?: "defer" }} ImportDeclaration */
106
108
  /** @typedef {import("estree").ExportNamedDeclaration & { attributes?: Array<ImportAttribute> }} ExportNamedDeclaration */
107
109
  /** @typedef {import("estree").ExportAllDeclaration & { attributes?: Array<ImportAttribute> }} ExportAllDeclaration */
108
- /** @typedef {import("estree").ImportExpression & { options?: Expression | null }} ImportExpression */
110
+ /** @typedef {import("estree").ImportExpression & { options?: Expression | null, phase?: "defer" }} ImportExpression */
109
111
  /** @typedef {ImportDeclaration | ExportNamedDeclaration | ExportDefaultDeclaration | ExportAllDeclaration} ModuleDeclaration */
110
112
 
111
113
  /** @type {string[]} */
@@ -120,7 +122,7 @@ const LEGACY_ASSERT_ATTRIBUTES = Symbol("assert");
120
122
  const importAssertions = Parser =>
121
123
  class extends Parser {
122
124
  /**
123
- * @this {TODO}
125
+ * @this {InstanceType<AcornParser>}
124
126
  * @returns {ImportAttribute[]} import attributes
125
127
  */
126
128
  parseWithClause() {
@@ -180,7 +182,10 @@ const importAssertions = Parser =>
180
182
  };
181
183
 
182
184
  // Syntax: https://developer.mozilla.org/en/SpiderMonkey/Parser_API
183
- const parser = AcornParser.extend(importAssertions);
185
+ const parser = AcornParser.extend(
186
+ importAssertions,
187
+ acornImportPhases({ source: false })
188
+ );
184
189
 
185
190
  /** @typedef {Record<string, string> & { _isLegacyAssert?: boolean }} ImportAttributes */
186
191
 
@@ -484,13 +489,15 @@ class JavascriptParser extends Parser {
484
489
  preDeclarator: new SyncBailHook(["declarator", "statement"]),
485
490
  /** @type {SyncBailHook<[VariableDeclarator, Statement], boolean | void>} */
486
491
  declarator: new SyncBailHook(["declarator", "statement"]),
487
- /** @type {HookMap<SyncBailHook<[Declaration], boolean | void>>} */
492
+ /** @type {HookMap<SyncBailHook<[Identifier], boolean | void>>} */
488
493
  varDeclaration: new HookMap(() => new SyncBailHook(["declaration"])),
489
- /** @type {HookMap<SyncBailHook<[Declaration], boolean | void>>} */
494
+ /** @type {HookMap<SyncBailHook<[Identifier], boolean | void>>} */
490
495
  varDeclarationLet: new HookMap(() => new SyncBailHook(["declaration"])),
491
- /** @type {HookMap<SyncBailHook<[Declaration], boolean | void>>} */
496
+ /** @type {HookMap<SyncBailHook<[Identifier], boolean | void>>} */
492
497
  varDeclarationConst: new HookMap(() => new SyncBailHook(["declaration"])),
493
- /** @type {HookMap<SyncBailHook<[Declaration], boolean | void>>} */
498
+ /** @type {HookMap<SyncBailHook<[Identifier], boolean | void>>} */
499
+ varDeclarationUsing: new HookMap(() => new SyncBailHook(["declaration"])),
500
+ /** @type {HookMap<SyncBailHook<[Identifier], boolean | void>>} */
494
501
  varDeclarationVar: new HookMap(() => new SyncBailHook(["declaration"])),
495
502
  /** @type {HookMap<SyncBailHook<[Identifier], boolean | void>>} */
496
503
  pattern: new HookMap(() => new SyncBailHook(["pattern"])),
@@ -649,8 +656,9 @@ class JavascriptParser extends Parser {
649
656
  } else if (
650
657
  expr.arguments.length > 2 ||
651
658
  this.getVariableInfo("RegExp") !== "RegExp"
652
- )
659
+ ) {
653
660
  return;
661
+ }
654
662
 
655
663
  let regExp;
656
664
  const arg1 = expr.arguments[0];
@@ -690,8 +698,9 @@ class JavascriptParser extends Parser {
690
698
  if (
691
699
  flags === undefined ||
692
700
  !BasicEvaluatedExpression.isValidRegExpFlags(flags)
693
- )
701
+ ) {
694
702
  return;
703
+ }
695
704
  }
696
705
  }
697
706
 
@@ -708,23 +717,28 @@ class JavascriptParser extends Parser {
708
717
  let allowedRight;
709
718
  if (expr.operator === "&&") {
710
719
  const leftAsBool = left.asBool();
711
- if (leftAsBool === false)
720
+ if (leftAsBool === false) {
712
721
  return left.setRange(/** @type {Range} */ (expr.range));
722
+ }
713
723
  returnRight = leftAsBool === true;
714
724
  allowedRight = false;
715
725
  } else if (expr.operator === "||") {
716
726
  const leftAsBool = left.asBool();
717
- if (leftAsBool === true)
727
+ if (leftAsBool === true) {
718
728
  return left.setRange(/** @type {Range} */ (expr.range));
729
+ }
719
730
  returnRight = leftAsBool === false;
720
731
  allowedRight = true;
721
732
  } else if (expr.operator === "??") {
722
733
  const leftAsNullish = left.asNullish();
723
- if (leftAsNullish === false)
734
+ if (leftAsNullish === false) {
724
735
  return left.setRange(/** @type {Range} */ (expr.range));
736
+ }
725
737
  if (leftAsNullish !== true) return;
726
738
  returnRight = true;
727
- } else return;
739
+ } else {
740
+ return;
741
+ }
728
742
  const right = this.evaluateExpression(expr.right);
729
743
  if (returnRight) {
730
744
  if (left.couldHaveSideEffects()) right.setSideEffects();
@@ -1135,11 +1149,12 @@ class JavascriptParser extends Parser {
1135
1149
  left.prefix,
1136
1150
  right.postfix,
1137
1151
  left.wrappedInnerExpressions &&
1138
- right.wrappedInnerExpressions &&
1139
- left.wrappedInnerExpressions
1140
- .concat(left.postfix ? [left.postfix] : [])
1141
- .concat(right.prefix ? [right.prefix] : [])
1142
- .concat(right.wrappedInnerExpressions)
1152
+ right.wrappedInnerExpressions && [
1153
+ ...left.wrappedInnerExpressions,
1154
+ ...(left.postfix ? [left.postfix] : []),
1155
+ ...(right.prefix ? [right.prefix] : []),
1156
+ ...right.wrappedInnerExpressions
1157
+ ]
1143
1158
  );
1144
1159
  } else {
1145
1160
  // ("prefix" + inner + postfix) + expr
@@ -1147,10 +1162,10 @@ class JavascriptParser extends Parser {
1147
1162
  res.setWrapped(
1148
1163
  left.prefix,
1149
1164
  null,
1150
- left.wrappedInnerExpressions &&
1151
- left.wrappedInnerExpressions.concat(
1152
- left.postfix ? [left.postfix, right] : [right]
1153
- )
1165
+ left.wrappedInnerExpressions && [
1166
+ ...left.wrappedInnerExpressions,
1167
+ ...(left.postfix ? [left.postfix, right] : [right])
1168
+ ]
1154
1169
  );
1155
1170
  }
1156
1171
  } else if (right.isString()) {
@@ -1163,16 +1178,17 @@ class JavascriptParser extends Parser {
1163
1178
  res.setWrapped(
1164
1179
  null,
1165
1180
  right.postfix,
1166
- right.wrappedInnerExpressions &&
1167
- (right.prefix ? [left, right.prefix] : [left]).concat(
1168
- right.wrappedInnerExpressions
1169
- )
1181
+ right.wrappedInnerExpressions && [
1182
+ ...(right.prefix ? [left, right.prefix] : [left]),
1183
+ ...right.wrappedInnerExpressions
1184
+ ]
1170
1185
  );
1171
1186
  } else {
1172
1187
  return;
1173
1188
  }
1174
- if (left.couldHaveSideEffects() || right.couldHaveSideEffects())
1189
+ if (left.couldHaveSideEffects() || right.couldHaveSideEffects()) {
1175
1190
  res.setSideEffects();
1191
+ }
1176
1192
  res.setRange(/** @type {Range} */ (expr.range));
1177
1193
  return res;
1178
1194
  } else if (expr.operator === "-") {
@@ -1370,9 +1386,10 @@ class JavascriptParser extends Parser {
1370
1386
  return this.callHooksForInfoWithFallback(
1371
1387
  this.hooks.evaluateIdentifier,
1372
1388
  info.name,
1373
- name => {
1389
+ _name => {
1374
1390
  cachedExpression = expression;
1375
1391
  cachedInfo = info;
1392
+ return undefined;
1376
1393
  },
1377
1394
  name => {
1378
1395
  const hook = this.hooks.evaluateDefinedIdentifier.get(name);
@@ -1424,7 +1441,7 @@ class JavascriptParser extends Parser {
1424
1441
  };
1425
1442
  }
1426
1443
  });
1427
- tapEvaluateWithVariableInfo("ThisExpression", expr => {
1444
+ tapEvaluateWithVariableInfo("ThisExpression", _expr => {
1428
1445
  const info = this.getVariableInfo("this");
1429
1446
  if (
1430
1447
  typeof info === "string" ||
@@ -1662,6 +1679,7 @@ class JavascriptParser extends Parser {
1662
1679
  if (!param.isString() && !param.isWrapped()) return;
1663
1680
  let stringSuffix = null;
1664
1681
  let hasUnknownParams = false;
1682
+ /** @type {BasicEvaluatedExpression[]} */
1665
1683
  const innerExpressions = [];
1666
1684
  for (let i = expr.arguments.length - 1; i >= 0; i--) {
1667
1685
  const arg = expr.arguments[i];
@@ -1701,7 +1719,10 @@ class JavascriptParser extends Parser {
1701
1719
  const prefix = param.isString() ? param : param.prefix;
1702
1720
  const inner =
1703
1721
  param.isWrapped() && param.wrappedInnerExpressions
1704
- ? param.wrappedInnerExpressions.concat(innerExpressions.reverse())
1722
+ ? [
1723
+ ...param.wrappedInnerExpressions,
1724
+ ...innerExpressions.reverse()
1725
+ ]
1705
1726
  : innerExpressions.reverse();
1706
1727
  return new BasicEvaluatedExpression()
1707
1728
  .setWrapped(prefix, stringSuffix, inner)
@@ -1709,7 +1730,7 @@ class JavascriptParser extends Parser {
1709
1730
  } else if (param.isWrapped()) {
1710
1731
  const postfix = stringSuffix || param.postfix;
1711
1732
  const inner = param.wrappedInnerExpressions
1712
- ? param.wrappedInnerExpressions.concat(innerExpressions.reverse())
1733
+ ? [...param.wrappedInnerExpressions, ...innerExpressions.reverse()]
1713
1734
  : innerExpressions.reverse();
1714
1735
  return new BasicEvaluatedExpression()
1715
1736
  .setWrapped(param.prefix, postfix, inner)
@@ -1879,13 +1900,20 @@ class JavascriptParser extends Parser {
1879
1900
  scopeParams.push(classy.id);
1880
1901
  }
1881
1902
  this.inClassScope(true, scopeParams, () => {
1882
- for (const classElement of /** @type {TODO} */ (classy.body.body)) {
1903
+ for (const classElement of classy.body.body) {
1883
1904
  if (!this.hooks.classBodyElement.call(classElement, classy)) {
1884
- if (classElement.computed && classElement.key) {
1885
- this.walkExpression(classElement.key);
1886
- }
1887
- if (classElement.value) {
1905
+ if (classElement.type === "StaticBlock") {
1906
+ const wasTopLevel = this.scope.topLevelScope;
1907
+ this.scope.topLevelScope = false;
1908
+ this.walkBlockStatement(classElement);
1909
+ this.scope.topLevelScope = wasTopLevel;
1910
+ } else {
1911
+ if (classElement.computed && classElement.key) {
1912
+ this.walkExpression(classElement.key);
1913
+ }
1914
+
1888
1915
  if (
1916
+ classElement.value &&
1889
1917
  !this.hooks.classBodyValue.call(
1890
1918
  classElement.value,
1891
1919
  classElement,
@@ -1897,11 +1925,6 @@ class JavascriptParser extends Parser {
1897
1925
  this.walkExpression(classElement.value);
1898
1926
  this.scope.topLevelScope = wasTopLevel;
1899
1927
  }
1900
- } else if (classElement.type === "StaticBlock") {
1901
- const wasTopLevel = this.scope.topLevelScope;
1902
- this.scope.topLevelScope = false;
1903
- this.walkBlockStatement(classElement);
1904
- this.scope.topLevelScope = wasTopLevel;
1905
1928
  }
1906
1929
  }
1907
1930
  }
@@ -2151,7 +2174,7 @@ class JavascriptParser extends Parser {
2151
2174
  }
2152
2175
 
2153
2176
  /**
2154
- * @param {BlockStatement} statement block statement
2177
+ * @param {BlockStatement | StaticBlock} statement block statement
2155
2178
  */
2156
2179
  walkBlockStatement(statement) {
2157
2180
  this.inBlockScope(() => {
@@ -2544,8 +2567,9 @@ class JavascriptParser extends Parser {
2544
2567
  if (
2545
2568
  expression.left.type !== "ObjectPattern" ||
2546
2569
  !this.destructuringAssignmentProperties
2547
- )
2570
+ ) {
2548
2571
  return;
2572
+ }
2549
2573
  const keys = this._preWalkObjectPattern(expression.left);
2550
2574
  if (!keys) return;
2551
2575
 
@@ -2815,16 +2839,19 @@ class JavascriptParser extends Parser {
2815
2839
  */
2816
2840
  blockPreWalkVariableDeclaration(statement) {
2817
2841
  if (statement.kind === "var") return;
2842
+
2818
2843
  const hookMap =
2819
2844
  statement.kind === "const"
2820
2845
  ? this.hooks.varDeclarationConst
2821
- : this.hooks.varDeclarationLet;
2846
+ : statement.kind === "using" || statement.kind === "await using"
2847
+ ? this.hooks.varDeclarationUsing
2848
+ : this.hooks.varDeclarationLet;
2822
2849
  this._preWalkVariableDeclaration(statement, hookMap);
2823
2850
  }
2824
2851
 
2825
2852
  /**
2826
2853
  * @param {VariableDeclaration} statement variable declaration
2827
- * @param {TODO} hookMap map of hooks
2854
+ * @param {HookMap<SyncBailHook<[Identifier], boolean | void>>} hookMap map of hooks
2828
2855
  */
2829
2856
  _preWalkVariableDeclaration(statement, hookMap) {
2830
2857
  for (const declarator of statement.declarations) {
@@ -2832,11 +2859,11 @@ class JavascriptParser extends Parser {
2832
2859
  case "VariableDeclarator": {
2833
2860
  this.preWalkVariableDeclarator(declarator);
2834
2861
  if (!this.hooks.preDeclarator.call(declarator, statement)) {
2835
- this.enterPattern(declarator.id, (name, decl) => {
2862
+ this.enterPattern(declarator.id, (name, ident) => {
2836
2863
  let hook = hookMap.get(name);
2837
- if (hook === undefined || !hook.call(decl)) {
2864
+ if (hook === undefined || !hook.call(ident)) {
2838
2865
  hook = this.hooks.varDeclaration.get(name);
2839
- if (hook === undefined || !hook.call(decl)) {
2866
+ if (hook === undefined || !hook.call(ident)) {
2840
2867
  this.defineVariable(name);
2841
2868
  }
2842
2869
  }
@@ -2904,8 +2931,9 @@ class JavascriptParser extends Parser {
2904
2931
  !declarator.init ||
2905
2932
  declarator.id.type !== "ObjectPattern" ||
2906
2933
  !this.destructuringAssignmentProperties
2907
- )
2934
+ ) {
2908
2935
  return;
2936
+ }
2909
2937
  const keys = this._preWalkObjectPattern(declarator.id);
2910
2938
 
2911
2939
  if (!keys) return;
@@ -3211,8 +3239,9 @@ class JavascriptParser extends Parser {
3211
3239
  * @param {AwaitExpression} expression await expression
3212
3240
  */
3213
3241
  walkAwaitExpression(expression) {
3214
- if (this.scope.topLevelScope === true)
3242
+ if (this.scope.topLevelScope === true) {
3215
3243
  this.hooks.topLevelAwait.call(expression);
3244
+ }
3216
3245
  this.walkExpression(expression.argument);
3217
3246
  }
3218
3247
 
@@ -3452,7 +3481,7 @@ class JavascriptParser extends Parser {
3452
3481
  return;
3453
3482
  }
3454
3483
  this.walkExpression(expression.right);
3455
- this.enterPattern(expression.left, (name, decl) => {
3484
+ this.enterPattern(expression.left, (name, _decl) => {
3456
3485
  if (!this.callHooksForName(this.hooks.assign, name, expression)) {
3457
3486
  this.walkExpression(
3458
3487
  /** @type {MemberExpression} */
@@ -3462,7 +3491,7 @@ class JavascriptParser extends Parser {
3462
3491
  });
3463
3492
  } else if (expression.left.type.endsWith("Pattern")) {
3464
3493
  this.walkExpression(expression.right);
3465
- this.enterPattern(expression.left, (name, decl) => {
3494
+ this.enterPattern(expression.left, (name, _decl) => {
3466
3495
  if (!this.callHooksForName(this.hooks.assign, name, expression)) {
3467
3496
  this.defineVariable(name);
3468
3497
  }
@@ -3765,8 +3794,9 @@ class JavascriptParser extends Parser {
3765
3794
  if (expression.callee.type === "MemberExpression") {
3766
3795
  // because of call context we need to walk the call context as expression
3767
3796
  this.walkExpression(expression.callee.object);
3768
- if (expression.callee.computed === true)
3797
+ if (expression.callee.computed === true) {
3769
3798
  this.walkExpression(expression.callee.property);
3799
+ }
3770
3800
  } else {
3771
3801
  this.walkExpression(expression.callee);
3772
3802
  }
@@ -3808,7 +3838,7 @@ class JavascriptParser extends Parser {
3808
3838
  expression,
3809
3839
  exprInfo.name,
3810
3840
  exprInfo.rootInfo,
3811
- members.slice(),
3841
+ [...members],
3812
3842
  () =>
3813
3843
  this.callHooksForInfo(
3814
3844
  this.hooks.unhandledExpressionMemberChain,
@@ -3928,7 +3958,7 @@ class JavascriptParser extends Parser {
3928
3958
  * @template R
3929
3959
  * @param {HookMap<SyncBailHook<T, R>>} hookMap hooks the should be called
3930
3960
  * @param {Expression | Super} expr expression info
3931
- * @param {((name: string, rootInfo: string | ScopeInfo | VariableInfo, getMembers: () => string[]) => TODO) | undefined} fallback callback when variable in not handled by hooks
3961
+ * @param {((name: string, rootInfo: string | ScopeInfo | VariableInfo, getMembers: () => string[]) => R) | undefined} fallback callback when variable in not handled by hooks
3932
3962
  * @param {((result?: string) => R | undefined) | undefined} defined callback when variable is defined
3933
3963
  * @param {AsArray<T>} args args for the hook
3934
3964
  * @returns {R | undefined} result of hook
@@ -3998,7 +4028,7 @@ class JavascriptParser extends Parser {
3998
4028
  * @template R
3999
4029
  * @param {HookMap<SyncBailHook<T, R>>} hookMap hooks the should be called
4000
4030
  * @param {ExportedVariableInfo} info variable info
4001
- * @param {((name: string) => TODO) | undefined} fallback callback when variable in not handled by hooks
4031
+ * @param {((name: string) => R | undefined) | undefined} fallback callback when variable in not handled by hooks
4002
4032
  * @param {((result?: string) => TODO) | undefined} defined callback when variable is defined
4003
4033
  * @param {AsArray<T>} args args for the hook
4004
4034
  * @returns {R | undefined} result of hook
@@ -4365,9 +4395,11 @@ class JavascriptParser extends Parser {
4365
4395
  );
4366
4396
  }
4367
4397
 
4398
+ /** @typedef {{ range?: Range, value: string, code: boolean, conditional: false | CalculatedStringResult[] }} CalculatedStringResult */
4399
+
4368
4400
  /**
4369
4401
  * @param {Expression} expression expression
4370
- * @returns {{ range?: Range, value: string, code: boolean, conditional: boolean | TODO }} result
4402
+ * @returns {CalculatedStringResult} result
4371
4403
  */
4372
4404
  parseCalculatedString(expression) {
4373
4405
  switch (expression.type) {
@@ -4415,6 +4447,7 @@ class JavascriptParser extends Parser {
4415
4447
  case "ConditionalExpression": {
4416
4448
  const consequent = this.parseCalculatedString(expression.consequent);
4417
4449
  const alternate = this.parseCalculatedString(expression.alternate);
4450
+ /** @type {CalculatedStringResult[]} */
4418
4451
  const items = [];
4419
4452
  if (consequent.conditional) {
4420
4453
  items.push(...consequent.conditional);
@@ -4467,7 +4500,7 @@ class JavascriptParser extends Parser {
4467
4500
  throw new Error("source must not be null");
4468
4501
  }
4469
4502
  if (Buffer.isBuffer(source)) {
4470
- source = source.toString("utf-8");
4503
+ source = source.toString("utf8");
4471
4504
  }
4472
4505
  if (typeof source === "object") {
4473
4506
  ast = /** @type {Program} */ (source);
@@ -4566,14 +4599,20 @@ class JavascriptParser extends Parser {
4566
4599
  ) {
4567
4600
  return false;
4568
4601
  }
4569
- const items =
4570
- /** @type {TODO[]} */
4571
- (expr.body.body);
4602
+ const items = expr.body.body;
4572
4603
  return items.every(item => {
4604
+ if (item.type === "StaticBlock") {
4605
+ return false;
4606
+ }
4607
+
4573
4608
  if (
4574
4609
  item.computed &&
4575
4610
  item.key &&
4576
- !this.isPure(item.key, item.range[0])
4611
+ !this.isPure(
4612
+ item.key,
4613
+ /** @type {Range} */
4614
+ (item.range)[0]
4615
+ )
4577
4616
  ) {
4578
4617
  return false;
4579
4618
  }
@@ -4583,16 +4622,14 @@ class JavascriptParser extends Parser {
4583
4622
  item.value &&
4584
4623
  !this.isPure(
4585
4624
  item.value,
4586
- item.key ? item.key.range[1] : item.range[0]
4625
+ item.key
4626
+ ? /** @type {Range} */ (item.key.range)[1]
4627
+ : /** @type {Range} */ (item.range)[0]
4587
4628
  )
4588
4629
  ) {
4589
4630
  return false;
4590
4631
  }
4591
4632
 
4592
- if (item.type === "StaticBlock") {
4593
- return false;
4594
- }
4595
-
4596
4633
  if (
4597
4634
  expr.superClass &&
4598
4635
  item.type === "MethodDefinition" &&
@@ -4816,8 +4853,12 @@ class JavascriptParser extends Parser {
4816
4853
  defineVariable(name) {
4817
4854
  const oldInfo = this.scope.definitions.get(name);
4818
4855
  // Don't redefine variable in same scope to keep existing tags
4819
- if (oldInfo instanceof VariableInfo && oldInfo.declaredScope === this.scope)
4856
+ if (
4857
+ oldInfo instanceof VariableInfo &&
4858
+ oldInfo.declaredScope === this.scope
4859
+ ) {
4820
4860
  return;
4861
+ }
4821
4862
  this.scope.definitions.set(name, this.scope);
4822
4863
  }
4823
4864
 
@@ -5098,9 +5139,9 @@ class JavascriptParser extends Parser {
5098
5139
 
5099
5140
  module.exports = JavascriptParser;
5100
5141
  module.exports.ALLOWED_MEMBER_TYPES_ALL = ALLOWED_MEMBER_TYPES_ALL;
5101
- module.exports.ALLOWED_MEMBER_TYPES_EXPRESSION =
5102
- ALLOWED_MEMBER_TYPES_EXPRESSION;
5103
5142
  module.exports.ALLOWED_MEMBER_TYPES_CALL_EXPRESSION =
5104
5143
  ALLOWED_MEMBER_TYPES_CALL_EXPRESSION;
5105
- module.exports.getImportAttributes = getImportAttributes;
5144
+ module.exports.ALLOWED_MEMBER_TYPES_EXPRESSION =
5145
+ ALLOWED_MEMBER_TYPES_EXPRESSION;
5106
5146
  module.exports.VariableInfo = VariableInfo;
5147
+ module.exports.getImportAttributes = getImportAttributes;
@@ -15,46 +15,7 @@ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
15
15
  /** @typedef {import("./JavascriptParser")} JavascriptParser */
16
16
  /** @typedef {import("./JavascriptParser").Range} Range */
17
17
 
18
- /**
19
- * @param {JavascriptParser} parser the parser
20
- * @param {string} value the const value
21
- * @param {(string[] | null)=} runtimeRequirements runtime requirements
22
- * @returns {(expression: Expression) => true} plugin function
23
- */
24
- module.exports.toConstantDependency = (parser, value, runtimeRequirements) =>
25
- function constDependency(expr) {
26
- const dep = new ConstDependency(
27
- value,
28
- /** @type {Range} */
29
- (expr.range),
30
- runtimeRequirements
31
- );
32
- dep.loc = /** @type {SourceLocation} */ (expr.loc);
33
- parser.state.module.addPresentationalDependency(dep);
34
- return true;
35
- };
36
-
37
- /**
38
- * @param {string} value the string value
39
- * @returns {(expression: Expression) => BasicEvaluatedExpression} plugin function
40
- */
41
- module.exports.evaluateToString = value =>
42
- function stringExpression(expr) {
43
- return new BasicEvaluatedExpression()
44
- .setString(value)
45
- .setRange(/** @type {Range} */ (expr.range));
46
- };
47
-
48
- /**
49
- * @param {number} value the number value
50
- * @returns {(expression: Expression) => BasicEvaluatedExpression} plugin function
51
- */
52
- module.exports.evaluateToNumber = value =>
53
- function stringExpression(expr) {
54
- return new BasicEvaluatedExpression()
55
- .setNumber(value)
56
- .setRange(/** @type {Range} */ (expr.range));
57
- };
18
+ module.exports.approve = () => true;
58
19
 
59
20
  /**
60
21
  * @param {boolean} value the boolean value
@@ -100,6 +61,28 @@ module.exports.evaluateToIdentifier = (
100
61
  return evaluatedExpression;
101
62
  };
102
63
 
64
+ /**
65
+ * @param {number} value the number value
66
+ * @returns {(expression: Expression) => BasicEvaluatedExpression} plugin function
67
+ */
68
+ module.exports.evaluateToNumber = value =>
69
+ function stringExpression(expr) {
70
+ return new BasicEvaluatedExpression()
71
+ .setNumber(value)
72
+ .setRange(/** @type {Range} */ (expr.range));
73
+ };
74
+
75
+ /**
76
+ * @param {string} value the string value
77
+ * @returns {(expression: Expression) => BasicEvaluatedExpression} plugin function
78
+ */
79
+ module.exports.evaluateToString = value =>
80
+ function stringExpression(expr) {
81
+ return new BasicEvaluatedExpression()
82
+ .setString(value)
83
+ .setRange(/** @type {Range} */ (expr.range));
84
+ };
85
+
103
86
  /**
104
87
  * @param {JavascriptParser} parser the parser
105
88
  * @param {string} message the message
@@ -126,4 +109,21 @@ module.exports.expressionIsUnsupported = (parser, message) =>
126
109
 
127
110
  module.exports.skipTraversal = () => true;
128
111
 
129
- module.exports.approve = () => true;
112
+ /**
113
+ * @param {JavascriptParser} parser the parser
114
+ * @param {string} value the const value
115
+ * @param {(string[] | null)=} runtimeRequirements runtime requirements
116
+ * @returns {(expression: Expression) => true} plugin function
117
+ */
118
+ module.exports.toConstantDependency = (parser, value, runtimeRequirements) =>
119
+ function constDependency(expr) {
120
+ const dep = new ConstDependency(
121
+ value,
122
+ /** @type {Range} */
123
+ (expr.range),
124
+ runtimeRequirements
125
+ );
126
+ dep.loc = /** @type {SourceLocation} */ (expr.loc);
127
+ parser.state.module.addPresentationalDependency(dep);
128
+ return true;
129
+ };
@@ -133,6 +133,23 @@ module.exports.generateEntryStartup = (
133
133
  return Template.asString(runtime);
134
134
  };
135
135
 
136
+ /**
137
+ * @param {Chunk} chunk the chunk
138
+ * @param {ChunkGraph} chunkGraph the chunk graph
139
+ * @param {(chunk: Chunk, chunkGraph: ChunkGraph) => boolean} filterFn filter function
140
+ * @returns {Set<number | string>} initially fulfilled chunk ids
141
+ */
142
+ module.exports.getInitialChunkIds = (chunk, chunkGraph, filterFn) => {
143
+ const initialChunkIds = new Set(chunk.ids);
144
+ for (const c of chunk.getAllInitialChunks()) {
145
+ if (c === chunk || filterFn(c, chunkGraph)) continue;
146
+ for (const id of /** @type {ChunkId[]} */ (c.ids)) {
147
+ initialChunkIds.add(id);
148
+ }
149
+ }
150
+ return initialChunkIds;
151
+ };
152
+
136
153
  /**
137
154
  * @param {Hash} hash the hash to update
138
155
  * @param {ChunkGraph} chunkGraph chunkGraph
@@ -161,20 +178,3 @@ module.exports.updateHashForEntryStartup = (
161
178
  }
162
179
  }
163
180
  };
164
-
165
- /**
166
- * @param {Chunk} chunk the chunk
167
- * @param {ChunkGraph} chunkGraph the chunk graph
168
- * @param {(chunk: Chunk, chunkGraph: ChunkGraph) => boolean} filterFn filter function
169
- * @returns {Set<number | string>} initially fulfilled chunk ids
170
- */
171
- module.exports.getInitialChunkIds = (chunk, chunkGraph, filterFn) => {
172
- const initialChunkIds = new Set(chunk.ids);
173
- for (const c of chunk.getAllInitialChunks()) {
174
- if (c === chunk || filterFn(c, chunkGraph)) continue;
175
- for (const id of /** @type {ChunkId[]} */ (c.ids)) {
176
- initialChunkIds.add(id);
177
- }
178
- }
179
- return initialChunkIds;
180
- };
@@ -47,8 +47,9 @@ const stringifySafe = data => {
47
47
  * @returns {JsonObject | JsonArray} reduced data
48
48
  */
49
49
  const createObjectForExportsInfo = (data, exportsInfo, runtime) => {
50
- if (exportsInfo.otherExportsInfo.getUsed(runtime) !== UsageState.Unused)
50
+ if (exportsInfo.otherExportsInfo.getUsed(runtime) !== UsageState.Unused) {
51
51
  return data;
52
+ }
52
53
  const isArray = Array.isArray(data);
53
54
  /** @type {JsonObject | JsonArray} */
54
55
  const reducedData = isArray ? [] : {};
@@ -95,13 +96,14 @@ const createObjectForExportsInfo = (data, exportsInfo, runtime) => {
95
96
  8 -
96
97
  (arrayLengthWhenUsed - reducedDataLength) * 2;
97
98
  }
98
- if (sizeObjectMinusArray < 0)
99
+ if (sizeObjectMinusArray < 0) {
99
100
  return Object.assign(
100
101
  arrayLengthWhenUsed === undefined
101
102
  ? {}
102
103
  : { length: arrayLengthWhenUsed },
103
104
  reducedData
104
105
  );
106
+ }
105
107
  /** @type {number} */
106
108
  const generatedLength =
107
109
  arrayLengthWhenUsed !== undefined