@depup/webpack 5.106.1-depup.0 → 5.109.2-depup.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 (669) hide show
  1. package/README.md +9 -11
  2. package/bin/webpack.js +12 -0
  3. package/changes.json +16 -24
  4. package/hot/dev-server.js +2 -0
  5. package/lib/APIPlugin.js +60 -35
  6. package/lib/AsyncDependenciesBlock.js +3 -0
  7. package/lib/AutomaticPrefetchPlugin.js +6 -1
  8. package/lib/BannerPlugin.js +13 -5
  9. package/lib/Cache.js +27 -5
  10. package/lib/CacheFacade.js +41 -0
  11. package/lib/Chunk.js +71 -25
  12. package/lib/ChunkGraph.js +153 -19
  13. package/lib/ChunkGroup.js +115 -28
  14. package/lib/ChunkTemplate.js +9 -0
  15. package/lib/CircularModulesPlugin.js +190 -0
  16. package/lib/CleanPlugin.js +27 -28
  17. package/lib/CodeGenerationResults.js +19 -0
  18. package/lib/CompatibilityPlugin.js +85 -37
  19. package/lib/Compilation.js +656 -112
  20. package/lib/Compiler.js +109 -35
  21. package/lib/ConcatenationScope.js +34 -4
  22. package/lib/ConditionalInitFragment.js +6 -0
  23. package/lib/ConstPlugin.js +15 -12
  24. package/lib/ContextExclusionPlugin.js +3 -1
  25. package/lib/ContextModule.js +345 -55
  26. package/lib/ContextModuleFactory.js +193 -51
  27. package/lib/ContextReplacementPlugin.js +8 -1
  28. package/lib/DefinePlugin.js +537 -139
  29. package/lib/DependenciesBlock.js +6 -1
  30. package/lib/Dependency.js +159 -11
  31. package/lib/DependencyTemplate.js +7 -1
  32. package/lib/DependencyTemplates.js +4 -0
  33. package/lib/DotenvPlugin.js +3 -0
  34. package/lib/DynamicEntryPlugin.js +3 -1
  35. package/lib/EntryOptionPlugin.js +42 -2
  36. package/lib/EntryPlugin.js +4 -1
  37. package/lib/Entrypoint.js +5 -1
  38. package/lib/EnvironmentPlugin.js +3 -2
  39. package/lib/ErrorHelpers.js +7 -0
  40. package/lib/EvalDevToolModulePlugin.js +3 -1
  41. package/lib/EvalSourceMapDevToolPlugin.js +11 -11
  42. package/lib/ExportsInfo.js +421 -113
  43. package/lib/ExportsInfoApiPlugin.js +4 -3
  44. package/lib/ExternalModule.js +381 -80
  45. package/lib/ExternalModuleFactoryPlugin.js +75 -3
  46. package/lib/ExternalsPlugin.js +3 -1
  47. package/lib/FileSystemInfo.js +701 -175
  48. package/lib/FlagAllModulesAsUsedPlugin.js +3 -6
  49. package/lib/FlagDependencyExportsPlugin.js +82 -9
  50. package/lib/FlagDependencyUsagePlugin.js +115 -8
  51. package/lib/FlagEntryExportAsUsedPlugin.js +4 -1
  52. package/lib/Generator.js +24 -3
  53. package/lib/HotModuleReplacementPlugin.js +110 -44
  54. package/lib/IgnorePlugin.js +5 -2
  55. package/lib/IgnoreWarningsPlugin.js +2 -1
  56. package/lib/InitFragment.js +33 -30
  57. package/lib/JavascriptMetaInfoPlugin.js +9 -6
  58. package/lib/LazyBarrel.js +389 -0
  59. package/lib/LibraryTemplatePlugin.js +2 -1
  60. package/lib/LoaderOptionsPlugin.js +3 -1
  61. package/lib/LoaderTargetPlugin.js +3 -1
  62. package/lib/MainTemplate.js +15 -0
  63. package/lib/ManifestPlugin.js +9 -2
  64. package/lib/Module.js +121 -57
  65. package/lib/ModuleFactory.js +6 -1
  66. package/lib/ModuleFilenameHelpers.js +18 -4
  67. package/lib/ModuleGraph.js +69 -2
  68. package/lib/ModuleGraphConnection.js +9 -0
  69. package/lib/ModuleInfoHeaderPlugin.js +5 -0
  70. package/lib/ModuleNotFoundError.js +3 -83
  71. package/lib/ModuleProfile.js +27 -1
  72. package/lib/ModuleSourceTypeConstants.js +52 -19
  73. package/lib/ModuleTemplate.js +10 -0
  74. package/lib/ModuleTypeConstants.js +20 -4
  75. package/lib/MultiCompiler.js +59 -4
  76. package/lib/MultiStats.js +9 -0
  77. package/lib/MultiWatching.js +6 -0
  78. package/lib/NoEmitOnErrorsPlugin.js +1 -1
  79. package/lib/NodeStuffPlugin.js +78 -46
  80. package/lib/NormalModule.js +519 -206
  81. package/lib/NormalModuleFactory.js +156 -31
  82. package/lib/NormalModuleReplacementPlugin.js +3 -1
  83. package/lib/NullFactory.js +1 -0
  84. package/lib/OptionsApply.js +1 -0
  85. package/lib/Parser.js +3 -1
  86. package/lib/PlatformPlugin.js +2 -1
  87. package/lib/PrefetchPlugin.js +4 -1
  88. package/lib/ProgressPlugin.js +351 -161
  89. package/lib/ProvidePlugin.js +6 -3
  90. package/lib/RawModule.js +32 -16
  91. package/lib/RecordIdsPlugin.js +9 -0
  92. package/lib/RequestShortener.js +8 -0
  93. package/lib/ResolverFactory.js +5 -0
  94. package/lib/RuntimeGlobals.js +58 -5
  95. package/lib/RuntimeModule.js +22 -7
  96. package/lib/RuntimePlugin.js +123 -118
  97. package/lib/RuntimeTemplate.js +616 -37
  98. package/lib/SelfModuleFactory.js +3 -0
  99. package/lib/SourceMapDevToolModuleOptionsPlugin.js +2 -0
  100. package/lib/SourceMapDevToolPlugin.js +341 -63
  101. package/lib/Stats.js +6 -0
  102. package/lib/Template.js +52 -6
  103. package/lib/TemplatedPathPlugin.js +505 -138
  104. package/lib/UseStrictPlugin.js +3 -2
  105. package/lib/WarnCaseSensitiveModulesPlugin.js +72 -3
  106. package/lib/WarnDeprecatedOptionPlugin.js +6 -2
  107. package/lib/WarnNoModeSetPlugin.js +18 -2
  108. package/lib/WatchIgnorePlugin.js +5 -1
  109. package/lib/Watching.js +25 -3
  110. package/lib/WebpackError.js +3 -74
  111. package/lib/WebpackIsIncludedPlugin.js +4 -2
  112. package/lib/WebpackOptionsApply.js +88 -25
  113. package/lib/WebpackOptionsDefaulter.js +1 -0
  114. package/lib/asset/AssetBytesGenerator.js +28 -10
  115. package/lib/asset/AssetBytesParser.js +1 -0
  116. package/lib/asset/AssetGenerator.js +199 -60
  117. package/lib/asset/AssetModule.js +47 -0
  118. package/lib/asset/AssetModulesPlugin.js +115 -24
  119. package/lib/asset/AssetParser.js +4 -2
  120. package/lib/asset/AssetSourceGenerator.js +26 -8
  121. package/lib/asset/AssetSourceParser.js +1 -0
  122. package/lib/asset/RawDataUrlModule.js +23 -13
  123. package/lib/asset/WebManifestGenerator.js +164 -0
  124. package/lib/asset/WebManifestParser.js +130 -0
  125. package/lib/async-modules/AsyncModuleHelpers.js +1 -0
  126. package/lib/async-modules/AwaitDependenciesInitFragment.js +18 -4
  127. package/lib/async-modules/InferAsyncModulesPlugin.js +1 -1
  128. package/lib/async-modules/isGeneratorLowered.js +26 -0
  129. package/lib/buildChunkGraph.js +107 -15
  130. package/lib/bun/BunTargetPlugin.js +42 -0
  131. package/lib/cache/AddBuildDependenciesPlugin.js +3 -1
  132. package/lib/cache/AddManagedPathsPlugin.js +5 -1
  133. package/lib/cache/IdleFileCachePlugin.js +6 -1
  134. package/lib/cache/MemoryCachePlugin.js +1 -1
  135. package/lib/cache/MemoryWithGcCachePlugin.js +4 -1
  136. package/lib/cache/PackFileCacheStrategy.js +302 -12
  137. package/lib/cache/ResolverCachePlugin.js +12 -1
  138. package/lib/cache/getLazyHashedEtag.js +13 -2
  139. package/lib/cache/mergeEtags.js +4 -0
  140. package/lib/cli.js +142 -20
  141. package/lib/config/browserslistTargetHandler.js +141 -0
  142. package/lib/config/defaults.js +612 -43
  143. package/lib/config/defineConfig.js +31 -0
  144. package/lib/config/normalization.js +46 -1
  145. package/lib/config/target.js +200 -2
  146. package/lib/container/ContainerEntryDependency.js +2 -0
  147. package/lib/container/ContainerEntryModule.js +27 -14
  148. package/lib/container/ContainerEntryModuleFactory.js +1 -0
  149. package/lib/container/ContainerExposedDependency.js +6 -2
  150. package/lib/container/ContainerPlugin.js +2 -1
  151. package/lib/container/ContainerReferencePlugin.js +3 -2
  152. package/lib/container/FallbackDependency.js +9 -7
  153. package/lib/container/FallbackItemDependency.js +1 -0
  154. package/lib/container/FallbackModule.js +22 -9
  155. package/lib/container/FallbackModuleFactory.js +1 -0
  156. package/lib/container/HoistContainerReferencesPlugin.js +47 -55
  157. package/lib/container/ModuleFederationPlugin.js +21 -29
  158. package/lib/container/RemoteModule.js +33 -10
  159. package/lib/container/RemoteRuntimeModule.js +15 -12
  160. package/lib/container/RemoteToExternalDependency.js +1 -0
  161. package/lib/container/options.js +7 -0
  162. package/lib/css/CssGenerator.js +540 -272
  163. package/lib/css/CssInjectStyleRuntimeModule.js +86 -70
  164. package/lib/css/CssLoadingRuntimeModule.js +173 -81
  165. package/lib/{CssModule.js → css/CssModule.js} +72 -37
  166. package/lib/css/CssModulesPlugin.js +371 -208
  167. package/lib/css/CssParser.js +3538 -1963
  168. package/lib/css/syntax.js +4155 -0
  169. package/lib/debug/ProfilingPlugin.js +33 -2
  170. package/lib/deno/DenoTargetPlugin.js +41 -0
  171. package/lib/dependencies/AMDDefineDependency.js +29 -17
  172. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +19 -6
  173. package/lib/dependencies/AMDPlugin.js +6 -3
  174. package/lib/dependencies/AMDRequireArrayDependency.js +13 -11
  175. package/lib/dependencies/AMDRequireContextDependency.js +10 -11
  176. package/lib/dependencies/AMDRequireDependenciesBlock.js +1 -0
  177. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +28 -14
  178. package/lib/dependencies/AMDRequireDependency.js +28 -20
  179. package/lib/dependencies/AMDRequireItemDependency.js +1 -0
  180. package/lib/dependencies/AMDRuntimeModules.js +3 -0
  181. package/lib/dependencies/CachedConstDependency.js +9 -1
  182. package/lib/dependencies/CommonJsDependencyHelpers.js +104 -0
  183. package/lib/dependencies/CommonJsExportRequireDependency.js +157 -38
  184. package/lib/dependencies/CommonJsExportsDependency.js +74 -20
  185. package/lib/dependencies/CommonJsExportsParserPlugin.js +246 -15
  186. package/lib/dependencies/CommonJsFullRequireDependency.js +91 -27
  187. package/lib/dependencies/CommonJsImportsParserPlugin.js +189 -24
  188. package/lib/dependencies/CommonJsPlugin.js +7 -4
  189. package/lib/dependencies/CommonJsRequireContextDependency.js +13 -13
  190. package/lib/dependencies/CommonJsRequireDependency.js +135 -13
  191. package/lib/dependencies/CommonJsSelfReferenceDependency.js +60 -16
  192. package/lib/dependencies/ConstDependency.js +22 -12
  193. package/lib/dependencies/ContextDependency.js +13 -2
  194. package/lib/dependencies/ContextDependencyHelpers.js +7 -4
  195. package/lib/dependencies/ContextDependencyTemplateAsId.js +2 -1
  196. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +1 -0
  197. package/lib/dependencies/ContextElementDependency.js +27 -14
  198. package/lib/dependencies/CreateRequireParserPlugin.js +14 -7
  199. package/lib/dependencies/CreateScriptUrlDependency.js +9 -7
  200. package/lib/dependencies/CriticalDependencyWarning.js +3 -1
  201. package/lib/dependencies/CssIcssExportDependency.js +681 -367
  202. package/lib/dependencies/CssIcssImportDependency.js +62 -17
  203. package/lib/dependencies/CssIcssSymbolDependency.js +36 -17
  204. package/lib/dependencies/CssImportDependency.js +37 -1
  205. package/lib/dependencies/CssUrlDependency.js +87 -14
  206. package/lib/dependencies/DelegatedSourceDependency.js +1 -0
  207. package/lib/dependencies/DllEntryDependency.js +12 -13
  208. package/lib/dependencies/DynamicExports.js +5 -0
  209. package/lib/dependencies/EntryDependency.js +1 -0
  210. package/lib/dependencies/ExportBindingInitFragment.js +164 -0
  211. package/lib/dependencies/ExportsInfoDependency.js +18 -12
  212. package/lib/dependencies/ExternalModuleDependency.js +13 -5
  213. package/lib/dependencies/ExternalModuleInitFragment.js +10 -5
  214. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +19 -12
  215. package/lib/dependencies/HarmonyAcceptDependency.js +24 -26
  216. package/lib/dependencies/HarmonyAcceptImportDependency.js +2 -0
  217. package/lib/dependencies/HarmonyCompatibilityDependency.js +33 -14
  218. package/lib/dependencies/HarmonyDetectionParserPlugin.js +108 -30
  219. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +34 -3
  220. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +70 -33
  221. package/lib/dependencies/HarmonyExportExpressionDependency.js +133 -43
  222. package/lib/dependencies/HarmonyExportHeaderDependency.js +11 -9
  223. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +268 -44
  224. package/lib/dependencies/HarmonyExportInitFragment.js +28 -20
  225. package/lib/dependencies/HarmonyExportSpecifierDependency.js +88 -18
  226. package/lib/dependencies/HarmonyExports.js +6 -1
  227. package/lib/dependencies/HarmonyImportDependency.js +60 -4
  228. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +139 -146
  229. package/lib/dependencies/HarmonyImportGuard.js +427 -0
  230. package/lib/dependencies/HarmonyImportSideEffectDependency.js +22 -1
  231. package/lib/dependencies/HarmonyImportSpecifierDependency.js +146 -24
  232. package/lib/{HarmonyLinkingError.js → dependencies/HarmonyLinkingError.js} +6 -3
  233. package/lib/dependencies/HarmonyModulesPlugin.js +11 -1
  234. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +2 -1
  235. package/lib/dependencies/HtmlEntryDependency.js +1295 -0
  236. package/lib/dependencies/HtmlInlineHtmlDependency.js +107 -0
  237. package/lib/dependencies/HtmlInlineScriptDependency.js +126 -0
  238. package/lib/dependencies/HtmlInlineStyleDependency.js +152 -0
  239. package/lib/dependencies/HtmlSourceDependency.js +172 -0
  240. package/lib/dependencies/ImportContextDependency.js +9 -9
  241. package/lib/dependencies/ImportDependency.js +92 -3
  242. package/lib/dependencies/ImportEagerDependency.js +2 -0
  243. package/lib/dependencies/ImportMetaContextDependency.js +1 -0
  244. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +35 -19
  245. package/lib/dependencies/ImportMetaContextPlugin.js +40 -8
  246. package/lib/dependencies/ImportMetaGlobDependency.js +81 -0
  247. package/lib/dependencies/ImportMetaGlobDependencyParserPlugin.js +78 -0
  248. package/lib/dependencies/ImportMetaGlobHelpers.js +660 -0
  249. package/lib/dependencies/ImportMetaHotAcceptDependency.js +2 -0
  250. package/lib/dependencies/ImportMetaHotDeclineDependency.js +2 -0
  251. package/lib/dependencies/ImportMetaPlugin.js +595 -209
  252. package/lib/dependencies/ImportMetaResolveDependency.js +90 -0
  253. package/lib/dependencies/ImportParserPlugin.js +114 -27
  254. package/lib/dependencies/ImportPhase.js +17 -11
  255. package/lib/dependencies/ImportPlugin.js +2 -1
  256. package/lib/dependencies/ImportWeakDependency.js +3 -0
  257. package/lib/dependencies/JsonExportsDependency.js +15 -10
  258. package/lib/dependencies/LoaderDependency.js +2 -0
  259. package/lib/dependencies/LoaderImportDependency.js +3 -0
  260. package/lib/dependencies/LoaderPlugin.js +9 -2
  261. package/lib/dependencies/LocalModule.js +15 -12
  262. package/lib/dependencies/LocalModuleDependency.js +15 -13
  263. package/lib/dependencies/LocalModulesHelpers.js +3 -0
  264. package/lib/dependencies/ModuleDecoratorDependency.js +16 -10
  265. package/lib/dependencies/ModuleDependency.js +14 -0
  266. package/lib/dependencies/ModuleDependencyTemplateAsId.js +1 -0
  267. package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +1 -0
  268. package/lib/dependencies/ModuleHotAcceptDependency.js +2 -0
  269. package/lib/dependencies/ModuleHotDeclineDependency.js +2 -0
  270. package/lib/dependencies/ModuleInitFragmentDependency.js +19 -11
  271. package/lib/dependencies/NullDependency.js +2 -0
  272. package/lib/dependencies/PrefetchDependency.js +1 -0
  273. package/lib/dependencies/ProvidedDependency.js +36 -27
  274. package/lib/dependencies/PureExpressionDependency.js +14 -10
  275. package/lib/dependencies/RequireContextDependency.js +1 -0
  276. package/lib/dependencies/RequireContextDependencyParserPlugin.js +2 -1
  277. package/lib/dependencies/RequireContextPlugin.js +2 -1
  278. package/lib/dependencies/RequireEnsureDependenciesBlock.js +1 -0
  279. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +4 -6
  280. package/lib/dependencies/RequireEnsureDependency.js +16 -13
  281. package/lib/dependencies/RequireEnsureItemDependency.js +1 -0
  282. package/lib/dependencies/RequireEnsurePlugin.js +2 -1
  283. package/lib/dependencies/RequireHeaderDependency.js +7 -4
  284. package/lib/dependencies/RequireIncludeDependency.js +2 -0
  285. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +11 -12
  286. package/lib/dependencies/RequireIncludePlugin.js +2 -1
  287. package/lib/{RequireJsStuffPlugin.js → dependencies/RequireJsStuffPlugin.js} +9 -8
  288. package/lib/dependencies/RequireResolveContextDependency.js +10 -11
  289. package/lib/dependencies/RequireResolveDependency.js +2 -0
  290. package/lib/dependencies/RequireResolveHeaderDependency.js +8 -5
  291. package/lib/dependencies/RuntimeRequirementsDependency.js +11 -8
  292. package/lib/dependencies/StaticExportsDependency.js +13 -10
  293. package/lib/dependencies/SystemPlugin.js +9 -6
  294. package/lib/dependencies/SystemRuntimeModule.js +1 -0
  295. package/lib/dependencies/TopLevelAwaitDependency.js +93 -0
  296. package/lib/dependencies/URLContextDependency.js +8 -7
  297. package/lib/dependencies/URLDependency.js +157 -33
  298. package/lib/dependencies/URLPlugin.js +2 -0
  299. package/lib/dependencies/UnsupportedDependency.js +12 -13
  300. package/lib/dependencies/WebAssemblyExportImportedDependency.js +15 -16
  301. package/lib/dependencies/WebAssemblyImportDependency.js +19 -18
  302. package/lib/dependencies/WebpackIsIncludedDependency.js +3 -0
  303. package/lib/dependencies/{WorkerPlugin.js → WorkerAndWorkletPlugin.js} +364 -114
  304. package/lib/dependencies/WorkerDependency.js +111 -27
  305. package/lib/dependencies/WorkletDependency.js +278 -0
  306. package/lib/dependencies/getFunctionExpression.js +1 -0
  307. package/lib/dependencies/processExportInfo.js +14 -11
  308. package/lib/{DelegatedModule.js → dll/DelegatedModule.js} +71 -44
  309. package/lib/{DelegatedModuleFactoryPlugin.js → dll/DelegatedModuleFactoryPlugin.js} +27 -4
  310. package/lib/{DelegatedPlugin.js → dll/DelegatedPlugin.js} +5 -3
  311. package/lib/{DllEntryPlugin.js → dll/DllEntryPlugin.js} +9 -5
  312. package/lib/{DllModule.js → dll/DllModule.js} +36 -24
  313. package/lib/{DllModuleFactory.js → dll/DllModuleFactory.js} +5 -4
  314. package/lib/{DllPlugin.js → dll/DllPlugin.js} +24 -6
  315. package/lib/{DllReferencePlugin.js → dll/DllReferencePlugin.js} +26 -18
  316. package/lib/{LibManifestPlugin.js → dll/LibManifestPlugin.js} +14 -10
  317. package/lib/electron/ElectronTargetPlugin.js +24 -5
  318. package/lib/{AbstractMethodError.js → errors/AbstractMethodError.js} +10 -1
  319. package/lib/{AsyncDependencyToInitialChunkError.js → errors/AsyncDependencyToInitialChunkError.js} +8 -3
  320. package/lib/errors/BuildCycleError.js +1 -1
  321. package/lib/{ChunkRenderError.js → errors/ChunkRenderError.js} +1 -1
  322. package/lib/{CodeGenerationError.js → errors/CodeGenerationError.js} +1 -1
  323. package/lib/{CommentCompilationWarning.js → errors/CommentCompilationWarning.js} +9 -3
  324. package/lib/{ConcurrentCompilationError.js → errors/ConcurrentCompilationError.js} +5 -2
  325. package/lib/{EnvironmentNotSupportAsyncWarning.js → errors/EnvironmentNotSupportAsyncWarning.js} +5 -5
  326. package/lib/{HookWebpackError.js → errors/HookWebpackError.js} +20 -16
  327. package/lib/{IgnoreErrorModuleFactory.js → errors/IgnoreErrorModuleFactory.js} +7 -4
  328. package/lib/{InvalidDependenciesModuleWarning.js → errors/InvalidDependenciesModuleWarning.js} +6 -3
  329. package/lib/errors/JSONParseError.js +115 -0
  330. package/lib/errors/LoaderLoadingError.js +20 -0
  331. package/lib/{ModuleBuildError.js → errors/ModuleBuildError.js} +22 -16
  332. package/lib/{ModuleDependencyError.js → errors/ModuleDependencyError.js} +10 -3
  333. package/lib/{ModuleDependencyWarning.js → errors/ModuleDependencyWarning.js} +13 -5
  334. package/lib/{ModuleError.js → errors/ModuleError.js} +10 -14
  335. package/lib/{ModuleHashingError.js → errors/ModuleHashingError.js} +5 -1
  336. package/lib/errors/ModuleNotFoundError.js +94 -0
  337. package/lib/errors/ModuleParseError.js +141 -0
  338. package/lib/{ModuleRestoreError.js → errors/ModuleRestoreError.js} +4 -1
  339. package/lib/{ModuleStoreError.js → errors/ModuleStoreError.js} +5 -1
  340. package/lib/{ModuleWarning.js → errors/ModuleWarning.js} +13 -14
  341. package/lib/{NodeStuffInWebError.js → errors/NodeStuffInWebError.js} +7 -5
  342. package/lib/errors/NonErrorEmittedError.js +30 -0
  343. package/lib/{UnhandledSchemeError.js → errors/UnhandledSchemeError.js} +9 -2
  344. package/lib/{UnsupportedFeatureWarning.js → errors/UnsupportedFeatureWarning.js} +4 -3
  345. package/lib/errors/WebpackError.js +84 -0
  346. package/lib/esm/ExportWebpackRequireRuntimeModule.js +2 -0
  347. package/lib/esm/ModuleChunkFormatPlugin.js +52 -15
  348. package/lib/esm/ModuleChunkLoadingPlugin.js +11 -3
  349. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +80 -52
  350. package/lib/hmr/HotModuleReplacement.runtime.js +175 -30
  351. package/lib/hmr/HotModuleReplacementRuntimeModule.js +8 -0
  352. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +173 -26
  353. package/lib/hmr/JavascriptHotModuleReplacementHelper.js +1 -0
  354. package/lib/hmr/LazyCompilationPlugin.js +154 -7
  355. package/lib/hmr/lazyCompilationBackend.js +53 -12
  356. package/lib/html/HtmlGenerator.js +1490 -0
  357. package/lib/html/HtmlModule.js +41 -0
  358. package/lib/html/HtmlModulesPlugin.js +1129 -0
  359. package/lib/html/HtmlParser.js +1970 -0
  360. package/lib/html/favicon.svg +1 -0
  361. package/lib/html/syntax.js +9106 -0
  362. package/lib/ids/ChunkModuleIdRangePlugin.js +3 -1
  363. package/lib/ids/DeterministicChunkIdsPlugin.js +3 -1
  364. package/lib/ids/DeterministicModuleIdsPlugin.js +3 -1
  365. package/lib/ids/HashedModuleIdsPlugin.js +2 -1
  366. package/lib/ids/IdHelpers.js +49 -12
  367. package/lib/ids/NamedChunkIdsPlugin.js +3 -1
  368. package/lib/ids/NamedModuleIdsPlugin.js +3 -1
  369. package/lib/ids/NaturalChunkIdsPlugin.js +1 -1
  370. package/lib/ids/NaturalModuleIdsPlugin.js +1 -1
  371. package/lib/ids/OccurrenceChunkIdsPlugin.js +2 -1
  372. package/lib/ids/OccurrenceModuleIdsPlugin.js +4 -1
  373. package/lib/ids/SyncModuleIdsPlugin.js +3 -1
  374. package/lib/index.js +66 -15
  375. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +5 -6
  376. package/lib/javascript/BasicEvaluatedExpression.js +370 -49
  377. package/lib/javascript/ChunkFormatHelpers.js +2 -1
  378. package/lib/javascript/ChunkHelpers.js +1 -0
  379. package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -1
  380. package/lib/javascript/EnableChunkLoadingPlugin.js +6 -1
  381. package/lib/javascript/JavascriptGenerator.js +213 -51
  382. package/lib/javascript/JavascriptModule.js +54 -0
  383. package/lib/javascript/JavascriptModulesPlugin.js +628 -198
  384. package/lib/javascript/JavascriptParser.js +1334 -471
  385. package/lib/javascript/JavascriptParserHelpers.js +10 -7
  386. package/lib/javascript/StartupHelpers.js +5 -0
  387. package/lib/javascript/syntax.js +5037 -0
  388. package/lib/json/JsonData.js +5 -0
  389. package/lib/json/JsonGenerator.js +21 -0
  390. package/lib/json/JsonModule.js +40 -0
  391. package/lib/json/JsonModulesPlugin.js +8 -1
  392. package/lib/json/JsonParser.js +18 -27
  393. package/lib/library/AbstractLibraryPlugin.js +17 -2
  394. package/lib/library/AmdLibraryPlugin.js +8 -0
  395. package/lib/library/AssignLibraryPlugin.js +21 -3
  396. package/lib/library/EnableLibraryPlugin.js +8 -2
  397. package/lib/library/ExportPropertyLibraryPlugin.js +10 -0
  398. package/lib/{FalseIIFEUmdWarning.js → library/FalseIIFEUmdWarning.js} +2 -1
  399. package/lib/library/JsonpLibraryPlugin.js +8 -0
  400. package/lib/library/ModuleLibraryPlugin.js +154 -7
  401. package/lib/library/SystemLibraryPlugin.js +11 -3
  402. package/lib/library/UmdLibraryPlugin.js +16 -0
  403. package/lib/loaders/LoaderRunner.js +714 -0
  404. package/lib/loaders/loadLoader.js +100 -0
  405. package/lib/logging/Logger.js +17 -0
  406. package/lib/logging/createConsoleLogger.js +7 -0
  407. package/lib/logging/runtime.js +2 -0
  408. package/lib/logging/truncateArgs.js +2 -0
  409. package/lib/node/CommonJsChunkLoadingPlugin.js +5 -1
  410. package/lib/node/NodeEnvironmentPlugin.js +7 -3
  411. package/lib/node/NodeSourcePlugin.js +1 -1
  412. package/lib/node/NodeTargetPlugin.js +4 -63
  413. package/lib/node/NodeTemplatePlugin.js +3 -1
  414. package/lib/node/NodeWatchFileSystem.js +40 -22
  415. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +13 -9
  416. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +33 -3
  417. package/lib/node/ReadFileCompileWasmPlugin.js +28 -3
  418. package/lib/node/RequireChunkLoadingRuntimeModule.js +21 -16
  419. package/lib/node/nodeBuiltins.js +80 -0
  420. package/lib/node/nodeConsole.js +116 -64
  421. package/lib/optimize/AggressiveMergingPlugin.js +22 -16
  422. package/lib/optimize/AggressiveSplittingPlugin.js +6 -1
  423. package/lib/optimize/ConcatenatedModule.js +603 -130
  424. package/lib/optimize/ConstExportsPlugin.js +211 -0
  425. package/lib/optimize/EnsureChunkConditionsPlugin.js +2 -1
  426. package/lib/optimize/FlagIncludedChunksPlugin.js +15 -4
  427. package/lib/optimize/InlineExports.js +178 -0
  428. package/lib/optimize/InnerGraph.js +374 -262
  429. package/lib/optimize/InnerGraphPlugin.js +246 -117
  430. package/lib/optimize/LimitChunkCountPlugin.js +9 -0
  431. package/lib/optimize/MangleExportsPlugin.js +5 -1
  432. package/lib/optimize/MergeDuplicateChunksPlugin.js +2 -0
  433. package/lib/optimize/MinChunkSizePlugin.js +2 -1
  434. package/lib/optimize/MinMaxSizeWarning.js +5 -4
  435. package/lib/optimize/ModuleConcatenationPlugin.js +229 -55
  436. package/lib/optimize/RealContentHashPlugin.js +130 -52
  437. package/lib/optimize/RemoveEmptyChunksPlugin.js +2 -1
  438. package/lib/optimize/RemoveParentModulesPlugin.js +3 -1
  439. package/lib/optimize/RuntimeChunkPlugin.js +2 -1
  440. package/lib/optimize/SideEffectsFlagPlugin.js +381 -55
  441. package/lib/optimize/SplitChunksPlugin.js +200 -50
  442. package/lib/performance/AssetsOverSizeLimitWarning.js +3 -2
  443. package/lib/performance/EntrypointsOverSizeLimitWarning.js +3 -2
  444. package/lib/performance/NoAsyncChunksWarning.js +5 -3
  445. package/lib/performance/SizeLimitsPlugin.js +8 -2
  446. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +1 -0
  447. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +21 -0
  448. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +1 -0
  449. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +5 -1
  450. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +25 -13
  451. package/lib/prefetch/ResourceHintPlugin.js +687 -0
  452. package/lib/prefetch/ResourceHintRuntimeModule.js +149 -0
  453. package/lib/prefetch/StartupAssetHintRuntimeModule.js +210 -0
  454. package/lib/prefetch/parseResourceHintOptions.js +103 -0
  455. package/lib/rules/BasicEffectRulePlugin.js +3 -0
  456. package/lib/rules/BasicMatcherRulePlugin.js +3 -0
  457. package/lib/rules/ObjectMatcherRulePlugin.js +3 -0
  458. package/lib/rules/RuleSetCompiler.js +132 -0
  459. package/lib/rules/UseEffectRulePlugin.js +10 -3
  460. package/lib/runtime/AsyncModuleGeneratorRuntimeModule.js +56 -0
  461. package/lib/runtime/AsyncModuleRuntimeModule.js +52 -33
  462. package/lib/runtime/AutoPublicPathRuntimeModule.js +22 -9
  463. package/lib/runtime/BaseUriRuntimeModule.js +1 -0
  464. package/lib/runtime/ChunkNameRuntimeModule.js +1 -0
  465. package/lib/runtime/CommonJsWrapRuntimeModule.js +37 -0
  466. package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +2 -1
  467. package/lib/runtime/CompatRuntimeModule.js +2 -0
  468. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +7 -4
  469. package/lib/runtime/CreateScriptRuntimeModule.js +1 -0
  470. package/lib/runtime/CreateScriptUrlRuntimeModule.js +1 -0
  471. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +34 -4
  472. package/lib/runtime/EnsureChunkRuntimeModule.js +1 -0
  473. package/lib/runtime/GetChunkFilenameRuntimeModule.js +88 -8
  474. package/lib/runtime/GetFullHashRuntimeModule.js +1 -0
  475. package/lib/runtime/GetMainFilenameRuntimeModule.js +1 -0
  476. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +2 -1
  477. package/lib/runtime/GetWorkletBootstrapRuntimeModule.js +59 -0
  478. package/lib/runtime/GlobalRuntimeModule.js +1 -0
  479. package/lib/runtime/HasOwnPropertyRuntimeModule.js +2 -1
  480. package/lib/runtime/HelperRuntimeModule.js +5 -0
  481. package/lib/runtime/LoadScriptRuntimeModule.js +28 -37
  482. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +354 -37
  483. package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +2 -1
  484. package/lib/runtime/NonceRuntimeModule.js +1 -0
  485. package/lib/runtime/OnChunksLoadedRuntimeModule.js +5 -4
  486. package/lib/runtime/PublicPathRuntimeModule.js +1 -0
  487. package/lib/runtime/RelativeUrlRuntimeModule.js +4 -2
  488. package/lib/runtime/RuntimeIdRuntimeModule.js +1 -0
  489. package/lib/runtime/SetAnonymousDefaultNameRuntimeModule.js +38 -0
  490. package/lib/runtime/StartupChunkDependenciesPlugin.js +13 -1
  491. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +2 -1
  492. package/lib/runtime/StartupEntrypointRuntimeModule.js +5 -3
  493. package/lib/runtime/SystemContextRuntimeModule.js +1 -0
  494. package/lib/runtime/ToBinaryRuntimeModule.js +1 -0
  495. package/lib/runtime/WorkerRuntimeModule.js +33 -0
  496. package/lib/schemes/DataUriPlugin.js +14 -2
  497. package/lib/schemes/FileUriPlugin.js +1 -1
  498. package/lib/schemes/HttpUriPlugin.js +86 -4
  499. package/lib/schemes/VirtualUrlPlugin.js +8 -4
  500. package/lib/serialization/AggregateErrorSerializer.js +9 -6
  501. package/lib/serialization/ArraySerializer.js +6 -8
  502. package/lib/serialization/BinaryMiddleware.js +427 -1006
  503. package/lib/serialization/DateObjectSerializer.js +4 -2
  504. package/lib/serialization/ErrorObjectSerializer.js +10 -6
  505. package/lib/serialization/FileMiddleware.js +345 -59
  506. package/lib/serialization/MapObjectSerializer.js +7 -9
  507. package/lib/serialization/NullPrototypeObjectSerializer.js +9 -9
  508. package/lib/serialization/ObjectMiddleware.js +73 -13
  509. package/lib/serialization/PlainObjectSerializer.js +16 -8
  510. package/lib/serialization/RegExpObjectSerializer.js +4 -2
  511. package/lib/serialization/Serializer.js +6 -0
  512. package/lib/serialization/SerializerMiddleware.js +14 -2
  513. package/lib/serialization/SetObjectSerializer.js +6 -8
  514. package/lib/serialization/SingleItemMiddleware.js +3 -0
  515. package/lib/sharing/ConsumeSharedFallbackDependency.js +1 -0
  516. package/lib/sharing/ConsumeSharedModule.js +21 -7
  517. package/lib/sharing/ConsumeSharedPlugin.js +11 -11
  518. package/lib/sharing/ConsumeSharedRuntimeModule.js +55 -45
  519. package/lib/sharing/ProvideForSharedDependency.js +1 -0
  520. package/lib/sharing/ProvideSharedDependency.js +34 -15
  521. package/lib/sharing/ProvideSharedModule.js +42 -12
  522. package/lib/sharing/ProvideSharedModuleFactory.js +1 -0
  523. package/lib/sharing/ProvideSharedPlugin.js +13 -8
  524. package/lib/sharing/SharePlugin.js +5 -1
  525. package/lib/sharing/ShareRuntimeModule.js +19 -16
  526. package/lib/sharing/resolveMatchedConfigs.js +6 -2
  527. package/lib/sharing/utils.js +9 -1
  528. package/lib/stats/DefaultStatsFactoryPlugin.js +289 -201
  529. package/lib/stats/DefaultStatsPresetPlugin.js +14 -2
  530. package/lib/stats/DefaultStatsPrinterPlugin.js +74 -170
  531. package/lib/stats/StatsFactory.js +70 -27
  532. package/lib/stats/StatsPrinter.js +16 -2
  533. package/lib/typescript/TypeScriptPlugin.js +210 -0
  534. package/lib/url/URLParserPlugin.js +111 -23
  535. package/lib/util/ArrayHelpers.js +1 -0
  536. package/lib/util/ArrayQueue.js +10 -5
  537. package/lib/util/AsyncQueue.js +154 -74
  538. package/lib/util/Hash.js +2 -2
  539. package/lib/util/IterableHelpers.js +3 -0
  540. package/lib/util/LazyBucketSortedSet.js +26 -0
  541. package/lib/util/LazySet.js +45 -4
  542. package/lib/util/LocConverter.js +64 -0
  543. package/lib/util/ParallelismFactorCalculator.js +1 -0
  544. package/lib/util/Queue.js +6 -3
  545. package/lib/util/Semaphore.js +15 -1
  546. package/lib/util/SetHelpers.js +4 -1
  547. package/lib/util/SortableSet.js +7 -1
  548. package/lib/util/SourceProcessor.js +119 -0
  549. package/lib/util/StackedCacheMap.js +20 -3
  550. package/lib/util/StackedMap.js +162 -43
  551. package/lib/util/StringXor.js +1 -1
  552. package/lib/util/TupleQueue.js +7 -3
  553. package/lib/util/TupleSet.js +14 -0
  554. package/lib/util/URLAbsoluteSpecifier.js +1 -0
  555. package/lib/util/WeakTupleMap.js +60 -1
  556. package/lib/util/binarySearchBounds.js +3 -2
  557. package/lib/util/chainedImports.js +3 -3
  558. package/lib/util/cleverMerge.js +19 -2
  559. package/lib/util/comparators.js +35 -4
  560. package/lib/util/compileBooleanMatcher.js +9 -0
  561. package/lib/util/concatenate.js +80 -24
  562. package/lib/util/conventions.js +46 -1
  563. package/lib/util/createHash.js +0 -1
  564. package/lib/util/createHooksRegistry.js +43 -0
  565. package/lib/util/createMappings.js +118 -0
  566. package/lib/util/dataURL.js +3 -2
  567. package/lib/util/deprecation.js +19 -0
  568. package/lib/util/deterministicGrouping.js +46 -17
  569. package/lib/util/extractSourceMap.js +2 -1
  570. package/lib/util/extractUrlAndGlobal.js +1 -0
  571. package/lib/util/findGraphRoots.js +7 -0
  572. package/lib/{formatLocation.js → util/formatLocation.js} +4 -2
  573. package/lib/{SizeFormatHelpers.js → util/formatSize.js} +10 -3
  574. package/lib/util/fs.js +87 -14
  575. package/lib/util/generateDebugId.js +1 -0
  576. package/lib/util/globUtils.js +710 -0
  577. package/lib/util/hash/BatchedHash.js +1 -0
  578. package/lib/util/hash/BulkUpdateHash.js +1 -0
  579. package/lib/util/hash/DebugHash.js +1 -0
  580. package/lib/util/hash/hash-digest.js +32 -15
  581. package/lib/util/hash/md4.js +1 -1
  582. package/lib/util/hash/wasm-hash.js +5 -0
  583. package/lib/util/hash/xxhash64.js +1 -1
  584. package/lib/util/identifier.js +118 -7
  585. package/lib/util/implicitTypeLoaderFallback.js +62 -0
  586. package/lib/util/internalSerializables.js +102 -60
  587. package/lib/util/magicComment.js +149 -7
  588. package/lib/util/makeSerializable.js +7 -0
  589. package/lib/util/memoize.js +2 -0
  590. package/lib/util/mimeTypes.js +176 -0
  591. package/lib/util/nonNumericOnlyHash.js +31 -1
  592. package/lib/util/numberHash.js +2 -2
  593. package/lib/util/parseJson.js +41 -0
  594. package/lib/util/processAsyncTree.js +8 -0
  595. package/lib/util/property.js +9 -2
  596. package/lib/util/publicPathPlaceholder.js +64 -0
  597. package/lib/util/registerExternalSerializer.js +24 -4
  598. package/lib/util/removeBOM.js +1 -0
  599. package/lib/util/runtime.js +32 -0
  600. package/lib/util/semver.js +15 -0
  601. package/lib/util/serialization.js +2 -0
  602. package/lib/util/smartGrouping.js +8 -0
  603. package/lib/util/source.js +23 -0
  604. package/lib/util/topologicalSort.js +69 -0
  605. package/lib/validateSchema.js +1 -0
  606. package/lib/wasm/EnableWasmLoadingPlugin.js +15 -1
  607. package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +25 -18
  608. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +34 -22
  609. package/lib/wasm-async/AsyncWasmModule.js +77 -0
  610. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +6 -0
  611. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +6 -1
  612. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +22 -126
  613. package/lib/wasm-async/AsyncWebAssemblyParser.js +3 -2
  614. package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +13 -2
  615. package/lib/wasm-sync/SyncWasmModule.js +39 -0
  616. package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +7 -3
  617. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +86 -19
  618. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +4 -3
  619. package/lib/wasm-sync/WebAssemblyGenerator.js +27 -1
  620. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +9 -3
  621. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +4 -0
  622. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +20 -1
  623. package/lib/wasm-sync/WebAssemblyParser.js +9 -3
  624. package/lib/wasm-sync/WebAssemblyUtils.js +2 -0
  625. package/lib/web/FetchCompileAsyncWasmPlugin.js +29 -1
  626. package/lib/web/FetchCompileWasmPlugin.js +27 -1
  627. package/lib/web/JsonpChunkLoadingPlugin.js +11 -1
  628. package/lib/web/JsonpChunkLoadingRuntimeModule.js +58 -64
  629. package/lib/web/JsonpTemplatePlugin.js +2 -1
  630. package/lib/webpack.js +78 -1
  631. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +10 -1
  632. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +15 -10
  633. package/lib/webworker/WebWorkerTemplatePlugin.js +1 -1
  634. package/module.d.ts +21 -0
  635. package/package.json +79 -77
  636. package/schemas/WebpackOptions.check.js +1 -1
  637. package/schemas/WebpackOptions.json +1173 -80
  638. package/schemas/plugins/{DllPlugin.check.d.ts → HtmlGeneratorOptions.check.d.ts} +1 -1
  639. package/schemas/plugins/HtmlGeneratorOptions.check.js +6 -0
  640. package/schemas/plugins/HtmlGeneratorOptions.json +3 -0
  641. package/schemas/plugins/{DllReferencePlugin.check.d.ts → HtmlParserOptions.check.d.ts} +1 -1
  642. package/schemas/plugins/HtmlParserOptions.check.js +6 -0
  643. package/schemas/plugins/HtmlParserOptions.json +3 -0
  644. package/schemas/plugins/ProgressPlugin.check.js +1 -1
  645. package/schemas/plugins/ProgressPlugin.json +38 -0
  646. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  647. package/schemas/plugins/container/ContainerReferencePlugin.json +2 -0
  648. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  649. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  650. package/schemas/plugins/container/ModuleFederationPlugin.json +2 -0
  651. package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.d.ts +7 -0
  652. package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +6 -0
  653. package/schemas/plugins/css/CssAutoOrModuleParserOptions.json +3 -0
  654. package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
  655. package/schemas/plugins/css/CssParserOptions.check.js +1 -1
  656. package/schemas/plugins/dll/DllPlugin.check.d.ts +7 -0
  657. package/schemas/plugins/dll/DllReferencePlugin.check.d.ts +7 -0
  658. package/types.d.ts +11053 -3019
  659. package/lib/CaseSensitiveModulesWarning.js +0 -72
  660. package/lib/GraphHelpers.js +0 -46
  661. package/lib/ModuleParseError.js +0 -125
  662. package/lib/NoModeWarning.js +0 -23
  663. package/lib/css/CssMergeStyleSheetsRuntimeModule.js +0 -56
  664. package/lib/css/walkCssTokens.js +0 -1843
  665. package/lib/util/AppendOnlyStackedSet.js +0 -78
  666. /package/schemas/plugins/{DllPlugin.check.js → dll/DllPlugin.check.js} +0 -0
  667. /package/schemas/plugins/{DllPlugin.json → dll/DllPlugin.json} +0 -0
  668. /package/schemas/plugins/{DllReferencePlugin.check.js → dll/DllReferencePlugin.check.js} +0 -0
  669. /package/schemas/plugins/{DllReferencePlugin.json → dll/DllReferencePlugin.json} +0 -0
@@ -1,1843 +0,0 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- */
5
-
6
- "use strict";
7
-
8
- /**
9
- * @typedef {object} CssTokenCallbacks
10
- * @property {((input: string, start: number, end: number) => number)=} comment
11
- * @property {((input: string, start: number, end: number) => number)=} whitespace
12
- * @property {((input: string, start: number, end: number) => number)=} string
13
- * @property {((input: string, start: number, end: number) => number)=} leftCurlyBracket
14
- * @property {((input: string, start: number, end: number) => number)=} rightCurlyBracket
15
- * @property {((input: string, start: number, end: number) => number)=} leftParenthesis
16
- * @property {((input: string, start: number, end: number) => number)=} rightParenthesis
17
- * @property {((input: string, start: number, end: number) => number)=} leftSquareBracket
18
- * @property {((input: string, start: number, end: number) => number)=} rightSquareBracket
19
- * @property {((input: string, start: number, end: number) => number)=} function
20
- * @property {((input: string, start: number, end: number, innerStart: number, innerEnd: number) => number)=} url
21
- * @property {((input: string, start: number, end: number) => number)=} colon
22
- * @property {((input: string, start: number, end: number) => number)=} atKeyword
23
- * @property {((input: string, start: number, end: number) => number)=} delim
24
- * @property {((input: string, start: number, end: number) => number)=} identifier
25
- * @property {((input: string, start: number, end: number) => number)=} percentage
26
- * @property {((input: string, start: number, end: number) => number)=} number
27
- * @property {((input: string, start: number, end: number) => number)=} dimension
28
- * @property {((input: string, start: number, end: number, isId: boolean) => number)=} hash
29
- * @property {((input: string, start: number, end: number) => number)=} semicolon
30
- * @property {((input: string, start: number, end: number) => number)=} comma
31
- * @property {((input: string, start: number, end: number) => number)=} cdo
32
- * @property {((input: string, start: number, end: number) => number)=} cdc
33
- * @property {((input: string, start: number, end: number) => number)=} badStringToken
34
- * @property {((input: string, start: number, end: number) => number)=} badUrlToken
35
- * @property {(() => boolean)=} needTerminate
36
- */
37
-
38
- /** @typedef {(input: string, pos: number, callbacks: CssTokenCallbacks) => number} CharHandler */
39
-
40
- // spec: https://drafts.csswg.org/css-syntax/
41
-
42
- const CC_LINE_FEED = "\n".charCodeAt(0);
43
- const CC_CARRIAGE_RETURN = "\r".charCodeAt(0);
44
- const CC_FORM_FEED = "\f".charCodeAt(0);
45
-
46
- const CC_TAB = "\t".charCodeAt(0);
47
- const CC_SPACE = " ".charCodeAt(0);
48
-
49
- const CC_SOLIDUS = "/".charCodeAt(0);
50
- const CC_REVERSE_SOLIDUS = "\\".charCodeAt(0);
51
- const CC_ASTERISK = "*".charCodeAt(0);
52
-
53
- const CC_LEFT_PARENTHESIS = "(".charCodeAt(0);
54
- const CC_RIGHT_PARENTHESIS = ")".charCodeAt(0);
55
- const CC_LEFT_CURLY = "{".charCodeAt(0);
56
- const CC_RIGHT_CURLY = "}".charCodeAt(0);
57
- const CC_LEFT_SQUARE = "[".charCodeAt(0);
58
- const CC_RIGHT_SQUARE = "]".charCodeAt(0);
59
-
60
- const CC_QUOTATION_MARK = '"'.charCodeAt(0);
61
- const CC_APOSTROPHE = "'".charCodeAt(0);
62
-
63
- const CC_FULL_STOP = ".".charCodeAt(0);
64
- const CC_COLON = ":".charCodeAt(0);
65
- const CC_SEMICOLON = ";".charCodeAt(0);
66
- const CC_COMMA = ",".charCodeAt(0);
67
- const CC_PERCENTAGE = "%".charCodeAt(0);
68
- const CC_AT_SIGN = "@".charCodeAt(0);
69
-
70
- const CC_LOW_LINE = "_".charCodeAt(0);
71
- const CC_LOWER_A = "a".charCodeAt(0);
72
- const CC_LOWER_F = "f".charCodeAt(0);
73
- const CC_LOWER_E = "e".charCodeAt(0);
74
- const CC_LOWER_U = "u".charCodeAt(0);
75
- const CC_LOWER_Z = "z".charCodeAt(0);
76
- const CC_UPPER_A = "A".charCodeAt(0);
77
- const CC_UPPER_F = "F".charCodeAt(0);
78
- const CC_UPPER_E = "E".charCodeAt(0);
79
- const CC_UPPER_U = "U".charCodeAt(0);
80
- const CC_UPPER_Z = "Z".charCodeAt(0);
81
- const CC_0 = "0".charCodeAt(0);
82
- const CC_9 = "9".charCodeAt(0);
83
-
84
- const CC_NUMBER_SIGN = "#".charCodeAt(0);
85
- const CC_PLUS_SIGN = "+".charCodeAt(0);
86
- const CC_HYPHEN_MINUS = "-".charCodeAt(0);
87
-
88
- const CC_LESS_THAN_SIGN = "<".charCodeAt(0);
89
- const CC_GREATER_THAN_SIGN = ">".charCodeAt(0);
90
-
91
- /** @type {CharHandler} */
92
- const consumeSpace = (input, pos, callbacks) => {
93
- const start = pos - 1;
94
-
95
- // Consume as much whitespace as possible.
96
- while (_isWhiteSpace(input.charCodeAt(pos))) {
97
- pos++;
98
- }
99
-
100
- // Return a <whitespace-token>.
101
- if (callbacks.whitespace !== undefined) {
102
- return callbacks.whitespace(input, start, pos);
103
- }
104
-
105
- return pos;
106
- };
107
-
108
- // U+000A LINE FEED. Note that U+000D CARRIAGE RETURN and U+000C FORM FEED are not included in this definition,
109
- // as they are converted to U+000A LINE FEED during preprocessing.
110
- //
111
- // Replace any U+000D CARRIAGE RETURN (CR) code points, U+000C FORM FEED (FF) code points, or pairs of U+000D CARRIAGE RETURN (CR) followed by U+000A LINE FEED (LF) in input by a single U+000A LINE FEED (LF) code point.
112
-
113
- /**
114
- * @param {number} cc char code
115
- * @returns {boolean} true, if cc is a newline
116
- */
117
- const _isNewline = (cc) =>
118
- cc === CC_LINE_FEED || cc === CC_CARRIAGE_RETURN || cc === CC_FORM_FEED;
119
-
120
- /**
121
- * @param {number} cc char code
122
- * @param {string} input input
123
- * @param {number} pos position
124
- * @returns {number} position
125
- */
126
- const consumeExtraNewline = (cc, input, pos) => {
127
- if (cc === CC_CARRIAGE_RETURN && input.charCodeAt(pos) === CC_LINE_FEED) {
128
- pos++;
129
- }
130
-
131
- return pos;
132
- };
133
-
134
- /**
135
- * @param {number} cc char code
136
- * @returns {boolean} true, if cc is a space (U+0009 CHARACTER TABULATION or U+0020 SPACE)
137
- */
138
- const _isSpace = (cc) => cc === CC_TAB || cc === CC_SPACE;
139
-
140
- /**
141
- * @param {number} cc char code
142
- * @returns {boolean} true, if cc is a whitespace
143
- */
144
- const _isWhiteSpace = (cc) => _isNewline(cc) || _isSpace(cc);
145
-
146
- /**
147
- * ident-start code point
148
- *
149
- * A letter, a non-ASCII code point, or U+005F LOW LINE (_).
150
- * @param {number} cc char code
151
- * @returns {boolean} true, if cc is a start code point of an identifier
152
- */
153
- const isIdentStartCodePoint = (cc) =>
154
- (cc >= CC_LOWER_A && cc <= CC_LOWER_Z) ||
155
- (cc >= CC_UPPER_A && cc <= CC_UPPER_Z) ||
156
- cc === CC_LOW_LINE ||
157
- cc >= 0x80;
158
-
159
- /** @type {CharHandler} */
160
- const consumeDelimToken = (input, pos, callbacks) => {
161
- // Return a <delim-token> with its value set to the current input code point.
162
- if (callbacks.delim) {
163
- pos = callbacks.delim(input, pos - 1, pos);
164
- }
165
-
166
- return pos;
167
- };
168
-
169
- /** @type {CharHandler} */
170
- const consumeComments = (input, pos, callbacks) => {
171
- // This section describes how to consume comments from a stream of code points. It returns nothing.
172
- // If the next two input code point are U+002F SOLIDUS (/) followed by a U+002A ASTERISK (*),
173
- // consume them and all following code points up to and including the first U+002A ASTERISK (*)
174
- // followed by a U+002F SOLIDUS (/), or up to an EOF code point.
175
- // Return to the start of this step.
176
- while (
177
- input.charCodeAt(pos) === CC_SOLIDUS &&
178
- input.charCodeAt(pos + 1) === CC_ASTERISK
179
- ) {
180
- const start = pos;
181
- pos += 2;
182
-
183
- for (;;) {
184
- if (pos === input.length) {
185
- // If the preceding paragraph ended by consuming an EOF code point, this is a parse error.
186
- return pos;
187
- }
188
-
189
- if (
190
- input.charCodeAt(pos) === CC_ASTERISK &&
191
- input.charCodeAt(pos + 1) === CC_SOLIDUS
192
- ) {
193
- pos += 2;
194
-
195
- if (callbacks.comment) {
196
- pos = callbacks.comment(input, start, pos);
197
- }
198
-
199
- break;
200
- }
201
-
202
- pos++;
203
- }
204
- }
205
-
206
- return pos;
207
- };
208
-
209
- /**
210
- * @param {number} cc char code
211
- * @returns {boolean} true, if cc is a hex digit
212
- */
213
- const _isHexDigit = (cc) =>
214
- _isDigit(cc) ||
215
- (cc >= CC_UPPER_A && cc <= CC_UPPER_F) ||
216
- (cc >= CC_LOWER_A && cc <= CC_LOWER_F);
217
-
218
- /**
219
- * @param {string} input input
220
- * @param {number} pos position
221
- * @returns {number} position
222
- */
223
- const _consumeAnEscapedCodePoint = (input, pos) => {
224
- // This section describes how to consume an escaped code point.
225
- // It assumes that the U+005C REVERSE SOLIDUS (\) has already been consumed and that the next input code point has already been verified to be part of a valid escape.
226
- // It will return a code point.
227
-
228
- // Consume the next input code point.
229
- const cc = input.charCodeAt(pos);
230
- pos++;
231
-
232
- // EOF
233
- // This is a parse error. Return U+FFFD REPLACEMENT CHARACTER (�).
234
- if (pos === input.length) {
235
- return pos;
236
- }
237
-
238
- // hex digit
239
- // Consume as many hex digits as possible, but no more than 5.
240
- // Note that this means 1-6 hex digits have been consumed in total.
241
- // If the next input code point is whitespace, consume it as well.
242
- // Interpret the hex digits as a hexadecimal number.
243
- // If this number is zero, or is for a surrogate, or is greater than the maximum allowed code point, return U+FFFD REPLACEMENT CHARACTER (�).
244
- // Otherwise, return the code point with that value.
245
- if (_isHexDigit(cc)) {
246
- for (let i = 0; i < 5; i++) {
247
- if (_isHexDigit(input.charCodeAt(pos))) {
248
- pos++;
249
- }
250
- }
251
-
252
- const cc = input.charCodeAt(pos);
253
-
254
- if (_isWhiteSpace(cc)) {
255
- pos++;
256
- pos = consumeExtraNewline(cc, input, pos);
257
- }
258
-
259
- return pos;
260
- }
261
-
262
- // anything else
263
- // Return the current input code point.
264
- return pos;
265
- };
266
-
267
- /** @type {CharHandler} */
268
- const consumeAStringToken = (input, pos, callbacks) => {
269
- // This section describes how to consume a string token from a stream of code points.
270
- // It returns either a <string-token> or <bad-string-token>.
271
- //
272
- // This algorithm may be called with an ending code point, which denotes the code point that ends the string.
273
- // If an ending code point is not specified, the current input code point is used.
274
- const start = pos - 1;
275
- const endingCodePoint = input.charCodeAt(pos - 1);
276
-
277
- // Initially create a <string-token> with its value set to the empty string.
278
-
279
- // Repeatedly consume the next input code point from the stream:
280
- for (;;) {
281
- // EOF
282
- // This is a parse error. Return the <string-token>.
283
- if (pos === input.length) {
284
- if (callbacks.string !== undefined) {
285
- return callbacks.string(input, start, pos);
286
- }
287
-
288
- return pos;
289
- }
290
-
291
- const cc = input.charCodeAt(pos);
292
- pos++;
293
-
294
- // ending code point
295
- // Return the <string-token>.
296
- if (cc === endingCodePoint) {
297
- if (callbacks.string !== undefined) {
298
- return callbacks.string(input, start, pos);
299
- }
300
-
301
- return pos;
302
- }
303
- // newline
304
- // This is a parse error.
305
- // Reconsume the current input code point, create a <bad-string-token>, and return it.
306
- else if (_isNewline(cc)) {
307
- pos--;
308
-
309
- if (callbacks.badStringToken !== undefined) {
310
- return callbacks.badStringToken(input, start, pos);
311
- }
312
-
313
- // bad string
314
- return pos;
315
- }
316
- // U+005C REVERSE SOLIDUS (\)
317
- else if (cc === CC_REVERSE_SOLIDUS) {
318
- // If the next input code point is EOF, do nothing.
319
- if (pos === input.length) {
320
- return pos;
321
- }
322
- // Otherwise, if the next input code point is a newline, consume it.
323
- else if (_isNewline(input.charCodeAt(pos))) {
324
- const cc = input.charCodeAt(pos);
325
- pos++;
326
- pos = consumeExtraNewline(cc, input, pos);
327
- }
328
- // Otherwise, (the stream starts with a valid escape) consume an escaped code point and append the returned code point to the <string-token>’s value.
329
- else if (_ifTwoCodePointsAreValidEscape(input, pos)) {
330
- pos = _consumeAnEscapedCodePoint(input, pos);
331
- }
332
- }
333
- // anything else
334
- // Append the current input code point to the <string-token>’s value.
335
- else {
336
- // Append
337
- }
338
- }
339
- };
340
-
341
- /**
342
- * @param {number} cc char code
343
- * @param {number} q char code
344
- * @returns {boolean} is non-ASCII code point
345
- */
346
- const isNonASCIICodePoint = (cc, q) =>
347
- // Simplify
348
- cc > 0x80;
349
-
350
- /**
351
- * @param {number} cc char code
352
- * @returns {boolean} is letter
353
- */
354
- const isLetter = (cc) =>
355
- (cc >= CC_LOWER_A && cc <= CC_LOWER_Z) ||
356
- (cc >= CC_UPPER_A && cc <= CC_UPPER_Z);
357
-
358
- /**
359
- * @param {number} cc char code
360
- * @param {number} q char code
361
- * @returns {boolean} is identifier start code
362
- */
363
- const _isIdentStartCodePoint = (cc, q) =>
364
- isLetter(cc) || isNonASCIICodePoint(cc, q) || cc === CC_LOW_LINE;
365
-
366
- /**
367
- * @param {number} cc char code
368
- * @param {number} q char code
369
- * @returns {boolean} is identifier code
370
- */
371
- const _isIdentCodePoint = (cc, q) =>
372
- _isIdentStartCodePoint(cc, q) || _isDigit(cc) || cc === CC_HYPHEN_MINUS;
373
- /**
374
- * @param {number} cc char code
375
- * @returns {boolean} is digit
376
- */
377
- const _isDigit = (cc) => cc >= CC_0 && cc <= CC_9;
378
-
379
- /**
380
- * @param {string} input input
381
- * @param {number} pos position
382
- * @param {number=} f first code point
383
- * @param {number=} s second code point
384
- * @returns {boolean} true if two code points are a valid escape
385
- */
386
- const _ifTwoCodePointsAreValidEscape = (input, pos, f, s) => {
387
- // This section describes how to check if two code points are a valid escape.
388
- // The algorithm described here can be called explicitly with two code points, or can be called with the input stream itself.
389
- // In the latter case, the two code points in question are the current input code point and the next input code point, in that order.
390
-
391
- // Note: This algorithm will not consume any additional code point.
392
- const first = f || input.charCodeAt(pos - 1);
393
- const second = s || input.charCodeAt(pos);
394
-
395
- // If the first code point is not U+005C REVERSE SOLIDUS (\), return false.
396
- if (first !== CC_REVERSE_SOLIDUS) return false;
397
- // Otherwise, if the second code point is a newline, return false.
398
- if (_isNewline(second)) return false;
399
- // Otherwise, return true.
400
- return true;
401
- };
402
-
403
- /**
404
- * @param {string} input input
405
- * @param {number} pos position
406
- * @param {number=} f first
407
- * @param {number=} s second
408
- * @param {number=} t third
409
- * @returns {boolean} true, if input at pos starts an identifier
410
- */
411
- const _ifThreeCodePointsWouldStartAnIdentSequence = (input, pos, f, s, t) => {
412
- // This section describes how to check if three code points would start an ident sequence.
413
- // The algorithm described here can be called explicitly with three code points, or can be called with the input stream itself.
414
- // In the latter case, the three code points in question are the current input code point and the next two input code points, in that order.
415
-
416
- // Note: This algorithm will not consume any additional code points.
417
-
418
- const first = f || input.charCodeAt(pos - 1);
419
- const second = s || input.charCodeAt(pos);
420
- const third = t || input.charCodeAt(pos + 1);
421
-
422
- // Look at the first code point:
423
-
424
- // U+002D HYPHEN-MINUS
425
- if (first === CC_HYPHEN_MINUS) {
426
- // If the second code point is an ident-start code point or a U+002D HYPHEN-MINUS
427
- // or a U+002D HYPHEN-MINUS, or the second and third code points are a valid escape, return true.
428
- if (
429
- _isIdentStartCodePoint(second, pos) ||
430
- second === CC_HYPHEN_MINUS ||
431
- _ifTwoCodePointsAreValidEscape(input, pos, second, third)
432
- ) {
433
- return true;
434
- }
435
- return false;
436
- }
437
- // ident-start code point
438
- else if (_isIdentStartCodePoint(first, pos - 1)) {
439
- return true;
440
- }
441
- // U+005C REVERSE SOLIDUS (\)
442
- // If the first and second code points are a valid escape, return true. Otherwise, return false.
443
- else if (first === CC_REVERSE_SOLIDUS) {
444
- if (_ifTwoCodePointsAreValidEscape(input, pos, first, second)) {
445
- return true;
446
- }
447
-
448
- return false;
449
- }
450
- // anything else
451
- // Return false.
452
- return false;
453
- };
454
-
455
- /**
456
- * @param {string} input input
457
- * @param {number} pos position
458
- * @param {number=} f first
459
- * @param {number=} s second
460
- * @param {number=} t third
461
- * @returns {boolean} true, if input at pos starts an identifier
462
- */
463
- const _ifThreeCodePointsWouldStartANumber = (input, pos, f, s, t) => {
464
- // This section describes how to check if three code points would start a number.
465
- // The algorithm described here can be called explicitly with three code points, or can be called with the input stream itself.
466
- // In the latter case, the three code points in question are the current input code point and the next two input code points, in that order.
467
-
468
- // Note: This algorithm will not consume any additional code points.
469
-
470
- const first = f || input.charCodeAt(pos - 1);
471
- const second = s || input.charCodeAt(pos);
472
- const third = t || input.charCodeAt(pos + 1);
473
-
474
- // Look at the first code point:
475
-
476
- // U+002B PLUS SIGN (+)
477
- // U+002D HYPHEN-MINUS (-)
478
- //
479
- // If the second code point is a digit, return true.
480
- // Otherwise, if the second code point is a U+002E FULL STOP (.) and the third code point is a digit, return true.
481
- // Otherwise, return false.
482
- if (first === CC_PLUS_SIGN || first === CC_HYPHEN_MINUS) {
483
- if (_isDigit(second)) {
484
- return true;
485
- } else if (second === CC_FULL_STOP && _isDigit(third)) {
486
- return true;
487
- }
488
-
489
- return false;
490
- }
491
- // U+002E FULL STOP (.)
492
- // If the second code point is a digit, return true. Otherwise, return false.
493
- else if (first === CC_FULL_STOP) {
494
- if (_isDigit(second)) {
495
- return true;
496
- }
497
-
498
- return false;
499
- }
500
- // digit
501
- // Return true.
502
- else if (_isDigit(first)) {
503
- return true;
504
- }
505
-
506
- // anything else
507
- // Return false.
508
- return false;
509
- };
510
-
511
- /** @type {CharHandler} */
512
- const consumeNumberSign = (input, pos, callbacks) => {
513
- // If the next input code point is an ident code point or the next two input code points are a valid escape, then:
514
- // - Create a <hash-token>.
515
- // - If the next 3 input code points would start an ident sequence, set the <hash-token>’s type flag to "id".
516
- // - Consume an ident sequence, and set the <hash-token>’s value to the returned string.
517
- // - Return the <hash-token>.
518
- const start = pos - 1;
519
- const first = input.charCodeAt(pos);
520
- const second = input.charCodeAt(pos + 1);
521
-
522
- if (
523
- _isIdentCodePoint(first, pos - 1) ||
524
- _ifTwoCodePointsAreValidEscape(input, pos, first, second)
525
- ) {
526
- const third = input.charCodeAt(pos + 2);
527
- let isId = false;
528
-
529
- if (
530
- _ifThreeCodePointsWouldStartAnIdentSequence(
531
- input,
532
- pos,
533
- first,
534
- second,
535
- third
536
- )
537
- ) {
538
- isId = true;
539
- }
540
-
541
- pos = _consumeAnIdentSequence(input, pos, callbacks);
542
-
543
- if (callbacks.hash !== undefined) {
544
- return callbacks.hash(input, start, pos, isId);
545
- }
546
-
547
- return pos;
548
- }
549
-
550
- if (callbacks.delim !== undefined) {
551
- return callbacks.delim(input, start, pos);
552
- }
553
-
554
- // Otherwise, return a <delim-token> with its value set to the current input code point.
555
- return pos;
556
- };
557
-
558
- /** @type {CharHandler} */
559
- const consumeHyphenMinus = (input, pos, callbacks) => {
560
- // If the input stream starts with a number, reconsume the current input code point, consume a numeric token, and return it.
561
- if (_ifThreeCodePointsWouldStartANumber(input, pos)) {
562
- pos--;
563
- return consumeANumericToken(input, pos, callbacks);
564
- }
565
- // Otherwise, if the next 2 input code points are U+002D HYPHEN-MINUS U+003E GREATER-THAN SIGN (->), consume them and return a <CDC-token>.
566
- else if (
567
- input.charCodeAt(pos) === CC_HYPHEN_MINUS &&
568
- input.charCodeAt(pos + 1) === CC_GREATER_THAN_SIGN
569
- ) {
570
- if (callbacks.cdc !== undefined) {
571
- return callbacks.cdc(input, pos - 1, pos + 2);
572
- }
573
-
574
- return pos + 2;
575
- }
576
- // Otherwise, if the input stream starts with an ident sequence, reconsume the current input code point, consume an ident-like token, and return it.
577
- else if (_ifThreeCodePointsWouldStartAnIdentSequence(input, pos)) {
578
- pos--;
579
- return consumeAnIdentLikeToken(input, pos, callbacks);
580
- }
581
-
582
- if (callbacks.delim !== undefined) {
583
- return callbacks.delim(input, pos - 1, pos);
584
- }
585
-
586
- // Otherwise, return a <delim-token> with its value set to the current input code point.
587
- return pos;
588
- };
589
-
590
- /** @type {CharHandler} */
591
- const consumeFullStop = (input, pos, callbacks) => {
592
- const start = pos - 1;
593
-
594
- // If the input stream starts with a number, reconsume the current input code point, consume a numeric token, and return it.
595
- if (_ifThreeCodePointsWouldStartANumber(input, pos)) {
596
- pos--;
597
- return consumeANumericToken(input, pos, callbacks);
598
- }
599
-
600
- // Otherwise, return a <delim-token> with its value set to the current input code point.
601
- if (callbacks.delim !== undefined) {
602
- return callbacks.delim(input, start, pos);
603
- }
604
-
605
- return pos;
606
- };
607
-
608
- /** @type {CharHandler} */
609
- const consumePlusSign = (input, pos, callbacks) => {
610
- const start = pos - 1;
611
-
612
- // If the input stream starts with a number, reconsume the current input code point, consume a numeric token, and return it.
613
- if (_ifThreeCodePointsWouldStartANumber(input, pos)) {
614
- pos--;
615
- return consumeANumericToken(input, pos, callbacks);
616
- }
617
-
618
- // Otherwise, return a <delim-token> with its value set to the current input code point.
619
- if (callbacks.delim !== undefined) {
620
- return callbacks.delim(input, start, pos);
621
- }
622
-
623
- return pos;
624
- };
625
-
626
- /** @type {CharHandler} */
627
- const _consumeANumber = (input, pos) => {
628
- // This section describes how to consume a number from a stream of code points.
629
- // It returns a numeric value, and a type which is either "integer" or "number".
630
-
631
- // Execute the following steps in order:
632
- // Initially set type to "integer". Let repr be the empty string.
633
-
634
- // If the next input code point is U+002B PLUS SIGN (+) or U+002D HYPHEN-MINUS (-), consume it and append it to repr.
635
- if (
636
- input.charCodeAt(pos) === CC_HYPHEN_MINUS ||
637
- input.charCodeAt(pos) === CC_PLUS_SIGN
638
- ) {
639
- pos++;
640
- }
641
-
642
- // While the next input code point is a digit, consume it and append it to repr.
643
- while (_isDigit(input.charCodeAt(pos))) {
644
- pos++;
645
- }
646
-
647
- // If the next 2 input code points are U+002E FULL STOP (.) followed by a digit, then:
648
- // 1. Consume the next input code point and append it to number part.
649
- // 2. While the next input code point is a digit, consume it and append it to number part.
650
- // 3. Set type to "number".
651
- if (
652
- input.charCodeAt(pos) === CC_FULL_STOP &&
653
- _isDigit(input.charCodeAt(pos + 1))
654
- ) {
655
- pos++;
656
-
657
- while (_isDigit(input.charCodeAt(pos))) {
658
- pos++;
659
- }
660
- }
661
-
662
- // If the next 2 or 3 input code points are U+0045 LATIN CAPITAL LETTER E (E) or U+0065 LATIN SMALL LETTER E (e), optionally followed by U+002D HYPHEN-MINUS (-) or U+002B PLUS SIGN (+), followed by a digit, then:
663
- // 1. Consume the next input code point.
664
- // 2. If the next input code point is "+" or "-", consume it and append it to exponent part.
665
- // 3. While the next input code point is a digit, consume it and append it to exponent part.
666
- // 4. Set type to "number".
667
- if (
668
- (input.charCodeAt(pos) === CC_LOWER_E ||
669
- input.charCodeAt(pos) === CC_UPPER_E) &&
670
- (((input.charCodeAt(pos + 1) === CC_HYPHEN_MINUS ||
671
- input.charCodeAt(pos + 1) === CC_PLUS_SIGN) &&
672
- _isDigit(input.charCodeAt(pos + 2))) ||
673
- _isDigit(input.charCodeAt(pos + 1)))
674
- ) {
675
- pos++;
676
-
677
- if (
678
- input.charCodeAt(pos) === CC_PLUS_SIGN ||
679
- input.charCodeAt(pos) === CC_HYPHEN_MINUS
680
- ) {
681
- pos++;
682
- }
683
-
684
- while (_isDigit(input.charCodeAt(pos))) {
685
- pos++;
686
- }
687
- }
688
-
689
- // Let value be the result of interpreting number part as a base-10 number.
690
-
691
- // If exponent part is non-empty, interpret it as a base-10 integer, then raise 10 to the power of the result, multiply it by value, and set value to that result.
692
-
693
- // Return value and type.
694
- return pos;
695
- };
696
-
697
- /** @type {CharHandler} */
698
- const consumeANumericToken = (input, pos, callbacks) => {
699
- // This section describes how to consume a numeric token from a stream of code points.
700
- // It returns either a <number-token>, <percentage-token>, or <dimension-token>.
701
-
702
- const start = pos;
703
-
704
- // Consume a number and let number be the result.
705
- pos = _consumeANumber(input, pos, callbacks);
706
-
707
- // If the next 3 input code points would start an ident sequence, then:
708
- //
709
- // - Create a <dimension-token> with the same value and type flag as number, and a unit set initially to the empty string.
710
- // - Consume an ident sequence. Set the <dimension-token>’s unit to the returned value.
711
- // - Return the <dimension-token>.
712
-
713
- const first = input.charCodeAt(pos);
714
- const second = input.charCodeAt(pos + 1);
715
- const third = input.charCodeAt(pos + 2);
716
-
717
- if (
718
- _ifThreeCodePointsWouldStartAnIdentSequence(
719
- input,
720
- pos,
721
- first,
722
- second,
723
- third
724
- )
725
- ) {
726
- pos = _consumeAnIdentSequence(input, pos, callbacks);
727
-
728
- if (callbacks.dimension !== undefined) {
729
- return callbacks.dimension(input, start, pos);
730
- }
731
-
732
- return pos;
733
- }
734
- // Otherwise, if the next input code point is U+0025 PERCENTAGE SIGN (%), consume it.
735
- // Create a <percentage-token> with the same value as number, and return it.
736
- else if (first === CC_PERCENTAGE) {
737
- if (callbacks.percentage !== undefined) {
738
- return callbacks.percentage(input, start, pos + 1);
739
- }
740
-
741
- return pos + 1;
742
- }
743
-
744
- // Otherwise, create a <number-token> with the same value and type flag as number, and return it.
745
- if (callbacks.number !== undefined) {
746
- return callbacks.number(input, start, pos);
747
- }
748
-
749
- return pos;
750
- };
751
-
752
- /** @type {CharHandler} */
753
- const consumeColon = (input, pos, callbacks) => {
754
- // Return a <colon-token>.
755
- if (callbacks.colon !== undefined) {
756
- return callbacks.colon(input, pos - 1, pos);
757
- }
758
-
759
- return pos;
760
- };
761
-
762
- /** @type {CharHandler} */
763
- const consumeLeftParenthesis = (input, pos, callbacks) => {
764
- // Return a <(-token>.
765
- if (callbacks.leftParenthesis !== undefined) {
766
- return callbacks.leftParenthesis(input, pos - 1, pos);
767
- }
768
-
769
- return pos;
770
- };
771
-
772
- /** @type {CharHandler} */
773
- const consumeRightParenthesis = (input, pos, callbacks) => {
774
- // Return a <)-token>.
775
- if (callbacks.rightParenthesis !== undefined) {
776
- return callbacks.rightParenthesis(input, pos - 1, pos);
777
- }
778
-
779
- return pos;
780
- };
781
-
782
- /** @type {CharHandler} */
783
- const consumeLeftSquareBracket = (input, pos, callbacks) => {
784
- // Return a <]-token>.
785
- if (callbacks.leftSquareBracket !== undefined) {
786
- return callbacks.leftSquareBracket(input, pos - 1, pos);
787
- }
788
-
789
- return pos;
790
- };
791
-
792
- /** @type {CharHandler} */
793
- const consumeRightSquareBracket = (input, pos, callbacks) => {
794
- // Return a <]-token>.
795
- if (callbacks.rightSquareBracket !== undefined) {
796
- return callbacks.rightSquareBracket(input, pos - 1, pos);
797
- }
798
-
799
- return pos;
800
- };
801
-
802
- /** @type {CharHandler} */
803
- const consumeLeftCurlyBracket = (input, pos, callbacks) => {
804
- // Return a <{-token>.
805
- if (callbacks.leftCurlyBracket !== undefined) {
806
- return callbacks.leftCurlyBracket(input, pos - 1, pos);
807
- }
808
-
809
- return pos;
810
- };
811
-
812
- /** @type {CharHandler} */
813
- const consumeRightCurlyBracket = (input, pos, callbacks) => {
814
- // Return a <}-token>.
815
- if (callbacks.rightCurlyBracket !== undefined) {
816
- return callbacks.rightCurlyBracket(input, pos - 1, pos);
817
- }
818
-
819
- return pos;
820
- };
821
-
822
- /** @type {CharHandler} */
823
- const consumeSemicolon = (input, pos, callbacks) => {
824
- // Return a <semicolon-token>.
825
- if (callbacks.semicolon !== undefined) {
826
- return callbacks.semicolon(input, pos - 1, pos);
827
- }
828
-
829
- return pos;
830
- };
831
-
832
- /** @type {CharHandler} */
833
- const consumeComma = (input, pos, callbacks) => {
834
- // Return a <comma-token>.
835
- if (callbacks.comma !== undefined) {
836
- return callbacks.comma(input, pos - 1, pos);
837
- }
838
-
839
- return pos;
840
- };
841
-
842
- /** @type {CharHandler} */
843
- const _consumeAnIdentSequence = (input, pos) => {
844
- // This section describes how to consume an ident sequence from a stream of code points.
845
- // It returns a string containing the largest name that can be formed from adjacent code points in the stream, starting from the first.
846
-
847
- // Note: This algorithm does not do the verification of the first few code points that are necessary to ensure the returned code points would constitute an <ident-token>.
848
- // If that is the intended use, ensure that the stream starts with an ident sequence before calling this algorithm.
849
-
850
- // Let result initially be an empty string.
851
-
852
- // Repeatedly consume the next input code point from the stream:
853
- for (;;) {
854
- const cc = input.charCodeAt(pos);
855
- pos++;
856
-
857
- // ident code point
858
- // Append the code point to result.
859
- if (_isIdentCodePoint(cc, pos - 1)) {
860
- // Nothing
861
- }
862
- // the stream starts with a valid escape
863
- // Consume an escaped code point. Append the returned code point to result.
864
- else if (_ifTwoCodePointsAreValidEscape(input, pos)) {
865
- pos = _consumeAnEscapedCodePoint(input, pos);
866
- }
867
- // anything else
868
- // Reconsume the current input code point. Return result.
869
- else {
870
- return pos - 1;
871
- }
872
- }
873
- };
874
-
875
- /**
876
- * @param {number} cc char code
877
- * @returns {boolean} true, when cc is the non-printable code point, otherwise false
878
- */
879
- const _isNonPrintableCodePoint = (cc) =>
880
- (cc >= 0x00 && cc <= 0x08) ||
881
- cc === 0x0b ||
882
- (cc >= 0x0e && cc <= 0x1f) ||
883
- cc === 0x7f;
884
-
885
- /**
886
- * @param {string} input input
887
- * @param {number} pos position
888
- * @returns {number} position
889
- */
890
- const consumeTheRemnantsOfABadUrl = (input, pos) => {
891
- // This section describes how to consume the remnants of a bad url from a stream of code points,
892
- // "cleaning up" after the tokenizer realizes that it’s in the middle of a <bad-url-token> rather than a <url-token>.
893
- // It returns nothing; its sole use is to consume enough of the input stream to reach a recovery point where normal tokenizing can resume.
894
-
895
- // Repeatedly consume the next input code point from the stream:
896
- for (;;) {
897
- // EOF
898
- // Return.
899
- if (pos === input.length) {
900
- return pos;
901
- }
902
-
903
- const cc = input.charCodeAt(pos);
904
- pos++;
905
-
906
- // U+0029 RIGHT PARENTHESIS ())
907
- // Return.
908
- if (cc === CC_RIGHT_PARENTHESIS) {
909
- return pos;
910
- }
911
- // the input stream starts with a valid escape
912
- // Consume an escaped code point.
913
- // This allows an escaped right parenthesis ("\)") to be encountered without ending the <bad-url-token>.
914
- // This is otherwise identical to the "anything else" clause.
915
- else if (_ifTwoCodePointsAreValidEscape(input, pos)) {
916
- pos = _consumeAnEscapedCodePoint(input, pos);
917
- }
918
- // anything else
919
- // Do nothing.
920
- else {
921
- // Do nothing.
922
- }
923
- }
924
- };
925
-
926
- /**
927
- * @param {string} input input
928
- * @param {number} pos position
929
- * @param {number} fnStart start
930
- * @param {CssTokenCallbacks} callbacks callbacks
931
- * @returns {pos} pos
932
- */
933
- const consumeAUrlToken = (input, pos, fnStart, callbacks) => {
934
- // This section describes how to consume a url token from a stream of code points.
935
- // It returns either a <url-token> or a <bad-url-token>.
936
-
937
- // Note: This algorithm assumes that the initial "url(" has already been consumed.
938
- // This algorithm also assumes that it’s being called to consume an "unquoted" value, like url(foo).
939
- // A quoted value, like url("foo"), is parsed as a <function-token>.
940
- // Consume an ident-like token automatically handles this distinction; this algorithm shouldn’t be called directly otherwise.
941
-
942
- // Initially create a <url-token> with its value set to the empty string.
943
-
944
- // Consume as much whitespace as possible.
945
- while (_isWhiteSpace(input.charCodeAt(pos))) {
946
- pos++;
947
- }
948
-
949
- const contentStart = pos;
950
-
951
- // Repeatedly consume the next input code point from the stream:
952
- for (;;) {
953
- // EOF
954
- // This is a parse error. Return the <url-token>.
955
- if (pos === input.length) {
956
- if (callbacks.url !== undefined) {
957
- return callbacks.url(input, fnStart, pos, contentStart, pos - 1);
958
- }
959
-
960
- return pos;
961
- }
962
-
963
- const cc = input.charCodeAt(pos);
964
- pos++;
965
-
966
- // U+0029 RIGHT PARENTHESIS ())
967
- // Return the <url-token>.
968
- if (cc === CC_RIGHT_PARENTHESIS) {
969
- if (callbacks.url !== undefined) {
970
- return callbacks.url(input, fnStart, pos, contentStart, pos - 1);
971
- }
972
-
973
- return pos;
974
- }
975
- // whitespace
976
- // Consume as much whitespace as possible.
977
- // If the next input code point is U+0029 RIGHT PARENTHESIS ()) or EOF, consume it and return the <url-token>
978
- // (if EOF was encountered, this is a parse error); otherwise, consume the remnants of a bad url, create a <bad-url-token>, and return it.
979
- else if (_isWhiteSpace(cc)) {
980
- const end = pos - 1;
981
-
982
- while (_isWhiteSpace(input.charCodeAt(pos))) {
983
- pos++;
984
- }
985
-
986
- if (pos === input.length) {
987
- if (callbacks.url !== undefined) {
988
- return callbacks.url(input, fnStart, pos, contentStart, end);
989
- }
990
-
991
- return pos;
992
- }
993
-
994
- if (input.charCodeAt(pos) === CC_RIGHT_PARENTHESIS) {
995
- pos++;
996
-
997
- if (callbacks.url !== undefined) {
998
- return callbacks.url(input, fnStart, pos, contentStart, end);
999
- }
1000
-
1001
- return pos;
1002
- }
1003
-
1004
- // Don't handle bad urls
1005
- pos = consumeTheRemnantsOfABadUrl(input, pos);
1006
-
1007
- if (callbacks.badUrlToken !== undefined) {
1008
- return callbacks.badUrlToken(input, fnStart, pos);
1009
- }
1010
-
1011
- return pos;
1012
- }
1013
- // U+0022 QUOTATION MARK (")
1014
- // U+0027 APOSTROPHE (')
1015
- // U+0028 LEFT PARENTHESIS (()
1016
- // non-printable code point
1017
- // This is a parse error. Consume the remnants of a bad url, create a <bad-url-token>, and return it.
1018
- else if (
1019
- cc === CC_QUOTATION_MARK ||
1020
- cc === CC_APOSTROPHE ||
1021
- cc === CC_LEFT_PARENTHESIS ||
1022
- _isNonPrintableCodePoint(cc)
1023
- ) {
1024
- // Don't handle bad urls
1025
- pos = consumeTheRemnantsOfABadUrl(input, pos);
1026
-
1027
- if (callbacks.badUrlToken !== undefined) {
1028
- return callbacks.badUrlToken(input, fnStart, pos);
1029
- }
1030
-
1031
- return pos;
1032
- }
1033
- // // U+005C REVERSE SOLIDUS (\)
1034
- // // If the stream starts with a valid escape, consume an escaped code point and append the returned code point to the <url-token>’s value.
1035
- // // Otherwise, this is a parse error. Consume the remnants of a bad url, create a <bad-url-token>, and return it.
1036
- else if (cc === CC_REVERSE_SOLIDUS) {
1037
- if (_ifTwoCodePointsAreValidEscape(input, pos)) {
1038
- pos = _consumeAnEscapedCodePoint(input, pos);
1039
- } else {
1040
- // Don't handle bad urls
1041
- pos = consumeTheRemnantsOfABadUrl(input, pos);
1042
-
1043
- if (callbacks.badUrlToken !== undefined) {
1044
- return callbacks.badUrlToken(input, fnStart, pos);
1045
- }
1046
-
1047
- return pos;
1048
- }
1049
- }
1050
- // anything else
1051
- // Append the current input code point to the <url-token>’s value.
1052
- else {
1053
- // Nothing
1054
- }
1055
- }
1056
- };
1057
-
1058
- /** @type {CharHandler} */
1059
- const consumeAnIdentLikeToken = (input, pos, callbacks) => {
1060
- const start = pos;
1061
- // This section describes how to consume an ident-like token from a stream of code points.
1062
- // It returns an <ident-token>, <function-token>, <url-token>, or <bad-url-token>.
1063
- pos = _consumeAnIdentSequence(input, pos, callbacks);
1064
-
1065
- // If string’s value is an ASCII case-insensitive match for "url", and the next input code point is U+0028 LEFT PARENTHESIS ((), consume it.
1066
- // While the next two input code points are whitespace, consume the next input code point.
1067
- // If the next one or two input code points are U+0022 QUOTATION MARK ("), U+0027 APOSTROPHE ('), or whitespace followed by U+0022 QUOTATION MARK (") or U+0027 APOSTROPHE ('), then create a <function-token> with its value set to string and return it.
1068
- // Otherwise, consume a url token, and return it.
1069
- if (
1070
- input.slice(start, pos).toLowerCase() === "url" &&
1071
- input.charCodeAt(pos) === CC_LEFT_PARENTHESIS
1072
- ) {
1073
- pos++;
1074
- const end = pos;
1075
-
1076
- while (
1077
- _isWhiteSpace(input.charCodeAt(pos)) &&
1078
- _isWhiteSpace(input.charCodeAt(pos + 1))
1079
- ) {
1080
- pos++;
1081
- }
1082
-
1083
- if (
1084
- input.charCodeAt(pos) === CC_QUOTATION_MARK ||
1085
- input.charCodeAt(pos) === CC_APOSTROPHE ||
1086
- (_isWhiteSpace(input.charCodeAt(pos)) &&
1087
- (input.charCodeAt(pos + 1) === CC_QUOTATION_MARK ||
1088
- input.charCodeAt(pos + 1) === CC_APOSTROPHE))
1089
- ) {
1090
- if (callbacks.function !== undefined) {
1091
- return callbacks.function(input, start, end);
1092
- }
1093
-
1094
- return pos;
1095
- }
1096
-
1097
- return consumeAUrlToken(input, pos, start, callbacks);
1098
- }
1099
-
1100
- // Otherwise, if the next input code point is U+0028 LEFT PARENTHESIS ((), consume it.
1101
- // Create a <function-token> with its value set to string and return it.
1102
- if (input.charCodeAt(pos) === CC_LEFT_PARENTHESIS) {
1103
- pos++;
1104
-
1105
- if (callbacks.function !== undefined) {
1106
- return callbacks.function(input, start, pos);
1107
- }
1108
-
1109
- return pos;
1110
- }
1111
-
1112
- // Otherwise, create an <ident-token> with its value set to string and return it.
1113
- if (callbacks.identifier !== undefined) {
1114
- return callbacks.identifier(input, start, pos);
1115
- }
1116
-
1117
- return pos;
1118
- };
1119
-
1120
- /** @type {CharHandler} */
1121
- const consumeLessThan = (input, pos, callbacks) => {
1122
- // If the next 3 input code points are U+0021 EXCLAMATION MARK U+002D HYPHEN-MINUS U+002D HYPHEN-MINUS (!--), consume them and return a <CDO-token>.
1123
- if (input.slice(pos, pos + 3) === "!--") {
1124
- if (callbacks.cdo !== undefined) {
1125
- return callbacks.cdo(input, pos - 1, pos + 3);
1126
- }
1127
-
1128
- return pos + 3;
1129
- }
1130
-
1131
- if (callbacks.delim !== undefined) {
1132
- return callbacks.delim(input, pos - 1, pos);
1133
- }
1134
-
1135
- // Otherwise, return a <delim-token> with its value set to the current input code point.
1136
- return pos;
1137
- };
1138
-
1139
- /** @type {CharHandler} */
1140
- const consumeCommercialAt = (input, pos, callbacks) => {
1141
- const start = pos - 1;
1142
-
1143
- // If the next 3 input code points would start an ident sequence, consume an ident sequence, create an <at-keyword-token> with its value set to the returned value, and return it.
1144
- if (
1145
- _ifThreeCodePointsWouldStartAnIdentSequence(
1146
- input,
1147
- pos,
1148
- input.charCodeAt(pos),
1149
- input.charCodeAt(pos + 1),
1150
- input.charCodeAt(pos + 2)
1151
- )
1152
- ) {
1153
- pos = _consumeAnIdentSequence(input, pos, callbacks);
1154
-
1155
- if (callbacks.atKeyword !== undefined) {
1156
- pos = callbacks.atKeyword(input, start, pos);
1157
- }
1158
-
1159
- return pos;
1160
- }
1161
-
1162
- // Otherwise, return a <delim-token> with its value set to the current input code point.
1163
- if (callbacks.delim !== undefined) {
1164
- return callbacks.delim(input, start, pos);
1165
- }
1166
-
1167
- return pos;
1168
- };
1169
-
1170
- /** @type {CharHandler} */
1171
- const consumeReverseSolidus = (input, pos, callbacks) => {
1172
- // If the input stream starts with a valid escape, reconsume the current input code point, consume an ident-like token, and return it.
1173
- if (_ifTwoCodePointsAreValidEscape(input, pos)) {
1174
- pos--;
1175
- return consumeAnIdentLikeToken(input, pos, callbacks);
1176
- }
1177
-
1178
- // Otherwise, this is a parse error. Return a <delim-token> with its value set to the current input code point.
1179
- if (callbacks.delim !== undefined) {
1180
- return callbacks.delim(input, pos - 1, pos);
1181
- }
1182
-
1183
- return pos;
1184
- };
1185
-
1186
- /** @type {CharHandler} */
1187
- const consumeAToken = (input, pos, callbacks) => {
1188
- const cc = input.charCodeAt(pos - 1);
1189
-
1190
- // https://drafts.csswg.org/css-syntax/#consume-token
1191
- switch (cc) {
1192
- // whitespace
1193
- case CC_LINE_FEED:
1194
- case CC_CARRIAGE_RETURN:
1195
- case CC_FORM_FEED:
1196
- case CC_TAB:
1197
- case CC_SPACE:
1198
- return consumeSpace(input, pos, callbacks);
1199
- // U+0022 QUOTATION MARK (")
1200
- case CC_QUOTATION_MARK:
1201
- return consumeAStringToken(input, pos, callbacks);
1202
- // U+0023 NUMBER SIGN (#)
1203
- case CC_NUMBER_SIGN:
1204
- return consumeNumberSign(input, pos, callbacks);
1205
- // U+0027 APOSTROPHE (')
1206
- case CC_APOSTROPHE:
1207
- return consumeAStringToken(input, pos, callbacks);
1208
- // U+0028 LEFT PARENTHESIS (()
1209
- case CC_LEFT_PARENTHESIS:
1210
- return consumeLeftParenthesis(input, pos, callbacks);
1211
- // U+0029 RIGHT PARENTHESIS ())
1212
- case CC_RIGHT_PARENTHESIS:
1213
- return consumeRightParenthesis(input, pos, callbacks);
1214
- // U+002B PLUS SIGN (+)
1215
- case CC_PLUS_SIGN:
1216
- return consumePlusSign(input, pos, callbacks);
1217
- // U+002C COMMA (,)
1218
- case CC_COMMA:
1219
- return consumeComma(input, pos, callbacks);
1220
- // U+002D HYPHEN-MINUS (-)
1221
- case CC_HYPHEN_MINUS:
1222
- return consumeHyphenMinus(input, pos, callbacks);
1223
- // U+002E FULL STOP (.)
1224
- case CC_FULL_STOP:
1225
- return consumeFullStop(input, pos, callbacks);
1226
- // U+003A COLON (:)
1227
- case CC_COLON:
1228
- return consumeColon(input, pos, callbacks);
1229
- // U+003B SEMICOLON (;)
1230
- case CC_SEMICOLON:
1231
- return consumeSemicolon(input, pos, callbacks);
1232
- // U+003C LESS-THAN SIGN (<)
1233
- case CC_LESS_THAN_SIGN:
1234
- return consumeLessThan(input, pos, callbacks);
1235
- // U+0040 COMMERCIAL AT (@)
1236
- case CC_AT_SIGN:
1237
- return consumeCommercialAt(input, pos, callbacks);
1238
- // U+005B LEFT SQUARE BRACKET ([)
1239
- case CC_LEFT_SQUARE:
1240
- return consumeLeftSquareBracket(input, pos, callbacks);
1241
- // U+005C REVERSE SOLIDUS (\)
1242
- case CC_REVERSE_SOLIDUS:
1243
- return consumeReverseSolidus(input, pos, callbacks);
1244
- // U+005D RIGHT SQUARE BRACKET (])
1245
- case CC_RIGHT_SQUARE:
1246
- return consumeRightSquareBracket(input, pos, callbacks);
1247
- // U+007B LEFT CURLY BRACKET ({)
1248
- case CC_LEFT_CURLY:
1249
- return consumeLeftCurlyBracket(input, pos, callbacks);
1250
- // U+007D RIGHT CURLY BRACKET (})
1251
- case CC_RIGHT_CURLY:
1252
- return consumeRightCurlyBracket(input, pos, callbacks);
1253
- default:
1254
- // digit
1255
- // Reconsume the current input code point, consume a numeric token, and return it.
1256
- if (_isDigit(cc)) {
1257
- pos--;
1258
- return consumeANumericToken(input, pos, callbacks);
1259
- } else if (cc === CC_LOWER_U || cc === CC_UPPER_U) {
1260
- // If unicode ranges allowed is true and the input stream would start a unicode-range,
1261
- // reconsume the current input code point, consume a unicode-range token, and return it.
1262
- // Skip now
1263
- // if (_ifThreeCodePointsWouldStartAUnicodeRange(input, pos)) {
1264
- // pos--;
1265
- // return consumeAUnicodeRangeToken(input, pos, callbacks);
1266
- // }
1267
-
1268
- // Otherwise, reconsume the current input code point, consume an ident-like token, and return it.
1269
- pos--;
1270
- return consumeAnIdentLikeToken(input, pos, callbacks);
1271
- }
1272
- // ident-start code point
1273
- // Reconsume the current input code point, consume an ident-like token, and return it.
1274
- else if (isIdentStartCodePoint(cc)) {
1275
- pos--;
1276
- return consumeAnIdentLikeToken(input, pos, callbacks);
1277
- }
1278
-
1279
- // EOF, but we don't have it
1280
-
1281
- // anything else
1282
- // Return a <delim-token> with its value set to the current input code point.
1283
- return consumeDelimToken(input, pos, callbacks);
1284
- }
1285
- };
1286
-
1287
- /**
1288
- * @param {string} input input css
1289
- * @param {number=} pos pos
1290
- * @param {CssTokenCallbacks=} callbacks callbacks
1291
- * @returns {number} pos
1292
- */
1293
- module.exports = (input, pos = 0, callbacks = {}) => {
1294
- // This section describes how to consume a token from a stream of code points. It will return a single token of any type.
1295
- while (pos < input.length) {
1296
- // Consume comments.
1297
- pos = consumeComments(input, pos, callbacks);
1298
-
1299
- // Consume the next input code point.
1300
- pos++;
1301
- pos = consumeAToken(input, pos, callbacks);
1302
-
1303
- if (callbacks.needTerminate && callbacks.needTerminate()) {
1304
- break;
1305
- }
1306
- }
1307
-
1308
- return pos;
1309
- };
1310
-
1311
- /**
1312
- * @param {string} input input css
1313
- * @param {number} pos pos
1314
- * @param {CssTokenCallbacks} callbacks callbacks
1315
- * @param {CssTokenCallbacks=} additional additional callbacks
1316
- * @param {{ onlyTopLevel?: boolean, declarationValue?: boolean, atRulePrelude?: boolean, functionValue?: boolean }=} options options
1317
- * @returns {number} pos
1318
- */
1319
- const consumeUntil = (input, pos, callbacks, additional, options = {}) => {
1320
- let needHandle = true;
1321
- let needTerminate = false;
1322
-
1323
- /** @type {CssTokenCallbacks} */
1324
- const servicedCallbacks = {};
1325
-
1326
- let balanced = 0;
1327
-
1328
- if (options.onlyTopLevel) {
1329
- servicedCallbacks.function = (input, start, end) => {
1330
- balanced++;
1331
- if (!options.functionValue) {
1332
- needHandle = false;
1333
- }
1334
-
1335
- if (additional && additional.function !== undefined) {
1336
- return additional.function(input, start, end);
1337
- }
1338
-
1339
- return end;
1340
- };
1341
-
1342
- servicedCallbacks.leftParenthesis = (_input, _start, end) => {
1343
- balanced++;
1344
- needHandle = false;
1345
- return end;
1346
- };
1347
- servicedCallbacks.rightParenthesis = (_input, _start, end) => {
1348
- balanced--;
1349
- if (balanced === 0) {
1350
- needHandle = true;
1351
- }
1352
- return end;
1353
- };
1354
- }
1355
-
1356
- if (options.declarationValue) {
1357
- servicedCallbacks.semicolon = (_input, _start, end) => {
1358
- needTerminate = true;
1359
- return end;
1360
- };
1361
-
1362
- servicedCallbacks.rightCurlyBracket = (_input, _start, end) => {
1363
- needTerminate = true;
1364
- return end;
1365
- };
1366
- } else if (options.functionValue) {
1367
- servicedCallbacks.rightParenthesis = (_input, _start, end) => {
1368
- balanced--;
1369
- if (balanced === 0) {
1370
- needTerminate = true;
1371
- }
1372
- return end;
1373
- };
1374
- } else if (options.atRulePrelude) {
1375
- servicedCallbacks.leftCurlyBracket = (_input, _start, end) => {
1376
- needTerminate = true;
1377
- return end;
1378
- };
1379
- servicedCallbacks.semicolon = (_input, _start, end) => {
1380
- needTerminate = true;
1381
- return end;
1382
- };
1383
- }
1384
-
1385
- const mergedCallbacks = { ...servicedCallbacks, ...callbacks };
1386
-
1387
- while (pos < input.length) {
1388
- // Consume comments.
1389
- pos = consumeComments(
1390
- input,
1391
- pos,
1392
- needHandle ? mergedCallbacks : servicedCallbacks
1393
- );
1394
-
1395
- const start = pos;
1396
-
1397
- // Consume the next input code point.
1398
- pos++;
1399
- pos = consumeAToken(
1400
- input,
1401
- pos,
1402
- needHandle ? mergedCallbacks : servicedCallbacks
1403
- );
1404
-
1405
- if (needTerminate) {
1406
- return start;
1407
- }
1408
- }
1409
-
1410
- return pos;
1411
- };
1412
-
1413
- /**
1414
- * @param {string} input input
1415
- * @param {number} pos position
1416
- * @returns {number} position after comments
1417
- */
1418
- const eatComments = (input, pos) => {
1419
- for (;;) {
1420
- const originalPos = pos;
1421
- pos = consumeComments(input, pos, {});
1422
- if (originalPos === pos) {
1423
- break;
1424
- }
1425
- }
1426
-
1427
- return pos;
1428
- };
1429
-
1430
- /**
1431
- * @param {string} input input
1432
- * @param {number} pos position
1433
- * @returns {number} position after whitespace
1434
- */
1435
- const eatWhitespace = (input, pos) => {
1436
- while (_isWhiteSpace(input.charCodeAt(pos))) {
1437
- pos++;
1438
- }
1439
-
1440
- return pos;
1441
- };
1442
-
1443
- /**
1444
- * @param {string} input input
1445
- * @param {number} pos position
1446
- * @returns {[number, boolean]} position after whitespace and comments
1447
- */
1448
- const eatWhitespaceAndComments = (input, pos) => {
1449
- let foundWhitespace = false;
1450
-
1451
- for (;;) {
1452
- const originalPos = pos;
1453
- pos = consumeComments(input, pos, {});
1454
- while (_isWhiteSpace(input.charCodeAt(pos))) {
1455
- if (!foundWhitespace) {
1456
- foundWhitespace = true;
1457
- }
1458
- pos++;
1459
- }
1460
- if (originalPos === pos) {
1461
- break;
1462
- }
1463
- }
1464
-
1465
- return [pos, foundWhitespace];
1466
- };
1467
-
1468
- /**
1469
- * @param {string} input input
1470
- * @param {number} pos position
1471
- * @returns {number} position after whitespace
1472
- */
1473
- const eatWhiteLine = (input, pos) => {
1474
- for (;;) {
1475
- const cc = input.charCodeAt(pos);
1476
- if (_isSpace(cc)) {
1477
- pos++;
1478
- continue;
1479
- }
1480
- if (_isNewline(cc)) pos++;
1481
- pos = consumeExtraNewline(cc, input, pos);
1482
- break;
1483
- }
1484
-
1485
- return pos;
1486
- };
1487
-
1488
- /**
1489
- * @param {string} input input
1490
- * @param {number} pos position
1491
- * @returns {[number, number] | undefined} positions of ident sequence
1492
- */
1493
- const skipCommentsAndEatIdentSequence = (input, pos) => {
1494
- pos = eatComments(input, pos);
1495
-
1496
- const start = pos;
1497
-
1498
- if (
1499
- _ifThreeCodePointsWouldStartAnIdentSequence(
1500
- input,
1501
- pos,
1502
- input.charCodeAt(pos),
1503
- input.charCodeAt(pos + 1),
1504
- input.charCodeAt(pos + 2)
1505
- )
1506
- ) {
1507
- return [start, _consumeAnIdentSequence(input, pos, {})];
1508
- }
1509
-
1510
- return undefined;
1511
- };
1512
-
1513
- /**
1514
- * @param {string} input input
1515
- * @param {number} pos position
1516
- * @returns {[number, number] | undefined} positions of ident sequence
1517
- */
1518
- const eatString = (input, pos) => {
1519
- pos = eatWhitespaceAndComments(input, pos)[0];
1520
-
1521
- const start = pos;
1522
-
1523
- if (
1524
- input.charCodeAt(pos) === CC_QUOTATION_MARK ||
1525
- input.charCodeAt(pos) === CC_APOSTROPHE
1526
- ) {
1527
- return [start, consumeAStringToken(input, pos + 1, {})];
1528
- }
1529
-
1530
- return undefined;
1531
- };
1532
-
1533
- /**
1534
- * @param {string} input input
1535
- * @param {number} pos position
1536
- * @param {CssTokenCallbacks} cbs callbacks
1537
- * @returns {[number, number][]} positions of ident sequence
1538
- */
1539
- const eatImageSetStrings = (input, pos, cbs) => {
1540
- /** @type {[number, number][]} */
1541
- const result = [];
1542
-
1543
- let isFirst = true;
1544
- let needStop = false;
1545
- // We already in `func(` token
1546
- let balanced = 1;
1547
-
1548
- /** @type {CssTokenCallbacks} */
1549
- const callbacks = {
1550
- ...cbs,
1551
- string: (_input, start, end) => {
1552
- if (isFirst && balanced === 1) {
1553
- result.push([start, end]);
1554
- isFirst = false;
1555
- }
1556
-
1557
- return end;
1558
- },
1559
- comma: (_input, _start, end) => {
1560
- if (balanced === 1) {
1561
- isFirst = true;
1562
- }
1563
-
1564
- return end;
1565
- },
1566
- leftParenthesis: (input, start, end) => {
1567
- balanced++;
1568
-
1569
- return end;
1570
- },
1571
- function: (_input, start, end) => {
1572
- balanced++;
1573
-
1574
- return end;
1575
- },
1576
- rightParenthesis: (_input, _start, end) => {
1577
- balanced--;
1578
-
1579
- if (balanced === 0) {
1580
- needStop = true;
1581
- }
1582
-
1583
- return end;
1584
- }
1585
- };
1586
-
1587
- while (pos < input.length) {
1588
- // Consume comments.
1589
- pos = consumeComments(input, pos, callbacks);
1590
-
1591
- // Consume the next input code point.
1592
- pos++;
1593
- pos = consumeAToken(input, pos, callbacks);
1594
-
1595
- if (needStop) {
1596
- break;
1597
- }
1598
- }
1599
-
1600
- return result;
1601
- };
1602
-
1603
- /**
1604
- * @param {string} input input
1605
- * @param {number} pos position
1606
- * @param {CssTokenCallbacks} cbs callbacks
1607
- * @returns {[[number, number, number, number] | undefined, [number, number] | undefined, [number, number] | undefined, [number, number] | undefined]} positions of top level tokens
1608
- */
1609
- const eatImportTokens = (input, pos, cbs) => {
1610
- const result =
1611
- /** @type {[[number, number, number, number] | undefined, [number, number] | undefined, [number, number] | undefined, [number, number] | undefined]} */
1612
- (Array.from({ length: 4 }));
1613
-
1614
- /** @type {0 | 1 | 2 | undefined} */
1615
- let scope;
1616
- let needStop = false;
1617
- let balanced = 0;
1618
-
1619
- /** @type {CssTokenCallbacks} */
1620
- const callbacks = {
1621
- ...cbs,
1622
- url: (_input, start, end, contentStart, contentEnd) => {
1623
- if (
1624
- result[0] === undefined &&
1625
- balanced === 0 &&
1626
- result[1] === undefined &&
1627
- result[2] === undefined &&
1628
- result[3] === undefined
1629
- ) {
1630
- result[0] = [start, end, contentStart, contentEnd];
1631
- scope = undefined;
1632
- }
1633
-
1634
- return end;
1635
- },
1636
- string: (_input, start, end) => {
1637
- if (
1638
- balanced === 0 &&
1639
- result[0] === undefined &&
1640
- result[1] === undefined &&
1641
- result[2] === undefined &&
1642
- result[3] === undefined
1643
- ) {
1644
- result[0] = [start, end, start + 1, end - 1];
1645
- scope = undefined;
1646
- } else if (result[0] !== undefined && scope === 0) {
1647
- result[0][2] = start + 1;
1648
- result[0][3] = end - 1;
1649
- }
1650
-
1651
- return end;
1652
- },
1653
- leftParenthesis: (_input, _start, end) => {
1654
- balanced++;
1655
-
1656
- return end;
1657
- },
1658
- rightParenthesis: (_input, _start, end) => {
1659
- balanced--;
1660
-
1661
- if (balanced === 0 && scope !== undefined) {
1662
- /** @type {[number, number]} */
1663
- (result[scope])[1] = end;
1664
- scope = undefined;
1665
- }
1666
-
1667
- return end;
1668
- },
1669
- function: (input, start, end) => {
1670
- if (balanced === 0) {
1671
- const name = input
1672
- .slice(start, end - 1)
1673
- .replace(/\\/g, "")
1674
- .toLowerCase();
1675
-
1676
- if (
1677
- name === "url" &&
1678
- result[0] === undefined &&
1679
- result[1] === undefined &&
1680
- result[2] === undefined &&
1681
- result[3] === undefined
1682
- ) {
1683
- scope = 0;
1684
- result[scope] = [start, end + 1, end + 1, end + 1];
1685
- } else if (
1686
- name === "layer" &&
1687
- result[1] === undefined &&
1688
- result[2] === undefined
1689
- ) {
1690
- scope = 1;
1691
- result[scope] = [start, end];
1692
- } else if (name === "supports" && result[2] === undefined) {
1693
- scope = 2;
1694
- result[scope] = [start, end];
1695
- } else {
1696
- scope = undefined;
1697
- }
1698
- }
1699
-
1700
- balanced++;
1701
-
1702
- return end;
1703
- },
1704
- identifier: (input, start, end) => {
1705
- if (
1706
- balanced === 0 &&
1707
- result[1] === undefined &&
1708
- result[2] === undefined
1709
- ) {
1710
- const name = input.slice(start, end).replace(/\\/g, "").toLowerCase();
1711
-
1712
- if (name === "layer") {
1713
- result[1] = [start, end];
1714
- scope = undefined;
1715
- }
1716
- }
1717
-
1718
- return end;
1719
- },
1720
- semicolon: (_input, start, end) => {
1721
- if (balanced === 0) {
1722
- needStop = true;
1723
- result[3] = [start, end];
1724
- }
1725
-
1726
- return end;
1727
- }
1728
- };
1729
-
1730
- while (pos < input.length) {
1731
- // Consume comments.
1732
- pos = consumeComments(input, pos, callbacks);
1733
-
1734
- // Consume the next input code point.
1735
- pos++;
1736
- pos = consumeAToken(input, pos, callbacks);
1737
-
1738
- if (needStop) {
1739
- break;
1740
- }
1741
- }
1742
-
1743
- return result;
1744
- };
1745
-
1746
- /**
1747
- * @param {string} input input
1748
- * @param {number} pos position
1749
- * @returns {[number, number] | undefined} positions of ident sequence
1750
- */
1751
- const eatIdentSequence = (input, pos) => {
1752
- pos = eatWhitespaceAndComments(input, pos)[0];
1753
-
1754
- const start = pos;
1755
-
1756
- if (
1757
- _ifThreeCodePointsWouldStartAnIdentSequence(
1758
- input,
1759
- pos,
1760
- input.charCodeAt(pos),
1761
- input.charCodeAt(pos + 1),
1762
- input.charCodeAt(pos + 2)
1763
- )
1764
- ) {
1765
- return [start, _consumeAnIdentSequence(input, pos, {})];
1766
- }
1767
-
1768
- return undefined;
1769
- };
1770
-
1771
- /**
1772
- * @param {string} input input
1773
- * @param {number} pos position
1774
- * @returns {[number, number, boolean] | undefined} positions of ident sequence or string
1775
- */
1776
- const eatIdentSequenceOrString = (input, pos) => {
1777
- pos = eatWhitespaceAndComments(input, pos)[0];
1778
-
1779
- const start = pos;
1780
-
1781
- if (
1782
- input.charCodeAt(pos) === CC_QUOTATION_MARK ||
1783
- input.charCodeAt(pos) === CC_APOSTROPHE
1784
- ) {
1785
- return [start, consumeAStringToken(input, pos + 1, {}), false];
1786
- } else if (
1787
- _ifThreeCodePointsWouldStartAnIdentSequence(
1788
- input,
1789
- pos,
1790
- input.charCodeAt(pos),
1791
- input.charCodeAt(pos + 1),
1792
- input.charCodeAt(pos + 2)
1793
- )
1794
- ) {
1795
- return [start, _consumeAnIdentSequence(input, pos, {}), true];
1796
- }
1797
-
1798
- return undefined;
1799
- };
1800
-
1801
- /**
1802
- * @param {string} chars characters
1803
- * @returns {(input: string, pos: number) => number} function to eat characters
1804
- */
1805
- const eatUntil = (chars) => {
1806
- const charCodes = Array.from({ length: chars.length }, (_, i) =>
1807
- chars.charCodeAt(i)
1808
- );
1809
- const arr = Array.from(
1810
- { length: Math.max(...charCodes, 0) + 1 },
1811
- () => false
1812
- );
1813
- for (const cc of charCodes) {
1814
- arr[cc] = true;
1815
- }
1816
-
1817
- return (input, pos) => {
1818
- for (;;) {
1819
- const cc = input.charCodeAt(pos);
1820
- if (cc < arr.length && arr[cc]) {
1821
- return pos;
1822
- }
1823
- pos++;
1824
- if (pos === input.length) return pos;
1825
- }
1826
- };
1827
- };
1828
-
1829
- module.exports.consumeUntil = consumeUntil;
1830
- module.exports.eatComments = eatComments;
1831
- module.exports.eatIdentSequence = eatIdentSequence;
1832
- module.exports.eatIdentSequenceOrString = eatIdentSequenceOrString;
1833
- module.exports.eatImageSetStrings = eatImageSetStrings;
1834
- module.exports.eatImportTokens = eatImportTokens;
1835
- module.exports.eatString = eatString;
1836
- module.exports.eatUntil = eatUntil;
1837
- module.exports.eatWhiteLine = eatWhiteLine;
1838
- module.exports.eatWhitespace = eatWhitespace;
1839
- module.exports.eatWhitespaceAndComments = eatWhitespaceAndComments;
1840
- module.exports.isIdentStartCodePoint = isIdentStartCodePoint;
1841
- module.exports.isWhiteSpace = _isWhiteSpace;
1842
- module.exports.skipCommentsAndEatIdentSequence =
1843
- skipCommentsAndEatIdentSequence;