webpack 5.76.1 → 5.88.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.

Potentially problematic release.


This version of webpack might be problematic. Click here for more details.

Files changed (436) hide show
  1. package/README.md +10 -4
  2. package/bin/webpack.js +26 -2
  3. package/hot/dev-server.js +2 -1
  4. package/hot/lazy-compilation-node.js +10 -0
  5. package/hot/lazy-compilation-web.js +9 -0
  6. package/hot/log-apply-result.js +5 -0
  7. package/hot/log.js +22 -0
  8. package/hot/only-dev-server.js +2 -1
  9. package/hot/poll.js +3 -0
  10. package/hot/signal.js +4 -0
  11. package/lib/APIPlugin.js +174 -116
  12. package/lib/AsyncDependenciesBlock.js +13 -5
  13. package/lib/AutomaticPrefetchPlugin.js +1 -0
  14. package/lib/BannerPlugin.js +4 -0
  15. package/lib/CacheFacade.js +4 -0
  16. package/lib/CaseSensitiveModulesWarning.js +3 -1
  17. package/lib/Chunk.js +36 -18
  18. package/lib/ChunkGraph.js +4 -4
  19. package/lib/ChunkGroup.js +25 -10
  20. package/lib/CleanPlugin.js +30 -7
  21. package/lib/CodeGenerationResults.js +2 -2
  22. package/lib/CompatibilityPlugin.js +85 -46
  23. package/lib/Compilation.js +17 -8
  24. package/lib/Compiler.js +12 -8
  25. package/lib/ConcatenationScope.js +2 -2
  26. package/lib/ConditionalInitFragment.js +11 -1
  27. package/lib/ConstPlugin.js +79 -44
  28. package/lib/ContextModule.js +20 -6
  29. package/lib/ContextModuleFactory.js +2 -1
  30. package/lib/ContextReplacementPlugin.js +13 -0
  31. package/lib/CssModule.js +169 -0
  32. package/lib/DefinePlugin.js +152 -86
  33. package/lib/DelegatedModule.js +22 -4
  34. package/lib/DelegatedModuleFactoryPlugin.js +6 -0
  35. package/lib/DependenciesBlock.js +17 -1
  36. package/lib/Dependency.js +19 -5
  37. package/lib/DllEntryPlugin.js +16 -1
  38. package/lib/DllModule.js +17 -2
  39. package/lib/DllModuleFactory.js +1 -1
  40. package/lib/DllReferencePlugin.js +13 -1
  41. package/lib/Entrypoint.js +1 -1
  42. package/lib/ErrorHelpers.js +62 -22
  43. package/lib/EvalSourceMapDevToolPlugin.js +9 -2
  44. package/lib/ExportsInfo.js +20 -3
  45. package/lib/ExportsInfoApiPlugin.js +30 -14
  46. package/lib/ExternalModule.js +30 -9
  47. package/lib/FileSystemInfo.js +9 -1
  48. package/lib/FlagAllModulesAsUsedPlugin.js +27 -27
  49. package/lib/FlagDependencyExportsPlugin.js +336 -348
  50. package/lib/FlagDependencyUsagePlugin.js +9 -9
  51. package/lib/FlagEntryExportAsUsedPlugin.js +26 -23
  52. package/lib/HookWebpackError.js +1 -1
  53. package/lib/HotModuleReplacementPlugin.js +60 -46
  54. package/lib/IgnoreErrorModuleFactory.js +1 -1
  55. package/lib/InitFragment.js +28 -5
  56. package/lib/JavascriptMetaInfoPlugin.js +27 -15
  57. package/lib/LibManifestPlugin.js +22 -5
  58. package/lib/LoaderOptionsPlugin.js +12 -2
  59. package/lib/MainTemplate.js +2 -2
  60. package/lib/Module.js +44 -12
  61. package/lib/ModuleBuildError.js +9 -0
  62. package/lib/ModuleDependencyError.js +4 -2
  63. package/lib/ModuleDependencyWarning.js +4 -2
  64. package/lib/ModuleError.js +9 -0
  65. package/lib/ModuleFactory.js +1 -1
  66. package/lib/ModuleFilenameHelpers.js +114 -4
  67. package/lib/ModuleGraph.js +33 -23
  68. package/lib/ModuleGraphConnection.js +19 -6
  69. package/lib/ModuleInfoHeaderPlugin.js +9 -2
  70. package/lib/ModuleNotFoundError.js +5 -2
  71. package/lib/ModuleParseError.js +9 -0
  72. package/lib/ModuleProfile.js +1 -0
  73. package/lib/ModuleRestoreError.js +2 -0
  74. package/lib/ModuleStoreError.js +2 -1
  75. package/lib/ModuleTypeConstants.js +169 -0
  76. package/lib/ModuleWarning.js +9 -0
  77. package/lib/MultiWatching.js +4 -0
  78. package/lib/NodeStuffPlugin.js +65 -35
  79. package/lib/NormalModule.js +12 -2
  80. package/lib/NormalModuleFactory.js +56 -8
  81. package/lib/NormalModuleReplacementPlugin.js +5 -3
  82. package/lib/NullFactory.js +1 -1
  83. package/lib/PrefetchPlugin.js +4 -0
  84. package/lib/ProgressPlugin.js +71 -15
  85. package/lib/ProvidePlugin.js +30 -14
  86. package/lib/RawModule.js +13 -2
  87. package/lib/RecordIdsPlugin.js +4 -4
  88. package/lib/RequireJsStuffPlugin.js +22 -15
  89. package/lib/RuntimeGlobals.js +5 -0
  90. package/lib/RuntimeModule.js +12 -11
  91. package/lib/RuntimePlugin.js +10 -3
  92. package/lib/RuntimeTemplate.js +29 -11
  93. package/lib/SelfModuleFactory.js +12 -0
  94. package/lib/SourceMapDevToolModuleOptionsPlugin.js +4 -0
  95. package/lib/SourceMapDevToolPlugin.js +47 -11
  96. package/lib/Template.js +5 -3
  97. package/lib/UseStrictPlugin.js +29 -11
  98. package/lib/WarnCaseSensitiveModulesPlugin.js +12 -0
  99. package/lib/WarnDeprecatedOptionPlugin.js +7 -0
  100. package/lib/WatchIgnorePlugin.js +4 -0
  101. package/lib/WebpackError.js +14 -5
  102. package/lib/WebpackIsIncludedPlugin.js +22 -13
  103. package/lib/WebpackOptionsApply.js +41 -44
  104. package/lib/WebpackOptionsDefaulter.js +10 -3
  105. package/lib/asset/AssetGenerator.js +24 -9
  106. package/lib/asset/AssetModulesPlugin.js +28 -12
  107. package/lib/asset/AssetParser.js +15 -7
  108. package/lib/asset/AssetSourceParser.js +8 -3
  109. package/lib/asset/RawDataUrlModule.js +15 -4
  110. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -0
  111. package/lib/async-modules/InferAsyncModulesPlugin.js +1 -1
  112. package/lib/cache/IdleFileCachePlugin.js +2 -1
  113. package/lib/cache/MemoryWithGcCachePlugin.js +2 -0
  114. package/lib/cache/PackFileCacheStrategy.js +42 -15
  115. package/lib/cache/ResolverCachePlugin.js +3 -0
  116. package/lib/config/browserslistTargetHandler.js +10 -10
  117. package/lib/config/defaults.js +306 -105
  118. package/lib/config/normalization.js +110 -71
  119. package/lib/config/target.js +37 -10
  120. package/lib/container/ContainerEntryModule.js +11 -1
  121. package/lib/container/ContainerEntryModuleFactory.js +1 -1
  122. package/lib/container/ContainerExposedDependency.js +9 -0
  123. package/lib/container/ContainerPlugin.js +3 -1
  124. package/lib/container/FallbackDependency.js +13 -0
  125. package/lib/container/FallbackItemDependency.js +3 -0
  126. package/lib/container/FallbackModule.js +12 -2
  127. package/lib/container/FallbackModuleFactory.js +1 -1
  128. package/lib/container/RemoteModule.js +11 -1
  129. package/lib/container/RemoteRuntimeModule.js +3 -2
  130. package/lib/container/RemoteToExternalDependency.js +3 -0
  131. package/lib/css/CssExportsGenerator.js +9 -0
  132. package/lib/css/CssGenerator.js +5 -1
  133. package/lib/css/CssLoadingRuntimeModule.js +53 -22
  134. package/lib/css/CssModulesPlugin.js +253 -74
  135. package/lib/css/CssParser.js +697 -282
  136. package/lib/css/walkCssTokens.js +269 -138
  137. package/lib/debug/ProfilingPlugin.js +33 -12
  138. package/lib/dependencies/AMDDefineDependency.js +54 -10
  139. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +13 -2
  140. package/lib/dependencies/AMDPlugin.js +33 -20
  141. package/lib/dependencies/AMDRequireArrayDependency.js +13 -0
  142. package/lib/dependencies/AMDRequireContextDependency.js +15 -0
  143. package/lib/dependencies/AMDRequireDependenciesBlock.js +6 -0
  144. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +8 -2
  145. package/lib/dependencies/AMDRequireDependency.js +16 -1
  146. package/lib/dependencies/AMDRequireItemDependency.js +6 -0
  147. package/lib/dependencies/AMDRuntimeModules.js +2 -2
  148. package/lib/dependencies/CachedConstDependency.js +14 -0
  149. package/lib/dependencies/CommonJsDependencyHelpers.js +9 -0
  150. package/lib/dependencies/CommonJsExportRequireDependency.js +19 -0
  151. package/lib/dependencies/CommonJsExportsDependency.js +16 -0
  152. package/lib/dependencies/CommonJsExportsParserPlugin.js +77 -5
  153. package/lib/dependencies/CommonJsFullRequireDependency.js +10 -1
  154. package/lib/dependencies/CommonJsImportsParserPlugin.js +174 -63
  155. package/lib/dependencies/CommonJsPlugin.js +51 -26
  156. package/lib/dependencies/CommonJsRequireContextDependency.js +17 -0
  157. package/lib/dependencies/CommonJsRequireDependency.js +7 -0
  158. package/lib/dependencies/CommonJsSelfReferenceDependency.js +16 -0
  159. package/lib/dependencies/ConstDependency.js +11 -2
  160. package/lib/dependencies/ContextDependency.js +15 -2
  161. package/lib/dependencies/ContextDependencyHelpers.js +3 -3
  162. package/lib/dependencies/ContextElementDependency.js +8 -0
  163. package/lib/dependencies/CreateScriptUrlDependency.js +10 -1
  164. package/lib/dependencies/CriticalDependencyWarning.js +3 -0
  165. package/lib/dependencies/CssExportDependency.js +8 -0
  166. package/lib/dependencies/CssImportDependency.js +55 -3
  167. package/lib/dependencies/CssLocalIdentifierDependency.js +15 -1
  168. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +10 -1
  169. package/lib/dependencies/CssUrlDependency.js +46 -16
  170. package/lib/dependencies/DelegatedSourceDependency.js +3 -0
  171. package/lib/dependencies/DllEntryDependency.js +14 -0
  172. package/lib/dependencies/DynamicExports.js +10 -6
  173. package/lib/dependencies/ExportsInfoDependency.js +25 -4
  174. package/lib/dependencies/HarmonyAcceptDependency.js +10 -1
  175. package/lib/dependencies/HarmonyAcceptImportDependency.js +3 -0
  176. package/lib/dependencies/HarmonyCompatibilityDependency.js +2 -1
  177. package/lib/dependencies/HarmonyDetectionParserPlugin.js +22 -2
  178. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +32 -6
  179. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +5 -0
  180. package/lib/dependencies/HarmonyExportExpressionDependency.js +20 -3
  181. package/lib/dependencies/HarmonyExportHeaderDependency.js +13 -0
  182. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +22 -6
  183. package/lib/dependencies/HarmonyExportInitFragment.js +2 -1
  184. package/lib/dependencies/HarmonyExportSpecifierDependency.js +12 -0
  185. package/lib/dependencies/HarmonyExports.js +11 -5
  186. package/lib/dependencies/HarmonyImportDependency.js +10 -1
  187. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +53 -22
  188. package/lib/dependencies/HarmonyImportSideEffectDependency.js +7 -2
  189. package/lib/dependencies/HarmonyImportSpecifierDependency.js +139 -16
  190. package/lib/dependencies/HarmonyModulesPlugin.js +23 -5
  191. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -3
  192. package/lib/dependencies/ImportContextDependency.js +15 -0
  193. package/lib/dependencies/ImportDependency.js +15 -4
  194. package/lib/dependencies/ImportEagerDependency.js +7 -4
  195. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +51 -13
  196. package/lib/dependencies/ImportMetaContextPlugin.js +18 -5
  197. package/lib/dependencies/ImportMetaHotAcceptDependency.js +6 -0
  198. package/lib/dependencies/ImportMetaHotDeclineDependency.js +6 -0
  199. package/lib/dependencies/ImportMetaPlugin.js +103 -51
  200. package/lib/dependencies/ImportParserPlugin.js +83 -25
  201. package/lib/dependencies/ImportPlugin.js +21 -7
  202. package/lib/dependencies/ImportWeakDependency.js +7 -4
  203. package/lib/dependencies/JsonExportsDependency.js +9 -1
  204. package/lib/dependencies/LocalModule.js +16 -0
  205. package/lib/dependencies/LocalModuleDependency.js +15 -0
  206. package/lib/dependencies/LocalModulesHelpers.js +18 -0
  207. package/lib/dependencies/ModuleDecoratorDependency.js +8 -0
  208. package/lib/dependencies/ModuleDependency.js +9 -1
  209. package/lib/dependencies/ModuleDependencyTemplateAsId.js +2 -1
  210. package/lib/dependencies/ModuleHotAcceptDependency.js +6 -0
  211. package/lib/dependencies/ModuleHotDeclineDependency.js +6 -0
  212. package/lib/dependencies/PrefetchDependency.js +3 -0
  213. package/lib/dependencies/ProvidedDependency.js +14 -2
  214. package/lib/dependencies/PureExpressionDependency.js +10 -1
  215. package/lib/dependencies/RequireContextDependency.js +6 -0
  216. package/lib/dependencies/RequireContextDependencyParserPlugin.js +13 -5
  217. package/lib/dependencies/RequireContextPlugin.js +19 -6
  218. package/lib/dependencies/RequireEnsureDependenciesBlock.js +7 -0
  219. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +6 -1
  220. package/lib/dependencies/RequireEnsureDependency.js +16 -2
  221. package/lib/dependencies/RequireEnsureItemDependency.js +3 -0
  222. package/lib/dependencies/RequireEnsurePlugin.js +27 -7
  223. package/lib/dependencies/RequireHeaderDependency.js +14 -1
  224. package/lib/dependencies/RequireIncludeDependency.js +5 -0
  225. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +29 -5
  226. package/lib/dependencies/RequireIncludePlugin.js +25 -5
  227. package/lib/dependencies/RequireResolveContextDependency.js +17 -0
  228. package/lib/dependencies/RequireResolveDependency.js +6 -0
  229. package/lib/dependencies/RequireResolveHeaderDependency.js +18 -0
  230. package/lib/dependencies/RuntimeRequirementsDependency.js +8 -0
  231. package/lib/dependencies/StaticExportsDependency.js +8 -0
  232. package/lib/dependencies/SystemPlugin.js +48 -21
  233. package/lib/dependencies/SystemRuntimeModule.js +1 -1
  234. package/lib/dependencies/URLDependency.js +13 -4
  235. package/lib/dependencies/URLPlugin.js +31 -18
  236. package/lib/dependencies/UnsupportedDependency.js +13 -0
  237. package/lib/dependencies/WebAssemblyExportImportedDependency.js +14 -0
  238. package/lib/dependencies/WebAssemblyImportDependency.js +9 -1
  239. package/lib/dependencies/WebpackIsIncludedDependency.js +5 -0
  240. package/lib/dependencies/WorkerDependency.js +47 -3
  241. package/lib/dependencies/WorkerPlugin.js +105 -32
  242. package/lib/dependencies/getFunctionExpression.js +7 -0
  243. package/lib/esm/ExportWebpackRequireRuntimeModule.js +3 -2
  244. package/lib/esm/ModuleChunkFormatPlugin.js +21 -8
  245. package/lib/esm/ModuleChunkLoadingPlugin.js +9 -0
  246. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +19 -12
  247. package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
  248. package/lib/hmr/LazyCompilationPlugin.js +14 -5
  249. package/lib/ids/ChunkModuleIdRangePlugin.js +11 -0
  250. package/lib/ids/DeterministicChunkIdsPlugin.js +11 -2
  251. package/lib/ids/DeterministicModuleIdsPlugin.js +11 -7
  252. package/lib/ids/HashedModuleIdsPlugin.js +9 -2
  253. package/lib/ids/IdHelpers.js +6 -0
  254. package/lib/ids/NamedChunkIdsPlugin.js +13 -1
  255. package/lib/ids/NamedModuleIdsPlugin.js +14 -3
  256. package/lib/ids/OccurrenceChunkIdsPlugin.js +6 -2
  257. package/lib/ids/OccurrenceModuleIdsPlugin.js +1 -1
  258. package/lib/ids/SyncModuleIdsPlugin.js +3 -2
  259. package/lib/index.js +8 -0
  260. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +3 -3
  261. package/lib/javascript/BasicEvaluatedExpression.js +137 -11
  262. package/lib/javascript/ChunkHelpers.js +2 -2
  263. package/lib/javascript/CommonJsChunkFormatPlugin.js +7 -3
  264. package/lib/javascript/EnableChunkLoadingPlugin.js +4 -0
  265. package/lib/javascript/JavascriptModulesPlugin.js +194 -194
  266. package/lib/javascript/JavascriptParser.js +941 -256
  267. package/lib/javascript/JavascriptParserHelpers.js +37 -15
  268. package/lib/javascript/StartupHelpers.js +2 -2
  269. package/lib/json/JsonData.js +26 -1
  270. package/lib/json/JsonGenerator.js +21 -7
  271. package/lib/json/JsonModulesPlugin.js +14 -5
  272. package/lib/json/JsonParser.js +27 -13
  273. package/lib/library/AbstractLibraryPlugin.js +4 -0
  274. package/lib/library/AmdLibraryPlugin.js +22 -6
  275. package/lib/library/AssignLibraryPlugin.js +6 -4
  276. package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
  277. package/lib/library/ModuleLibraryPlugin.js +8 -4
  278. package/lib/library/SystemLibraryPlugin.js +1 -0
  279. package/lib/library/UmdLibraryPlugin.js +4 -0
  280. package/lib/logging/runtime.js +1 -1
  281. package/lib/logging/truncateArgs.js +4 -0
  282. package/lib/node/CommonJsChunkLoadingPlugin.js +17 -2
  283. package/lib/node/NodeTargetPlugin.js +3 -0
  284. package/lib/node/NodeTemplatePlugin.js +10 -2
  285. package/lib/node/NodeWatchFileSystem.js +1 -1
  286. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +18 -9
  287. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +12 -2
  288. package/lib/node/ReadFileCompileWasmPlugin.js +21 -3
  289. package/lib/node/RequireChunkLoadingRuntimeModule.js +15 -8
  290. package/lib/node/nodeConsole.js +2 -4
  291. package/lib/optimize/AggressiveMergingPlugin.js +8 -0
  292. package/lib/optimize/AggressiveSplittingPlugin.js +9 -2
  293. package/lib/optimize/ConcatenatedModule.js +8 -6
  294. package/lib/optimize/EnsureChunkConditionsPlugin.js +3 -0
  295. package/lib/optimize/FlagIncludedChunksPlugin.js +11 -5
  296. package/lib/optimize/InnerGraph.js +5 -5
  297. package/lib/optimize/InnerGraphPlugin.js +57 -48
  298. package/lib/optimize/LimitChunkCountPlugin.js +29 -4
  299. package/lib/optimize/MangleExportsPlugin.js +1 -1
  300. package/lib/optimize/MinMaxSizeWarning.js +5 -0
  301. package/lib/optimize/ModuleConcatenationPlugin.js +59 -2
  302. package/lib/optimize/RealContentHashPlugin.js +86 -30
  303. package/lib/optimize/RemoveParentModulesPlugin.js +6 -0
  304. package/lib/optimize/RuntimeChunkPlugin.js +9 -1
  305. package/lib/optimize/SideEffectsFlagPlugin.js +53 -44
  306. package/lib/optimize/SplitChunksPlugin.js +71 -31
  307. package/lib/performance/SizeLimitsPlugin.js +7 -4
  308. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +4 -2
  309. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +3 -1
  310. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +6 -3
  311. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +4 -2
  312. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +4 -2
  313. package/lib/rules/BasicEffectRulePlugin.js +4 -0
  314. package/lib/rules/BasicMatcherRulePlugin.js +5 -0
  315. package/lib/rules/RuleSetCompiler.js +3 -3
  316. package/lib/rules/UseEffectRulePlugin.js +6 -4
  317. package/lib/runtime/AsyncModuleRuntimeModule.js +9 -6
  318. package/lib/runtime/AutoPublicPathRuntimeModule.js +16 -5
  319. package/lib/runtime/BaseUriRuntimeModule.js +8 -4
  320. package/lib/runtime/ChunkNameRuntimeModule.js +1 -1
  321. package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +5 -2
  322. package/lib/runtime/CompatRuntimeModule.js +7 -2
  323. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +5 -2
  324. package/lib/runtime/CreateScriptRuntimeModule.js +4 -2
  325. package/lib/runtime/CreateScriptUrlRuntimeModule.js +4 -2
  326. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +5 -2
  327. package/lib/runtime/EnsureChunkRuntimeModule.js +18 -4
  328. package/lib/runtime/GetChunkFilenameRuntimeModule.js +45 -26
  329. package/lib/runtime/GetFullHashRuntimeModule.js +4 -3
  330. package/lib/runtime/GetMainFilenameRuntimeModule.js +5 -2
  331. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +27 -6
  332. package/lib/runtime/GlobalRuntimeModule.js +1 -1
  333. package/lib/runtime/HasOwnPropertyRuntimeModule.js +5 -2
  334. package/lib/runtime/LoadScriptRuntimeModule.js +65 -50
  335. package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +5 -2
  336. package/lib/runtime/NonceRuntimeModule.js +1 -1
  337. package/lib/runtime/OnChunksLoadedRuntimeModule.js +4 -2
  338. package/lib/runtime/PublicPathRuntimeModule.js +9 -2
  339. package/lib/runtime/RelativeUrlRuntimeModule.js +5 -2
  340. package/lib/runtime/RuntimeIdRuntimeModule.js +6 -2
  341. package/lib/runtime/StartupChunkDependenciesPlugin.js +15 -0
  342. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +13 -4
  343. package/lib/runtime/StartupEntrypointRuntimeModule.js +11 -7
  344. package/lib/runtime/SystemContextRuntimeModule.js +1 -1
  345. package/lib/schemes/DataUriPlugin.js +16 -3
  346. package/lib/schemes/HttpUriPlugin.js +38 -0
  347. package/lib/serialization/ArraySerializer.js +22 -6
  348. package/lib/serialization/BinaryMiddleware.js +164 -1
  349. package/lib/serialization/DateObjectSerializer.js +15 -4
  350. package/lib/serialization/ErrorObjectSerializer.js +23 -8
  351. package/lib/serialization/FileMiddleware.js +17 -0
  352. package/lib/serialization/MapObjectSerializer.js +24 -8
  353. package/lib/serialization/NullPrototypeObjectSerializer.js +25 -8
  354. package/lib/serialization/ObjectMiddleware.js +33 -2
  355. package/lib/serialization/PlainObjectSerializer.js +23 -12
  356. package/lib/serialization/RegExpObjectSerializer.js +16 -5
  357. package/lib/serialization/SetObjectSerializer.js +21 -6
  358. package/lib/serialization/types.js +1 -1
  359. package/lib/sharing/ConsumeSharedFallbackDependency.js +3 -0
  360. package/lib/sharing/ConsumeSharedModule.js +13 -2
  361. package/lib/sharing/ConsumeSharedPlugin.js +4 -0
  362. package/lib/sharing/ConsumeSharedRuntimeModule.js +22 -7
  363. package/lib/sharing/ProvideSharedDependency.js +17 -0
  364. package/lib/sharing/ProvideSharedModule.js +11 -1
  365. package/lib/sharing/ProvideSharedModuleFactory.js +1 -1
  366. package/lib/sharing/ProvideSharedPlugin.js +22 -21
  367. package/lib/sharing/ShareRuntimeModule.js +19 -9
  368. package/lib/sharing/resolveMatchedConfigs.js +1 -1
  369. package/lib/sharing/utils.js +320 -7
  370. package/lib/stats/DefaultStatsFactoryPlugin.js +105 -29
  371. package/lib/stats/DefaultStatsPresetPlugin.js +9 -0
  372. package/lib/stats/DefaultStatsPrinterPlugin.js +43 -0
  373. package/lib/util/AsyncQueue.js +4 -2
  374. package/lib/util/LazySet.js +10 -2
  375. package/lib/util/MapHelpers.js +19 -5
  376. package/lib/util/ParallelismFactorCalculator.js +10 -0
  377. package/lib/util/Semaphore.js +1 -1
  378. package/lib/util/StackedCacheMap.js +6 -0
  379. package/lib/util/StringXor.js +51 -0
  380. package/lib/util/binarySearchBounds.js +49 -0
  381. package/lib/util/compileBooleanMatcher.js +31 -0
  382. package/lib/util/createHash.js +35 -13
  383. package/lib/util/deprecation.js +18 -3
  384. package/lib/util/deterministicGrouping.js +50 -11
  385. package/lib/util/findGraphRoots.js +4 -2
  386. package/lib/util/hash/md4.js +2 -2
  387. package/lib/util/hash/xxhash64.js +1 -1
  388. package/lib/util/identifier.js +4 -0
  389. package/lib/util/internalSerializables.js +1 -0
  390. package/lib/util/makeSerializable.js +7 -0
  391. package/lib/util/memoize.js +3 -3
  392. package/lib/util/numberHash.js +75 -21
  393. package/lib/util/processAsyncTree.js +7 -1
  394. package/lib/util/propertyAccess.js +9 -54
  395. package/lib/util/propertyName.js +79 -0
  396. package/lib/util/registerExternalSerializer.js +1 -1
  397. package/lib/util/runtime.js +14 -1
  398. package/lib/util/semver.js +1 -1
  399. package/lib/util/serialization.js +10 -0
  400. package/lib/util/smartGrouping.js +1 -1
  401. package/lib/validateSchema.js +6 -2
  402. package/lib/wasm/EnableWasmLoadingPlugin.js +4 -0
  403. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +15 -2
  404. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +9 -1
  405. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +14 -3
  406. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +28 -8
  407. package/lib/wasm-async/AsyncWebAssemblyParser.js +11 -4
  408. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +39 -8
  409. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +17 -6
  410. package/lib/wasm-sync/WebAssemblyGenerator.js +19 -5
  411. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +1 -1
  412. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +53 -43
  413. package/lib/wasm-sync/WebAssemblyParser.js +15 -4
  414. package/lib/wasm-sync/WebAssemblyUtils.js +1 -1
  415. package/lib/web/FetchCompileAsyncWasmPlugin.js +11 -1
  416. package/lib/web/FetchCompileWasmPlugin.js +59 -42
  417. package/lib/web/JsonpChunkLoadingPlugin.js +9 -0
  418. package/lib/web/JsonpChunkLoadingRuntimeModule.js +26 -9
  419. package/lib/webpack.js +12 -3
  420. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +9 -0
  421. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +20 -17
  422. package/module.d.ts +55 -37
  423. package/package.json +59 -56
  424. package/schemas/WebpackOptions.check.js +1 -1
  425. package/schemas/WebpackOptions.json +132 -5
  426. package/schemas/plugins/ProgressPlugin.check.js +1 -1
  427. package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
  428. package/schemas/plugins/SourceMapDevToolPlugin.json +4 -0
  429. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  430. package/schemas/plugins/container/ContainerPlugin.json +8 -0
  431. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  432. package/schemas/plugins/container/ModuleFederationPlugin.json +8 -0
  433. package/schemas/plugins/css/CssGeneratorOptions.json +1 -1
  434. package/schemas/plugins/css/CssParserOptions.json +1 -1
  435. package/schemas/plugins/sharing/SharePlugin.check.js +1 -1
  436. package/types.d.ts +1608 -667
@@ -5,7 +5,10 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const ModuleDependencyWarning = require("../ModuleDependencyWarning");
9
+ const { CSS_MODULE_TYPE_AUTO } = require("../ModuleTypeConstants");
8
10
  const Parser = require("../Parser");
11
+ const WebpackError = require("../WebpackError");
9
12
  const ConstDependency = require("../dependencies/ConstDependency");
10
13
  const CssExportDependency = require("../dependencies/CssExportDependency");
11
14
  const CssImportDependency = require("../dependencies/CssImportDependency");
@@ -13,10 +16,12 @@ const CssLocalIdentifierDependency = require("../dependencies/CssLocalIdentifier
13
16
  const CssSelfLocalIdentifierDependency = require("../dependencies/CssSelfLocalIdentifierDependency");
14
17
  const CssUrlDependency = require("../dependencies/CssUrlDependency");
15
18
  const StaticExportsDependency = require("../dependencies/StaticExportsDependency");
19
+ const { parseResource } = require("../util/identifier");
16
20
  const walkCssTokens = require("./walkCssTokens");
17
21
 
18
22
  /** @typedef {import("../Parser").ParserState} ParserState */
19
23
  /** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
24
+ /** @typedef {[number, number]} Range */
20
25
 
21
26
  const CC_LEFT_CURLY = "{".charCodeAt(0);
22
27
  const CC_RIGHT_CURLY = "}".charCodeAt(0);
@@ -24,17 +29,63 @@ const CC_COLON = ":".charCodeAt(0);
24
29
  const CC_SLASH = "/".charCodeAt(0);
25
30
  const CC_SEMICOLON = ";".charCodeAt(0);
26
31
 
27
- const cssUnescape = str => {
28
- return str.replace(/\\([0-9a-fA-F]{1,6}[ \t\n\r\f]?|[\s\S])/g, match => {
29
- if (match.length > 2) {
30
- return String.fromCharCode(parseInt(match.slice(1).trim(), 16));
31
- } else {
32
- return match[1];
32
+ // https://www.w3.org/TR/css-syntax-3/#newline
33
+ // We don't have `preprocessing` stage, so we need specify all of them
34
+ const STRING_MULTILINE = /\\[\n\r\f]/g;
35
+ // https://www.w3.org/TR/css-syntax-3/#whitespace
36
+ const TRIM_WHITE_SPACES = /(^[ \t\n\r\f]*|[ \t\n\r\f]*$)/g;
37
+ const UNESCAPE = /\\([0-9a-fA-F]{1,6}[ \t\n\r\f]?|[\s\S])/g;
38
+ const IMAGE_SET_FUNCTION = /^(-\w+-)?image-set$/i;
39
+ const OPTIONALLY_VENDOR_PREFIXED_KEYFRAMES_AT_RULE = /^@(-\w+-)?keyframes$/;
40
+ const OPTIONALLY_VENDOR_PREFIXED_ANIMATION_PROPERTY =
41
+ /^(-\w+-)?animation(-name)?$/i;
42
+ const IS_MODULES = /\.module(s)?\.[^.]+$/i;
43
+
44
+ /**
45
+ * @param {string} str url string
46
+ * @param {boolean} isString is url wrapped in quotes
47
+ * @returns {string} normalized url
48
+ */
49
+ const normalizeUrl = (str, isString) => {
50
+ // Remove extra spaces and newlines:
51
+ // `url("im\
52
+ // g.png")`
53
+ if (isString) {
54
+ str = str.replace(STRING_MULTILINE, "");
55
+ }
56
+
57
+ str = str
58
+ // Remove unnecessary spaces from `url(" img.png ")`
59
+ .replace(TRIM_WHITE_SPACES, "")
60
+ // Unescape
61
+ .replace(UNESCAPE, match => {
62
+ if (match.length > 2) {
63
+ return String.fromCharCode(parseInt(match.slice(1).trim(), 16));
64
+ } else {
65
+ return match[1];
66
+ }
67
+ });
68
+
69
+ if (/^data:/i.test(str)) {
70
+ return str;
71
+ }
72
+
73
+ if (str.includes("%")) {
74
+ // Convert `url('%2E/img.png')` -> `url('./img.png')`
75
+ try {
76
+ str = decodeURIComponent(str);
77
+ } catch (error) {
78
+ // Ignore
33
79
  }
34
- });
80
+ }
81
+
82
+ return str;
35
83
  };
36
84
 
37
85
  class LocConverter {
86
+ /**
87
+ * @param {string} input input
88
+ */
38
89
  constructor(input) {
39
90
  this._input = input;
40
91
  this.line = 1;
@@ -42,6 +93,10 @@ class LocConverter {
42
93
  this.pos = 0;
43
94
  }
44
95
 
96
+ /**
97
+ * @param {number} pos position
98
+ * @returns {LocConverter} location converter
99
+ */
45
100
  get(pos) {
46
101
  if (this.pos !== pos) {
47
102
  if (this.pos < pos) {
@@ -70,47 +125,37 @@ class LocConverter {
70
125
  }
71
126
 
72
127
  const CSS_MODE_TOP_LEVEL = 0;
73
- const CSS_MODE_IN_RULE = 1;
74
- const CSS_MODE_IN_LOCAL_RULE = 2;
75
- const CSS_MODE_AT_IMPORT_EXPECT_URL = 3;
76
- // TODO implement layer and supports for @import
77
- const CSS_MODE_AT_IMPORT_EXPECT_SUPPORTS = 4;
78
- const CSS_MODE_AT_IMPORT_EXPECT_MEDIA = 5;
79
- const CSS_MODE_AT_OTHER = 6;
80
-
81
- const explainMode = mode => {
82
- switch (mode) {
83
- case CSS_MODE_TOP_LEVEL:
84
- return "parsing top level css";
85
- case CSS_MODE_IN_RULE:
86
- return "parsing css rule content (global)";
87
- case CSS_MODE_IN_LOCAL_RULE:
88
- return "parsing css rule content (local)";
89
- case CSS_MODE_AT_IMPORT_EXPECT_URL:
90
- return "parsing @import (expecting url)";
91
- case CSS_MODE_AT_IMPORT_EXPECT_SUPPORTS:
92
- return "parsing @import (expecting optionally supports or media query)";
93
- case CSS_MODE_AT_IMPORT_EXPECT_MEDIA:
94
- return "parsing @import (expecting optionally media query)";
95
- case CSS_MODE_AT_OTHER:
96
- return "parsing at-rule";
97
- default:
98
- return mode;
99
- }
100
- };
128
+ const CSS_MODE_IN_BLOCK = 1;
129
+ const CSS_MODE_IN_AT_IMPORT = 2;
130
+ const CSS_MODE_AT_IMPORT_INVALID = 3;
131
+ const CSS_MODE_AT_NAMESPACE_INVALID = 4;
101
132
 
102
133
  class CssParser extends Parser {
103
- constructor({
104
- allowPseudoBlocks = true,
105
- allowModeSwitch = true,
106
- defaultMode = "global"
107
- } = {}) {
134
+ constructor({ allowModeSwitch = true, defaultMode = "global" } = {}) {
108
135
  super();
109
- this.allowPseudoBlocks = allowPseudoBlocks;
110
136
  this.allowModeSwitch = allowModeSwitch;
111
137
  this.defaultMode = defaultMode;
112
138
  }
113
139
 
140
+ /**
141
+ * @param {ParserState} state parser state
142
+ * @param {string} message warning message
143
+ * @param {LocConverter} locConverter location converter
144
+ * @param {number} start start offset
145
+ * @param {number} end end offset
146
+ */
147
+ _emitWarning(state, message, locConverter, start, end) {
148
+ const { line: sl, column: sc } = locConverter.get(start);
149
+ const { line: el, column: ec } = locConverter.get(end);
150
+
151
+ state.current.addWarning(
152
+ new ModuleDependencyWarning(state.module, new WebpackError(message), {
153
+ start: { line: sl, column: sc },
154
+ end: { line: el, column: ec }
155
+ })
156
+ );
157
+ }
158
+
114
159
  /**
115
160
  * @param {string | Buffer | PreparsedAst} source the source to parse
116
161
  * @param {ParserState} state the parser state
@@ -128,31 +173,71 @@ class CssParser extends Parser {
128
173
 
129
174
  const module = state.module;
130
175
 
131
- const declaredCssVariables = new Set();
176
+ /** @type {string | undefined} */
177
+ let oldDefaultMode;
178
+
179
+ if (
180
+ module.type === CSS_MODULE_TYPE_AUTO &&
181
+ IS_MODULES.test(
182
+ parseResource(module.matchResource || module.resource).path
183
+ )
184
+ ) {
185
+ oldDefaultMode = this.defaultMode;
186
+
187
+ this.defaultMode = "local";
188
+ }
132
189
 
133
190
  const locConverter = new LocConverter(source);
134
- let mode = CSS_MODE_TOP_LEVEL;
135
- let modePos = 0;
136
- let modeNestingLevel = 0;
191
+ /** @type {Set<string>}*/
192
+ const declaredCssVariables = new Set();
193
+ /** @type {number} */
194
+ let scope = CSS_MODE_TOP_LEVEL;
195
+ /** @type {number} */
196
+ let blockNestingLevel = 0;
197
+ /** @type {boolean} */
198
+ let allowImportAtRule = true;
199
+ /** @type {"local" | "global" | undefined} */
137
200
  let modeData = undefined;
138
- let singleClassSelector = undefined;
201
+ /** @type {[number, number] | undefined} */
139
202
  let lastIdentifier = undefined;
140
- const modeStack = [];
141
- const isTopLevelLocal = () =>
142
- modeData === "local" ||
143
- (this.defaultMode === "local" && modeData === undefined);
144
- const eatWhiteLine = (input, pos) => {
145
- for (;;) {
146
- const cc = input.charCodeAt(pos);
147
- if (cc === 32 || cc === 9) {
148
- pos++;
149
- continue;
150
- }
151
- if (cc === 10) pos++;
152
- break;
203
+ /** @type [string, number, number][] */
204
+ let balanced = [];
205
+ /** @type {undefined | { start: number, url?: string, urlStart?: number, urlEnd?: number, layer?: string, layerStart?: number, layerEnd?: number, supports?: string, supportsStart?: number, supportsEnd?: number, inSupports?:boolean, media?: string }} */
206
+ let importData = undefined;
207
+ /** @type {boolean} */
208
+ let inAnimationProperty = false;
209
+ /** @type {boolean} */
210
+ let isNextRulePrelude = true;
211
+
212
+ /**
213
+ * @param {string} input input
214
+ * @param {number} pos position
215
+ * @returns {boolean} true, when next is nested syntax
216
+ */
217
+ const isNextNestedSyntax = (input, pos) => {
218
+ pos = walkCssTokens.eatWhitespaceAndComments(input, pos);
219
+
220
+ if (input[pos] === "}") {
221
+ return false;
153
222
  }
154
- return pos;
223
+
224
+ // According spec only identifier can be used as a property name
225
+ const isIdentifier = walkCssTokens.isIdentStartCodePoint(
226
+ input.charCodeAt(pos)
227
+ );
228
+
229
+ return !isIdentifier;
155
230
  };
231
+ /**
232
+ * @returns {boolean} true, when in local scope
233
+ */
234
+ const isLocalMode = () =>
235
+ modeData === "local" ||
236
+ (this.defaultMode === "local" && modeData === undefined);
237
+ /**
238
+ * @param {string} chars characters
239
+ * @returns {(input: string, pos: number) => number} function to eat characters
240
+ */
156
241
  const eatUntil = chars => {
157
242
  const charCodes = Array.from({ length: chars.length }, (_, i) =>
158
243
  chars.charCodeAt(i)
@@ -173,6 +258,12 @@ class CssParser extends Parser {
173
258
  }
174
259
  };
175
260
  };
261
+ /**
262
+ * @param {string} input input
263
+ * @param {number} pos start position
264
+ * @param {(input: string, pos: number) => number} eater eater
265
+ * @returns {[number,string]} new position and text
266
+ */
176
267
  const eatText = (input, pos, eater) => {
177
268
  let text = "";
178
269
  for (;;) {
@@ -200,13 +291,24 @@ class CssParser extends Parser {
200
291
  };
201
292
  const eatExportName = eatUntil(":};/");
202
293
  const eatExportValue = eatUntil("};/");
294
+ /**
295
+ * @param {string} input input
296
+ * @param {number} pos start position
297
+ * @returns {number} position after parse
298
+ */
203
299
  const parseExports = (input, pos) => {
204
300
  pos = walkCssTokens.eatWhitespaceAndComments(input, pos);
205
301
  const cc = input.charCodeAt(pos);
206
- if (cc !== CC_LEFT_CURLY)
207
- throw new Error(
208
- `Unexpected ${input[pos]} at ${pos} during parsing of ':export' (expected '{')`
302
+ if (cc !== CC_LEFT_CURLY) {
303
+ this._emitWarning(
304
+ state,
305
+ `Unexpected '${input[pos]}' at ${pos} during parsing of ':export' (expected '{')`,
306
+ locConverter,
307
+ pos,
308
+ pos
209
309
  );
310
+ return pos;
311
+ }
210
312
  pos++;
211
313
  pos = walkCssTokens.eatWhitespaceAndComments(input, pos);
212
314
  for (;;) {
@@ -218,9 +320,14 @@ class CssParser extends Parser {
218
320
  [pos, name] = eatText(input, pos, eatExportName);
219
321
  if (pos === input.length) return pos;
220
322
  if (input.charCodeAt(pos) !== CC_COLON) {
221
- throw new Error(
222
- `Unexpected ${input[pos]} at ${pos} during parsing of export name in ':export' (expected ':')`
323
+ this._emitWarning(
324
+ state,
325
+ `Unexpected '${input[pos]}' at ${pos} during parsing of export name in ':export' (expected ':')`,
326
+ locConverter,
327
+ start,
328
+ pos
223
329
  );
330
+ return pos;
224
331
  }
225
332
  pos++;
226
333
  if (pos === input.length) return pos;
@@ -236,9 +343,14 @@ class CssParser extends Parser {
236
343
  pos = walkCssTokens.eatWhitespaceAndComments(input, pos);
237
344
  if (pos === input.length) return pos;
238
345
  } else if (cc !== CC_RIGHT_CURLY) {
239
- throw new Error(
240
- `Unexpected ${input[pos]} at ${pos} during parsing of export value in ':export' (expected ';' or '}')`
346
+ this._emitWarning(
347
+ state,
348
+ `Unexpected '${input[pos]}' at ${pos} during parsing of export value in ':export' (expected ';' or '}')`,
349
+ locConverter,
350
+ start,
351
+ pos
241
352
  );
353
+ return pos;
242
354
  }
243
355
  const dep = new CssExportDependency(name, value);
244
356
  const { line: sl, column: sc } = locConverter.get(start);
@@ -248,13 +360,18 @@ class CssParser extends Parser {
248
360
  }
249
361
  pos++;
250
362
  if (pos === input.length) return pos;
251
- pos = eatWhiteLine(input, pos);
363
+ pos = walkCssTokens.eatWhiteLine(input, pos);
252
364
  return pos;
253
365
  };
254
366
  const eatPropertyName = eatUntil(":{};");
255
- const processLocalDeclaration = (input, pos) => {
367
+ /**
368
+ * @param {string} input input
369
+ * @param {number} pos name start position
370
+ * @param {number} end name end position
371
+ * @returns {number} position after handling
372
+ */
373
+ const processLocalDeclaration = (input, pos, end) => {
256
374
  modeData = undefined;
257
- const start = pos;
258
375
  pos = walkCssTokens.eatWhitespaceAndComments(input, pos);
259
376
  const propertyNameStart = pos;
260
377
  const [propertyNameEnd, propertyName] = eatText(
@@ -262,7 +379,7 @@ class CssParser extends Parser {
262
379
  pos,
263
380
  eatPropertyName
264
381
  );
265
- if (input.charCodeAt(propertyNameEnd) !== CC_COLON) return start;
382
+ if (input.charCodeAt(propertyNameEnd) !== CC_COLON) return end;
266
383
  pos = propertyNameEnd + 1;
267
384
  if (propertyName.startsWith("--")) {
268
385
  // CSS Variable
@@ -278,47 +395,74 @@ class CssParser extends Parser {
278
395
  module.addDependency(dep);
279
396
  declaredCssVariables.add(name);
280
397
  } else if (
281
- propertyName === "animation-name" ||
282
- propertyName === "animation"
398
+ !propertyName.startsWith("--") &&
399
+ OPTIONALLY_VENDOR_PREFIXED_ANIMATION_PROPERTY.test(propertyName)
283
400
  ) {
284
- modeData = "animation";
285
- lastIdentifier = undefined;
401
+ inAnimationProperty = true;
286
402
  }
287
403
  return pos;
288
404
  };
289
- const processDeclarationValueDone = (input, pos) => {
290
- if (modeData === "animation" && lastIdentifier) {
405
+ /**
406
+ * @param {string} input input
407
+ */
408
+ const processDeclarationValueDone = input => {
409
+ if (inAnimationProperty && lastIdentifier) {
291
410
  const { line: sl, column: sc } = locConverter.get(lastIdentifier[0]);
292
411
  const { line: el, column: ec } = locConverter.get(lastIdentifier[1]);
293
412
  const name = input.slice(lastIdentifier[0], lastIdentifier[1]);
294
413
  const dep = new CssSelfLocalIdentifierDependency(name, lastIdentifier);
295
414
  dep.setLoc(sl, sc, el, ec);
296
415
  module.addDependency(dep);
416
+ lastIdentifier = undefined;
297
417
  }
298
418
  };
299
419
  const eatKeyframes = eatUntil("{};/");
300
420
  const eatNameInVar = eatUntil(",)};/");
301
421
  walkCssTokens(source, {
302
422
  isSelector: () => {
303
- return mode !== CSS_MODE_IN_RULE && mode !== CSS_MODE_IN_LOCAL_RULE;
423
+ return isNextRulePrelude;
304
424
  },
305
425
  url: (input, start, end, contentStart, contentEnd) => {
306
- const value = cssUnescape(input.slice(contentStart, contentEnd));
307
- switch (mode) {
308
- case CSS_MODE_AT_IMPORT_EXPECT_URL: {
309
- modeData.url = value;
310
- mode = CSS_MODE_AT_IMPORT_EXPECT_SUPPORTS;
311
- break;
312
- }
313
- case CSS_MODE_AT_IMPORT_EXPECT_SUPPORTS:
314
- case CSS_MODE_AT_IMPORT_EXPECT_MEDIA:
315
- throw new Error(
316
- `Unexpected ${input.slice(
426
+ let value = normalizeUrl(input.slice(contentStart, contentEnd), false);
427
+
428
+ switch (scope) {
429
+ case CSS_MODE_IN_AT_IMPORT: {
430
+ // Do not parse URLs in `supports(...)`
431
+ if (importData.inSupports) {
432
+ break;
433
+ }
434
+
435
+ if (importData.url) {
436
+ this._emitWarning(
437
+ state,
438
+ `Duplicate of 'url(...)' in '${input.slice(
439
+ importData.start,
440
+ end
441
+ )}'`,
442
+ locConverter,
317
443
  start,
318
444
  end
319
- )} at ${start} during ${explainMode(mode)}`
320
- );
321
- default: {
445
+ );
446
+
447
+ break;
448
+ }
449
+
450
+ importData.url = value;
451
+ importData.urlStart = start;
452
+ importData.urlEnd = end;
453
+ break;
454
+ }
455
+ // Do not parse URLs in import between rules
456
+ case CSS_MODE_AT_NAMESPACE_INVALID:
457
+ case CSS_MODE_AT_IMPORT_INVALID: {
458
+ break;
459
+ }
460
+ case CSS_MODE_IN_BLOCK: {
461
+ // Ignore `url()`, `url('')` and `url("")`, they are valid by spec
462
+ if (value.length === 0) {
463
+ break;
464
+ }
465
+
322
466
  const dep = new CssUrlDependency(value, [start, end], "url");
323
467
  const { line: sl, column: sc } = locConverter.get(start);
324
468
  const { line: el, column: ec } = locConverter.get(end);
@@ -331,283 +475,554 @@ class CssParser extends Parser {
331
475
  return end;
332
476
  },
333
477
  string: (input, start, end) => {
334
- switch (mode) {
335
- case CSS_MODE_AT_IMPORT_EXPECT_URL: {
336
- modeData.url = cssUnescape(input.slice(start + 1, end - 1));
337
- mode = CSS_MODE_AT_IMPORT_EXPECT_SUPPORTS;
478
+ switch (scope) {
479
+ case CSS_MODE_IN_AT_IMPORT: {
480
+ const insideURLFunction =
481
+ balanced[balanced.length - 1] &&
482
+ balanced[balanced.length - 1][0] === "url";
483
+
484
+ // Do not parse URLs in `supports(...)` and other strings if we already have a URL
485
+ if (
486
+ importData.inSupports ||
487
+ (!insideURLFunction && importData.url)
488
+ ) {
489
+ break;
490
+ }
491
+
492
+ if (insideURLFunction && importData.url) {
493
+ this._emitWarning(
494
+ state,
495
+ `Duplicate of 'url(...)' in '${input.slice(
496
+ importData.start,
497
+ end
498
+ )}'`,
499
+ locConverter,
500
+ start,
501
+ end
502
+ );
503
+
504
+ break;
505
+ }
506
+
507
+ importData.url = normalizeUrl(
508
+ input.slice(start + 1, end - 1),
509
+ true
510
+ );
511
+
512
+ if (!insideURLFunction) {
513
+ importData.urlStart = start;
514
+ importData.urlEnd = end;
515
+ }
516
+
338
517
  break;
339
518
  }
519
+ case CSS_MODE_IN_BLOCK: {
520
+ // TODO move escaped parsing to tokenizer
521
+ const last = balanced[balanced.length - 1];
522
+
523
+ if (
524
+ last &&
525
+ (last[0].replace(/\\/g, "").toLowerCase() === "url" ||
526
+ IMAGE_SET_FUNCTION.test(last[0].replace(/\\/g, "")))
527
+ ) {
528
+ let value = normalizeUrl(input.slice(start + 1, end - 1), true);
529
+
530
+ // Ignore `url()`, `url('')` and `url("")`, they are valid by spec
531
+ if (value.length === 0) {
532
+ break;
533
+ }
534
+
535
+ const isUrl = last[0].replace(/\\/g, "").toLowerCase() === "url";
536
+ const dep = new CssUrlDependency(
537
+ value,
538
+ [start, end],
539
+ isUrl ? "string" : "url"
540
+ );
541
+ const { line: sl, column: sc } = locConverter.get(start);
542
+ const { line: el, column: ec } = locConverter.get(end);
543
+ dep.setLoc(sl, sc, el, ec);
544
+ module.addDependency(dep);
545
+ module.addCodeGenerationDependency(dep);
546
+ }
547
+ }
340
548
  }
341
549
  return end;
342
550
  },
343
551
  atKeyword: (input, start, end) => {
344
- const name = input.slice(start, end);
552
+ const name = input.slice(start, end).toLowerCase();
345
553
  if (name === "@namespace") {
346
- throw new Error("@namespace is not supported in bundled CSS");
347
- }
348
- if (name === "@import") {
349
- if (mode !== CSS_MODE_TOP_LEVEL) {
350
- throw new Error(
351
- `Unexpected @import at ${start} during ${explainMode(mode)}`
554
+ scope = CSS_MODE_AT_NAMESPACE_INVALID;
555
+ this._emitWarning(
556
+ state,
557
+ "'@namespace' is not supported in bundled CSS",
558
+ locConverter,
559
+ start,
560
+ end
561
+ );
562
+ return end;
563
+ } else if (name === "@import") {
564
+ if (!allowImportAtRule) {
565
+ scope = CSS_MODE_AT_IMPORT_INVALID;
566
+ this._emitWarning(
567
+ state,
568
+ "Any '@import' rules must precede all other rules",
569
+ locConverter,
570
+ start,
571
+ end
352
572
  );
573
+ return end;
353
574
  }
354
- mode = CSS_MODE_AT_IMPORT_EXPECT_URL;
355
- modePos = end;
356
- modeData = {
357
- start: start,
358
- url: undefined,
359
- supports: undefined
360
- };
361
- }
362
- if (name === "@keyframes") {
575
+
576
+ scope = CSS_MODE_IN_AT_IMPORT;
577
+ importData = { start };
578
+ } else if (
579
+ this.allowModeSwitch &&
580
+ OPTIONALLY_VENDOR_PREFIXED_KEYFRAMES_AT_RULE.test(name)
581
+ ) {
363
582
  let pos = end;
364
583
  pos = walkCssTokens.eatWhitespaceAndComments(input, pos);
365
584
  if (pos === input.length) return pos;
366
585
  const [newPos, name] = eatText(input, pos, eatKeyframes);
586
+ if (newPos === input.length) return newPos;
587
+ if (input.charCodeAt(newPos) !== CC_LEFT_CURLY) {
588
+ this._emitWarning(
589
+ state,
590
+ `Unexpected '${input[newPos]}' at ${newPos} during parsing of @keyframes (expected '{')`,
591
+ locConverter,
592
+ start,
593
+ end
594
+ );
595
+
596
+ return newPos;
597
+ }
367
598
  const { line: sl, column: sc } = locConverter.get(pos);
368
599
  const { line: el, column: ec } = locConverter.get(newPos);
369
600
  const dep = new CssLocalIdentifierDependency(name, [pos, newPos]);
370
601
  dep.setLoc(sl, sc, el, ec);
371
602
  module.addDependency(dep);
372
603
  pos = newPos;
604
+ return pos + 1;
605
+ } else if (this.allowModeSwitch && name === "@property") {
606
+ let pos = end;
607
+ pos = walkCssTokens.eatWhitespaceAndComments(input, pos);
373
608
  if (pos === input.length) return pos;
374
- if (input.charCodeAt(pos) !== CC_LEFT_CURLY) {
375
- throw new Error(
376
- `Unexpected ${input[pos]} at ${pos} during parsing of @keyframes (expected '{')`
609
+ const propertyNameStart = pos;
610
+ const [propertyNameEnd, propertyName] = eatText(
611
+ input,
612
+ pos,
613
+ eatKeyframes
614
+ );
615
+ if (propertyNameEnd === input.length) return propertyNameEnd;
616
+ if (!propertyName.startsWith("--")) return propertyNameEnd;
617
+ if (input.charCodeAt(propertyNameEnd) !== CC_LEFT_CURLY) {
618
+ this._emitWarning(
619
+ state,
620
+ `Unexpected '${input[propertyNameEnd]}' at ${propertyNameEnd} during parsing of @property (expected '{')`,
621
+ locConverter,
622
+ start,
623
+ end
377
624
  );
625
+
626
+ return propertyNameEnd;
378
627
  }
379
- mode = CSS_MODE_IN_LOCAL_RULE;
380
- modeNestingLevel = 1;
628
+ const { line: sl, column: sc } = locConverter.get(pos);
629
+ const { line: el, column: ec } = locConverter.get(propertyNameEnd);
630
+ const name = propertyName.slice(2);
631
+ const dep = new CssLocalIdentifierDependency(
632
+ name,
633
+ [propertyNameStart, propertyNameEnd],
634
+ "--"
635
+ );
636
+ dep.setLoc(sl, sc, el, ec);
637
+ module.addDependency(dep);
638
+ declaredCssVariables.add(name);
639
+ pos = propertyNameEnd;
381
640
  return pos + 1;
641
+ } else if (
642
+ name === "@media" ||
643
+ name === "@supports" ||
644
+ name === "@layer" ||
645
+ name === "@container"
646
+ ) {
647
+ modeData = isLocalMode() ? "local" : "global";
648
+ isNextRulePrelude = true;
649
+ return end;
650
+ } else if (this.allowModeSwitch) {
651
+ modeData = "global";
652
+ isNextRulePrelude = false;
382
653
  }
383
654
  return end;
384
655
  },
385
656
  semicolon: (input, start, end) => {
386
- switch (mode) {
387
- case CSS_MODE_AT_IMPORT_EXPECT_URL:
388
- throw new Error(`Expected URL for @import at ${start}`);
389
- case CSS_MODE_AT_IMPORT_EXPECT_MEDIA:
390
- case CSS_MODE_AT_IMPORT_EXPECT_SUPPORTS: {
391
- const { line: sl, column: sc } = locConverter.get(modeData.start);
657
+ switch (scope) {
658
+ case CSS_MODE_IN_AT_IMPORT: {
659
+ const { start } = importData;
660
+
661
+ if (importData.url === undefined) {
662
+ this._emitWarning(
663
+ state,
664
+ `Expected URL in '${input.slice(start, end)}'`,
665
+ locConverter,
666
+ start,
667
+ end
668
+ );
669
+ importData = undefined;
670
+ scope = CSS_MODE_TOP_LEVEL;
671
+ return end;
672
+ }
673
+ if (
674
+ importData.urlStart > importData.layerStart ||
675
+ importData.urlStart > importData.supportsStart
676
+ ) {
677
+ this._emitWarning(
678
+ state,
679
+ `An URL in '${input.slice(
680
+ start,
681
+ end
682
+ )}' should be before 'layer(...)' or 'supports(...)'`,
683
+ locConverter,
684
+ start,
685
+ end
686
+ );
687
+ importData = undefined;
688
+ scope = CSS_MODE_TOP_LEVEL;
689
+ return end;
690
+ }
691
+ if (importData.layerStart > importData.supportsStart) {
692
+ this._emitWarning(
693
+ state,
694
+ `The 'layer(...)' in '${input.slice(
695
+ start,
696
+ end
697
+ )}' should be before 'supports(...)'`,
698
+ locConverter,
699
+ start,
700
+ end
701
+ );
702
+ importData = undefined;
703
+ scope = CSS_MODE_TOP_LEVEL;
704
+ return end;
705
+ }
706
+
707
+ const semicolonPos = end;
708
+ end = walkCssTokens.eatWhiteLine(input, end + 1);
709
+ const { line: sl, column: sc } = locConverter.get(start);
392
710
  const { line: el, column: ec } = locConverter.get(end);
393
- end = eatWhiteLine(input, end);
394
- const media = input.slice(modePos, start).trim();
395
- const dep = new CssImportDependency(
396
- modeData.url,
397
- [modeData.start, end],
398
- modeData.supports,
399
- media
400
- );
401
- dep.setLoc(sl, sc, el, ec);
402
- module.addDependency(dep);
711
+ const lastEnd =
712
+ importData.supportsEnd ||
713
+ importData.layerEnd ||
714
+ importData.urlEnd ||
715
+ start;
716
+ const pos = walkCssTokens.eatWhitespaceAndComments(input, lastEnd);
717
+ // Prevent to consider comments as a part of media query
718
+ if (pos !== semicolonPos - 1) {
719
+ importData.media = input.slice(lastEnd, semicolonPos - 1).trim();
720
+ }
721
+
722
+ const url = importData.url.trim();
723
+
724
+ if (url.length === 0) {
725
+ const dep = new ConstDependency("", [start, end]);
726
+ module.addPresentationalDependency(dep);
727
+ dep.setLoc(sl, sc, el, ec);
728
+ } else {
729
+ const dep = new CssImportDependency(
730
+ url,
731
+ [start, end],
732
+ importData.layer,
733
+ importData.supports,
734
+ importData.media && importData.media.length > 0
735
+ ? importData.media
736
+ : undefined
737
+ );
738
+ dep.setLoc(sl, sc, el, ec);
739
+ module.addDependency(dep);
740
+ }
741
+
742
+ importData = undefined;
743
+ scope = CSS_MODE_TOP_LEVEL;
744
+
403
745
  break;
404
746
  }
405
- case CSS_MODE_IN_LOCAL_RULE: {
406
- processDeclarationValueDone(input, start);
407
- return processLocalDeclaration(input, end);
747
+ case CSS_MODE_AT_IMPORT_INVALID:
748
+ case CSS_MODE_AT_NAMESPACE_INVALID: {
749
+ scope = CSS_MODE_TOP_LEVEL;
750
+
751
+ break;
408
752
  }
409
- case CSS_MODE_IN_RULE: {
410
- return end;
753
+ case CSS_MODE_IN_BLOCK: {
754
+ if (this.allowModeSwitch) {
755
+ processDeclarationValueDone(input);
756
+ inAnimationProperty = false;
757
+ isNextRulePrelude = isNextNestedSyntax(input, end);
758
+ }
759
+ break;
411
760
  }
412
761
  }
413
- mode = CSS_MODE_TOP_LEVEL;
414
- modeData = undefined;
415
- singleClassSelector = undefined;
416
762
  return end;
417
763
  },
418
764
  leftCurlyBracket: (input, start, end) => {
419
- switch (mode) {
420
- case CSS_MODE_TOP_LEVEL:
421
- mode = isTopLevelLocal()
422
- ? CSS_MODE_IN_LOCAL_RULE
423
- : CSS_MODE_IN_RULE;
424
- modeNestingLevel = 1;
425
- if (mode === CSS_MODE_IN_LOCAL_RULE)
426
- return processLocalDeclaration(input, end);
765
+ switch (scope) {
766
+ case CSS_MODE_TOP_LEVEL: {
767
+ allowImportAtRule = false;
768
+ scope = CSS_MODE_IN_BLOCK;
769
+ blockNestingLevel = 1;
770
+
771
+ if (this.allowModeSwitch) {
772
+ isNextRulePrelude = isNextNestedSyntax(input, end);
773
+ }
774
+
427
775
  break;
428
- case CSS_MODE_IN_RULE:
429
- case CSS_MODE_IN_LOCAL_RULE:
430
- modeNestingLevel++;
776
+ }
777
+ case CSS_MODE_IN_BLOCK: {
778
+ blockNestingLevel++;
779
+
780
+ if (this.allowModeSwitch) {
781
+ isNextRulePrelude = isNextNestedSyntax(input, end);
782
+ }
431
783
  break;
784
+ }
432
785
  }
433
786
  return end;
434
787
  },
435
788
  rightCurlyBracket: (input, start, end) => {
436
- switch (mode) {
437
- case CSS_MODE_IN_LOCAL_RULE:
438
- processDeclarationValueDone(input, start);
439
- /* falls through */
440
- case CSS_MODE_IN_RULE:
441
- if (--modeNestingLevel === 0) {
442
- mode = CSS_MODE_TOP_LEVEL;
443
- modeData = undefined;
444
- singleClassSelector = undefined;
789
+ switch (scope) {
790
+ case CSS_MODE_IN_BLOCK: {
791
+ if (isLocalMode()) {
792
+ processDeclarationValueDone(input);
793
+ inAnimationProperty = false;
445
794
  }
446
- break;
447
- }
448
- return end;
449
- },
450
- id: (input, start, end) => {
451
- singleClassSelector = false;
452
- switch (mode) {
453
- case CSS_MODE_TOP_LEVEL:
454
- if (isTopLevelLocal()) {
455
- const name = input.slice(start + 1, end);
456
- const dep = new CssLocalIdentifierDependency(name, [
457
- start + 1,
458
- end
459
- ]);
460
- const { line: sl, column: sc } = locConverter.get(start);
461
- const { line: el, column: ec } = locConverter.get(end);
462
- dep.setLoc(sl, sc, el, ec);
463
- module.addDependency(dep);
795
+ if (--blockNestingLevel === 0) {
796
+ scope = CSS_MODE_TOP_LEVEL;
797
+
798
+ if (this.allowModeSwitch) {
799
+ isNextRulePrelude = true;
800
+ modeData = undefined;
801
+ }
802
+ } else if (this.allowModeSwitch) {
803
+ isNextRulePrelude = isNextNestedSyntax(input, end);
464
804
  }
465
805
  break;
806
+ }
466
807
  }
467
808
  return end;
468
809
  },
469
810
  identifier: (input, start, end) => {
470
- singleClassSelector = false;
471
- switch (mode) {
472
- case CSS_MODE_IN_LOCAL_RULE:
473
- if (modeData === "animation") {
474
- lastIdentifier = [start, end];
811
+ switch (scope) {
812
+ case CSS_MODE_IN_BLOCK: {
813
+ if (isLocalMode()) {
814
+ // Handle only top level values and not inside functions
815
+ if (inAnimationProperty && balanced.length === 0) {
816
+ lastIdentifier = [start, end];
817
+ } else {
818
+ return processLocalDeclaration(input, start, end);
819
+ }
820
+ }
821
+ break;
822
+ }
823
+ case CSS_MODE_IN_AT_IMPORT: {
824
+ if (input.slice(start, end).toLowerCase() === "layer") {
825
+ importData.layer = "";
826
+ importData.layerStart = start;
827
+ importData.layerEnd = end;
475
828
  }
476
829
  break;
830
+ }
477
831
  }
478
832
  return end;
479
833
  },
480
834
  class: (input, start, end) => {
481
- switch (mode) {
482
- case CSS_MODE_TOP_LEVEL: {
483
- if (isTopLevelLocal()) {
484
- const name = input.slice(start + 1, end);
485
- const dep = new CssLocalIdentifierDependency(name, [
486
- start + 1,
487
- end
488
- ]);
489
- const { line: sl, column: sc } = locConverter.get(start);
490
- const { line: el, column: ec } = locConverter.get(end);
491
- dep.setLoc(sl, sc, el, ec);
492
- module.addDependency(dep);
493
- if (singleClassSelector === undefined) singleClassSelector = name;
494
- } else {
495
- singleClassSelector = false;
496
- }
497
- break;
498
- }
835
+ if (isLocalMode()) {
836
+ const name = input.slice(start + 1, end);
837
+ const dep = new CssLocalIdentifierDependency(name, [start + 1, end]);
838
+ const { line: sl, column: sc } = locConverter.get(start);
839
+ const { line: el, column: ec } = locConverter.get(end);
840
+ dep.setLoc(sl, sc, el, ec);
841
+ module.addDependency(dep);
499
842
  }
843
+
500
844
  return end;
501
845
  },
502
- leftParenthesis: (input, start, end) => {
503
- switch (mode) {
504
- case CSS_MODE_TOP_LEVEL: {
505
- modeStack.push(false);
506
- break;
846
+ id: (input, start, end) => {
847
+ if (isLocalMode()) {
848
+ const name = input.slice(start + 1, end);
849
+ const dep = new CssLocalIdentifierDependency(name, [start + 1, end]);
850
+ const { line: sl, column: sc } = locConverter.get(start);
851
+ const { line: el, column: ec } = locConverter.get(end);
852
+ dep.setLoc(sl, sc, el, ec);
853
+ module.addDependency(dep);
854
+ }
855
+ return end;
856
+ },
857
+ function: (input, start, end) => {
858
+ let name = input.slice(start, end - 1);
859
+
860
+ balanced.push([name, start, end]);
861
+
862
+ if (
863
+ scope === CSS_MODE_IN_AT_IMPORT &&
864
+ name.toLowerCase() === "supports"
865
+ ) {
866
+ importData.inSupports = true;
867
+ }
868
+
869
+ if (isLocalMode()) {
870
+ name = name.toLowerCase();
871
+
872
+ // Don't rename animation name when we have `var()` function
873
+ if (inAnimationProperty && balanced.length === 1) {
874
+ lastIdentifier = undefined;
875
+ }
876
+
877
+ if (name === "var") {
878
+ let pos = walkCssTokens.eatWhitespaceAndComments(input, end);
879
+ if (pos === input.length) return pos;
880
+ const [newPos, name] = eatText(input, pos, eatNameInVar);
881
+ if (!name.startsWith("--")) return end;
882
+ const { line: sl, column: sc } = locConverter.get(pos);
883
+ const { line: el, column: ec } = locConverter.get(newPos);
884
+ const dep = new CssSelfLocalIdentifierDependency(
885
+ name.slice(2),
886
+ [pos, newPos],
887
+ "--",
888
+ declaredCssVariables
889
+ );
890
+ dep.setLoc(sl, sc, el, ec);
891
+ module.addDependency(dep);
892
+ return newPos;
507
893
  }
508
894
  }
895
+
896
+ return end;
897
+ },
898
+ leftParenthesis: (input, start, end) => {
899
+ balanced.push(["(", start, end]);
900
+
509
901
  return end;
510
902
  },
511
903
  rightParenthesis: (input, start, end) => {
512
- switch (mode) {
513
- case CSS_MODE_TOP_LEVEL: {
514
- const newModeData = modeStack.pop();
515
- if (newModeData !== false) {
516
- modeData = newModeData;
517
- const dep = new ConstDependency("", [start, end]);
518
- module.addPresentationalDependency(dep);
904
+ const last = balanced[balanced.length - 1];
905
+ const popped = balanced.pop();
906
+
907
+ if (
908
+ this.allowModeSwitch &&
909
+ popped &&
910
+ (popped[0] === ":local" || popped[0] === ":global")
911
+ ) {
912
+ modeData = balanced[balanced.length - 1]
913
+ ? /** @type {"local" | "global"} */
914
+ (balanced[balanced.length - 1][0])
915
+ : undefined;
916
+ const dep = new ConstDependency("", [start, end]);
917
+ module.addPresentationalDependency(dep);
918
+
919
+ return end;
920
+ }
921
+
922
+ switch (scope) {
923
+ case CSS_MODE_IN_AT_IMPORT: {
924
+ if (last && last[0] === "url" && !importData.inSupports) {
925
+ importData.urlStart = last[1];
926
+ importData.urlEnd = end;
927
+ } else if (
928
+ last &&
929
+ last[0].toLowerCase() === "layer" &&
930
+ !importData.inSupports
931
+ ) {
932
+ importData.layer = input.slice(last[2], end - 1).trim();
933
+ importData.layerStart = last[1];
934
+ importData.layerEnd = end;
935
+ } else if (last && last[0].toLowerCase() === "supports") {
936
+ importData.supports = input.slice(last[2], end - 1).trim();
937
+ importData.supportsStart = last[1];
938
+ importData.supportsEnd = end;
939
+ importData.inSupports = false;
519
940
  }
520
941
  break;
521
942
  }
522
943
  }
944
+
523
945
  return end;
524
946
  },
525
947
  pseudoClass: (input, start, end) => {
526
- singleClassSelector = false;
527
- switch (mode) {
528
- case CSS_MODE_TOP_LEVEL: {
529
- const name = input.slice(start, end);
530
- if (this.allowModeSwitch && name === ":global") {
531
- modeData = "global";
532
- const dep = new ConstDependency("", [start, end]);
533
- module.addPresentationalDependency(dep);
534
- } else if (this.allowModeSwitch && name === ":local") {
535
- modeData = "local";
536
- const dep = new ConstDependency("", [start, end]);
537
- module.addPresentationalDependency(dep);
538
- } else if (this.allowPseudoBlocks && name === ":export") {
539
- const pos = parseExports(input, end);
540
- const dep = new ConstDependency("", [start, pos]);
541
- module.addPresentationalDependency(dep);
542
- return pos;
948
+ if (this.allowModeSwitch) {
949
+ const name = input.slice(start, end).toLowerCase();
950
+
951
+ if (name === ":global") {
952
+ modeData = "global";
953
+ // Eat extra whitespace and comments
954
+ end = walkCssTokens.eatWhitespace(input, end);
955
+ const dep = new ConstDependency("", [start, end]);
956
+ module.addPresentationalDependency(dep);
957
+ return end;
958
+ } else if (name === ":local") {
959
+ modeData = "local";
960
+ // Eat extra whitespace and comments
961
+ end = walkCssTokens.eatWhitespace(input, end);
962
+ const dep = new ConstDependency("", [start, end]);
963
+ module.addPresentationalDependency(dep);
964
+ return end;
965
+ }
966
+
967
+ switch (scope) {
968
+ case CSS_MODE_TOP_LEVEL: {
969
+ if (name === ":export") {
970
+ const pos = parseExports(input, end);
971
+ const dep = new ConstDependency("", [start, pos]);
972
+ module.addPresentationalDependency(dep);
973
+ return pos;
974
+ }
975
+ break;
543
976
  }
544
- break;
545
977
  }
546
978
  }
979
+
547
980
  return end;
548
981
  },
549
982
  pseudoFunction: (input, start, end) => {
550
- switch (mode) {
551
- case CSS_MODE_TOP_LEVEL: {
552
- const name = input.slice(start, end - 1);
553
- if (this.allowModeSwitch && name === ":global") {
554
- modeStack.push(modeData);
555
- modeData = "global";
556
- const dep = new ConstDependency("", [start, end]);
557
- module.addPresentationalDependency(dep);
558
- } else if (this.allowModeSwitch && name === ":local") {
559
- modeStack.push(modeData);
560
- modeData = "local";
561
- const dep = new ConstDependency("", [start, end]);
562
- module.addPresentationalDependency(dep);
563
- } else {
564
- modeStack.push(false);
565
- }
566
- break;
983
+ let name = input.slice(start, end - 1);
984
+
985
+ balanced.push([name, start, end]);
986
+
987
+ if (this.allowModeSwitch) {
988
+ name = name.toLowerCase();
989
+
990
+ if (name === ":global") {
991
+ modeData = "global";
992
+ const dep = new ConstDependency("", [start, end]);
993
+ module.addPresentationalDependency(dep);
994
+ } else if (name === ":local") {
995
+ modeData = "local";
996
+ const dep = new ConstDependency("", [start, end]);
997
+ module.addPresentationalDependency(dep);
567
998
  }
568
999
  }
1000
+
569
1001
  return end;
570
1002
  },
571
- function: (input, start, end) => {
572
- switch (mode) {
573
- case CSS_MODE_IN_LOCAL_RULE: {
574
- const name = input.slice(start, end - 1);
575
- if (name === "var") {
576
- let pos = walkCssTokens.eatWhitespaceAndComments(input, end);
577
- if (pos === input.length) return pos;
578
- const [newPos, name] = eatText(input, pos, eatNameInVar);
579
- if (!name.startsWith("--")) return end;
580
- const { line: sl, column: sc } = locConverter.get(pos);
581
- const { line: el, column: ec } = locConverter.get(newPos);
582
- const dep = new CssSelfLocalIdentifierDependency(
583
- name.slice(2),
584
- [pos, newPos],
585
- "--",
586
- declaredCssVariables
587
- );
588
- dep.setLoc(sl, sc, el, ec);
589
- module.addDependency(dep);
590
- return newPos;
1003
+ comma: (input, start, end) => {
1004
+ if (this.allowModeSwitch) {
1005
+ // Reset stack for `:global .class :local .class-other` selector after
1006
+ modeData = undefined;
1007
+
1008
+ switch (scope) {
1009
+ case CSS_MODE_IN_BLOCK: {
1010
+ if (isLocalMode()) {
1011
+ processDeclarationValueDone(input);
1012
+ }
1013
+
1014
+ break;
591
1015
  }
592
- break;
593
1016
  }
594
1017
  }
595
1018
  return end;
596
- },
597
- comma: (input, start, end) => {
598
- switch (mode) {
599
- case CSS_MODE_TOP_LEVEL:
600
- modeData = undefined;
601
- modeStack.length = 0;
602
- break;
603
- case CSS_MODE_IN_LOCAL_RULE:
604
- processDeclarationValueDone(input, start);
605
- break;
606
- }
607
- return end;
608
1019
  }
609
1020
  });
610
1021
 
1022
+ if (oldDefaultMode) {
1023
+ this.defaultMode = oldDefaultMode;
1024
+ }
1025
+
611
1026
  module.buildInfo.strict = true;
612
1027
  module.buildMeta.exportsType = "namespace";
613
1028
  module.addDependency(new StaticExportsDependency([], true));