@feiyoug/skill-lab 0.0.0 → 0.0.2

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 (465) hide show
  1. package/README.md +73 -0
  2. package/esm/analyzer/astgrep/client.d.ts +20 -8
  3. package/esm/analyzer/astgrep/client.d.ts.map +1 -1
  4. package/esm/analyzer/astgrep/client.js +58 -31
  5. package/esm/analyzer/config/default.d.ts +8 -0
  6. package/esm/analyzer/config/default.d.ts.map +1 -0
  7. package/esm/analyzer/config/default.js +91 -0
  8. package/esm/analyzer/config/helpers.d.ts +8 -0
  9. package/esm/analyzer/config/helpers.d.ts.map +1 -0
  10. package/esm/analyzer/config/helpers.js +72 -0
  11. package/esm/analyzer/config/mod.d.ts +4 -0
  12. package/esm/analyzer/config/mod.d.ts.map +1 -0
  13. package/esm/analyzer/config/mod.js +3 -0
  14. package/esm/analyzer/config/types.d.ts +58 -0
  15. package/esm/analyzer/config/types.d.ts.map +1 -0
  16. package/esm/analyzer/{config.js → config/types.js} +0 -28
  17. package/esm/analyzer/logging.d.ts +3 -0
  18. package/esm/analyzer/logging.d.ts.map +1 -0
  19. package/esm/analyzer/logging.js +6 -0
  20. package/esm/analyzer/mod.d.ts +12 -5
  21. package/esm/analyzer/mod.d.ts.map +1 -1
  22. package/esm/analyzer/mod.js +25 -12
  23. package/esm/analyzer/result.d.ts +35 -0
  24. package/esm/analyzer/result.d.ts.map +1 -0
  25. package/esm/analyzer/result.js +311 -0
  26. package/esm/analyzer/rules/bash/commands/mod.d.ts +1 -0
  27. package/esm/analyzer/rules/bash/commands/mod.d.ts.map +1 -1
  28. package/esm/analyzer/rules/bash/commands/mod.js +3 -0
  29. package/esm/analyzer/rules/bash/commands/pip.d.ts +3 -0
  30. package/esm/analyzer/rules/bash/commands/pip.d.ts.map +1 -0
  31. package/esm/analyzer/rules/bash/commands/pip.js +14 -0
  32. package/esm/analyzer/rules/bash/extractFileRefs.d.ts +1 -1
  33. package/esm/analyzer/rules/bash/extractFileRefs.d.ts.map +1 -1
  34. package/esm/analyzer/rules/bash/extractFileRefs.js +2 -2
  35. package/esm/analyzer/rules/bash/inline-command-classifier.d.ts +1 -1
  36. package/esm/analyzer/rules/bash/inline-command-classifier.d.ts.map +1 -1
  37. package/esm/analyzer/rules/bash/inline-command-classifier.js +4 -4
  38. package/esm/analyzer/rules/javascript/extractFileRefs.d.ts +3 -4
  39. package/esm/analyzer/rules/javascript/extractFileRefs.d.ts.map +1 -1
  40. package/esm/analyzer/rules/javascript/extractFileRefs.js +3 -4
  41. package/esm/analyzer/rules/markdown/extractCodeBlocks.d.ts.map +1 -1
  42. package/esm/analyzer/rules/markdown/extractCodeBlocks.js +6 -3
  43. package/esm/analyzer/rules/markdown/extractFileRefs.d.ts.map +1 -1
  44. package/esm/analyzer/rules/markdown/extractFileRefs.js +2 -0
  45. package/esm/analyzer/rules/python/extractFileRefs.d.ts +1 -1
  46. package/esm/analyzer/rules/python/extractFileRefs.d.ts.map +1 -1
  47. package/esm/analyzer/rules/python/extractFileRefs.js +2 -2
  48. package/esm/analyzer/steps/001-discovery/discover-files.d.ts +4 -0
  49. package/esm/analyzer/steps/001-discovery/discover-files.d.ts.map +1 -1
  50. package/esm/analyzer/steps/001-discovery/discover-files.js +18 -2
  51. package/esm/analyzer/steps/001-discovery/mod.d.ts.map +1 -1
  52. package/esm/analyzer/steps/001-discovery/mod.js +39 -9
  53. package/esm/analyzer/steps/002-permissions/mod.d.ts.map +1 -1
  54. package/esm/analyzer/steps/002-permissions/mod.js +156 -73
  55. package/esm/analyzer/steps/002-permissions/scan-file.d.ts +1 -1
  56. package/esm/analyzer/steps/002-permissions/scan-file.d.ts.map +1 -1
  57. package/esm/analyzer/steps/002-permissions/scan-file.js +40 -5
  58. package/esm/analyzer/steps/002-permissions/seed-frontmatter.js +2 -2
  59. package/esm/analyzer/steps/003-risks/dep-risks.d.ts +3 -0
  60. package/esm/analyzer/steps/003-risks/dep-risks.d.ts.map +1 -0
  61. package/esm/analyzer/steps/003-risks/dep-risks.js +74 -0
  62. package/esm/analyzer/steps/003-risks/helpers.d.ts +1 -0
  63. package/esm/analyzer/steps/003-risks/helpers.d.ts.map +1 -1
  64. package/esm/analyzer/steps/003-risks/helpers.js +1 -0
  65. package/esm/analyzer/steps/003-risks/mod.d.ts +3 -2
  66. package/esm/analyzer/steps/003-risks/mod.d.ts.map +1 -1
  67. package/esm/analyzer/steps/003-risks/mod.js +41 -4
  68. package/esm/analyzer/steps/003-risks/policy.d.ts +7 -0
  69. package/esm/analyzer/steps/003-risks/policy.d.ts.map +1 -0
  70. package/esm/analyzer/steps/003-risks/policy.js +23 -0
  71. package/esm/analyzer/steps/003-risks/rule-mapped.d.ts +2 -2
  72. package/esm/analyzer/steps/003-risks/rule-mapped.d.ts.map +1 -1
  73. package/esm/analyzer/steps/003-risks/rule-mapped.js +83 -2
  74. package/esm/analyzer/steps/003-risks/scoring.d.ts +9 -1
  75. package/esm/analyzer/steps/003-risks/scoring.d.ts.map +1 -1
  76. package/esm/analyzer/steps/003-risks/scoring.js +55 -42
  77. package/esm/analyzer/treesitter/client.d.ts +31 -0
  78. package/esm/analyzer/treesitter/client.d.ts.map +1 -0
  79. package/esm/analyzer/{treesiter → treesitter}/client.js +43 -39
  80. package/esm/analyzer/treesitter/registry.d.ts +73 -0
  81. package/esm/analyzer/treesitter/registry.d.ts.map +1 -0
  82. package/esm/analyzer/treesitter/registry.js +165 -0
  83. package/esm/analyzer/types.d.ts +14 -28
  84. package/esm/analyzer/types.d.ts.map +1 -1
  85. package/esm/deps/jsr.io/@deno-library/progress/1.5.1/deps.d.ts +3 -0
  86. package/esm/deps/jsr.io/@deno-library/progress/1.5.1/deps.d.ts.map +1 -0
  87. package/esm/deps/jsr.io/@deno-library/progress/1.5.1/deps.js +3 -0
  88. package/esm/deps/jsr.io/@deno-library/progress/1.5.1/mod.d.ts +93 -0
  89. package/esm/deps/jsr.io/@deno-library/progress/1.5.1/mod.d.ts.map +1 -0
  90. package/esm/deps/jsr.io/@deno-library/progress/1.5.1/mod.js +297 -0
  91. package/esm/deps/jsr.io/@deno-library/progress/1.5.1/multi.d.ts +84 -0
  92. package/esm/deps/jsr.io/@deno-library/progress/1.5.1/multi.d.ts.map +1 -0
  93. package/esm/deps/jsr.io/@deno-library/progress/1.5.1/multi.js +268 -0
  94. package/esm/deps/jsr.io/@deno-library/progress/1.5.1/time.d.ts +18 -0
  95. package/esm/deps/jsr.io/@deno-library/progress/1.5.1/time.d.ts.map +1 -0
  96. package/esm/deps/jsr.io/@deno-library/progress/1.5.1/time.js +45 -0
  97. package/esm/deps/jsr.io/@std/fmt/1.0.3/colors.d.ts +700 -0
  98. package/esm/deps/jsr.io/@std/fmt/1.0.3/colors.d.ts.map +1 -0
  99. package/esm/deps/jsr.io/@std/fmt/1.0.3/colors.js +903 -0
  100. package/esm/deps/jsr.io/@std/io/0.225.0/types.d.ts +146 -0
  101. package/esm/deps/jsr.io/@std/io/0.225.0/types.d.ts.map +1 -0
  102. package/esm/deps/jsr.io/@std/io/0.225.0/types.js +15 -0
  103. package/esm/deps/jsr.io/@std/io/0.225.0/write_all.d.ts +51 -0
  104. package/esm/deps/jsr.io/@std/io/0.225.0/write_all.d.ts.map +1 -0
  105. package/esm/deps/jsr.io/@std/io/0.225.0/write_all.js +61 -0
  106. package/esm/shared/deep_merge.d.ts +12 -0
  107. package/esm/shared/deep_merge.d.ts.map +1 -0
  108. package/esm/shared/deep_merge.js +49 -0
  109. package/esm/shared/mod.d.ts +1 -0
  110. package/esm/shared/mod.d.ts.map +1 -1
  111. package/esm/shared/mod.js +1 -0
  112. package/esm/shared/types/filetypes.d.ts +2 -2
  113. package/esm/shared/types/filetypes.d.ts.map +1 -1
  114. package/esm/shared/types/permissions.d.ts +1 -1
  115. package/esm/shared/types/permissions.d.ts.map +1 -1
  116. package/esm/shared/types/risks.d.ts +4 -1
  117. package/esm/shared/types/risks.d.ts.map +1 -1
  118. package/esm/skillreader/types.d.ts +2 -2
  119. package/esm/skillreader/types.d.ts.map +1 -1
  120. package/esm/skillreader/types.js +2 -2
  121. package/package.json +1 -1
  122. package/script/analyzer/astgrep/client.d.ts +20 -8
  123. package/script/analyzer/astgrep/client.d.ts.map +1 -1
  124. package/script/analyzer/astgrep/client.js +58 -64
  125. package/script/analyzer/config/default.d.ts +8 -0
  126. package/script/analyzer/config/default.d.ts.map +1 -0
  127. package/script/analyzer/config/default.js +94 -0
  128. package/script/analyzer/config/helpers.d.ts +8 -0
  129. package/script/analyzer/config/helpers.d.ts.map +1 -0
  130. package/script/analyzer/config/helpers.js +76 -0
  131. package/script/analyzer/config/mod.d.ts +4 -0
  132. package/script/analyzer/config/mod.d.ts.map +1 -0
  133. package/script/analyzer/config/mod.js +21 -0
  134. package/script/analyzer/config/types.d.ts +58 -0
  135. package/script/analyzer/config/types.d.ts.map +1 -0
  136. package/script/analyzer/{config.js → config/types.js} +1 -29
  137. package/script/analyzer/logging.d.ts +3 -0
  138. package/script/analyzer/logging.d.ts.map +1 -0
  139. package/script/analyzer/logging.js +9 -0
  140. package/script/analyzer/mod.d.ts +12 -5
  141. package/script/analyzer/mod.d.ts.map +1 -1
  142. package/script/analyzer/mod.js +35 -20
  143. package/script/analyzer/result.d.ts +35 -0
  144. package/script/analyzer/result.d.ts.map +1 -0
  145. package/script/analyzer/result.js +315 -0
  146. package/script/analyzer/rules/bash/commands/mod.d.ts +1 -0
  147. package/script/analyzer/rules/bash/commands/mod.d.ts.map +1 -1
  148. package/script/analyzer/rules/bash/commands/mod.js +3 -0
  149. package/script/analyzer/rules/bash/commands/pip.d.ts +3 -0
  150. package/script/analyzer/rules/bash/commands/pip.d.ts.map +1 -0
  151. package/script/analyzer/rules/bash/commands/pip.js +17 -0
  152. package/script/analyzer/rules/bash/extractFileRefs.d.ts +1 -1
  153. package/script/analyzer/rules/bash/extractFileRefs.d.ts.map +1 -1
  154. package/script/analyzer/rules/bash/extractFileRefs.js +2 -2
  155. package/script/analyzer/rules/bash/inline-command-classifier.d.ts +1 -1
  156. package/script/analyzer/rules/bash/inline-command-classifier.d.ts.map +1 -1
  157. package/script/analyzer/rules/bash/inline-command-classifier.js +4 -4
  158. package/script/analyzer/rules/javascript/extractFileRefs.d.ts +3 -4
  159. package/script/analyzer/rules/javascript/extractFileRefs.d.ts.map +1 -1
  160. package/script/analyzer/rules/javascript/extractFileRefs.js +3 -4
  161. package/script/analyzer/rules/markdown/extractCodeBlocks.d.ts.map +1 -1
  162. package/script/analyzer/rules/markdown/extractCodeBlocks.js +6 -3
  163. package/script/analyzer/rules/markdown/extractFileRefs.d.ts.map +1 -1
  164. package/script/analyzer/rules/markdown/extractFileRefs.js +2 -0
  165. package/script/analyzer/rules/python/extractFileRefs.d.ts +1 -1
  166. package/script/analyzer/rules/python/extractFileRefs.d.ts.map +1 -1
  167. package/script/analyzer/rules/python/extractFileRefs.js +2 -2
  168. package/script/analyzer/steps/001-discovery/discover-files.d.ts +4 -0
  169. package/script/analyzer/steps/001-discovery/discover-files.d.ts.map +1 -1
  170. package/script/analyzer/steps/001-discovery/discover-files.js +18 -2
  171. package/script/analyzer/steps/001-discovery/mod.d.ts.map +1 -1
  172. package/script/analyzer/steps/001-discovery/mod.js +77 -11
  173. package/script/analyzer/steps/002-permissions/mod.d.ts.map +1 -1
  174. package/script/analyzer/steps/002-permissions/mod.js +194 -75
  175. package/script/analyzer/steps/002-permissions/scan-file.d.ts +1 -1
  176. package/script/analyzer/steps/002-permissions/scan-file.d.ts.map +1 -1
  177. package/script/analyzer/steps/002-permissions/scan-file.js +40 -5
  178. package/script/analyzer/steps/002-permissions/seed-frontmatter.js +3 -3
  179. package/script/analyzer/steps/003-risks/dep-risks.d.ts +3 -0
  180. package/script/analyzer/steps/003-risks/dep-risks.d.ts.map +1 -0
  181. package/script/analyzer/steps/003-risks/dep-risks.js +77 -0
  182. package/script/analyzer/steps/003-risks/helpers.d.ts +1 -0
  183. package/script/analyzer/steps/003-risks/helpers.d.ts.map +1 -1
  184. package/script/analyzer/steps/003-risks/helpers.js +1 -0
  185. package/script/analyzer/steps/003-risks/mod.d.ts +3 -2
  186. package/script/analyzer/steps/003-risks/mod.d.ts.map +1 -1
  187. package/script/analyzer/steps/003-risks/mod.js +77 -4
  188. package/script/analyzer/steps/003-risks/policy.d.ts +7 -0
  189. package/script/analyzer/steps/003-risks/policy.d.ts.map +1 -0
  190. package/script/analyzer/steps/003-risks/policy.js +29 -0
  191. package/script/analyzer/steps/003-risks/rule-mapped.d.ts +2 -2
  192. package/script/analyzer/steps/003-risks/rule-mapped.d.ts.map +1 -1
  193. package/script/analyzer/steps/003-risks/rule-mapped.js +83 -2
  194. package/script/analyzer/steps/003-risks/scoring.d.ts +9 -1
  195. package/script/analyzer/steps/003-risks/scoring.d.ts.map +1 -1
  196. package/script/analyzer/steps/003-risks/scoring.js +55 -42
  197. package/script/analyzer/treesitter/client.d.ts +31 -0
  198. package/script/analyzer/treesitter/client.d.ts.map +1 -0
  199. package/script/analyzer/treesitter/client.js +136 -0
  200. package/script/analyzer/treesitter/registry.d.ts +73 -0
  201. package/script/analyzer/treesitter/registry.d.ts.map +1 -0
  202. package/script/analyzer/treesitter/registry.js +206 -0
  203. package/script/analyzer/types.d.ts +14 -28
  204. package/script/analyzer/types.d.ts.map +1 -1
  205. package/script/deps/jsr.io/@deno-library/progress/1.5.1/deps.d.ts +3 -0
  206. package/script/deps/jsr.io/@deno-library/progress/1.5.1/deps.d.ts.map +1 -0
  207. package/script/deps/jsr.io/@deno-library/progress/1.5.1/deps.js +10 -0
  208. package/script/deps/jsr.io/@deno-library/progress/1.5.1/mod.d.ts +93 -0
  209. package/script/deps/jsr.io/@deno-library/progress/1.5.1/mod.d.ts.map +1 -0
  210. package/script/deps/jsr.io/@deno-library/progress/1.5.1/mod.js +334 -0
  211. package/script/deps/jsr.io/@deno-library/progress/1.5.1/multi.d.ts +84 -0
  212. package/script/deps/jsr.io/@deno-library/progress/1.5.1/multi.d.ts.map +1 -0
  213. package/script/deps/jsr.io/@deno-library/progress/1.5.1/multi.js +305 -0
  214. package/script/deps/jsr.io/@deno-library/progress/1.5.1/time.d.ts +18 -0
  215. package/script/deps/jsr.io/@deno-library/progress/1.5.1/time.d.ts.map +1 -0
  216. package/script/deps/jsr.io/@deno-library/progress/1.5.1/time.js +48 -0
  217. package/script/deps/jsr.io/@std/fmt/1.0.3/colors.d.ts +700 -0
  218. package/script/deps/jsr.io/@std/fmt/1.0.3/colors.d.ts.map +1 -0
  219. package/script/deps/jsr.io/@std/fmt/1.0.3/colors.js +986 -0
  220. package/script/deps/jsr.io/@std/io/0.225.0/types.d.ts +146 -0
  221. package/script/deps/jsr.io/@std/io/0.225.0/types.d.ts.map +1 -0
  222. package/script/deps/jsr.io/@std/io/0.225.0/types.js +18 -0
  223. package/script/deps/jsr.io/@std/io/0.225.0/write_all.d.ts +51 -0
  224. package/script/deps/jsr.io/@std/io/0.225.0/write_all.d.ts.map +1 -0
  225. package/script/deps/jsr.io/@std/io/0.225.0/write_all.js +65 -0
  226. package/script/shared/deep_merge.d.ts +12 -0
  227. package/script/shared/deep_merge.d.ts.map +1 -0
  228. package/script/shared/deep_merge.js +53 -0
  229. package/script/shared/mod.d.ts +1 -0
  230. package/script/shared/mod.d.ts.map +1 -1
  231. package/script/shared/mod.js +1 -0
  232. package/script/shared/types/filetypes.d.ts +2 -2
  233. package/script/shared/types/filetypes.d.ts.map +1 -1
  234. package/script/shared/types/permissions.d.ts +1 -1
  235. package/script/shared/types/permissions.d.ts.map +1 -1
  236. package/script/shared/types/risks.d.ts +4 -1
  237. package/script/shared/types/risks.d.ts.map +1 -1
  238. package/script/skillreader/types.d.ts +2 -2
  239. package/script/skillreader/types.d.ts.map +1 -1
  240. package/script/skillreader/types.js +2 -2
  241. package/src/_dnt.polyfills.ts +27 -0
  242. package/src/_dnt.shims.ts +64 -0
  243. package/src/analyzer/astgrep/client.ts +184 -0
  244. package/src/analyzer/astgrep/mod.ts +2 -0
  245. package/src/analyzer/config/default.ts +98 -0
  246. package/src/analyzer/config/helpers.ts +107 -0
  247. package/src/analyzer/config/mod.ts +3 -0
  248. package/src/analyzer/config/types.ts +103 -0
  249. package/src/analyzer/logging.ts +8 -0
  250. package/src/analyzer/mod.ts +118 -0
  251. package/src/analyzer/result.ts +393 -0
  252. package/src/analyzer/rules/bash/astTypes.ts +5 -0
  253. package/src/analyzer/rules/bash/commands/bd.ts +23 -0
  254. package/src/analyzer/rules/bash/commands/cron.ts +21 -0
  255. package/src/analyzer/rules/bash/commands/docker.ts +37 -0
  256. package/src/analyzer/rules/bash/commands/eval.ts +52 -0
  257. package/src/analyzer/rules/bash/commands/generic.ts +16 -0
  258. package/src/analyzer/rules/bash/commands/gh.ts +21 -0
  259. package/src/analyzer/rules/bash/commands/git.ts +28 -0
  260. package/src/analyzer/rules/bash/commands/mod.ts +38 -0
  261. package/src/analyzer/rules/bash/commands/node.ts +64 -0
  262. package/src/analyzer/rules/bash/commands/openspec.ts +16 -0
  263. package/src/analyzer/rules/bash/commands/pip.ts +16 -0
  264. package/src/analyzer/rules/bash/commands/sudo.ts +21 -0
  265. package/src/analyzer/rules/bash/destructive.ts +28 -0
  266. package/src/analyzer/rules/bash/extractFileRefs.ts +101 -0
  267. package/src/analyzer/rules/bash/filesystem.ts +50 -0
  268. package/src/analyzer/rules/bash/injection.ts +21 -0
  269. package/src/analyzer/rules/bash/inline-command-classifier.ts +94 -0
  270. package/src/analyzer/rules/bash/mod.ts +23 -0
  271. package/src/analyzer/rules/bash/network.ts +64 -0
  272. package/src/analyzer/rules/bash/secret-detection.ts +43 -0
  273. package/src/analyzer/rules/javascript/astTypes.ts +8 -0
  274. package/src/analyzer/rules/javascript/extractFileRefs.ts +131 -0
  275. package/src/analyzer/rules/javascript/filesystem.ts +28 -0
  276. package/src/analyzer/rules/javascript/injection.ts +21 -0
  277. package/src/analyzer/rules/javascript/mod.ts +26 -0
  278. package/src/analyzer/rules/javascript/network.ts +27 -0
  279. package/src/analyzer/rules/javascript/secret-detection.ts +68 -0
  280. package/src/analyzer/rules/javascript/subprocess.ts +16 -0
  281. package/src/analyzer/rules/markdown/astTypes.ts +35 -0
  282. package/src/analyzer/rules/markdown/extractCodeBlocks.ts +101 -0
  283. package/src/analyzer/rules/markdown/extractFileRefs.ts +179 -0
  284. package/src/analyzer/rules/markdown/mod.ts +12 -0
  285. package/src/analyzer/rules/mod.ts +77 -0
  286. package/src/analyzer/rules/python/astTypes.ts +9 -0
  287. package/src/analyzer/rules/python/extractFileRefs.ts +92 -0
  288. package/src/analyzer/rules/python/mod.ts +15 -0
  289. package/src/analyzer/rules/python/network.ts +26 -0
  290. package/src/analyzer/rules/python/secret-detection.ts +30 -0
  291. package/src/analyzer/rules/shared/file-refs.ts +38 -0
  292. package/src/analyzer/rules/shared/network-evaluators.ts +107 -0
  293. package/src/analyzer/rules/shared/prompt-injection.ts +48 -0
  294. package/src/analyzer/rules/shared/secret-evaluators.ts +13 -0
  295. package/src/analyzer/rules/text/mod.ts +12 -0
  296. package/src/analyzer/rules/typescript/mod.ts +7 -0
  297. package/src/analyzer/steps/001-discovery/discover-files.ts +211 -0
  298. package/src/analyzer/steps/001-discovery/filter-files.ts +72 -0
  299. package/src/analyzer/steps/001-discovery/mod.ts +103 -0
  300. package/src/analyzer/steps/002-permissions/mod.ts +329 -0
  301. package/src/analyzer/steps/002-permissions/scan-file.ts +258 -0
  302. package/src/analyzer/steps/002-permissions/seed-frontmatter.ts +66 -0
  303. package/src/analyzer/steps/002-permissions/synthesize.ts +42 -0
  304. package/src/analyzer/steps/003-risks/dep-risks.ts +89 -0
  305. package/src/analyzer/steps/003-risks/helpers.ts +41 -0
  306. package/src/analyzer/steps/003-risks/mod.ts +86 -0
  307. package/src/analyzer/steps/003-risks/policy.ts +38 -0
  308. package/src/analyzer/steps/003-risks/rule-mapped.ts +206 -0
  309. package/src/analyzer/steps/003-risks/scoring.ts +117 -0
  310. package/src/analyzer/steps/mod.ts +3 -0
  311. package/src/analyzer/treesitter/client.ts +120 -0
  312. package/src/analyzer/treesitter/registry.ts +198 -0
  313. package/src/analyzer/types.ts +78 -0
  314. package/src/analyzer/utils/code-block-path.ts +33 -0
  315. package/src/analyzer/utils/id-generator.ts +59 -0
  316. package/src/analyzer/utils/secret-validator.ts +29 -0
  317. package/src/analyzer/utils/url-parser.ts +25 -0
  318. package/src/deps/jsr.io/@deno-library/progress/1.5.1/deps.ts +3 -0
  319. package/src/deps/jsr.io/@deno-library/progress/1.5.1/mod.ts +265 -0
  320. package/src/deps/jsr.io/@deno-library/progress/1.5.1/multi.ts +250 -0
  321. package/src/deps/jsr.io/@deno-library/progress/1.5.1/time.ts +69 -0
  322. package/src/deps/jsr.io/@std/fmt/1.0.3/colors.ts +1004 -0
  323. package/src/deps/jsr.io/@std/internal/1.0.12/_os.ts +15 -0
  324. package/src/deps/jsr.io/@std/internal/1.0.12/os.ts +7 -0
  325. package/src/deps/jsr.io/@std/io/0.225.0/types.ts +157 -0
  326. package/src/deps/jsr.io/@std/io/0.225.0/write_all.ts +65 -0
  327. package/src/deps/jsr.io/@std/path/1.1.4/_common/assert_path.ts +10 -0
  328. package/src/deps/jsr.io/@std/path/1.1.4/_common/basename.ts +53 -0
  329. package/src/deps/jsr.io/@std/path/1.1.4/_common/common.ts +26 -0
  330. package/src/deps/jsr.io/@std/path/1.1.4/_common/constants.ts +49 -0
  331. package/src/deps/jsr.io/@std/path/1.1.4/_common/dirname.ts +9 -0
  332. package/src/deps/jsr.io/@std/path/1.1.4/_common/format.ts +25 -0
  333. package/src/deps/jsr.io/@std/path/1.1.4/_common/from_file_url.ts +12 -0
  334. package/src/deps/jsr.io/@std/path/1.1.4/_common/glob_to_reg_exp.ts +295 -0
  335. package/src/deps/jsr.io/@std/path/1.1.4/_common/normalize.ts +9 -0
  336. package/src/deps/jsr.io/@std/path/1.1.4/_common/normalize_string.ts +74 -0
  337. package/src/deps/jsr.io/@std/path/1.1.4/_common/relative.ts +10 -0
  338. package/src/deps/jsr.io/@std/path/1.1.4/_common/strip_trailing_separators.ts +25 -0
  339. package/src/deps/jsr.io/@std/path/1.1.4/_common/to_file_url.ts +17 -0
  340. package/src/deps/jsr.io/@std/path/1.1.4/basename.ts +37 -0
  341. package/src/deps/jsr.io/@std/path/1.1.4/common.ts +35 -0
  342. package/src/deps/jsr.io/@std/path/1.1.4/constants.ts +18 -0
  343. package/src/deps/jsr.io/@std/path/1.1.4/dirname.ts +30 -0
  344. package/src/deps/jsr.io/@std/path/1.1.4/extname.ts +29 -0
  345. package/src/deps/jsr.io/@std/path/1.1.4/format.ts +30 -0
  346. package/src/deps/jsr.io/@std/path/1.1.4/from_file_url.ts +30 -0
  347. package/src/deps/jsr.io/@std/path/1.1.4/glob_to_regexp.ts +94 -0
  348. package/src/deps/jsr.io/@std/path/1.1.4/is_absolute.ts +30 -0
  349. package/src/deps/jsr.io/@std/path/1.1.4/is_glob.ts +49 -0
  350. package/src/deps/jsr.io/@std/path/1.1.4/join.ts +31 -0
  351. package/src/deps/jsr.io/@std/path/1.1.4/join_globs.ts +42 -0
  352. package/src/deps/jsr.io/@std/path/1.1.4/mod.ts +217 -0
  353. package/src/deps/jsr.io/@std/path/1.1.4/normalize.ts +33 -0
  354. package/src/deps/jsr.io/@std/path/1.1.4/normalize_glob.ts +45 -0
  355. package/src/deps/jsr.io/@std/path/1.1.4/parse.ts +44 -0
  356. package/src/deps/jsr.io/@std/path/1.1.4/posix/_util.ts +10 -0
  357. package/src/deps/jsr.io/@std/path/1.1.4/posix/basename.ts +62 -0
  358. package/src/deps/jsr.io/@std/path/1.1.4/posix/constants.ts +15 -0
  359. package/src/deps/jsr.io/@std/path/1.1.4/posix/dirname.ts +72 -0
  360. package/src/deps/jsr.io/@std/path/1.1.4/posix/extname.ts +96 -0
  361. package/src/deps/jsr.io/@std/path/1.1.4/posix/format.ts +31 -0
  362. package/src/deps/jsr.io/@std/path/1.1.4/posix/from_file_url.ts +25 -0
  363. package/src/deps/jsr.io/@std/path/1.1.4/posix/glob_to_regexp.ts +94 -0
  364. package/src/deps/jsr.io/@std/path/1.1.4/posix/is_absolute.ts +25 -0
  365. package/src/deps/jsr.io/@std/path/1.1.4/posix/join.ts +46 -0
  366. package/src/deps/jsr.io/@std/path/1.1.4/posix/join_globs.ts +45 -0
  367. package/src/deps/jsr.io/@std/path/1.1.4/posix/normalize.ts +63 -0
  368. package/src/deps/jsr.io/@std/path/1.1.4/posix/normalize_glob.ts +43 -0
  369. package/src/deps/jsr.io/@std/path/1.1.4/posix/parse.ts +121 -0
  370. package/src/deps/jsr.io/@std/path/1.1.4/posix/relative.ts +103 -0
  371. package/src/deps/jsr.io/@std/path/1.1.4/posix/resolve.ts +71 -0
  372. package/src/deps/jsr.io/@std/path/1.1.4/posix/to_file_url.ts +32 -0
  373. package/src/deps/jsr.io/@std/path/1.1.4/posix/to_namespaced_path.ts +21 -0
  374. package/src/deps/jsr.io/@std/path/1.1.4/relative.ts +32 -0
  375. package/src/deps/jsr.io/@std/path/1.1.4/resolve.ts +32 -0
  376. package/src/deps/jsr.io/@std/path/1.1.4/to_file_url.ts +30 -0
  377. package/src/deps/jsr.io/@std/path/1.1.4/to_namespaced_path.ts +31 -0
  378. package/src/deps/jsr.io/@std/path/1.1.4/types.ts +40 -0
  379. package/src/deps/jsr.io/@std/path/1.1.4/windows/_util.ts +28 -0
  380. package/src/deps/jsr.io/@std/path/1.1.4/windows/basename.ts +54 -0
  381. package/src/deps/jsr.io/@std/path/1.1.4/windows/constants.ts +15 -0
  382. package/src/deps/jsr.io/@std/path/1.1.4/windows/dirname.ts +118 -0
  383. package/src/deps/jsr.io/@std/path/1.1.4/windows/extname.ts +90 -0
  384. package/src/deps/jsr.io/@std/path/1.1.4/windows/format.ts +31 -0
  385. package/src/deps/jsr.io/@std/path/1.1.4/windows/from_file_url.ts +34 -0
  386. package/src/deps/jsr.io/@std/path/1.1.4/windows/glob_to_regexp.ts +92 -0
  387. package/src/deps/jsr.io/@std/path/1.1.4/windows/is_absolute.ts +40 -0
  388. package/src/deps/jsr.io/@std/path/1.1.4/windows/join.ts +78 -0
  389. package/src/deps/jsr.io/@std/path/1.1.4/windows/join_globs.ts +46 -0
  390. package/src/deps/jsr.io/@std/path/1.1.4/windows/normalize.ts +136 -0
  391. package/src/deps/jsr.io/@std/path/1.1.4/windows/normalize_glob.ts +43 -0
  392. package/src/deps/jsr.io/@std/path/1.1.4/windows/parse.ts +184 -0
  393. package/src/deps/jsr.io/@std/path/1.1.4/windows/relative.ts +128 -0
  394. package/src/deps/jsr.io/@std/path/1.1.4/windows/resolve.ts +178 -0
  395. package/src/deps/jsr.io/@std/path/1.1.4/windows/to_file_url.ts +38 -0
  396. package/src/deps/jsr.io/@std/path/1.1.4/windows/to_namespaced_path.ts +60 -0
  397. package/src/deps/jsr.io/@std/yaml/1.0.11/_chars.ts +55 -0
  398. package/src/deps/jsr.io/@std/yaml/1.0.11/_dumper_state.ts +841 -0
  399. package/src/deps/jsr.io/@std/yaml/1.0.11/_loader_state.ts +1780 -0
  400. package/src/deps/jsr.io/@std/yaml/1.0.11/_schema.ts +183 -0
  401. package/src/deps/jsr.io/@std/yaml/1.0.11/_type/binary.ts +127 -0
  402. package/src/deps/jsr.io/@std/yaml/1.0.11/_type/bool.ts +37 -0
  403. package/src/deps/jsr.io/@std/yaml/1.0.11/_type/float.ts +112 -0
  404. package/src/deps/jsr.io/@std/yaml/1.0.11/_type/int.ts +174 -0
  405. package/src/deps/jsr.io/@std/yaml/1.0.11/_type/map.ts +17 -0
  406. package/src/deps/jsr.io/@std/yaml/1.0.11/_type/merge.ts +13 -0
  407. package/src/deps/jsr.io/@std/yaml/1.0.11/_type/nil.ts +27 -0
  408. package/src/deps/jsr.io/@std/yaml/1.0.11/_type/omap.ts +30 -0
  409. package/src/deps/jsr.io/@std/yaml/1.0.11/_type/pairs.ts +22 -0
  410. package/src/deps/jsr.io/@std/yaml/1.0.11/_type/regexp.ts +33 -0
  411. package/src/deps/jsr.io/@std/yaml/1.0.11/_type/seq.ts +13 -0
  412. package/src/deps/jsr.io/@std/yaml/1.0.11/_type/set.ts +17 -0
  413. package/src/deps/jsr.io/@std/yaml/1.0.11/_type/str.ts +12 -0
  414. package/src/deps/jsr.io/@std/yaml/1.0.11/_type/timestamp.ts +101 -0
  415. package/src/deps/jsr.io/@std/yaml/1.0.11/_type/undefined.ts +23 -0
  416. package/src/deps/jsr.io/@std/yaml/1.0.11/_type.ts +49 -0
  417. package/src/deps/jsr.io/@std/yaml/1.0.11/_utils.ts +16 -0
  418. package/src/deps/jsr.io/@std/yaml/1.0.11/mod.ts +54 -0
  419. package/src/deps/jsr.io/@std/yaml/1.0.11/parse.ts +128 -0
  420. package/src/deps/jsr.io/@std/yaml/1.0.11/stringify.ts +118 -0
  421. package/src/shared/deep_merge.ts +73 -0
  422. package/src/shared/mod.ts +2 -0
  423. package/src/shared/types/filetypes.ts +101 -0
  424. package/src/shared/types/findings.ts +7 -0
  425. package/src/shared/types/mod.ts +6 -0
  426. package/src/shared/types/permissions.ts +17 -0
  427. package/src/shared/types/references.ts +62 -0
  428. package/src/shared/types/risks.ts +72 -0
  429. package/src/shared/types/syntaxNode.ts +7 -0
  430. package/src/skillreader/cloudStorage/mod.ts +170 -0
  431. package/src/skillreader/factory.ts +71 -0
  432. package/src/skillreader/fs/git.ts +153 -0
  433. package/src/skillreader/fs/mod.ts +84 -0
  434. package/src/skillreader/github/base.ts +162 -0
  435. package/src/skillreader/github/githubApi.ts +40 -0
  436. package/src/skillreader/github/githubRaw.ts +24 -0
  437. package/src/skillreader/github/mod.ts +45 -0
  438. package/src/skillreader/github/utils.ts +40 -0
  439. package/src/skillreader/manifest.ts +67 -0
  440. package/src/skillreader/mod.ts +26 -0
  441. package/src/skillreader/types.ts +150 -0
  442. package/src/skillreader/utils/frontmatter-parser.ts +72 -0
  443. package/src/skillreader/utils/http-range.ts +38 -0
  444. package/src/skillreader/utils/mod.ts +12 -0
  445. package/esm/analyzer/astgrep/registry.d.ts +0 -18
  446. package/esm/analyzer/astgrep/registry.d.ts.map +0 -1
  447. package/esm/analyzer/astgrep/registry.js +0 -71
  448. package/esm/analyzer/config.d.ts +0 -27
  449. package/esm/analyzer/config.d.ts.map +0 -1
  450. package/esm/analyzer/steps/003-risks/output.d.ts +0 -3
  451. package/esm/analyzer/steps/003-risks/output.d.ts.map +0 -1
  452. package/esm/analyzer/steps/003-risks/output.js +0 -16
  453. package/esm/analyzer/treesiter/client.d.ts +0 -26
  454. package/esm/analyzer/treesiter/client.d.ts.map +0 -1
  455. package/script/analyzer/astgrep/registry.d.ts +0 -18
  456. package/script/analyzer/astgrep/registry.d.ts.map +0 -1
  457. package/script/analyzer/astgrep/registry.js +0 -109
  458. package/script/analyzer/config.d.ts +0 -27
  459. package/script/analyzer/config.d.ts.map +0 -1
  460. package/script/analyzer/steps/003-risks/output.d.ts +0 -3
  461. package/script/analyzer/steps/003-risks/output.d.ts.map +0 -1
  462. package/script/analyzer/steps/003-risks/output.js +0 -19
  463. package/script/analyzer/treesiter/client.d.ts +0 -26
  464. package/script/analyzer/treesiter/client.d.ts.map +0 -1
  465. package/script/analyzer/treesiter/client.js +0 -165
@@ -0,0 +1,1780 @@
1
+ // Ported from js-yaml v3.13.1:
2
+ // https://github.com/nodeca/js-yaml/commit/665aadda42349dcae869f12040d9b10ef18d12da
3
+ // Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license.
4
+ // Copyright 2018-2026 the Deno authors. MIT license.
5
+
6
+ import {
7
+ AMPERSAND,
8
+ ASTERISK,
9
+ BACKSLASH,
10
+ CARRIAGE_RETURN,
11
+ COLON,
12
+ COMMA,
13
+ COMMERCIAL_AT,
14
+ DOT,
15
+ DOUBLE_QUOTE,
16
+ EXCLAMATION,
17
+ GRAVE_ACCENT,
18
+ GREATER_THAN,
19
+ isEOL,
20
+ isFlowIndicator,
21
+ isWhiteSpace,
22
+ isWhiteSpaceOrEOL,
23
+ LEFT_CURLY_BRACKET,
24
+ LEFT_SQUARE_BRACKET,
25
+ LINE_FEED,
26
+ MINUS,
27
+ PERCENT,
28
+ PLUS,
29
+ QUESTION,
30
+ RIGHT_CURLY_BRACKET,
31
+ RIGHT_SQUARE_BRACKET,
32
+ SHARP,
33
+ SINGLE_QUOTE,
34
+ SMALLER_THAN,
35
+ SPACE,
36
+ VERTICAL_LINE,
37
+ } from "./_chars.js";
38
+
39
+ import { DEFAULT_SCHEMA, type Schema, type TypeMap } from "./_schema.js";
40
+ import type { KindType, Type } from "./_type.js";
41
+ import { isObject, isPlainObject } from "./_utils.js";
42
+
43
+ const CONTEXT_FLOW_IN = 1;
44
+ const CONTEXT_FLOW_OUT = 2;
45
+ const CONTEXT_BLOCK_IN = 3;
46
+ const CONTEXT_BLOCK_OUT = 4;
47
+
48
+ const CHOMPING_CLIP = 1;
49
+ const CHOMPING_STRIP = 2;
50
+ const CHOMPING_KEEP = 3;
51
+
52
+ const PATTERN_NON_PRINTABLE =
53
+ // deno-lint-ignore no-control-regex
54
+ /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
55
+ const PATTERN_NON_ASCII_LINE_BREAKS = /[\x85\u2028\u2029]/;
56
+ const PATTERN_FLOW_INDICATORS = /[,\[\]\{\}]/;
57
+ const PATTERN_TAG_HANDLE = /^(?:!|!!|![a-z\-]+!)$/i;
58
+ const PATTERN_TAG_URI =
59
+ /^(?:!|[^,\[\]\{\}])(?:%[0-9a-f]{2}|[0-9a-z\-#;\/\?:@&=\+\$,_\.!~\*'\(\)\[\]])*$/i;
60
+
61
+ export interface LoaderStateOptions {
62
+ /** specifies a schema to use. */
63
+ schema?: Schema;
64
+ /** compatibility with JSON.parse behaviour. */
65
+ allowDuplicateKeys?: boolean;
66
+ /** function to call on warning messages. */
67
+ onWarning?(error: Error): void;
68
+ }
69
+
70
+ const ESCAPED_HEX_LENGTHS = new Map<number, number>([
71
+ [0x78, 2], // x
72
+ [0x75, 4], // u
73
+ [0x55, 8], // U
74
+ ]);
75
+
76
+ const SIMPLE_ESCAPE_SEQUENCES = new Map<number, string>([
77
+ [0x30, "\x00"], // 0
78
+ [0x61, "\x07"], // a
79
+ [0x62, "\x08"], // b
80
+ [0x74, "\x09"], // t
81
+ [0x09, "\x09"], // Tab
82
+ [0x6e, "\x0A"], // n
83
+ [0x76, "\x0B"], // v
84
+ [0x66, "\x0C"], // f
85
+ [0x72, "\x0D"], // r
86
+ [0x65, "\x1B"], // e
87
+ [0x20, " "], // Space
88
+ [0x22, '"'], // "
89
+ [0x2f, "/"], // /
90
+ [0x5c, "\\"], // \
91
+ [0x4e, "\x85"], // N
92
+ [0x5f, "\xA0"], // _
93
+ [0x4c, "\u2028"], // L
94
+ [0x50, "\u2029"], // P
95
+ ]);
96
+
97
+ /**
98
+ * Converts a hexadecimal character code to its decimal value.
99
+ */
100
+ function hexCharCodeToNumber(charCode: number) {
101
+ // Check if the character code is in the range for '0' to '9'
102
+ if (0x30 <= charCode && charCode <= 0x39) return charCode - 0x30; // Convert '0'-'9' to 0-9
103
+
104
+ // Normalize the character code to lowercase if it's a letter
105
+ const lc = charCode | 0x20;
106
+
107
+ // Check if the character code is in the range for 'a' to 'f'
108
+ if (0x61 <= lc && lc <= 0x66) return lc - 0x61 + 10; // Convert 'a'-'f' to 10-15
109
+
110
+ return -1;
111
+ }
112
+
113
+ /**
114
+ * Converts a decimal character code to its decimal value.
115
+ */
116
+ function decimalCharCodeToNumber(charCode: number): number {
117
+ // Check if the character code is in the range for '0' to '9'
118
+ if (0x30 <= charCode && charCode <= 0x39) return charCode - 0x30; // Convert '0'-'9' to 0-9
119
+ return -1;
120
+ }
121
+
122
+ /**
123
+ * Converts a Unicode code point to a string.
124
+ */
125
+ function codepointToChar(codepoint: number): string {
126
+ // Check if the code point is within the Basic Multilingual Plane (BMP)
127
+ if (codepoint <= 0xffff) return String.fromCharCode(codepoint); // Convert BMP code point to character
128
+
129
+ // Encode UTF-16 surrogate pair for code points beyond BMP
130
+ // Reference: https://en.wikipedia.org/wiki/UTF-16#Code_points_U.2B010000_to_U.2B10FFFF
131
+ return String.fromCharCode(
132
+ ((codepoint - 0x010000) >> 10) + 0xd800, // High surrogate
133
+ ((codepoint - 0x010000) & 0x03ff) + 0xdc00, // Low surrogate
134
+ );
135
+ }
136
+
137
+ const INDENT = 4;
138
+ const MAX_LENGTH = 75;
139
+ const DELIMITERS = "\x00\r\n\x85\u2028\u2029";
140
+
141
+ function getSnippet(buffer: string, position: number): string | null {
142
+ if (!buffer) return null;
143
+ let start = position;
144
+ let end = position;
145
+ let head = "";
146
+ let tail = "";
147
+
148
+ while (start > 0 && !DELIMITERS.includes(buffer.charAt(start - 1))) {
149
+ start--;
150
+ if (position - start > MAX_LENGTH / 2 - 1) {
151
+ head = " ... ";
152
+ start += 5;
153
+ break;
154
+ }
155
+ }
156
+
157
+ while (end < buffer.length && !DELIMITERS.includes(buffer.charAt(end))) {
158
+ end++;
159
+ if (end - position > MAX_LENGTH / 2 - 1) {
160
+ tail = " ... ";
161
+ end -= 5;
162
+ break;
163
+ }
164
+ }
165
+
166
+ const snippet = buffer.slice(start, end);
167
+ const indent = " ".repeat(INDENT);
168
+ const caretIndent = " ".repeat(INDENT + position - start + head.length);
169
+ return `${indent + head + snippet + tail}\n${caretIndent}^`;
170
+ }
171
+
172
+ function markToString(
173
+ buffer: string,
174
+ position: number,
175
+ line: number,
176
+ column: number,
177
+ ): string {
178
+ let where = `at line ${line + 1}, column ${column + 1}`;
179
+ const snippet = getSnippet(buffer, position);
180
+ if (snippet) where += `:\n${snippet}`;
181
+ return where;
182
+ }
183
+
184
+ function getIndentStatus(lineIndent: number, parentIndent: number) {
185
+ if (lineIndent > parentIndent) return 1;
186
+ if (lineIndent < parentIndent) return -1;
187
+ return 0;
188
+ }
189
+
190
+ function writeFoldedLines(count: number) {
191
+ if (count === 1) return " ";
192
+ if (count > 1) return "\n".repeat(count - 1);
193
+ return "";
194
+ }
195
+
196
+ interface State {
197
+ tag: string | null;
198
+ anchor: string | null;
199
+ kind: KindType | null;
200
+ result: unknown[] | Record<string, unknown> | string | null;
201
+ }
202
+ export class LoaderState {
203
+ input: string;
204
+ length: number;
205
+ lineIndent = 0;
206
+ lineStart = 0;
207
+ position = 0;
208
+ line = 0;
209
+ onWarning: ((error: Error) => void) | undefined;
210
+ allowDuplicateKeys: boolean;
211
+ implicitTypes: Type<"scalar">[];
212
+ typeMap: TypeMap;
213
+
214
+ checkLineBreaks = false;
215
+ tagMap = new Map();
216
+ anchorMap = new Map();
217
+
218
+ constructor(
219
+ input: string,
220
+ {
221
+ schema = DEFAULT_SCHEMA,
222
+ onWarning,
223
+ allowDuplicateKeys = false,
224
+ }: LoaderStateOptions,
225
+ ) {
226
+ this.input = input;
227
+ this.onWarning = onWarning;
228
+ this.allowDuplicateKeys = allowDuplicateKeys;
229
+ this.implicitTypes = schema.implicitTypes;
230
+ this.typeMap = schema.typeMap;
231
+ this.length = input.length;
232
+
233
+ this.readIndent();
234
+ }
235
+
236
+ skipWhitespaces() {
237
+ let ch = this.peek();
238
+ while (isWhiteSpace(ch)) {
239
+ ch = this.next();
240
+ }
241
+ }
242
+
243
+ skipComment() {
244
+ let ch = this.peek();
245
+ if (ch !== SHARP) return;
246
+ ch = this.next();
247
+ while (ch !== 0 && !isEOL(ch)) {
248
+ ch = this.next();
249
+ }
250
+ }
251
+
252
+ readIndent() {
253
+ let char = this.peek();
254
+ while (char === SPACE) {
255
+ this.lineIndent += 1;
256
+ char = this.next();
257
+ }
258
+ }
259
+
260
+ peek(offset = 0) {
261
+ return this.input.charCodeAt(this.position + offset);
262
+ }
263
+ next() {
264
+ this.position += 1;
265
+ return this.peek();
266
+ }
267
+
268
+ #createError(message: string): SyntaxError {
269
+ const mark = markToString(
270
+ this.input,
271
+ this.position,
272
+ this.line,
273
+ this.position - this.lineStart,
274
+ );
275
+ return new SyntaxError(`${message} ${mark}`);
276
+ }
277
+
278
+ dispatchWarning(message: string) {
279
+ const error = this.#createError(message);
280
+ this.onWarning?.(error);
281
+ }
282
+
283
+ yamlDirectiveHandler(args: string[]): string | null {
284
+ if (args.length !== 1) {
285
+ throw this.#createError(
286
+ "Cannot handle YAML directive: YAML directive accepts exactly one argument",
287
+ );
288
+ }
289
+
290
+ const match = /^([0-9]+)\.([0-9]+)$/.exec(args[0]!);
291
+ if (match === null) {
292
+ throw this.#createError(
293
+ "Cannot handle YAML directive: ill-formed argument",
294
+ );
295
+ }
296
+
297
+ const major = parseInt(match[1]!, 10);
298
+ const minor = parseInt(match[2]!, 10);
299
+ if (major !== 1) {
300
+ throw this.#createError(
301
+ "Cannot handle YAML directive: unacceptable YAML version",
302
+ );
303
+ }
304
+ this.checkLineBreaks = minor < 2;
305
+ if (minor !== 1 && minor !== 2) {
306
+ this.dispatchWarning(
307
+ "Cannot handle YAML directive: unsupported YAML version",
308
+ );
309
+ }
310
+ return args[0] ?? null;
311
+ }
312
+ tagDirectiveHandler(args: string[]) {
313
+ if (args.length !== 2) {
314
+ throw this.#createError(
315
+ `Cannot handle tag directive: directive accepts exactly two arguments, received ${args.length}`,
316
+ );
317
+ }
318
+
319
+ const handle = args[0]!;
320
+ const prefix = args[1]!;
321
+
322
+ if (!PATTERN_TAG_HANDLE.test(handle)) {
323
+ throw this.#createError(
324
+ `Cannot handle tag directive: ill-formed handle (first argument) in "${handle}"`,
325
+ );
326
+ }
327
+
328
+ if (this.tagMap.has(handle)) {
329
+ throw this.#createError(
330
+ `Cannot handle tag directive: previously declared suffix for "${handle}" tag handle`,
331
+ );
332
+ }
333
+
334
+ if (!PATTERN_TAG_URI.test(prefix)) {
335
+ throw this.#createError(
336
+ "Cannot handle tag directive: ill-formed tag prefix (second argument) of the TAG directive",
337
+ );
338
+ }
339
+
340
+ this.tagMap.set(handle, prefix);
341
+ }
342
+ captureSegment(start: number, end: number, checkJson: boolean) {
343
+ if (start < end) {
344
+ const result = this.input.slice(start, end);
345
+
346
+ if (checkJson) {
347
+ for (
348
+ let position = 0;
349
+ position < result.length;
350
+ position++
351
+ ) {
352
+ const character = result.charCodeAt(position);
353
+ if (
354
+ !(character === 0x09 ||
355
+ (0x20 <= character && character <= 0x10ffff))
356
+ ) {
357
+ throw this.#createError(
358
+ `Expected valid JSON character: received "${character}"`,
359
+ );
360
+ }
361
+ }
362
+ } else if (PATTERN_NON_PRINTABLE.test(result)) {
363
+ throw this.#createError("Stream contains non-printable characters");
364
+ }
365
+
366
+ return result;
367
+ }
368
+ }
369
+ readBlockSequence(
370
+ tag: string | null,
371
+ anchor: string | null,
372
+ nodeIndent: number,
373
+ ): State | void {
374
+ let detected = false;
375
+
376
+ const result: unknown[] = [];
377
+
378
+ if (anchor !== null) this.anchorMap.set(anchor, result);
379
+
380
+ let ch = this.peek();
381
+
382
+ while (ch !== 0) {
383
+ if (ch !== MINUS) {
384
+ break;
385
+ }
386
+
387
+ const following = this.peek(1);
388
+
389
+ if (!isWhiteSpaceOrEOL(following)) {
390
+ break;
391
+ }
392
+
393
+ detected = true;
394
+ this.position++;
395
+
396
+ if (this.skipSeparationSpace(true, -1)) {
397
+ if (this.lineIndent <= nodeIndent) {
398
+ result.push(null);
399
+ ch = this.peek();
400
+ continue;
401
+ }
402
+ }
403
+
404
+ const line = this.line;
405
+ const newState = this.composeNode({
406
+ parentIndent: nodeIndent,
407
+ nodeContext: CONTEXT_BLOCK_IN,
408
+ allowToSeek: false,
409
+ allowCompact: true,
410
+ });
411
+ if (newState) result.push(newState.result);
412
+ this.skipSeparationSpace(true, -1);
413
+
414
+ ch = this.peek();
415
+
416
+ if ((this.line === line || this.lineIndent > nodeIndent) && ch !== 0) {
417
+ throw this.#createError(
418
+ "Cannot read block sequence: bad indentation of a sequence entry",
419
+ );
420
+ } else if (this.lineIndent < nodeIndent) {
421
+ break;
422
+ }
423
+ }
424
+
425
+ if (detected) return { tag, anchor, kind: "sequence", result };
426
+ }
427
+ mergeMappings(
428
+ destination: Record<string, unknown>,
429
+ source: Record<string, unknown>,
430
+ overridableKeys: Set<string>,
431
+ ) {
432
+ if (!isObject(source)) {
433
+ throw this.#createError(
434
+ "Cannot merge mappings: the provided source object is unacceptable",
435
+ );
436
+ }
437
+
438
+ for (const [key, value] of Object.entries(source)) {
439
+ if (Object.hasOwn(destination, key)) continue;
440
+ Object.defineProperty(destination, key, {
441
+ value,
442
+ writable: true,
443
+ enumerable: true,
444
+ configurable: true,
445
+ });
446
+ overridableKeys.add(key);
447
+ }
448
+ }
449
+ storeMappingPair(
450
+ result: Record<string, unknown>,
451
+ overridableKeys: Set<string>,
452
+ keyTag: string | null,
453
+ keyNode: Record<PropertyKey, unknown> | unknown[] | string | null,
454
+ valueNode: unknown,
455
+ startLine?: number,
456
+ startPos?: number,
457
+ ): Record<string, unknown> {
458
+ // The output is a plain object here, so keys can only be strings.
459
+ // We need to convert keyNode to a string, but doing so can hang the process
460
+ // (deeply nested arrays that explode exponentially using aliases).
461
+ if (Array.isArray(keyNode)) {
462
+ keyNode = Array.prototype.slice.call(keyNode);
463
+
464
+ for (let index = 0; index < keyNode.length; index++) {
465
+ if (Array.isArray(keyNode[index])) {
466
+ throw this.#createError(
467
+ "Cannot store mapping pair: nested arrays are not supported inside keys",
468
+ );
469
+ }
470
+
471
+ if (typeof keyNode === "object" && isPlainObject(keyNode[index])) {
472
+ keyNode[index] = "[object Object]";
473
+ }
474
+ }
475
+ }
476
+
477
+ // Avoid code execution in load() via toString property
478
+ // (still use its own toString for arrays, timestamps,
479
+ // and whatever user schema extensions happen to have @@toStringTag)
480
+ if (typeof keyNode === "object" && isPlainObject(keyNode)) {
481
+ keyNode = "[object Object]";
482
+ }
483
+
484
+ keyNode = String(keyNode);
485
+
486
+ if (keyTag === "tag:yaml.org,2002:merge") {
487
+ if (Array.isArray(valueNode)) {
488
+ for (
489
+ let index = 0;
490
+ index < valueNode.length;
491
+ index++
492
+ ) {
493
+ this.mergeMappings(result, valueNode[index], overridableKeys);
494
+ }
495
+ } else {
496
+ this.mergeMappings(
497
+ result,
498
+ valueNode as Record<string, unknown>,
499
+ overridableKeys,
500
+ );
501
+ }
502
+ } else {
503
+ if (
504
+ !this.allowDuplicateKeys &&
505
+ !overridableKeys.has(keyNode) &&
506
+ Object.hasOwn(result, keyNode)
507
+ ) {
508
+ this.line = startLine || this.line;
509
+ this.position = startPos || this.position;
510
+ throw this.#createError("Cannot store mapping pair: duplicated key");
511
+ }
512
+ Object.defineProperty(result, keyNode, {
513
+ value: valueNode,
514
+ writable: true,
515
+ enumerable: true,
516
+ configurable: true,
517
+ });
518
+ overridableKeys.delete(keyNode);
519
+ }
520
+
521
+ return result;
522
+ }
523
+ readLineBreak() {
524
+ const ch = this.peek();
525
+
526
+ if (ch === LINE_FEED) {
527
+ this.position++;
528
+ } else if (ch === CARRIAGE_RETURN) {
529
+ this.position++;
530
+ if (this.peek() === LINE_FEED) {
531
+ this.position++;
532
+ }
533
+ } else {
534
+ throw this.#createError("Cannot read line: line break not found");
535
+ }
536
+
537
+ this.line += 1;
538
+ this.lineStart = this.position;
539
+ }
540
+ skipSeparationSpace(allowComments: boolean, checkIndent: number): number {
541
+ let lineBreaks = 0;
542
+ let ch = this.peek();
543
+
544
+ while (ch !== 0) {
545
+ this.skipWhitespaces();
546
+ ch = this.peek();
547
+
548
+ if (allowComments) {
549
+ this.skipComment();
550
+ ch = this.peek();
551
+ }
552
+
553
+ if (isEOL(ch)) {
554
+ this.readLineBreak();
555
+
556
+ ch = this.peek();
557
+ lineBreaks++;
558
+ this.lineIndent = 0;
559
+
560
+ this.readIndent();
561
+ ch = this.peek();
562
+ } else {
563
+ break;
564
+ }
565
+ }
566
+
567
+ if (
568
+ checkIndent !== -1 &&
569
+ lineBreaks !== 0 &&
570
+ this.lineIndent < checkIndent
571
+ ) {
572
+ this.dispatchWarning("deficient indentation");
573
+ }
574
+
575
+ return lineBreaks;
576
+ }
577
+ testDocumentSeparator(): boolean {
578
+ let ch = this.peek();
579
+
580
+ // Condition this.position === this.lineStart is tested
581
+ // in parent on each call, for efficiency. No needs to test here again.
582
+ if (
583
+ (ch === MINUS || ch === DOT) &&
584
+ ch === this.peek(1) &&
585
+ ch === this.peek(2)
586
+ ) {
587
+ ch = this.peek(3);
588
+
589
+ if (ch === 0 || isWhiteSpaceOrEOL(ch)) {
590
+ return true;
591
+ }
592
+ }
593
+
594
+ return false;
595
+ }
596
+
597
+ readPlainScalar(
598
+ tag: string | null,
599
+ anchor: string | null,
600
+ nodeIndent: number,
601
+ withinFlowCollection: boolean,
602
+ ): State | void {
603
+ let ch = this.peek();
604
+
605
+ if (
606
+ isWhiteSpaceOrEOL(ch) ||
607
+ isFlowIndicator(ch) ||
608
+ ch === SHARP ||
609
+ ch === AMPERSAND ||
610
+ ch === ASTERISK ||
611
+ ch === EXCLAMATION ||
612
+ ch === VERTICAL_LINE ||
613
+ ch === GREATER_THAN ||
614
+ ch === SINGLE_QUOTE ||
615
+ ch === DOUBLE_QUOTE ||
616
+ ch === PERCENT ||
617
+ ch === COMMERCIAL_AT ||
618
+ ch === GRAVE_ACCENT
619
+ ) {
620
+ return;
621
+ }
622
+
623
+ let following: number;
624
+ if (ch === QUESTION || ch === MINUS) {
625
+ following = this.peek(1);
626
+
627
+ if (
628
+ isWhiteSpaceOrEOL(following) ||
629
+ (withinFlowCollection && isFlowIndicator(following))
630
+ ) {
631
+ return;
632
+ }
633
+ }
634
+
635
+ let result = "";
636
+
637
+ let captureEnd = this.position;
638
+ let captureStart = this.position;
639
+ let hasPendingContent = false;
640
+ let line = 0;
641
+ while (ch !== 0) {
642
+ if (ch === COLON) {
643
+ following = this.peek(1);
644
+
645
+ if (
646
+ isWhiteSpaceOrEOL(following) ||
647
+ (withinFlowCollection && isFlowIndicator(following))
648
+ ) {
649
+ break;
650
+ }
651
+ } else if (ch === SHARP) {
652
+ const preceding = this.peek(-1);
653
+
654
+ if (isWhiteSpaceOrEOL(preceding)) {
655
+ break;
656
+ }
657
+ } else if (
658
+ (this.position === this.lineStart && this.testDocumentSeparator()) ||
659
+ (withinFlowCollection && isFlowIndicator(ch))
660
+ ) {
661
+ break;
662
+ } else if (isEOL(ch)) {
663
+ line = this.line;
664
+ const lineStart = this.lineStart;
665
+ const lineIndent = this.lineIndent;
666
+ this.skipSeparationSpace(false, -1);
667
+
668
+ if (this.lineIndent >= nodeIndent) {
669
+ hasPendingContent = true;
670
+ ch = this.peek();
671
+ continue;
672
+ } else {
673
+ this.position = captureEnd;
674
+ this.line = line;
675
+ this.lineStart = lineStart;
676
+ this.lineIndent = lineIndent;
677
+ break;
678
+ }
679
+ }
680
+
681
+ if (hasPendingContent) {
682
+ const segment = this.captureSegment(captureStart, captureEnd, false);
683
+ if (segment) result += segment;
684
+ result += writeFoldedLines(this.line - line);
685
+ captureStart = captureEnd = this.position;
686
+ hasPendingContent = false;
687
+ }
688
+
689
+ if (!isWhiteSpace(ch)) {
690
+ captureEnd = this.position + 1;
691
+ }
692
+
693
+ ch = this.next();
694
+ }
695
+
696
+ const segment = this.captureSegment(captureStart, captureEnd, false);
697
+ if (segment) result += segment;
698
+ if (anchor !== null) this.anchorMap.set(anchor, result);
699
+ if (result) return { tag, anchor, kind: "scalar", result };
700
+ }
701
+ readSingleQuotedScalar(
702
+ tag: string | null,
703
+ anchor: string | null,
704
+ nodeIndent: number,
705
+ ): State | void {
706
+ let ch = this.peek();
707
+
708
+ if (ch !== SINGLE_QUOTE) return;
709
+
710
+ let result = "";
711
+ this.position++;
712
+ let captureStart = this.position;
713
+ let captureEnd = this.position;
714
+
715
+ ch = this.peek();
716
+ while (ch !== 0) {
717
+ if (ch === SINGLE_QUOTE) {
718
+ const segment = this.captureSegment(captureStart, this.position, true);
719
+ if (segment) result += segment;
720
+ ch = this.next();
721
+
722
+ if (ch === SINGLE_QUOTE) {
723
+ captureStart = this.position;
724
+ this.position++;
725
+ captureEnd = this.position;
726
+ } else {
727
+ if (anchor !== null) this.anchorMap.set(anchor, result);
728
+ return { tag, anchor, kind: "scalar", result };
729
+ }
730
+ } else if (isEOL(ch)) {
731
+ const segment = this.captureSegment(captureStart, captureEnd, true);
732
+ if (segment) result += segment;
733
+ result += writeFoldedLines(
734
+ this.skipSeparationSpace(false, nodeIndent),
735
+ );
736
+ captureStart = captureEnd = this.position;
737
+ } else if (
738
+ this.position === this.lineStart &&
739
+ this.testDocumentSeparator()
740
+ ) {
741
+ throw this.#createError(
742
+ "Unexpected end of the document within a single quoted scalar",
743
+ );
744
+ } else {
745
+ this.position++;
746
+ captureEnd = this.position;
747
+ }
748
+ ch = this.peek();
749
+ }
750
+
751
+ throw this.#createError(
752
+ "Unexpected end of the stream within a single quoted scalar",
753
+ );
754
+ }
755
+ readDoubleQuotedScalar(
756
+ tag: string | null,
757
+ anchor: string | null,
758
+ nodeIndent: number,
759
+ ): State | void {
760
+ let ch = this.peek();
761
+
762
+ if (ch !== DOUBLE_QUOTE) return;
763
+
764
+ let result = "";
765
+ this.position++;
766
+ let captureEnd = this.position;
767
+ let captureStart = this.position;
768
+ let tmp: number;
769
+ ch = this.peek();
770
+ while (ch !== 0) {
771
+ if (ch === DOUBLE_QUOTE) {
772
+ const segment = this.captureSegment(captureStart, this.position, true);
773
+ if (segment) result += segment;
774
+ this.position++;
775
+ if (anchor !== null) this.anchorMap.set(anchor, result);
776
+ return { tag, anchor, kind: "scalar", result };
777
+ }
778
+ if (ch === BACKSLASH) {
779
+ const segment = this.captureSegment(captureStart, this.position, true);
780
+ if (segment) result += segment;
781
+ ch = this.next();
782
+
783
+ if (isEOL(ch)) {
784
+ this.skipSeparationSpace(false, nodeIndent);
785
+ } else if (ch < 256 && SIMPLE_ESCAPE_SEQUENCES.has(ch)) {
786
+ result += SIMPLE_ESCAPE_SEQUENCES.get(ch);
787
+ this.position++;
788
+ } else if ((tmp = ESCAPED_HEX_LENGTHS.get(ch) ?? 0) > 0) {
789
+ let hexLength = tmp;
790
+ let hexResult = 0;
791
+
792
+ for (; hexLength > 0; hexLength--) {
793
+ ch = this.next();
794
+
795
+ if ((tmp = hexCharCodeToNumber(ch)) >= 0) {
796
+ hexResult = (hexResult << 4) + tmp;
797
+ } else {
798
+ throw this.#createError(
799
+ "Cannot read double quoted scalar: expected hexadecimal character",
800
+ );
801
+ }
802
+ }
803
+
804
+ result += codepointToChar(hexResult);
805
+
806
+ this.position++;
807
+ } else {
808
+ throw this.#createError(
809
+ "Cannot read double quoted scalar: unknown escape sequence",
810
+ );
811
+ }
812
+
813
+ captureStart = captureEnd = this.position;
814
+ } else if (isEOL(ch)) {
815
+ const segment = this.captureSegment(captureStart, captureEnd, true);
816
+ if (segment) result += segment;
817
+ result += writeFoldedLines(
818
+ this.skipSeparationSpace(false, nodeIndent),
819
+ );
820
+ captureStart = captureEnd = this.position;
821
+ } else if (
822
+ this.position === this.lineStart &&
823
+ this.testDocumentSeparator()
824
+ ) {
825
+ throw this.#createError(
826
+ "Unexpected end of the document within a double quoted scalar",
827
+ );
828
+ } else {
829
+ this.position++;
830
+ captureEnd = this.position;
831
+ }
832
+ ch = this.peek();
833
+ }
834
+
835
+ throw this.#createError(
836
+ "Unexpected end of the stream within a double quoted scalar",
837
+ );
838
+ }
839
+ readFlowCollection(
840
+ tag: string | null,
841
+ anchor: string | null,
842
+ nodeIndent: number,
843
+ ): State | void {
844
+ let ch = this.peek();
845
+ let terminator: number;
846
+ let isMapping = true;
847
+ let result = {};
848
+ if (ch === LEFT_SQUARE_BRACKET) {
849
+ terminator = RIGHT_SQUARE_BRACKET;
850
+ isMapping = false;
851
+ result = [];
852
+ } else if (ch === LEFT_CURLY_BRACKET) {
853
+ terminator = RIGHT_CURLY_BRACKET;
854
+ } else {
855
+ return;
856
+ }
857
+
858
+ if (anchor !== null) this.anchorMap.set(anchor, result);
859
+
860
+ ch = this.next();
861
+
862
+ let readNext = true;
863
+ let valueNode = null;
864
+ let keyNode = null;
865
+ let keyTag: string | null = null;
866
+ let isExplicitPair = false;
867
+ let isPair = false;
868
+ let following = 0;
869
+ let line = 0;
870
+ const overridableKeys = new Set<string>();
871
+ while (ch !== 0) {
872
+ this.skipSeparationSpace(true, nodeIndent);
873
+
874
+ ch = this.peek();
875
+
876
+ if (ch === terminator) {
877
+ this.position++;
878
+ const kind = isMapping ? "mapping" : "sequence";
879
+ return { tag, anchor, kind, result };
880
+ }
881
+ if (!readNext) {
882
+ throw this.#createError(
883
+ "Cannot read flow collection: missing comma between flow collection entries",
884
+ );
885
+ }
886
+
887
+ keyTag = keyNode = valueNode = null;
888
+ isPair = isExplicitPair = false;
889
+
890
+ if (ch === QUESTION) {
891
+ following = this.peek(1);
892
+
893
+ if (isWhiteSpaceOrEOL(following)) {
894
+ isPair = isExplicitPair = true;
895
+ this.position++;
896
+ this.skipSeparationSpace(true, nodeIndent);
897
+ }
898
+ }
899
+
900
+ line = this.line;
901
+ const newState = this.composeNode({
902
+ parentIndent: nodeIndent,
903
+ nodeContext: CONTEXT_FLOW_IN,
904
+ allowToSeek: false,
905
+ allowCompact: true,
906
+ });
907
+ if (newState) {
908
+ keyTag = newState.tag || null;
909
+ keyNode = newState.result;
910
+ }
911
+ this.skipSeparationSpace(true, nodeIndent);
912
+
913
+ ch = this.peek();
914
+
915
+ if ((isExplicitPair || this.line === line) && ch === COLON) {
916
+ isPair = true;
917
+ ch = this.next();
918
+ this.skipSeparationSpace(true, nodeIndent);
919
+ const newState = this.composeNode({
920
+ parentIndent: nodeIndent,
921
+ nodeContext: CONTEXT_FLOW_IN,
922
+ allowToSeek: false,
923
+ allowCompact: true,
924
+ });
925
+ if (newState) valueNode = newState.result;
926
+ }
927
+
928
+ if (isMapping) {
929
+ this.storeMappingPair(
930
+ result as Record<string, unknown>,
931
+ overridableKeys,
932
+ keyTag,
933
+ keyNode,
934
+ valueNode,
935
+ );
936
+ } else if (isPair) {
937
+ (result as Record<string, unknown>[]).push(
938
+ this.storeMappingPair(
939
+ {},
940
+ overridableKeys,
941
+ keyTag,
942
+ keyNode,
943
+ valueNode,
944
+ ),
945
+ );
946
+ } else {
947
+ (result as unknown[]).push(keyNode);
948
+ }
949
+
950
+ this.skipSeparationSpace(true, nodeIndent);
951
+
952
+ ch = this.peek();
953
+
954
+ if (ch === COMMA) {
955
+ readNext = true;
956
+ ch = this.next();
957
+ } else {
958
+ readNext = false;
959
+ }
960
+ }
961
+
962
+ throw this.#createError(
963
+ "Cannot read flow collection: unexpected end of the stream within a flow collection",
964
+ );
965
+ }
966
+ // Handles block scaler styles: e.g. '|', '>', '|-' and '>-'.
967
+ // https://yaml.org/spec/1.2.2/#81-block-scalar-styles
968
+ readBlockScalar(
969
+ tag: string | null,
970
+ anchor: string | null,
971
+ nodeIndent: number,
972
+ ): State | void {
973
+ let chomping = CHOMPING_CLIP;
974
+ let didReadContent = false;
975
+ let detectedIndent = false;
976
+ let textIndent = nodeIndent;
977
+ let emptyLines = 0;
978
+ let atMoreIndented = false;
979
+
980
+ let ch = this.peek();
981
+
982
+ let folding = false;
983
+ if (ch === VERTICAL_LINE) {
984
+ folding = false;
985
+ } else if (ch === GREATER_THAN) {
986
+ folding = true;
987
+ } else {
988
+ return;
989
+ }
990
+
991
+ let result = "";
992
+
993
+ let tmp = 0;
994
+ while (ch !== 0) {
995
+ ch = this.next();
996
+
997
+ if (ch === PLUS || ch === MINUS) {
998
+ if (CHOMPING_CLIP === chomping) {
999
+ chomping = ch === PLUS ? CHOMPING_KEEP : CHOMPING_STRIP;
1000
+ } else {
1001
+ throw this.#createError(
1002
+ "Cannot read block: chomping mode identifier repeated",
1003
+ );
1004
+ }
1005
+ } else if ((tmp = decimalCharCodeToNumber(ch)) >= 0) {
1006
+ if (tmp === 0) {
1007
+ throw this.#createError(
1008
+ "Cannot read block: indentation width must be greater than 0",
1009
+ );
1010
+ } else if (!detectedIndent) {
1011
+ textIndent = nodeIndent + tmp - 1;
1012
+ detectedIndent = true;
1013
+ } else {
1014
+ throw this.#createError(
1015
+ "Cannot read block: indentation width identifier repeated",
1016
+ );
1017
+ }
1018
+ } else {
1019
+ break;
1020
+ }
1021
+ }
1022
+
1023
+ if (isWhiteSpace(ch)) {
1024
+ this.skipWhitespaces();
1025
+ this.skipComment();
1026
+ ch = this.peek();
1027
+ }
1028
+
1029
+ while (ch !== 0) {
1030
+ this.readLineBreak();
1031
+ this.lineIndent = 0;
1032
+
1033
+ ch = this.peek();
1034
+
1035
+ while (
1036
+ (!detectedIndent || this.lineIndent < textIndent) &&
1037
+ ch === SPACE
1038
+ ) {
1039
+ this.lineIndent++;
1040
+ ch = this.next();
1041
+ }
1042
+
1043
+ if (!detectedIndent && this.lineIndent > textIndent) {
1044
+ textIndent = this.lineIndent;
1045
+ }
1046
+
1047
+ if (isEOL(ch)) {
1048
+ emptyLines++;
1049
+ continue;
1050
+ }
1051
+
1052
+ // End of the scalar.
1053
+ if (this.lineIndent < textIndent) {
1054
+ // Perform the chomping.
1055
+ if (chomping === CHOMPING_KEEP) {
1056
+ result += "\n".repeat(
1057
+ didReadContent ? 1 + emptyLines : emptyLines,
1058
+ );
1059
+ } else if (chomping === CHOMPING_CLIP) {
1060
+ if (didReadContent) {
1061
+ // i.e. only if the scalar is not empty.
1062
+ result += "\n";
1063
+ }
1064
+ }
1065
+
1066
+ // Break this `while` cycle and go to the function's epilogue.
1067
+ break;
1068
+ }
1069
+
1070
+ // Folded style: use fancy rules to handle line breaks.
1071
+ if (folding) {
1072
+ // Lines starting with white space characters (more-indented lines) are not folded.
1073
+ if (isWhiteSpace(ch)) {
1074
+ atMoreIndented = true;
1075
+ // except for the first content line (cf. Example 8.1)
1076
+ result += "\n".repeat(
1077
+ didReadContent ? 1 + emptyLines : emptyLines,
1078
+ );
1079
+
1080
+ // End of more-indented block.
1081
+ } else if (atMoreIndented) {
1082
+ atMoreIndented = false;
1083
+ result += "\n".repeat(emptyLines + 1);
1084
+
1085
+ // Just one line break - perceive as the same line.
1086
+ } else if (emptyLines === 0) {
1087
+ if (didReadContent) {
1088
+ // i.e. only if we have already read some scalar content.
1089
+ result += " ";
1090
+ }
1091
+
1092
+ // Several line breaks - perceive as different lines.
1093
+ } else {
1094
+ result += "\n".repeat(emptyLines);
1095
+ }
1096
+
1097
+ // Literal style: just add exact number of line breaks between content lines.
1098
+ } else {
1099
+ // Keep all line breaks except the header line break.
1100
+ result += "\n".repeat(
1101
+ didReadContent ? 1 + emptyLines : emptyLines,
1102
+ );
1103
+ }
1104
+
1105
+ didReadContent = true;
1106
+ detectedIndent = true;
1107
+ emptyLines = 0;
1108
+ const captureStart = this.position;
1109
+
1110
+ while (!isEOL(ch) && ch !== 0) {
1111
+ ch = this.next();
1112
+ }
1113
+
1114
+ const segment = this.captureSegment(captureStart, this.position, false);
1115
+ if (segment) result += segment;
1116
+ }
1117
+
1118
+ if (anchor !== null) this.anchorMap.set(anchor, result);
1119
+ return { tag, anchor, kind: "scalar", result };
1120
+ }
1121
+ readBlockMapping(
1122
+ tag: string | null,
1123
+ anchor: string | null,
1124
+ nodeIndent: number,
1125
+ flowIndent: number,
1126
+ ): State | void {
1127
+ const result = {};
1128
+ const overridableKeys = new Set<string>();
1129
+
1130
+ let allowCompact = false;
1131
+ let line: number;
1132
+ let pos: number;
1133
+ let keyTag = null;
1134
+ let keyNode = null;
1135
+ let valueNode = null;
1136
+ let atExplicitKey = false;
1137
+ let detected = false;
1138
+
1139
+ if (anchor !== null) this.anchorMap.set(anchor, result);
1140
+
1141
+ let ch = this.peek();
1142
+
1143
+ while (ch !== 0) {
1144
+ const following = this.peek(1);
1145
+ line = this.line; // Save the current line.
1146
+ pos = this.position;
1147
+
1148
+ //
1149
+ // Explicit notation case. There are two separate blocks:
1150
+ // first for the key (denoted by "?") and second for the value (denoted by ":")
1151
+ //
1152
+ if ((ch === QUESTION || ch === COLON) && isWhiteSpaceOrEOL(following)) {
1153
+ if (ch === QUESTION) {
1154
+ if (atExplicitKey) {
1155
+ this.storeMappingPair(
1156
+ result,
1157
+ overridableKeys,
1158
+ keyTag as string,
1159
+ keyNode,
1160
+ null,
1161
+ );
1162
+ keyTag = null;
1163
+ keyNode = null;
1164
+ valueNode = null;
1165
+ }
1166
+
1167
+ detected = true;
1168
+ atExplicitKey = true;
1169
+ allowCompact = true;
1170
+ } else if (atExplicitKey) {
1171
+ // i.e. 0x3A/* : */ === character after the explicit key.
1172
+ atExplicitKey = false;
1173
+ allowCompact = true;
1174
+ } else {
1175
+ throw this.#createError(
1176
+ "Cannot read block as explicit mapping pair is incomplete: a key node is missed or followed by a non-tabulated empty line",
1177
+ );
1178
+ }
1179
+
1180
+ this.position += 1;
1181
+ ch = following;
1182
+
1183
+ //
1184
+ // Implicit notation case. Flow-style node as the key first, then ":", and the value.
1185
+ //
1186
+ } else {
1187
+ const newState = this.composeNode({
1188
+ parentIndent: flowIndent,
1189
+ nodeContext: CONTEXT_FLOW_OUT,
1190
+ allowToSeek: false,
1191
+ allowCompact: true,
1192
+ });
1193
+ if (!newState) break; // Reading is done. Go to the epilogue.
1194
+ if (this.line === line) {
1195
+ ch = this.peek();
1196
+
1197
+ this.skipWhitespaces();
1198
+ ch = this.peek();
1199
+
1200
+ if (ch === COLON) {
1201
+ ch = this.next();
1202
+
1203
+ if (!isWhiteSpaceOrEOL(ch)) {
1204
+ throw this.#createError(
1205
+ "Cannot read block: a whitespace character is expected after the key-value separator within a block mapping",
1206
+ );
1207
+ }
1208
+
1209
+ if (atExplicitKey) {
1210
+ this.storeMappingPair(
1211
+ result,
1212
+ overridableKeys,
1213
+ keyTag as string,
1214
+ keyNode,
1215
+ null,
1216
+ );
1217
+ keyTag = null;
1218
+ keyNode = null;
1219
+ valueNode = null;
1220
+ }
1221
+
1222
+ detected = true;
1223
+ atExplicitKey = false;
1224
+ allowCompact = false;
1225
+ keyTag = newState.tag;
1226
+ keyNode = newState.result;
1227
+ } else if (detected) {
1228
+ throw this.#createError(
1229
+ "Cannot read an implicit mapping pair: missing colon",
1230
+ );
1231
+ } else {
1232
+ const { kind, result } = newState;
1233
+ return { tag, anchor, kind, result }; // Keep the result of `composeNode`.
1234
+ }
1235
+ } else if (detected) {
1236
+ throw this.#createError(
1237
+ "Cannot read a block mapping entry: a multiline key may not be an implicit key",
1238
+ );
1239
+ } else {
1240
+ const { kind, result } = newState;
1241
+ return { tag, anchor, kind, result }; // Keep the result of `composeNode`.
1242
+ }
1243
+ }
1244
+
1245
+ //
1246
+ // Common reading code for both explicit and implicit notations.
1247
+ //
1248
+ if (this.line === line || this.lineIndent > nodeIndent) {
1249
+ const newState = this.composeNode({
1250
+ parentIndent: nodeIndent,
1251
+ nodeContext: CONTEXT_BLOCK_OUT,
1252
+ allowToSeek: true,
1253
+ allowCompact,
1254
+ });
1255
+ if (newState) {
1256
+ if (atExplicitKey) {
1257
+ keyNode = newState.result;
1258
+ } else {
1259
+ valueNode = newState.result;
1260
+ }
1261
+ }
1262
+
1263
+ if (!atExplicitKey) {
1264
+ this.storeMappingPair(
1265
+ result,
1266
+ overridableKeys,
1267
+ keyTag as string,
1268
+ keyNode,
1269
+ valueNode,
1270
+ line,
1271
+ pos,
1272
+ );
1273
+ keyTag = keyNode = valueNode = null;
1274
+ }
1275
+
1276
+ this.skipSeparationSpace(true, -1);
1277
+ ch = this.peek();
1278
+ }
1279
+
1280
+ if (this.lineIndent > nodeIndent && ch !== 0) {
1281
+ throw this.#createError(
1282
+ "Cannot read block: bad indentation of a mapping entry",
1283
+ );
1284
+ } else if (this.lineIndent < nodeIndent) {
1285
+ break;
1286
+ }
1287
+ }
1288
+
1289
+ //
1290
+ // Epilogue.
1291
+ //
1292
+
1293
+ // Special case: last mapping's node contains only the key in explicit notation.
1294
+ if (atExplicitKey) {
1295
+ this.storeMappingPair(
1296
+ result,
1297
+ overridableKeys,
1298
+ keyTag as string,
1299
+ keyNode,
1300
+ null,
1301
+ );
1302
+ }
1303
+
1304
+ // Expose the resulting mapping.
1305
+ if (detected) return { tag, anchor, kind: "mapping", result };
1306
+ }
1307
+ readTagProperty(tag: string | null): string | void {
1308
+ let isVerbatim = false;
1309
+ let isNamed = false;
1310
+ let tagHandle = "";
1311
+ let tagName: string;
1312
+
1313
+ let ch = this.peek();
1314
+
1315
+ if (ch !== EXCLAMATION) return;
1316
+
1317
+ if (tag !== null) {
1318
+ throw this.#createError(
1319
+ "Cannot read tag property: duplication of a tag property",
1320
+ );
1321
+ }
1322
+
1323
+ ch = this.next();
1324
+
1325
+ if (ch === SMALLER_THAN) {
1326
+ isVerbatim = true;
1327
+ ch = this.next();
1328
+ } else if (ch === EXCLAMATION) {
1329
+ isNamed = true;
1330
+ tagHandle = "!!";
1331
+ ch = this.next();
1332
+ } else {
1333
+ tagHandle = "!";
1334
+ }
1335
+
1336
+ let position = this.position;
1337
+
1338
+ if (isVerbatim) {
1339
+ do {
1340
+ ch = this.next();
1341
+ } while (ch !== 0 && ch !== GREATER_THAN);
1342
+
1343
+ if (this.position < this.length) {
1344
+ tagName = this.input.slice(position, this.position);
1345
+ ch = this.next();
1346
+ } else {
1347
+ throw this.#createError(
1348
+ "Cannot read tag property: unexpected end of stream",
1349
+ );
1350
+ }
1351
+ } else {
1352
+ while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
1353
+ if (ch === EXCLAMATION) {
1354
+ if (!isNamed) {
1355
+ tagHandle = this.input.slice(position - 1, this.position + 1);
1356
+
1357
+ if (!PATTERN_TAG_HANDLE.test(tagHandle)) {
1358
+ throw this.#createError(
1359
+ "Cannot read tag property: named tag handle contains invalid characters",
1360
+ );
1361
+ }
1362
+
1363
+ isNamed = true;
1364
+ position = this.position + 1;
1365
+ } else {
1366
+ throw this.#createError(
1367
+ "Cannot read tag property: tag suffix cannot contain an exclamation mark",
1368
+ );
1369
+ }
1370
+ }
1371
+
1372
+ ch = this.next();
1373
+ }
1374
+
1375
+ tagName = this.input.slice(position, this.position);
1376
+
1377
+ if (PATTERN_FLOW_INDICATORS.test(tagName)) {
1378
+ throw this.#createError(
1379
+ "Cannot read tag property: tag suffix cannot contain flow indicator characters",
1380
+ );
1381
+ }
1382
+ }
1383
+
1384
+ if (tagName && !PATTERN_TAG_URI.test(tagName)) {
1385
+ throw this.#createError(
1386
+ `Cannot read tag property: invalid characters in tag name "${tagName}"`,
1387
+ );
1388
+ }
1389
+
1390
+ if (isVerbatim) {
1391
+ return tagName;
1392
+ } else if (this.tagMap.has(tagHandle)) {
1393
+ return this.tagMap.get(tagHandle) + tagName;
1394
+ } else if (tagHandle === "!") {
1395
+ return `!${tagName}`;
1396
+ } else if (tagHandle === "!!") {
1397
+ return `tag:yaml.org,2002:${tagName}`;
1398
+ }
1399
+
1400
+ throw this.#createError(
1401
+ `Cannot read tag property: undeclared tag handle "${tagHandle}"`,
1402
+ );
1403
+ }
1404
+ readAnchorProperty(anchor: string | null): string | void {
1405
+ let ch = this.peek();
1406
+ if (ch !== AMPERSAND) return;
1407
+
1408
+ if (anchor !== null) {
1409
+ throw this.#createError(
1410
+ "Cannot read anchor property: duplicate anchor property",
1411
+ );
1412
+ }
1413
+ ch = this.next();
1414
+
1415
+ const position = this.position;
1416
+ while (ch !== 0 && !isWhiteSpaceOrEOL(ch) && !isFlowIndicator(ch)) {
1417
+ ch = this.next();
1418
+ }
1419
+
1420
+ if (this.position === position) {
1421
+ throw this.#createError(
1422
+ "Cannot read anchor property: name of an anchor node must contain at least one character",
1423
+ );
1424
+ }
1425
+
1426
+ return this.input.slice(position, this.position);
1427
+ }
1428
+ readAlias(): string | void {
1429
+ if (this.peek() !== ASTERISK) return;
1430
+
1431
+ let ch = this.next();
1432
+
1433
+ const position = this.position;
1434
+
1435
+ while (ch !== 0 && !isWhiteSpaceOrEOL(ch) && !isFlowIndicator(ch)) {
1436
+ ch = this.next();
1437
+ }
1438
+
1439
+ if (this.position === position) {
1440
+ throw this.#createError(
1441
+ "Cannot read alias: alias name must contain at least one character",
1442
+ );
1443
+ }
1444
+
1445
+ const alias = this.input.slice(position, this.position);
1446
+ if (!this.anchorMap.has(alias)) {
1447
+ throw this.#createError(
1448
+ `Cannot read alias: unidentified alias "${alias}"`,
1449
+ );
1450
+ }
1451
+
1452
+ this.skipSeparationSpace(true, -1);
1453
+
1454
+ return this.anchorMap.get(alias);
1455
+ }
1456
+ resolveTag(state: State) {
1457
+ switch (state.tag) {
1458
+ case null:
1459
+ case "!":
1460
+ return state;
1461
+ case "?": {
1462
+ for (const type of this.implicitTypes) {
1463
+ // Implicit resolving is not allowed for non-scalar types, and '?'
1464
+ // non-specific tag is only assigned to plain scalars. So, it isn't
1465
+ // needed to check for 'kind' conformity.
1466
+
1467
+ if (!type.resolve(state.result)) continue;
1468
+ // `state.result` updated in resolver if matched
1469
+ const result = type.construct(state.result);
1470
+ state.result = result;
1471
+ state.tag = type.tag;
1472
+ const { anchor } = state;
1473
+ if (anchor !== null) this.anchorMap.set(anchor, result);
1474
+ return state;
1475
+ }
1476
+ return state;
1477
+ }
1478
+ }
1479
+
1480
+ const kind = state.kind ?? "fallback";
1481
+
1482
+ const map = this.typeMap[kind];
1483
+ const type = map.get(state.tag);
1484
+
1485
+ if (!type) {
1486
+ throw this.#createError(
1487
+ `Cannot resolve unknown tag !<${state.tag}>`,
1488
+ );
1489
+ }
1490
+
1491
+ if (state.result !== null && type.kind !== state.kind) {
1492
+ throw this.#createError(
1493
+ `Unacceptable node kind for !<${state.tag}> tag: it should be "${type.kind}", not "${state.kind}"`,
1494
+ );
1495
+ }
1496
+
1497
+ if (!type.resolve(state.result)) {
1498
+ // `state.result` updated in resolver if matched
1499
+ throw this.#createError(
1500
+ `Cannot resolve a node with !<${state.tag}> explicit tag`,
1501
+ );
1502
+ }
1503
+
1504
+ const result = type.construct(state.result);
1505
+ state.result = result;
1506
+ const { anchor } = state;
1507
+ if (anchor !== null) this.anchorMap.set(anchor, result);
1508
+ return state;
1509
+ }
1510
+ composeNode({ parentIndent, nodeContext, allowToSeek, allowCompact }: {
1511
+ parentIndent: number;
1512
+ nodeContext: number;
1513
+ allowToSeek: boolean;
1514
+ allowCompact: boolean;
1515
+ }): State | void {
1516
+ let indentStatus = 1; // 1: this>parent, 0: this=parent, -1: this<parent
1517
+ let atNewLine = false;
1518
+
1519
+ const allowBlockScalars = CONTEXT_BLOCK_OUT === nodeContext ||
1520
+ CONTEXT_BLOCK_IN === nodeContext;
1521
+
1522
+ let allowBlockCollections = allowBlockScalars;
1523
+ const allowBlockStyles = allowBlockScalars;
1524
+
1525
+ if (allowToSeek) {
1526
+ if (this.skipSeparationSpace(true, -1)) {
1527
+ atNewLine = true;
1528
+ indentStatus = getIndentStatus(this.lineIndent, parentIndent);
1529
+ }
1530
+ }
1531
+
1532
+ let tag: string | null = null;
1533
+ let anchor: string | null = null;
1534
+
1535
+ if (indentStatus === 1) {
1536
+ while (true) {
1537
+ const newTag = this.readTagProperty(tag);
1538
+ if (newTag) {
1539
+ tag = newTag;
1540
+ } else {
1541
+ const newAnchor = this.readAnchorProperty(anchor);
1542
+ if (!newAnchor) break;
1543
+ anchor = newAnchor;
1544
+ }
1545
+ if (this.skipSeparationSpace(true, -1)) {
1546
+ atNewLine = true;
1547
+ allowBlockCollections = allowBlockStyles;
1548
+ indentStatus = getIndentStatus(this.lineIndent, parentIndent);
1549
+ } else {
1550
+ allowBlockCollections = false;
1551
+ }
1552
+ }
1553
+ }
1554
+
1555
+ if (allowBlockCollections) {
1556
+ allowBlockCollections = atNewLine || allowCompact;
1557
+ }
1558
+
1559
+ if (indentStatus === 1) {
1560
+ const cond = CONTEXT_FLOW_IN === nodeContext ||
1561
+ CONTEXT_FLOW_OUT === nodeContext;
1562
+ const flowIndent = cond ? parentIndent : parentIndent + 1;
1563
+
1564
+ if (allowBlockCollections) {
1565
+ const blockIndent = this.position - this.lineStart;
1566
+ const blockSequenceState = this.readBlockSequence(
1567
+ tag,
1568
+ anchor,
1569
+ blockIndent,
1570
+ );
1571
+ if (blockSequenceState) return this.resolveTag(blockSequenceState);
1572
+
1573
+ const blockMappingState = this.readBlockMapping(
1574
+ tag,
1575
+ anchor,
1576
+ blockIndent,
1577
+ flowIndent,
1578
+ );
1579
+ if (blockMappingState) return this.resolveTag(blockMappingState);
1580
+ }
1581
+ const flowCollectionState = this.readFlowCollection(
1582
+ tag,
1583
+ anchor,
1584
+ flowIndent,
1585
+ );
1586
+ if (flowCollectionState) return this.resolveTag(flowCollectionState);
1587
+
1588
+ if (allowBlockScalars) {
1589
+ const blockScalarState = this.readBlockScalar(
1590
+ tag,
1591
+ anchor,
1592
+ flowIndent,
1593
+ );
1594
+ if (blockScalarState) return this.resolveTag(blockScalarState);
1595
+ }
1596
+ const singleQuoteState = this.readSingleQuotedScalar(
1597
+ tag,
1598
+ anchor,
1599
+ flowIndent,
1600
+ );
1601
+ if (singleQuoteState) return this.resolveTag(singleQuoteState);
1602
+
1603
+ const doubleQuoteState = this.readDoubleQuotedScalar(
1604
+ tag,
1605
+ anchor,
1606
+ flowIndent,
1607
+ );
1608
+ if (doubleQuoteState) return this.resolveTag(doubleQuoteState);
1609
+
1610
+ const alias = this.readAlias();
1611
+ if (alias) {
1612
+ if (tag !== null || anchor !== null) {
1613
+ throw this.#createError(
1614
+ "Cannot compose node: alias node should not have any properties",
1615
+ );
1616
+ }
1617
+ return this.resolveTag({ tag, anchor, kind: null, result: alias });
1618
+ }
1619
+ const plainScalarState = this.readPlainScalar(
1620
+ tag,
1621
+ anchor,
1622
+ flowIndent,
1623
+ CONTEXT_FLOW_IN === nodeContext,
1624
+ );
1625
+ if (plainScalarState) {
1626
+ plainScalarState.tag ??= "?";
1627
+ return this.resolveTag(plainScalarState);
1628
+ }
1629
+ } else if (
1630
+ indentStatus === 0 &&
1631
+ CONTEXT_BLOCK_OUT === nodeContext &&
1632
+ allowBlockCollections
1633
+ ) {
1634
+ // Special case: block sequences are allowed to have same indentation level as the parent.
1635
+ // http://www.yaml.org/spec/1.2/spec.html#id2799784
1636
+ const blockIndent = this.position - this.lineStart;
1637
+ const newState = this.readBlockSequence(tag, anchor, blockIndent);
1638
+ if (newState) return this.resolveTag(newState);
1639
+ }
1640
+
1641
+ const newState = this.resolveTag({ tag, anchor, kind: null, result: null });
1642
+ if (newState.tag !== null || newState.anchor !== null) return newState;
1643
+ }
1644
+
1645
+ readDirectives() {
1646
+ let hasDirectives = false;
1647
+ let version = null;
1648
+
1649
+ let ch = this.peek();
1650
+ while (ch !== 0) {
1651
+ this.skipSeparationSpace(true, -1);
1652
+
1653
+ ch = this.peek();
1654
+
1655
+ if (this.lineIndent > 0 || ch !== PERCENT) {
1656
+ break;
1657
+ }
1658
+
1659
+ hasDirectives = true;
1660
+ ch = this.next();
1661
+ let position = this.position;
1662
+
1663
+ while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
1664
+ ch = this.next();
1665
+ }
1666
+
1667
+ const directiveName = this.input.slice(position, this.position);
1668
+ const directiveArgs = [];
1669
+
1670
+ if (directiveName.length < 1) {
1671
+ throw this.#createError(
1672
+ "Cannot read document: directive name length must be greater than zero",
1673
+ );
1674
+ }
1675
+
1676
+ while (ch !== 0) {
1677
+ this.skipWhitespaces();
1678
+ this.skipComment();
1679
+ ch = this.peek();
1680
+
1681
+ if (isEOL(ch)) break;
1682
+
1683
+ position = this.position;
1684
+
1685
+ while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
1686
+ ch = this.next();
1687
+ }
1688
+
1689
+ directiveArgs.push(this.input.slice(position, this.position));
1690
+ }
1691
+
1692
+ if (ch !== 0) this.readLineBreak();
1693
+
1694
+ switch (directiveName) {
1695
+ case "YAML":
1696
+ if (version !== null) {
1697
+ throw this.#createError(
1698
+ "Cannot handle YAML directive: duplication of %YAML directive",
1699
+ );
1700
+ }
1701
+ version = this.yamlDirectiveHandler(directiveArgs);
1702
+ break;
1703
+ case "TAG":
1704
+ this.tagDirectiveHandler(directiveArgs);
1705
+ break;
1706
+ default:
1707
+ this.dispatchWarning(`unknown document directive "${directiveName}"`);
1708
+ break;
1709
+ }
1710
+
1711
+ ch = this.peek();
1712
+ }
1713
+ return hasDirectives;
1714
+ }
1715
+
1716
+ readDocument() {
1717
+ const documentStart = this.position;
1718
+
1719
+ this.checkLineBreaks = false;
1720
+ this.tagMap = new Map();
1721
+ this.anchorMap = new Map();
1722
+
1723
+ const hasDirectives = this.readDirectives();
1724
+
1725
+ this.skipSeparationSpace(true, -1);
1726
+
1727
+ let result = null;
1728
+
1729
+ if (
1730
+ this.lineIndent === 0 &&
1731
+ this.peek() === MINUS &&
1732
+ this.peek(1) === MINUS &&
1733
+ this.peek(2) === MINUS
1734
+ ) {
1735
+ this.position += 3;
1736
+ this.skipSeparationSpace(true, -1);
1737
+ } else if (hasDirectives) {
1738
+ throw this.#createError(
1739
+ "Cannot read document: directives end mark is expected",
1740
+ );
1741
+ }
1742
+
1743
+ const newState = this.composeNode({
1744
+ parentIndent: this.lineIndent - 1,
1745
+ nodeContext: CONTEXT_BLOCK_OUT,
1746
+ allowToSeek: false,
1747
+ allowCompact: true,
1748
+ });
1749
+ if (newState) result = newState.result;
1750
+ this.skipSeparationSpace(true, -1);
1751
+
1752
+ if (
1753
+ this.checkLineBreaks &&
1754
+ PATTERN_NON_ASCII_LINE_BREAKS.test(
1755
+ this.input.slice(documentStart, this.position),
1756
+ )
1757
+ ) {
1758
+ this.dispatchWarning("non-ASCII line breaks are interpreted as content");
1759
+ }
1760
+
1761
+ if (this.position === this.lineStart && this.testDocumentSeparator()) {
1762
+ if (this.peek() === DOT) {
1763
+ this.position += 3;
1764
+ this.skipSeparationSpace(true, -1);
1765
+ }
1766
+ } else if (this.position < this.length - 1) {
1767
+ throw this.#createError(
1768
+ "Cannot read document: end of the stream or a document separator is expected",
1769
+ );
1770
+ }
1771
+
1772
+ return result;
1773
+ }
1774
+
1775
+ *readDocuments() {
1776
+ while (this.position < this.length - 1) {
1777
+ yield this.readDocument();
1778
+ }
1779
+ }
1780
+ }