webpack 5.92.1 → 5.94.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 (350) hide show
  1. package/README.md +8 -5
  2. package/bin/webpack.js +6 -7
  3. package/hot/log.js +1 -2
  4. package/hot/only-dev-server.js +1 -1
  5. package/hot/poll.js +1 -1
  6. package/hot/signal.js +1 -1
  7. package/lib/APIPlugin.js +4 -3
  8. package/lib/AbstractMethodError.js +10 -5
  9. package/lib/AutomaticPrefetchPlugin.js +1 -1
  10. package/lib/BannerPlugin.js +12 -6
  11. package/lib/Cache.js +8 -10
  12. package/lib/CacheFacade.js +3 -3
  13. package/lib/CaseSensitiveModulesWarning.js +5 -7
  14. package/lib/Chunk.js +14 -11
  15. package/lib/ChunkGraph.js +58 -36
  16. package/lib/ChunkGroup.js +2 -3
  17. package/lib/ChunkTemplate.js +43 -0
  18. package/lib/CleanPlugin.js +10 -11
  19. package/lib/CodeGenerationResults.js +6 -5
  20. package/lib/CommentCompilationWarning.js +0 -1
  21. package/lib/Compilation.js +223 -191
  22. package/lib/Compiler.js +81 -82
  23. package/lib/ConcatenationScope.js +3 -6
  24. package/lib/ConditionalInitFragment.js +6 -7
  25. package/lib/ConstPlugin.js +7 -15
  26. package/lib/ContextExclusionPlugin.js +3 -3
  27. package/lib/ContextModule.js +36 -21
  28. package/lib/ContextModuleFactory.js +89 -44
  29. package/lib/ContextReplacementPlugin.js +10 -9
  30. package/lib/DefinePlugin.js +76 -69
  31. package/lib/DelegatedModule.js +7 -3
  32. package/lib/DelegatedModuleFactoryPlugin.js +36 -22
  33. package/lib/DelegatedPlugin.js +4 -0
  34. package/lib/DependenciesBlock.js +0 -1
  35. package/lib/Dependency.js +10 -14
  36. package/lib/DllEntryPlugin.js +4 -2
  37. package/lib/DllModuleFactory.js +1 -0
  38. package/lib/DllPlugin.js +9 -7
  39. package/lib/DllReferencePlugin.js +30 -15
  40. package/lib/EntryPlugin.js +1 -3
  41. package/lib/EnvironmentPlugin.js +5 -2
  42. package/lib/ErrorHelpers.js +11 -12
  43. package/lib/EvalDevToolModulePlugin.js +10 -12
  44. package/lib/EvalSourceMapDevToolPlugin.js +15 -13
  45. package/lib/ExportsInfo.js +185 -120
  46. package/lib/ExternalModule.js +104 -64
  47. package/lib/ExternalModuleFactoryPlugin.js +23 -10
  48. package/lib/FileSystemInfo.js +791 -422
  49. package/lib/FlagAllModulesAsUsedPlugin.js +1 -1
  50. package/lib/FlagDependencyExportsPlugin.js +12 -11
  51. package/lib/FlagDependencyUsagePlugin.js +1 -1
  52. package/lib/Generator.js +2 -5
  53. package/lib/GraphHelpers.js +3 -2
  54. package/lib/HookWebpackError.js +8 -10
  55. package/lib/HotModuleReplacementPlugin.js +78 -64
  56. package/lib/IgnoreErrorModuleFactory.js +3 -3
  57. package/lib/IgnorePlugin.js +1 -3
  58. package/lib/IgnoreWarningsPlugin.js +6 -9
  59. package/lib/InitFragment.js +2 -3
  60. package/lib/LibManifestPlugin.js +4 -3
  61. package/lib/MainTemplate.js +72 -19
  62. package/lib/Module.js +25 -9
  63. package/lib/ModuleBuildError.js +4 -11
  64. package/lib/ModuleDependencyError.js +5 -5
  65. package/lib/ModuleDependencyWarning.js +5 -5
  66. package/lib/ModuleError.js +1 -5
  67. package/lib/ModuleFilenameHelpers.js +29 -46
  68. package/lib/ModuleGraph.js +7 -6
  69. package/lib/ModuleGraphConnection.js +6 -6
  70. package/lib/ModuleInfoHeaderPlugin.js +82 -30
  71. package/lib/ModuleParseError.js +8 -9
  72. package/lib/ModuleRestoreError.js +1 -1
  73. package/lib/ModuleStoreError.js +1 -1
  74. package/lib/ModuleTemplate.js +33 -1
  75. package/lib/ModuleTypeConstants.js +21 -22
  76. package/lib/ModuleWarning.js +1 -5
  77. package/lib/MultiCompiler.js +24 -26
  78. package/lib/MultiStats.js +73 -31
  79. package/lib/MultiWatching.js +1 -1
  80. package/lib/NormalModule.js +132 -70
  81. package/lib/NormalModuleFactory.js +53 -49
  82. package/lib/OptimizationStages.js +3 -3
  83. package/lib/ProgressPlugin.js +9 -9
  84. package/lib/ProvidePlugin.js +4 -4
  85. package/lib/RuntimeGlobals.js +71 -70
  86. package/lib/RuntimeModule.js +1 -1
  87. package/lib/RuntimePlugin.js +24 -12
  88. package/lib/RuntimeTemplate.js +40 -44
  89. package/lib/SizeFormatHelpers.js +2 -4
  90. package/lib/SourceMapDevToolPlugin.js +42 -34
  91. package/lib/Stats.js +5 -11
  92. package/lib/Template.js +18 -24
  93. package/lib/TemplatedPathPlugin.js +12 -10
  94. package/lib/UseStrictPlugin.js +8 -1
  95. package/lib/WarnDeprecatedOptionPlugin.js +0 -1
  96. package/lib/WatchIgnorePlugin.js +26 -9
  97. package/lib/Watching.js +10 -5
  98. package/lib/WebpackOptionsApply.js +89 -62
  99. package/lib/asset/AssetGenerator.js +107 -42
  100. package/lib/asset/AssetModulesPlugin.js +29 -23
  101. package/lib/asset/AssetSourceGenerator.js +2 -7
  102. package/lib/async-modules/AwaitDependenciesInitFragment.js +6 -7
  103. package/lib/buildChunkGraph.js +14 -19
  104. package/lib/cache/IdleFileCachePlugin.js +4 -4
  105. package/lib/cache/MemoryWithGcCachePlugin.js +5 -5
  106. package/lib/cache/PackFileCacheStrategy.js +51 -50
  107. package/lib/cache/ResolverCachePlugin.js +6 -6
  108. package/lib/cache/mergeEtags.js +16 -21
  109. package/lib/cli.js +148 -104
  110. package/lib/config/browserslistTargetHandler.js +16 -13
  111. package/lib/config/defaults.js +31 -28
  112. package/lib/config/normalization.js +335 -344
  113. package/lib/config/target.js +42 -52
  114. package/lib/container/ContainerEntryModule.js +2 -2
  115. package/lib/container/ContainerPlugin.js +1 -1
  116. package/lib/container/RemoteRuntimeModule.js +11 -8
  117. package/lib/container/options.js +18 -4
  118. package/lib/css/CssExportsGenerator.js +39 -40
  119. package/lib/css/CssGenerator.js +11 -14
  120. package/lib/css/CssLoadingRuntimeModule.js +10 -10
  121. package/lib/css/CssModulesPlugin.js +127 -47
  122. package/lib/css/CssParser.js +20 -18
  123. package/lib/css/walkCssTokens.js +80 -95
  124. package/lib/debug/ProfilingPlugin.js +19 -20
  125. package/lib/dependencies/AMDDefineDependency.js +1 -1
  126. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +83 -47
  127. package/lib/dependencies/AMDRequireArrayDependency.js +9 -10
  128. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +22 -16
  129. package/lib/dependencies/AMDRuntimeModules.js +2 -2
  130. package/lib/dependencies/CommonJsDependencyHelpers.js +6 -2
  131. package/lib/dependencies/CommonJsExportRequireDependency.js +37 -41
  132. package/lib/dependencies/CommonJsExportsDependency.js +0 -1
  133. package/lib/dependencies/CommonJsExportsParserPlugin.js +19 -23
  134. package/lib/dependencies/CommonJsFullRequireDependency.js +1 -1
  135. package/lib/dependencies/CommonJsImportsParserPlugin.js +52 -61
  136. package/lib/dependencies/CommonJsSelfReferenceDependency.js +6 -8
  137. package/lib/dependencies/ConstDependency.js +1 -1
  138. package/lib/dependencies/ContextDependency.js +1 -1
  139. package/lib/dependencies/ContextDependencyHelpers.js +31 -34
  140. package/lib/dependencies/ContextElementDependency.js +2 -2
  141. package/lib/dependencies/CriticalDependencyWarning.js +1 -1
  142. package/lib/dependencies/CssExportDependency.js +72 -9
  143. package/lib/dependencies/CssImportDependency.js +0 -2
  144. package/lib/dependencies/CssLocalIdentifierDependency.js +68 -21
  145. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +2 -1
  146. package/lib/dependencies/CssUrlDependency.js +4 -5
  147. package/lib/dependencies/DynamicExports.js +5 -5
  148. package/lib/dependencies/ExportsInfoDependency.js +1 -2
  149. package/lib/dependencies/HarmonyAcceptImportDependency.js +1 -1
  150. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +4 -5
  151. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +27 -16
  152. package/lib/dependencies/HarmonyExportExpressionDependency.js +1 -1
  153. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +107 -64
  154. package/lib/dependencies/HarmonyExports.js +2 -2
  155. package/lib/dependencies/HarmonyImportDependency.js +2 -4
  156. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +19 -4
  157. package/lib/dependencies/HarmonyImportSpecifierDependency.js +41 -16
  158. package/lib/dependencies/ImportDependency.js +1 -1
  159. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +5 -5
  160. package/lib/dependencies/ImportMetaPlugin.js +11 -13
  161. package/lib/dependencies/ImportParserPlugin.js +39 -44
  162. package/lib/dependencies/JsonExportsDependency.js +22 -18
  163. package/lib/dependencies/LoaderPlugin.js +47 -36
  164. package/lib/dependencies/LocalModule.js +1 -1
  165. package/lib/dependencies/LocalModulesHelpers.js +4 -4
  166. package/lib/dependencies/ModuleDecoratorDependency.js +1 -1
  167. package/lib/dependencies/ProvidedDependency.js +1 -1
  168. package/lib/dependencies/PureExpressionDependency.js +6 -6
  169. package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -1
  170. package/lib/dependencies/RuntimeRequirementsDependency.js +1 -1
  171. package/lib/dependencies/SystemPlugin.js +1 -1
  172. package/lib/dependencies/URLDependency.js +3 -3
  173. package/lib/dependencies/URLPlugin.js +66 -12
  174. package/lib/dependencies/WorkerPlugin.js +25 -24
  175. package/lib/dependencies/processExportInfo.js +3 -1
  176. package/lib/electron/ElectronTargetPlugin.js +1 -0
  177. package/lib/esm/ModuleChunkFormatPlugin.js +11 -12
  178. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +7 -3
  179. package/lib/formatLocation.js +1 -2
  180. package/lib/hmr/HotModuleReplacement.runtime.js +4 -5
  181. package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -0
  182. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +9 -12
  183. package/lib/hmr/LazyCompilationPlugin.js +27 -12
  184. package/lib/hmr/lazyCompilationBackend.js +64 -40
  185. package/lib/ids/ChunkModuleIdRangePlugin.js +1 -3
  186. package/lib/ids/DeterministicChunkIdsPlugin.js +2 -4
  187. package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
  188. package/lib/ids/HashedModuleIdsPlugin.js +5 -1
  189. package/lib/ids/IdHelpers.js +29 -39
  190. package/lib/ids/SyncModuleIdsPlugin.js +7 -2
  191. package/lib/index.js +1 -5
  192. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +6 -4
  193. package/lib/javascript/BasicEvaluatedExpression.js +4 -19
  194. package/lib/javascript/ChunkHelpers.js +1 -1
  195. package/lib/javascript/CommonJsChunkFormatPlugin.js +10 -11
  196. package/lib/javascript/EnableChunkLoadingPlugin.js +7 -6
  197. package/lib/javascript/JavascriptGenerator.js +23 -7
  198. package/lib/javascript/JavascriptModulesPlugin.js +97 -70
  199. package/lib/javascript/JavascriptParser.js +179 -200
  200. package/lib/javascript/JavascriptParserHelpers.js +20 -21
  201. package/lib/javascript/StartupHelpers.js +41 -13
  202. package/lib/json/JsonGenerator.js +7 -13
  203. package/lib/json/JsonModulesPlugin.js +1 -4
  204. package/lib/json/JsonParser.js +5 -3
  205. package/lib/library/AmdLibraryPlugin.js +12 -16
  206. package/lib/library/AssignLibraryPlugin.js +9 -11
  207. package/lib/library/EnableLibraryPlugin.js +25 -15
  208. package/lib/library/ExportPropertyLibraryPlugin.js +8 -2
  209. package/lib/library/JsonpLibraryPlugin.js +2 -1
  210. package/lib/library/ModernModuleLibraryPlugin.js +144 -0
  211. package/lib/library/ModuleLibraryPlugin.js +2 -1
  212. package/lib/library/SystemLibraryPlugin.js +2 -1
  213. package/lib/library/UmdLibraryPlugin.js +66 -92
  214. package/lib/logging/Logger.js +32 -4
  215. package/lib/logging/createConsoleLogger.js +12 -13
  216. package/lib/logging/runtime.js +7 -8
  217. package/lib/logging/truncateArgs.js +5 -8
  218. package/lib/node/NodeWatchFileSystem.js +3 -18
  219. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -2
  220. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +1 -0
  221. package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -2
  222. package/lib/node/nodeConsole.js +22 -22
  223. package/lib/optimize/AggressiveMergingPlugin.js +2 -4
  224. package/lib/optimize/AggressiveSplittingPlugin.js +16 -19
  225. package/lib/optimize/ConcatenatedModule.js +144 -61
  226. package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -1
  227. package/lib/optimize/FlagIncludedChunksPlugin.js +3 -3
  228. package/lib/optimize/InnerGraph.js +17 -17
  229. package/lib/optimize/InnerGraphPlugin.js +8 -7
  230. package/lib/optimize/LimitChunkCountPlugin.js +2 -3
  231. package/lib/optimize/MangleExportsPlugin.js +1 -0
  232. package/lib/optimize/MinMaxSizeWarning.js +1 -1
  233. package/lib/optimize/ModuleConcatenationPlugin.js +56 -78
  234. package/lib/optimize/RealContentHashPlugin.js +7 -10
  235. package/lib/optimize/RemoveParentModulesPlugin.js +3 -3
  236. package/lib/optimize/SideEffectsFlagPlugin.js +6 -2
  237. package/lib/optimize/SplitChunksPlugin.js +34 -30
  238. package/lib/performance/SizeLimitsPlugin.js +2 -2
  239. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +1 -0
  240. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +1 -1
  241. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +1 -1
  242. package/lib/rules/BasicEffectRulePlugin.js +3 -1
  243. package/lib/rules/BasicMatcherRulePlugin.js +3 -1
  244. package/lib/rules/ObjectMatcherRulePlugin.js +4 -1
  245. package/lib/rules/RuleSetCompiler.js +41 -22
  246. package/lib/rules/UseEffectRulePlugin.js +36 -32
  247. package/lib/runtime/AsyncModuleRuntimeModule.js +1 -1
  248. package/lib/runtime/AutoPublicPathRuntimeModule.js +8 -3
  249. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +2 -2
  250. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +1 -1
  251. package/lib/runtime/EnsureChunkRuntimeModule.js +10 -11
  252. package/lib/runtime/GetChunkFilenameRuntimeModule.js +11 -17
  253. package/lib/runtime/LoadScriptRuntimeModule.js +17 -18
  254. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -3
  255. package/lib/schemes/DataUriPlugin.js +1 -1
  256. package/lib/schemes/HttpUriPlugin.js +241 -126
  257. package/lib/serialization/BinaryMiddleware.js +44 -28
  258. package/lib/serialization/DateObjectSerializer.js +1 -0
  259. package/lib/serialization/ErrorObjectSerializer.js +2 -0
  260. package/lib/serialization/FileMiddleware.js +154 -106
  261. package/lib/serialization/MapObjectSerializer.js +2 -1
  262. package/lib/serialization/NullPrototypeObjectSerializer.js +3 -2
  263. package/lib/serialization/ObjectMiddleware.js +52 -56
  264. package/lib/serialization/PlainObjectSerializer.js +32 -6
  265. package/lib/serialization/RegExpObjectSerializer.js +1 -0
  266. package/lib/serialization/Serializer.js +4 -5
  267. package/lib/serialization/SerializerMiddleware.js +6 -6
  268. package/lib/serialization/SetObjectSerializer.js +2 -1
  269. package/lib/sharing/ConsumeSharedModule.js +19 -14
  270. package/lib/sharing/ConsumeSharedPlugin.js +116 -97
  271. package/lib/sharing/ConsumeSharedRuntimeModule.js +108 -141
  272. package/lib/sharing/ProvideForSharedDependency.js +0 -1
  273. package/lib/sharing/ProvideSharedPlugin.js +2 -2
  274. package/lib/sharing/resolveMatchedConfigs.js +2 -1
  275. package/lib/sharing/utils.js +15 -27
  276. package/lib/stats/DefaultStatsFactoryPlugin.js +424 -281
  277. package/lib/stats/DefaultStatsPresetPlugin.js +73 -18
  278. package/lib/stats/DefaultStatsPrinterPlugin.js +370 -101
  279. package/lib/stats/StatsFactory.js +127 -56
  280. package/lib/stats/StatsPrinter.js +75 -44
  281. package/lib/util/ArrayHelpers.js +8 -4
  282. package/lib/util/ArrayQueue.js +1 -1
  283. package/lib/util/AsyncQueue.js +31 -12
  284. package/lib/util/IterableHelpers.js +3 -4
  285. package/lib/util/LazyBucketSortedSet.js +60 -44
  286. package/lib/util/LazySet.js +1 -0
  287. package/lib/util/MapHelpers.js +1 -3
  288. package/lib/util/ParallelismFactorCalculator.js +1 -1
  289. package/lib/util/Queue.js +1 -1
  290. package/lib/util/Semaphore.js +4 -7
  291. package/lib/util/SetHelpers.js +5 -5
  292. package/lib/util/SortableSet.js +4 -3
  293. package/lib/util/StackedCacheMap.js +4 -6
  294. package/lib/util/StackedMap.js +1 -3
  295. package/lib/util/StringXor.js +0 -5
  296. package/lib/util/TupleQueue.js +1 -1
  297. package/lib/util/TupleSet.js +15 -5
  298. package/lib/util/URLAbsoluteSpecifier.js +7 -7
  299. package/lib/util/WeakTupleMap.js +19 -21
  300. package/lib/util/binarySearchBounds.js +5 -12
  301. package/lib/util/chainedImports.js +1 -1
  302. package/lib/util/cleverMerge.js +21 -19
  303. package/lib/util/comparators.js +57 -52
  304. package/lib/util/compileBooleanMatcher.js +3 -6
  305. package/lib/util/conventions.js +10 -13
  306. package/lib/util/createHash.js +9 -6
  307. package/lib/util/deprecation.js +22 -12
  308. package/lib/util/deterministicGrouping.js +19 -26
  309. package/lib/util/findGraphRoots.js +2 -2
  310. package/lib/util/fs.js +31 -31
  311. package/lib/util/hash/md4.js +2 -2
  312. package/lib/util/hash/wasm-hash.js +7 -7
  313. package/lib/util/hash/xxhash64.js +2 -2
  314. package/lib/util/identifier.js +81 -59
  315. package/lib/util/memoize.js +8 -10
  316. package/lib/util/mergeScope.js +6 -9
  317. package/lib/util/nonNumericOnlyHash.js +2 -2
  318. package/lib/util/numberHash.js +1 -6
  319. package/lib/util/objectToMap.js +0 -1
  320. package/lib/util/propertyAccess.js +2 -5
  321. package/lib/util/propertyName.js +1 -3
  322. package/lib/util/registerExternalSerializer.js +1 -1
  323. package/lib/util/runtime.js +103 -113
  324. package/lib/util/semver.js +29 -27
  325. package/lib/util/serialization.js +16 -1
  326. package/lib/util/smartGrouping.js +5 -5
  327. package/lib/util/source.js +1 -1
  328. package/lib/wasm/EnableWasmLoadingPlugin.js +5 -4
  329. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +3 -3
  330. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -6
  331. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -3
  332. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +20 -19
  333. package/lib/wasm-sync/WebAssemblyGenerator.js +14 -29
  334. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +1 -1
  335. package/lib/wasm-sync/WebAssemblyUtils.js +2 -2
  336. package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -3
  337. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -1
  338. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +1 -1
  339. package/package.json +17 -16
  340. package/schemas/WebpackOptions.check.js +1 -1
  341. package/schemas/WebpackOptions.json +17 -0
  342. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
  343. package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.js +1 -1
  344. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
  345. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  346. package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
  347. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  348. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  349. package/schemas/plugins/container/ModuleFederationPlugin.json +1 -0
  350. package/types.d.ts +682 -347
@@ -5,6 +5,7 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const ConditionalInitFragment = require("../ConditionalInitFragment");
8
9
  const Dependency = require("../Dependency");
9
10
  const { UsageState } = require("../ExportsInfo");
10
11
  const HarmonyLinkingError = require("../HarmonyLinkingError");
@@ -16,7 +17,11 @@ const { first, combine } = require("../util/SetHelpers");
16
17
  const makeSerializable = require("../util/makeSerializable");
17
18
  const propertyAccess = require("../util/propertyAccess");
18
19
  const { propertyName } = require("../util/propertyName");
19
- const { getRuntimeKey, keyToRuntime } = require("../util/runtime");
20
+ const {
21
+ getRuntimeKey,
22
+ keyToRuntime,
23
+ filterRuntime
24
+ } = require("../util/runtime");
20
25
  const HarmonyExportInitFragment = require("./HarmonyExportInitFragment");
21
26
  const HarmonyImportDependency = require("./HarmonyImportDependency");
22
27
  const processExportInfo = require("./processExportInfo");
@@ -31,6 +36,7 @@ const processExportInfo = require("./processExportInfo");
31
36
  /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
32
37
  /** @typedef {import("../ExportsInfo")} ExportsInfo */
33
38
  /** @typedef {import("../ExportsInfo").ExportInfo} ExportInfo */
39
+ /** @typedef {import("../ExportsInfo").UsedName} UsedName */
34
40
  /** @typedef {import("../Generator").GenerateContext} GenerateContext */
35
41
  /** @typedef {import("../Module")} Module */
36
42
  /** @typedef {import("../Module").BuildMeta} BuildMeta */
@@ -45,6 +51,7 @@ const processExportInfo = require("./processExportInfo");
45
51
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
46
52
  /** @typedef {import("../util/Hash")} Hash */
47
53
  /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
54
+ /** @typedef {import("./processExportInfo").ReferencedExports} ReferencedExports */
48
55
 
49
56
  /** @typedef {"missing"|"unused"|"empty-star"|"reexport-dynamic-default"|"reexport-named-default"|"reexport-namespace-object"|"reexport-fake-namespace-object"|"reexport-undefined"|"normal-reexport"|"dynamic-reexport"} ExportModeType */
50
57
 
@@ -69,6 +76,9 @@ class NormalReexportItem {
69
76
  }
70
77
  }
71
78
 
79
+ /** @typedef {Set<string>} ExportModeIgnored */
80
+ /** @typedef {Set<string>} ExportModeHidden */
81
+
72
82
  class ExportMode {
73
83
  /**
74
84
  * @param {ExportModeType} type type of the mode
@@ -88,11 +98,11 @@ class ExportMode {
88
98
  this.partialNamespaceExportInfo = null;
89
99
 
90
100
  // for "dynamic-reexport":
91
- /** @type {Set<string> | null} */
101
+ /** @type {ExportModeIgnored | null} */
92
102
  this.ignored = null;
93
103
 
94
104
  // for "dynamic-reexport" | "empty-star":
95
- /** @type {Set<string> | null} */
105
+ /** @type {ExportModeHidden | null} */
96
106
  this.hidden = null;
97
107
 
98
108
  // for "missing":
@@ -306,7 +316,8 @@ const getMode = (moduleGraph, dep, runtimeKey) => {
306
316
  exportName,
307
317
  [exportName],
308
318
  exportsInfo.getReadOnlyExportInfo(exportName),
309
- checked.has(exportName),
319
+ /** @type {Set<string>} */
320
+ (checked).has(exportName),
310
321
  false
311
322
  )
312
323
  );
@@ -327,11 +338,17 @@ const getMode = (moduleGraph, dep, runtimeKey) => {
327
338
  return mode;
328
339
  };
329
340
 
341
+ /** @typedef {string[]} Ids */
342
+ /** @typedef {Set<string>} Exports */
343
+ /** @typedef {Set<string>} Checked */
344
+ /** @typedef {Set<string>} Hidden */
345
+ /** @typedef {Set<string>} IgnoredExports */
346
+
330
347
  class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
331
348
  /**
332
349
  * @param {string} request the request string
333
350
  * @param {number} sourceOrder the order in the original source file
334
- * @param {string[]} ids the requested export name of the imported module
351
+ * @param {Ids} ids the requested export name of the imported module
335
352
  * @param {string | null} name the export name of for this module
336
353
  * @param {Set<string>} activeExports other named exports in the module
337
354
  * @param {ReadonlyArray<HarmonyExportImportedSpecifierDependency> | Iterable<HarmonyExportImportedSpecifierDependency> | null} otherStarExports other star exports in the module before this import
@@ -388,7 +405,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
388
405
 
389
406
  /**
390
407
  * @param {ModuleGraph} moduleGraph the module graph
391
- * @returns {string[]} the imported id
408
+ * @returns {Ids} the imported id
392
409
  */
393
410
  getIds(moduleGraph) {
394
411
  return moduleGraph.getMeta(this)[idsSymbol] || this.ids;
@@ -396,7 +413,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
396
413
 
397
414
  /**
398
415
  * @param {ModuleGraph} moduleGraph the module graph
399
- * @param {string[]} ids the imported ids
416
+ * @param {Ids} ids the imported ids
400
417
  * @returns {void}
401
418
  */
402
419
  setIds(moduleGraph, ids) {
@@ -421,7 +438,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
421
438
  * @param {RuntimeSpec} runtime the runtime
422
439
  * @param {ExportsInfo} exportsInfo exports info about the current module (optional)
423
440
  * @param {Module} importedModule the imported module (optional)
424
- * @returns {{exports?: Set<string>, checked?: Set<string>, ignoredExports: Set<string>, hidden?: Set<string>}} information
441
+ * @returns {{exports?: Exports, checked?: Checked, ignoredExports: IgnoredExports, hidden?: Hidden}} information
425
442
  */
426
443
  getStarReexports(
427
444
  moduleGraph,
@@ -439,7 +456,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
439
456
 
440
457
  const ignoredExports = new Set(["default", ...this.activeExports]);
441
458
 
442
- let hiddenExports = undefined;
459
+ let hiddenExports;
443
460
  const otherStarExports =
444
461
  this._discoverActiveExportsFromOtherStarExports(moduleGraph);
445
462
  if (otherStarExports !== undefined) {
@@ -457,11 +474,11 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
457
474
  };
458
475
  }
459
476
 
460
- /** @type {Set<string>} */
477
+ /** @type {Exports} */
461
478
  const exports = new Set();
462
- /** @type {Set<string>} */
479
+ /** @type {Checked} */
463
480
  const checked = new Set();
464
- /** @type {Set<string> | undefined} */
481
+ /** @type {Hidden | undefined} */
465
482
  const hidden = hiddenExports !== undefined ? new Set() : undefined;
466
483
 
467
484
  if (noExtraImports) {
@@ -489,7 +506,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
489
506
  const exportInfo = exportsInfo.getReadOnlyExportInfo(name);
490
507
  if (exportInfo.getUsed(runtime) === UsageState.Unused) continue;
491
508
  if (hiddenExports !== undefined && hiddenExports.has(name)) {
492
- /** @type {Set<string>} */
509
+ /** @type {ExportModeHidden} */
493
510
  (hidden).add(name);
494
511
  continue;
495
512
  }
@@ -543,7 +560,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
543
560
  case "reexport-named-default": {
544
561
  if (!mode.partialNamespaceExportInfo)
545
562
  return Dependency.EXPORTS_OBJECT_REFERENCED;
546
- /** @type {string[][]} */
563
+ /** @type {ReferencedExports} */
547
564
  const referencedExports = [];
548
565
  processExportInfo(
549
566
  runtime,
@@ -558,7 +575,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
558
575
  case "reexport-fake-namespace-object": {
559
576
  if (!mode.partialNamespaceExportInfo)
560
577
  return Dependency.EXPORTS_OBJECT_REFERENCED;
561
- /** @type {string[][]} */
578
+ /** @type {ReferencedExports} */
562
579
  const referencedExports = [];
563
580
  processExportInfo(
564
581
  runtime,
@@ -574,6 +591,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
574
591
  return Dependency.EXPORTS_OBJECT_REFERENCED;
575
592
 
576
593
  case "normal-reexport": {
594
+ /** @type {ReferencedExports} */
577
595
  const referencedExports = [];
578
596
  for (const { ids, exportInfo, hidden } of mode.items) {
579
597
  if (hidden) continue;
@@ -592,13 +610,13 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
592
610
  * @returns {{ names: string[], namesSlice: number, dependencyIndices: number[], dependencyIndex: number } | undefined} exported names and their origin dependency
593
611
  */
594
612
  _discoverActiveExportsFromOtherStarExports(moduleGraph) {
595
- if (!this.otherStarExports) return undefined;
613
+ if (!this.otherStarExports) return;
596
614
 
597
615
  const i =
598
616
  "length" in this.otherStarExports
599
617
  ? this.otherStarExports.length
600
618
  : countIterable(this.otherStarExports);
601
- if (i === 0) return undefined;
619
+ if (i === 0) return;
602
620
 
603
621
  if (this.allStarExports) {
604
622
  const { names, dependencyIndices } = moduleGraph.cached(
@@ -638,7 +656,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
638
656
 
639
657
  switch (mode.type) {
640
658
  case "missing":
641
- return undefined;
659
+ return;
642
660
  case "dynamic-reexport": {
643
661
  const from =
644
662
  /** @type {ModuleGraphConnection} */
@@ -648,8 +666,11 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
648
666
  from,
649
667
  canMangle: false,
650
668
  excludeExports: mode.hidden
651
- ? combine(mode.ignored, mode.hidden)
652
- : mode.ignored,
669
+ ? combine(
670
+ /** @type {ExportModeIgnored} */ (mode.ignored),
671
+ mode.hidden
672
+ )
673
+ : /** @type {ExportModeIgnored} */ (mode.ignored),
653
674
  hideExports: mode.hidden,
654
675
  dependencies: [from.module]
655
676
  };
@@ -677,22 +698,20 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
677
698
  };
678
699
  }
679
700
  case "reexport-dynamic-default": {
680
- {
681
- const from =
682
- /** @type {ModuleGraphConnection} */
683
- (moduleGraph.getConnection(this));
684
- return {
685
- exports: [
686
- {
687
- name: /** @type {string} */ (mode.name),
688
- from,
689
- export: ["default"]
690
- }
691
- ],
692
- priority: 1,
693
- dependencies: [from.module]
694
- };
695
- }
701
+ const from =
702
+ /** @type {ModuleGraphConnection} */
703
+ (moduleGraph.getConnection(this));
704
+ return {
705
+ exports: [
706
+ {
707
+ name: /** @type {string} */ (mode.name),
708
+ from,
709
+ export: ["default"]
710
+ }
711
+ ],
712
+ priority: 1,
713
+ dependencies: [from.module]
714
+ };
696
715
  }
697
716
  case "reexport-undefined":
698
717
  return {
@@ -825,6 +844,7 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
825
844
  const importedModule = moduleGraph.getModule(this);
826
845
  if (importedModule) {
827
846
  const exportsInfo = moduleGraph.getExportsInfo(importedModule);
847
+ /** @type {Map<string, string[]>} */
828
848
  const conflicts = new Map();
829
849
  for (const exportInfo of exportsInfo.orderedExports) {
830
850
  if (exportInfo.provided !== true) continue;
@@ -841,12 +861,12 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
841
861
  if (!conflictingDependency) continue;
842
862
  const target = exportInfo.getTerminalBinding(moduleGraph);
843
863
  if (!target) continue;
844
- const conflictingModule = moduleGraph.getModule(
845
- conflictingDependency
846
- );
864
+ const conflictingModule =
865
+ /** @type {Module} */
866
+ (moduleGraph.getModule(conflictingDependency));
847
867
  if (conflictingModule === importedModule) continue;
848
868
  const conflictingExportInfo = moduleGraph.getExportInfo(
849
- /** @type {Module} */ (conflictingModule),
869
+ conflictingModule,
850
870
  exportInfo.name
851
871
  );
852
872
  const conflictingTarget =
@@ -944,7 +964,7 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
944
964
  switch (mode.type) {
945
965
  case "reexport-undefined":
946
966
  concatenationScope.registerRawExport(
947
- mode.name,
967
+ /** @type {NonNullable<ExportMode["name"]>} */ (mode.name),
948
968
  "/* reexport non-default export from non-harmony */ undefined"
949
969
  );
950
970
  }
@@ -1080,23 +1100,36 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
1080
1100
  break;
1081
1101
 
1082
1102
  case "normal-reexport":
1083
- for (const { name, ids, checked, hidden } of mode.items) {
1103
+ for (const {
1104
+ name,
1105
+ ids,
1106
+ checked,
1107
+ hidden
1108
+ } of /** @type {NormalReexportItem[]} */ (mode.items)) {
1084
1109
  if (hidden) continue;
1085
1110
  if (checked) {
1111
+ const connection = moduleGraph.getConnection(dep);
1112
+ const key = `harmony reexport (checked) ${importVar} ${name}`;
1113
+ const runtimeCondition = dep.weak
1114
+ ? false
1115
+ : connection
1116
+ ? filterRuntime(runtime, r => connection.isTargetActive(r))
1117
+ : true;
1086
1118
  initFragments.push(
1087
- new InitFragment(
1088
- "/* harmony reexport (checked) */ " +
1089
- this.getConditionalReexportStatement(
1090
- module,
1091
- name,
1092
- importVar,
1093
- ids,
1094
- runtimeRequirements
1095
- ),
1119
+ new ConditionalInitFragment(
1120
+ `/* harmony reexport (checked) */ ${this.getConditionalReexportStatement(
1121
+ module,
1122
+ name,
1123
+ importVar,
1124
+ ids,
1125
+ runtimeRequirements
1126
+ )}`,
1096
1127
  moduleGraph.isAsync(importedModule)
1097
1128
  ? InitFragment.STAGE_ASYNC_HARMONY_IMPORTS
1098
1129
  : InitFragment.STAGE_HARMONY_IMPORTS,
1099
- dep.sourceOrder
1130
+ dep.sourceOrder,
1131
+ key,
1132
+ runtimeCondition
1100
1133
  )
1101
1134
  );
1102
1135
  } else {
@@ -1118,8 +1151,12 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
1118
1151
 
1119
1152
  case "dynamic-reexport": {
1120
1153
  const ignored = mode.hidden
1121
- ? combine(mode.ignored, mode.hidden)
1122
- : mode.ignored;
1154
+ ? combine(
1155
+ /** @type {ExportModeIgnored} */
1156
+ (mode.ignored),
1157
+ mode.hidden
1158
+ )
1159
+ : /** @type {ExportModeIgnored} */ (mode.ignored);
1123
1160
  const modern =
1124
1161
  runtimeTemplate.supportsConst() &&
1125
1162
  runtimeTemplate.supportsArrowFunction();
@@ -1132,22 +1169,19 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
1132
1169
  // Filter out exports which are defined by other exports
1133
1170
  // and filter out default export because it cannot be reexported with *
1134
1171
  if (ignored.size > 1) {
1135
- content +=
1136
- "if(" +
1137
- JSON.stringify(Array.from(ignored)) +
1138
- ".indexOf(__WEBPACK_IMPORT_KEY__) < 0) ";
1172
+ content += `if(${JSON.stringify(
1173
+ Array.from(ignored)
1174
+ )}.indexOf(__WEBPACK_IMPORT_KEY__) < 0) `;
1139
1175
  } else if (ignored.size === 1) {
1140
1176
  content += `if(__WEBPACK_IMPORT_KEY__ !== ${JSON.stringify(
1141
1177
  first(ignored)
1142
1178
  )}) `;
1143
1179
  }
1144
1180
 
1145
- content += `__WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = `;
1146
- if (modern) {
1147
- content += `() => ${importVar}[__WEBPACK_IMPORT_KEY__]`;
1148
- } else {
1149
- content += `function(key) { return ${importVar}[key]; }.bind(0, __WEBPACK_IMPORT_KEY__)`;
1150
- }
1181
+ content += "__WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = ";
1182
+ content += modern
1183
+ ? `() => ${importVar}[__WEBPACK_IMPORT_KEY__]`
1184
+ : `function(key) { return ${importVar}[key]; }.bind(0, __WEBPACK_IMPORT_KEY__)`;
1151
1185
 
1152
1186
  runtimeRequirements.add(RuntimeGlobals.exports);
1153
1187
  runtimeRequirements.add(RuntimeGlobals.definePropertyGetters);
@@ -1170,6 +1204,15 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
1170
1204
  }
1171
1205
  }
1172
1206
 
1207
+ /**
1208
+ * @param {Module} module the current module
1209
+ * @param {string} comment comment
1210
+ * @param {UsedName} key key
1211
+ * @param {string} name name
1212
+ * @param {string | string[] | null | false} valueKey value key
1213
+ * @param {RuntimeRequirements} runtimeRequirements runtime requirements
1214
+ * @returns {HarmonyExportInitFragment} harmony export init fragment
1215
+ */
1173
1216
  getReexportFragment(
1174
1217
  module,
1175
1218
  comment,
@@ -19,7 +19,7 @@ const parserStateExportsState = new WeakMap();
19
19
  * @param {boolean} isStrictHarmony strict harmony mode should be enabled
20
20
  * @returns {void}
21
21
  */
22
- exports.enable = (parserState, isStrictHarmony) => {
22
+ module.exports.enable = (parserState, isStrictHarmony) => {
23
23
  const value = parserStateExportsState.get(parserState);
24
24
  if (value === false) return;
25
25
  parserStateExportsState.set(parserState, true);
@@ -40,7 +40,7 @@ exports.enable = (parserState, isStrictHarmony) => {
40
40
  * @param {ParserState} parserState parser state
41
41
  * @returns {boolean} true, when enabled
42
42
  */
43
- exports.isEnabled = parserState => {
43
+ module.exports.isEnabled = parserState => {
44
44
  const value = parserStateExportsState.get(parserState);
45
45
  return value === true;
46
46
  };
@@ -59,7 +59,6 @@ const ExportPresenceModes = {
59
59
 
60
60
  class HarmonyImportDependency extends ModuleDependency {
61
61
  /**
62
- *
63
62
  * @param {string} request request string
64
63
  * @param {number} sourceOrder source order
65
64
  * @param {ImportAttributes=} attributes import attributes
@@ -89,7 +88,7 @@ class HarmonyImportDependency extends ModuleDependency {
89
88
  * @returns {string} name of the variable for the import
90
89
  */
91
90
  getImportVar(moduleGraph) {
92
- const module = moduleGraph.getParentModule(this);
91
+ const module = /** @type {Module} */ (moduleGraph.getParentModule(this));
93
92
  const meta = /** @type {TODO} */ (moduleGraph.getMeta(module));
94
93
  let importVarMap = meta.importVarMap;
95
94
  if (!importVarMap) meta.importVarMap = importVarMap = new Map();
@@ -351,7 +350,7 @@ HarmonyImportDependency.Template = class HarmonyImportDependencyTemplate extends
351
350
  importStatement[1],
352
351
  InitFragment.STAGE_ASYNC_HARMONY_IMPORTS,
353
352
  dep.sourceOrder,
354
- key + " compat",
353
+ `${key} compat`,
355
354
  runtimeCondition
356
355
  )
357
356
  );
@@ -369,7 +368,6 @@ HarmonyImportDependency.Template = class HarmonyImportDependencyTemplate extends
369
368
  }
370
369
 
371
370
  /**
372
- *
373
371
  * @param {Module} module the module
374
372
  * @param {Module} referencedModule the referenced module
375
373
  * @returns {RuntimeSpec | boolean} runtimeCondition in which this import has been emitted
@@ -50,7 +50,7 @@ const harmonySpecifierTag = Symbol("harmony import");
50
50
 
51
51
  /**
52
52
  * @param {ImportDeclaration | ExportNamedDeclaration | ExportAllDeclaration | (ImportExpression & { arguments?: ObjectExpression[] })} node node with assertions
53
- * @returns {ImportAttributes} import attributes
53
+ * @returns {ImportAttributes | undefined} import attributes
54
54
  */
55
55
  function getAttributes(node) {
56
56
  if (
@@ -96,7 +96,7 @@ function getAttributes(node) {
96
96
  ? /** @type {{ assertions?: ImportAttributeNode[] }} */ (node).assertions
97
97
  : /** @type {{ attributes?: ImportAttributeNode[] }} */ (node).attributes;
98
98
  if (attributes === undefined) {
99
- return undefined;
99
+ return;
100
100
  }
101
101
  const result = /** @type {ImportAttributes} */ ({});
102
102
  for (const attribute of attributes) {
@@ -138,12 +138,22 @@ module.exports = class HarmonyImportDependencyParserPlugin {
138
138
  apply(parser) {
139
139
  const { exportPresenceMode } = this;
140
140
 
141
+ /**
142
+ * @param {string[]} members members
143
+ * @param {boolean[]} membersOptionals members Optionals
144
+ * @returns {string[]} a non optional part
145
+ */
141
146
  function getNonOptionalPart(members, membersOptionals) {
142
147
  let i = 0;
143
148
  while (i < members.length && membersOptionals[i] === false) i++;
144
149
  return i !== members.length ? members.slice(0, i) : members;
145
150
  }
146
151
 
152
+ /**
153
+ * @param {TODO} node member expression
154
+ * @param {number} count count
155
+ * @returns {TODO} member expression
156
+ */
147
157
  function getNonOptionalMemberChain(node, count) {
148
158
  while (count--) node = node.object;
149
159
  return node;
@@ -221,7 +231,9 @@ module.exports = class HarmonyImportDependencyParserPlugin {
221
231
  )
222
232
  return;
223
233
  const settings = rootInfo.tagInfo.data;
224
- const members = rightPart.getMembers();
234
+ const members =
235
+ /** @type {(() => string[])} */
236
+ (rightPart.getMembers)();
225
237
  const dep = new HarmonyEvaluatedImportSpecifierDependency(
226
238
  settings.source,
227
239
  settings.sourceOrder,
@@ -280,6 +292,7 @@ module.exports = class HarmonyImportDependencyParserPlugin {
280
292
  members,
281
293
  membersOptionals
282
294
  );
295
+ /** @type {Range[]} */
283
296
  const ranges = memberRanges.slice(
284
297
  0,
285
298
  memberRanges.length - (members.length - nonOptionalMembers.length)
@@ -326,6 +339,7 @@ module.exports = class HarmonyImportDependencyParserPlugin {
326
339
  members,
327
340
  membersOptionals
328
341
  );
342
+ /** @type {Range[]} */
329
343
  const ranges = memberRanges.slice(
330
344
  0,
331
345
  memberRanges.length - (members.length - nonOptionalMembers.length)
@@ -355,7 +369,8 @@ module.exports = class HarmonyImportDependencyParserPlugin {
355
369
  );
356
370
  // only in case when we strictly follow the spec we need a special case here
357
371
  dep.namespaceObjectAsContext =
358
- members.length > 0 && this.strictThisContextOnImports;
372
+ members.length > 0 &&
373
+ /** @type {boolean} */ (this.strictThisContextOnImports);
359
374
  dep.loc = /** @type {DependencyLocation} */ (expr.loc);
360
375
  parser.state.module.addDependency(dep);
361
376
  if (args) parser.walkExpressions(args);
@@ -42,7 +42,7 @@ const { ExportPresenceModes } = HarmonyImportDependency;
42
42
 
43
43
  class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
44
44
  /**
45
- * @param {TODO} request request
45
+ * @param {string} request request
46
46
  * @param {number} sourceOrder source order
47
47
  * @param {string[]} ids ids
48
48
  * @param {string} name name
@@ -67,7 +67,6 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
67
67
  this.range = range;
68
68
  this.idRanges = idRanges;
69
69
  this.exportPresenceMode = exportPresenceMode;
70
- /** @type {boolean | undefined} */
71
70
  this.namespaceObjectAsContext = false;
72
71
  this.call = undefined;
73
72
  this.directImport = undefined;
@@ -105,7 +104,7 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
105
104
  getIds(moduleGraph) {
106
105
  const meta = moduleGraph.getMetaIfExisting(this);
107
106
  if (meta === undefined) return this.ids;
108
- const ids = meta[idsSymbol];
107
+ const ids = meta[/** @type {keyof object} */ (idsSymbol)];
109
108
  return ids !== undefined ? ids : this.ids;
110
109
  }
111
110
 
@@ -149,7 +148,9 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
149
148
  if (ids.length === 0) return this._getReferencedExportsInDestructuring();
150
149
  let namespaceObjectAsContext = this.namespaceObjectAsContext;
151
150
  if (ids[0] === "default") {
152
- const selfModule = moduleGraph.getParentModule(this);
151
+ const selfModule =
152
+ /** @type {Module} */
153
+ (moduleGraph.getParentModule(this));
153
154
  const importedModule =
154
155
  /** @type {Module} */
155
156
  (moduleGraph.getModule(this));
@@ -196,9 +197,8 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
196
197
  refs.push(ids ? ids.concat([id]) : [id]);
197
198
  }
198
199
  return refs;
199
- } else {
200
- return ids ? [ids] : Dependency.EXPORTS_OBJECT_REFERENCED;
201
200
  }
201
+ return ids ? [ids] : Dependency.EXPORTS_OBJECT_REFERENCED;
202
202
  }
203
203
 
204
204
  /**
@@ -208,9 +208,12 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
208
208
  _getEffectiveExportPresenceLevel(moduleGraph) {
209
209
  if (this.exportPresenceMode !== ExportPresenceModes.AUTO)
210
210
  return this.exportPresenceMode;
211
- const buildMeta = /** @type {BuildMeta} */ (
212
- moduleGraph.getParentModule(this).buildMeta
213
- );
211
+ const buildMeta =
212
+ /** @type {BuildMeta} */
213
+ (
214
+ /** @type {Module} */
215
+ (moduleGraph.getParentModule(this)).buildMeta
216
+ );
214
217
  return buildMeta.strictHarmonyModule
215
218
  ? ExportPresenceModes.ERROR
216
219
  : ExportPresenceModes.WARN;
@@ -344,14 +347,34 @@ HarmonyImportSpecifierDependency.Template = class HarmonyImportSpecifierDependen
344
347
  }
345
348
 
346
349
  if (dep.referencedPropertiesInDestructuring) {
347
- for (let {
350
+ let prefixedIds = ids;
351
+
352
+ if (ids[0] === "default") {
353
+ const selfModule = moduleGraph.getParentModule(dep);
354
+ const importedModule =
355
+ /** @type {Module} */
356
+ (moduleGraph.getModule(dep));
357
+ const exportsType = importedModule.getExportsType(
358
+ moduleGraph,
359
+ /** @type {BuildMeta} */
360
+ (selfModule.buildMeta).strictHarmonyModule
361
+ );
362
+ if (
363
+ (exportsType === "default-only" ||
364
+ exportsType === "default-with-named") &&
365
+ ids.length >= 1
366
+ ) {
367
+ prefixedIds = ids.slice(1);
368
+ }
369
+ }
370
+
371
+ for (const {
348
372
  id,
349
373
  shorthand,
350
374
  range
351
375
  } of dep.referencedPropertiesInDestructuring) {
352
- const concatedIds = ids.concat([id]);
353
- if (concatedIds[0] === "default") concatedIds.shift();
354
- const module = moduleGraph.getModule(dep);
376
+ const concatedIds = prefixedIds.concat([id]);
377
+ const module = /** @type {Module} */ (moduleGraph.getModule(dep));
355
378
  const used = moduleGraph
356
379
  .getExportsInfo(module)
357
380
  .getUsedName(concatedIds, runtime);
@@ -360,11 +383,13 @@ HarmonyImportSpecifierDependency.Template = class HarmonyImportSpecifierDependen
360
383
  const name = concatedIds[concatedIds.length - 1];
361
384
  if (newName === name) continue;
362
385
 
363
- const comment = Template.toNormalComment(name) + " ";
386
+ const comment = `${Template.toNormalComment(name)} `;
364
387
  const key = comment + JSON.stringify(newName);
365
388
  source.replace(
366
- range[0],
367
- range[1] - 1,
389
+ /** @type {Range} */
390
+ (range)[0],
391
+ /** @type {Range} */
392
+ (range)[1] - 1,
368
393
  shorthand ? `${key}: ${name}` : `${key}`
369
394
  );
370
395
  }
@@ -124,7 +124,7 @@ ImportDependency.Template = class ImportDependencyTemplate extends (
124
124
  );
125
125
  const content = runtimeTemplate.moduleNamespacePromise({
126
126
  chunkGraph,
127
- block: block,
127
+ block,
128
128
  module: /** @type {Module} */ (moduleGraph.getModule(dep)),
129
129
  request: dep.request,
130
130
  strict: /** @type {BuildMeta} */ (module.buildMeta).strictHarmonyModule,
@@ -57,14 +57,14 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
57
57
  apply(parser) {
58
58
  parser.hooks.evaluateIdentifier
59
59
  .for("import.meta.webpackContext")
60
- .tap("ImportMetaContextDependencyParserPlugin", expr => {
61
- return evaluateToIdentifier(
60
+ .tap("ImportMetaContextDependencyParserPlugin", expr =>
61
+ evaluateToIdentifier(
62
62
  "import.meta.webpackContext",
63
63
  "import.meta",
64
64
  () => ["webpackContext"],
65
65
  true
66
- )(expr);
67
- });
66
+ )(expr)
67
+ );
68
68
  parser.hooks.call
69
69
  .for("import.meta.webpackContext")
70
70
  .tap("ImportMetaContextDependencyParserPlugin", expr => {
@@ -293,7 +293,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
293
293
  /** @type {Range} */ (expr.range)
294
294
  );
295
295
  dep.loc = /** @type {DependencyLocation} */ (expr.loc);
296
- dep.optional = !!parser.scope.inTry;
296
+ dep.optional = Boolean(parser.scope.inTry);
297
297
  parser.state.current.addDependency(dep);
298
298
  return true;
299
299
  });