@tinta-lang/syntax 0.0.0-stage → 0.1.0-dev.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 (245) hide show
  1. package/LICENSE +21 -0
  2. package/THIRD_PARTY_NOTICES.txt +13651 -0
  3. package/dist/directive.d.ts +40 -0
  4. package/dist/editing.d.ts +46 -0
  5. package/dist/enrichment.d.ts +5 -0
  6. package/dist/expression.d.ts +26 -0
  7. package/dist/image-destinations.d.ts +3 -0
  8. package/dist/index.d.ts +8 -0
  9. package/dist/index.js +10118 -0
  10. package/dist/parser.d.ts +40 -0
  11. package/dist/registry.d.ts +144 -0
  12. package/dist/source.d.ts +28 -0
  13. package/package.json +280 -3
  14. package/parser-provenance.json +1419 -0
  15. package/patches/README.md +5 -0
  16. package/patches/micromark.patch +84 -0
  17. package/vendor/@noble/hashes/LICENSE +21 -0
  18. package/vendor/@noble/hashes/_md.js +209 -0
  19. package/vendor/@noble/hashes/_u64.js +77 -0
  20. package/vendor/@noble/hashes/package.json +91 -0
  21. package/vendor/@noble/hashes/sha2.js +446 -0
  22. package/vendor/@noble/hashes/utils.js +687 -0
  23. package/vendor/character-entities/index.js +2132 -0
  24. package/vendor/character-entities/license +22 -0
  25. package/vendor/character-entities/package.json +78 -0
  26. package/vendor/decode-named-character-reference/index.js +19 -0
  27. package/vendor/decode-named-character-reference/license +22 -0
  28. package/vendor/decode-named-character-reference/package.json +90 -0
  29. package/vendor/devlop/lib/default.js +9 -0
  30. package/vendor/devlop/license +22 -0
  31. package/vendor/devlop/package.json +80 -0
  32. package/vendor/longest-streak/index.js +36 -0
  33. package/vendor/longest-streak/license +22 -0
  34. package/vendor/longest-streak/package.json +73 -0
  35. package/vendor/markdown-table/index.js +393 -0
  36. package/vendor/markdown-table/license +22 -0
  37. package/vendor/markdown-table/package.json +77 -0
  38. package/vendor/mdast-util-from-markdown/index.js +2 -0
  39. package/vendor/mdast-util-from-markdown/lib/index.js +1270 -0
  40. package/vendor/mdast-util-from-markdown/license +22 -0
  41. package/vendor/mdast-util-from-markdown/package.json +98 -0
  42. package/vendor/mdast-util-gfm-strikethrough/index.js +5 -0
  43. package/vendor/mdast-util-gfm-strikethrough/lib/index.js +133 -0
  44. package/vendor/mdast-util-gfm-strikethrough/license +22 -0
  45. package/vendor/mdast-util-gfm-strikethrough/package.json +84 -0
  46. package/vendor/mdast-util-gfm-table/index.js +2 -0
  47. package/vendor/mdast-util-gfm-table/lib/index.js +300 -0
  48. package/vendor/mdast-util-gfm-table/license +22 -0
  49. package/vendor/mdast-util-gfm-table/package.json +101 -0
  50. package/vendor/mdast-util-gfm-task-list-item/index.js +4 -0
  51. package/vendor/mdast-util-gfm-task-list-item/lib/index.js +141 -0
  52. package/vendor/mdast-util-gfm-task-list-item/license +22 -0
  53. package/vendor/mdast-util-gfm-task-list-item/package.json +90 -0
  54. package/vendor/mdast-util-phrasing/index.js +1 -0
  55. package/vendor/mdast-util-phrasing/lib/index.js +45 -0
  56. package/vendor/mdast-util-phrasing/license +23 -0
  57. package/vendor/mdast-util-phrasing/package.json +78 -0
  58. package/vendor/mdast-util-to-markdown/index.js +3 -0
  59. package/vendor/mdast-util-to-markdown/lib/configure.js +98 -0
  60. package/vendor/mdast-util-to-markdown/lib/handle/blockquote.js +40 -0
  61. package/vendor/mdast-util-to-markdown/lib/handle/break.js +41 -0
  62. package/vendor/mdast-util-to-markdown/lib/handle/code.js +86 -0
  63. package/vendor/mdast-util-to-markdown/lib/handle/definition.js +83 -0
  64. package/vendor/mdast-util-to-markdown/lib/handle/emphasis.js +67 -0
  65. package/vendor/mdast-util-to-markdown/lib/handle/heading.js +84 -0
  66. package/vendor/mdast-util-to-markdown/lib/handle/html.js +27 -0
  67. package/vendor/mdast-util-to-markdown/lib/handle/image-reference.js +78 -0
  68. package/vendor/mdast-util-to-markdown/lib/handle/image.js +92 -0
  69. package/vendor/mdast-util-to-markdown/lib/handle/index.js +45 -0
  70. package/vendor/mdast-util-to-markdown/lib/handle/inline-code.js +86 -0
  71. package/vendor/mdast-util-to-markdown/lib/handle/link-reference.js +78 -0
  72. package/vendor/mdast-util-to-markdown/lib/handle/link.js +129 -0
  73. package/vendor/mdast-util-to-markdown/lib/handle/list-item.js +73 -0
  74. package/vendor/mdast-util-to-markdown/lib/handle/list.js +107 -0
  75. package/vendor/mdast-util-to-markdown/lib/handle/paragraph.js +27 -0
  76. package/vendor/mdast-util-to-markdown/lib/handle/root.js +34 -0
  77. package/vendor/mdast-util-to-markdown/lib/handle/strong.js +67 -0
  78. package/vendor/mdast-util-to-markdown/lib/handle/text.js +30 -0
  79. package/vendor/mdast-util-to-markdown/lib/handle/thematic-break.js +27 -0
  80. package/vendor/mdast-util-to-markdown/lib/index.js +213 -0
  81. package/vendor/mdast-util-to-markdown/lib/join.js +56 -0
  82. package/vendor/mdast-util-to-markdown/lib/unsafe.js +160 -0
  83. package/vendor/mdast-util-to-markdown/lib/util/association.js +33 -0
  84. package/vendor/mdast-util-to-markdown/lib/util/character.js +32 -0
  85. package/vendor/mdast-util-to-markdown/lib/util/check-bullet-ordered.js +25 -0
  86. package/vendor/mdast-util-to-markdown/lib/util/check-bullet-other.js +42 -0
  87. package/vendor/mdast-util-to-markdown/lib/util/check-bullet.js +25 -0
  88. package/vendor/mdast-util-to-markdown/lib/util/check-emphasis.js +25 -0
  89. package/vendor/mdast-util-to-markdown/lib/util/check-fence.js +25 -0
  90. package/vendor/mdast-util-to-markdown/lib/util/check-list-item-indent.js +25 -0
  91. package/vendor/mdast-util-to-markdown/lib/util/check-quote.js +25 -0
  92. package/vendor/mdast-util-to-markdown/lib/util/check-rule-repetition.js +25 -0
  93. package/vendor/mdast-util-to-markdown/lib/util/check-rule.js +25 -0
  94. package/vendor/mdast-util-to-markdown/lib/util/check-strong.js +25 -0
  95. package/vendor/mdast-util-to-markdown/lib/util/compile-pattern.js +30 -0
  96. package/vendor/mdast-util-to-markdown/lib/util/container-flow.js +93 -0
  97. package/vendor/mdast-util-to-markdown/lib/util/container-phrasing.js +704 -0
  98. package/vendor/mdast-util-to-markdown/lib/util/encode-character-reference.js +11 -0
  99. package/vendor/mdast-util-to-markdown/lib/util/encode-info.js +82 -0
  100. package/vendor/mdast-util-to-markdown/lib/util/format-code-as-indented.js +27 -0
  101. package/vendor/mdast-util-to-markdown/lib/util/format-heading-as-setext.js +39 -0
  102. package/vendor/mdast-util-to-markdown/lib/util/format-link-as-autolink.js +39 -0
  103. package/vendor/mdast-util-to-markdown/lib/util/html-kind.js +63 -0
  104. package/vendor/mdast-util-to-markdown/lib/util/indent-lines.js +40 -0
  105. package/vendor/mdast-util-to-markdown/lib/util/pattern-in-scope.js +52 -0
  106. package/vendor/mdast-util-to-markdown/lib/util/safe.js +263 -0
  107. package/vendor/mdast-util-to-markdown/lib/util/track.js +55 -0
  108. package/vendor/mdast-util-to-markdown/license +22 -0
  109. package/vendor/mdast-util-to-markdown/package.json +88 -0
  110. package/vendor/mdast-util-to-string/index.js +5 -0
  111. package/vendor/mdast-util-to-string/lib/index.js +108 -0
  112. package/vendor/mdast-util-to-string/license +22 -0
  113. package/vendor/mdast-util-to-string/package.json +78 -0
  114. package/vendor/micromark/index.js +60 -0
  115. package/vendor/micromark/lib/compile.js +1068 -0
  116. package/vendor/micromark/lib/constructs.js +85 -0
  117. package/vendor/micromark/lib/create-tokenizer.js +615 -0
  118. package/vendor/micromark/lib/initialize/content.js +79 -0
  119. package/vendor/micromark/lib/initialize/document.js +370 -0
  120. package/vendor/micromark/lib/initialize/flow.js +58 -0
  121. package/vendor/micromark/lib/initialize/text.js +216 -0
  122. package/vendor/micromark/lib/parse.js +56 -0
  123. package/vendor/micromark/lib/postprocess.js +18 -0
  124. package/vendor/micromark/lib/preprocess.js +112 -0
  125. package/vendor/micromark/license +22 -0
  126. package/vendor/micromark/package.json +87 -0
  127. package/vendor/micromark-core-commonmark/index.js +22 -0
  128. package/vendor/micromark-core-commonmark/lib/attention.js +231 -0
  129. package/vendor/micromark-core-commonmark/lib/autolink.js +233 -0
  130. package/vendor/micromark-core-commonmark/lib/blank-line.js +61 -0
  131. package/vendor/micromark-core-commonmark/lib/block-quote.js +143 -0
  132. package/vendor/micromark-core-commonmark/lib/character-escape.js +64 -0
  133. package/vendor/micromark-core-commonmark/lib/character-reference.js +149 -0
  134. package/vendor/micromark-core-commonmark/lib/code-fenced.js +422 -0
  135. package/vendor/micromark-core-commonmark/lib/code-indented.js +159 -0
  136. package/vendor/micromark-core-commonmark/lib/code-text.js +225 -0
  137. package/vendor/micromark-core-commonmark/lib/content.js +163 -0
  138. package/vendor/micromark-core-commonmark/lib/definition.js +254 -0
  139. package/vendor/micromark-core-commonmark/lib/hard-break-escape.js +60 -0
  140. package/vendor/micromark-core-commonmark/lib/heading-atx.js +191 -0
  141. package/vendor/micromark-core-commonmark/lib/html-flow.js +827 -0
  142. package/vendor/micromark-core-commonmark/lib/html-text.js +678 -0
  143. package/vendor/micromark-core-commonmark/lib/label-end.js +561 -0
  144. package/vendor/micromark-core-commonmark/lib/label-start-image.js +110 -0
  145. package/vendor/micromark-core-commonmark/lib/label-start-link.js +63 -0
  146. package/vendor/micromark-core-commonmark/lib/line-ending.js +33 -0
  147. package/vendor/micromark-core-commonmark/lib/list.js +213 -0
  148. package/vendor/micromark-core-commonmark/lib/partial-non-lazy-continuation.js +61 -0
  149. package/vendor/micromark-core-commonmark/lib/setext-underline.js +187 -0
  150. package/vendor/micromark-core-commonmark/lib/thematic-break.js +102 -0
  151. package/vendor/micromark-core-commonmark/license +22 -0
  152. package/vendor/micromark-core-commonmark/package.json +62 -0
  153. package/vendor/micromark-extension-gfm-strikethrough/index.js +3 -0
  154. package/vendor/micromark-extension-gfm-strikethrough/lib/html.js +26 -0
  155. package/vendor/micromark-extension-gfm-strikethrough/lib/syntax.js +142 -0
  156. package/vendor/micromark-extension-gfm-strikethrough/license +22 -0
  157. package/vendor/micromark-extension-gfm-strikethrough/package.json +129 -0
  158. package/vendor/micromark-extension-gfm-table/index.js +2 -0
  159. package/vendor/micromark-extension-gfm-table/lib/edit-map.js +222 -0
  160. package/vendor/micromark-extension-gfm-table/lib/html.js +135 -0
  161. package/vendor/micromark-extension-gfm-table/lib/infer.js +52 -0
  162. package/vendor/micromark-extension-gfm-table/lib/syntax.js +846 -0
  163. package/vendor/micromark-extension-gfm-table/license +22 -0
  164. package/vendor/micromark-extension-gfm-table/package.json +86 -0
  165. package/vendor/micromark-extension-gfm-task-list-item/index.js +2 -0
  166. package/vendor/micromark-extension-gfm-task-list-item/lib/html.js +29 -0
  167. package/vendor/micromark-extension-gfm-task-list-item/lib/syntax.js +158 -0
  168. package/vendor/micromark-extension-gfm-task-list-item/license +22 -0
  169. package/vendor/micromark-extension-gfm-task-list-item/package.json +131 -0
  170. package/vendor/micromark-factory-destination/index.js +206 -0
  171. package/vendor/micromark-factory-destination/license +22 -0
  172. package/vendor/micromark-factory-destination/package.json +57 -0
  173. package/vendor/micromark-factory-label/index.js +148 -0
  174. package/vendor/micromark-factory-label/license +22 -0
  175. package/vendor/micromark-factory-label/package.json +60 -0
  176. package/vendor/micromark-factory-space/index.js +116 -0
  177. package/vendor/micromark-factory-space/license +22 -0
  178. package/vendor/micromark-factory-space/package.json +46 -0
  179. package/vendor/micromark-factory-title/index.js +158 -0
  180. package/vendor/micromark-factory-title/license +22 -0
  181. package/vendor/micromark-factory-title/package.json +58 -0
  182. package/vendor/micromark-factory-whitespace/index.js +44 -0
  183. package/vendor/micromark-factory-whitespace/license +22 -0
  184. package/vendor/micromark-factory-whitespace/package.json +57 -0
  185. package/vendor/micromark-util-character/index.js +246 -0
  186. package/vendor/micromark-util-character/license +22 -0
  187. package/vendor/micromark-util-character/package.json +57 -0
  188. package/vendor/micromark-util-chunked/index.js +81 -0
  189. package/vendor/micromark-util-chunked/license +22 -0
  190. package/vendor/micromark-util-chunked/package.json +57 -0
  191. package/vendor/micromark-util-classify-character/index.js +27 -0
  192. package/vendor/micromark-util-classify-character/license +22 -0
  193. package/vendor/micromark-util-classify-character/package.json +59 -0
  194. package/vendor/micromark-util-combine-extensions/index.js +143 -0
  195. package/vendor/micromark-util-combine-extensions/license +22 -0
  196. package/vendor/micromark-util-combine-extensions/package.json +52 -0
  197. package/vendor/micromark-util-decode-numeric-character-reference/index.js +32 -0
  198. package/vendor/micromark-util-decode-numeric-character-reference/license +22 -0
  199. package/vendor/micromark-util-decode-numeric-character-reference/package.json +59 -0
  200. package/vendor/micromark-util-decode-string/index.js +45 -0
  201. package/vendor/micromark-util-decode-string/license +22 -0
  202. package/vendor/micromark-util-decode-string/package.json +63 -0
  203. package/vendor/micromark-util-edit-map/index.js +225 -0
  204. package/vendor/micromark-util-edit-map/license +22 -0
  205. package/vendor/micromark-util-edit-map/package.json +48 -0
  206. package/vendor/micromark-util-encode/index.js +33 -0
  207. package/vendor/micromark-util-encode/license +22 -0
  208. package/vendor/micromark-util-encode/package.json +47 -0
  209. package/vendor/micromark-util-html-tag-name/index.js +93 -0
  210. package/vendor/micromark-util-html-tag-name/license +22 -0
  211. package/vendor/micromark-util-html-tag-name/package.json +47 -0
  212. package/vendor/micromark-util-normalize-identifier/index.js +33 -0
  213. package/vendor/micromark-util-normalize-identifier/license +22 -0
  214. package/vendor/micromark-util-normalize-identifier/package.json +58 -0
  215. package/vendor/micromark-util-resolve-all/index.js +32 -0
  216. package/vendor/micromark-util-resolve-all/license +22 -0
  217. package/vendor/micromark-util-resolve-all/package.json +48 -0
  218. package/vendor/micromark-util-sanitize-uri/index.js +107 -0
  219. package/vendor/micromark-util-sanitize-uri/license +22 -0
  220. package/vendor/micromark-util-sanitize-uri/package.json +59 -0
  221. package/vendor/micromark-util-subtokenize/index.js +228 -0
  222. package/vendor/micromark-util-subtokenize/lib/splice-buffer.js +251 -0
  223. package/vendor/micromark-util-subtokenize/license +22 -0
  224. package/vendor/micromark-util-subtokenize/package.json +60 -0
  225. package/vendor/unist-util-is/index.js +7 -0
  226. package/vendor/unist-util-is/lib/index.js +296 -0
  227. package/vendor/unist-util-is/license +22 -0
  228. package/vendor/unist-util-is/package.json +103 -0
  229. package/vendor/unist-util-stringify-position/index.js +1 -0
  230. package/vendor/unist-util-stringify-position/lib/index.js +84 -0
  231. package/vendor/unist-util-stringify-position/license +22 -0
  232. package/vendor/unist-util-stringify-position/package.json +80 -0
  233. package/vendor/unist-util-visit/index.js +2 -0
  234. package/vendor/unist-util-visit/lib/index.js +312 -0
  235. package/vendor/unist-util-visit/license +22 -0
  236. package/vendor/unist-util-visit/package.json +108 -0
  237. package/vendor/unist-util-visit-parents/index.js +2 -0
  238. package/vendor/unist-util-visit-parents/lib/color.js +7 -0
  239. package/vendor/unist-util-visit-parents/lib/index.js +399 -0
  240. package/vendor/unist-util-visit-parents/license +22 -0
  241. package/vendor/unist-util-visit-parents/package.json +106 -0
  242. package/vendor/zwitch/index.js +118 -0
  243. package/vendor/zwitch/license +22 -0
  244. package/vendor/zwitch/package.json +72 -0
  245. package/README.md +0 -3
@@ -0,0 +1,108 @@
1
+ {
2
+ "name": "unist-util-visit",
3
+ "version": "5.1.0",
4
+ "description": "unist utility to visit nodes",
5
+ "license": "MIT",
6
+ "keywords": [
7
+ "unist",
8
+ "unist-util",
9
+ "util",
10
+ "utility",
11
+ "remark",
12
+ "retext",
13
+ "rehype",
14
+ "mdast",
15
+ "hast",
16
+ "xast",
17
+ "nlcst",
18
+ "natural",
19
+ "language",
20
+ "markdown",
21
+ "html",
22
+ "xml",
23
+ "tree",
24
+ "ast",
25
+ "node",
26
+ "visit",
27
+ "walk"
28
+ ],
29
+ "repository": "syntax-tree/unist-util-visit",
30
+ "bugs": "https://github.com/syntax-tree/unist-util-visit/issues",
31
+ "funding": {
32
+ "type": "opencollective",
33
+ "url": "https://opencollective.com/unified"
34
+ },
35
+ "author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
36
+ "contributors": [
37
+ "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
38
+ "Eugene Sharygin <eush77@gmail.com>",
39
+ "Richard Gibson <richard.gibson@gmail.com>"
40
+ ],
41
+ "sideEffects": false,
42
+ "type": "module",
43
+ "exports": "./index.js",
44
+ "files": [
45
+ "lib/",
46
+ "index.d.ts.map",
47
+ "index.d.ts",
48
+ "index.js"
49
+ ],
50
+ "dependencies": {
51
+ "@types/unist": "^3.0.0",
52
+ "unist-util-is": "^6.0.0",
53
+ "unist-util-visit-parents": "^6.0.0"
54
+ },
55
+ "devDependencies": {
56
+ "@types/mdast": "^4.0.0",
57
+ "@types/node": "^25.0.0",
58
+ "c8": "^10.0.0",
59
+ "mdast-util-from-markdown": "^2.0.0",
60
+ "mdast-util-gfm": "^3.0.0",
61
+ "micromark-extension-gfm": "^3.0.0",
62
+ "prettier": "^3.0.0",
63
+ "remark-cli": "^12.0.0",
64
+ "remark-preset-wooorm": "^11.0.0",
65
+ "tsd": "^0.33.0",
66
+ "type-coverage": "^2.0.0",
67
+ "typescript": "^5.0.0",
68
+ "xo": "^1.0.0"
69
+ },
70
+ "scripts": {
71
+ "prepack": "npm run build && npm run format",
72
+ "build": "tsc --build --clean && tsc --build && tsd && type-coverage",
73
+ "format": "remark . -qfo && prettier . -w --log-level warn && xo --fix",
74
+ "test-api": "node --conditions development test.js",
75
+ "test-coverage": "c8 --100 --reporter lcov npm run test-api",
76
+ "test": "npm run build && npm run format && npm run test-coverage"
77
+ },
78
+ "prettier": {
79
+ "bracketSpacing": false,
80
+ "semi": false,
81
+ "singleQuote": true,
82
+ "tabWidth": 2,
83
+ "trailingComma": "none",
84
+ "useTabs": false
85
+ },
86
+ "remarkConfig": {
87
+ "plugins": [
88
+ "remark-preset-wooorm"
89
+ ]
90
+ },
91
+ "typeCoverage": {
92
+ "atLeast": 100,
93
+ "detail": true,
94
+ "#": "needed `any`s",
95
+ "ignoreFiles": [
96
+ "lib/index.d.ts"
97
+ ],
98
+ "ignoreCatch": true,
99
+ "strict": true
100
+ },
101
+ "xo": {
102
+ "space": true,
103
+ "prettier": true,
104
+ "rules": {
105
+ "unicorn/prefer-at": "off"
106
+ }
107
+ }
108
+ }
@@ -0,0 +1,2 @@
1
+ // Note: types exported from `index.d.ts`
2
+ export {CONTINUE, EXIT, SKIP, visitParents} from './lib/index.js'
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @param {string} d
3
+ * @returns {string}
4
+ */
5
+ export function color(d) {
6
+ return d
7
+ }
@@ -0,0 +1,399 @@
1
+ /**
2
+ * @import {Node as UnistNode, Parent as UnistParent} from 'unist'
3
+ */
4
+
5
+ /**
6
+ * @typedef {Exclude<import('unist-util-is').Test, undefined> | undefined} Test
7
+ * Test from `unist-util-is`.
8
+ *
9
+ * Note: we have remove and add `undefined`, because otherwise when generating
10
+ * automatic `.d.ts` files, TS tries to flatten paths from a local perspective,
11
+ * which doesn’t work when publishing on npm.
12
+ */
13
+
14
+ /**
15
+ * @typedef {(
16
+ * Fn extends (value: any) => value is infer Thing
17
+ * ? Thing
18
+ * : Fallback
19
+ * )} Predicate
20
+ * Get the value of a type guard `Fn`.
21
+ * @template Fn
22
+ * Value; typically function that is a type guard (such as `(x): x is Y`).
23
+ * @template Fallback
24
+ * Value to yield if `Fn` is not a type guard.
25
+ */
26
+
27
+ /**
28
+ * @typedef {(
29
+ * Check extends null | undefined // No test.
30
+ * ? Value
31
+ * : Value extends {type: Check} // String (type) test.
32
+ * ? Value
33
+ * : Value extends Check // Partial test.
34
+ * ? Value
35
+ * : Check extends Function // Function test.
36
+ * ? Predicate<Check, Value> extends Value
37
+ * ? Predicate<Check, Value>
38
+ * : never
39
+ * : never // Some other test?
40
+ * )} MatchesOne
41
+ * Check whether a node matches a primitive check in the type system.
42
+ * @template Value
43
+ * Value; typically unist `Node`.
44
+ * @template Check
45
+ * Value; typically `unist-util-is`-compatible test, but not arrays.
46
+ */
47
+
48
+ /**
49
+ * @typedef {(
50
+ * Check extends ReadonlyArray<infer T>
51
+ * ? MatchesOne<Value, T>
52
+ * : Check extends Array<infer T>
53
+ * ? MatchesOne<Value, T>
54
+ * : MatchesOne<Value, Check>
55
+ * )} Matches
56
+ * Check whether a node matches a check in the type system.
57
+ * @template Value
58
+ * Value; typically unist `Node`.
59
+ * @template Check
60
+ * Value; typically `unist-util-is`-compatible test.
61
+ */
62
+
63
+ /**
64
+ * @typedef {0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10} Uint
65
+ * Number; capped reasonably.
66
+ */
67
+
68
+ /**
69
+ * @typedef {I extends 0 ? 1 : I extends 1 ? 2 : I extends 2 ? 3 : I extends 3 ? 4 : I extends 4 ? 5 : I extends 5 ? 6 : I extends 6 ? 7 : I extends 7 ? 8 : I extends 8 ? 9 : 10} Increment
70
+ * Increment a number in the type system.
71
+ * @template {Uint} [I=0]
72
+ * Index.
73
+ */
74
+
75
+ /**
76
+ * @typedef {(
77
+ * Node extends UnistParent
78
+ * ? Node extends {children: Array<infer Children>}
79
+ * ? Child extends Children ? Node : never
80
+ * : never
81
+ * : never
82
+ * )} InternalParent
83
+ * Collect nodes that can be parents of `Child`.
84
+ * @template {UnistNode} Node
85
+ * All node types in a tree.
86
+ * @template {UnistNode} Child
87
+ * Node to search for.
88
+ */
89
+
90
+ /**
91
+ * @typedef {InternalParent<InclusiveDescendant<Tree>, Child>} Parent
92
+ * Collect nodes in `Tree` that can be parents of `Child`.
93
+ * @template {UnistNode} Tree
94
+ * All node types in a tree.
95
+ * @template {UnistNode} Child
96
+ * Node to search for.
97
+ */
98
+
99
+ /**
100
+ * @typedef {(
101
+ * Depth extends Max
102
+ * ? never
103
+ * :
104
+ * | InternalParent<Node, Child>
105
+ * | InternalAncestor<Node, InternalParent<Node, Child>, Max, Increment<Depth>>
106
+ * )} InternalAncestor
107
+ * Collect nodes in `Tree` that can be ancestors of `Child`.
108
+ * @template {UnistNode} Node
109
+ * All node types in a tree.
110
+ * @template {UnistNode} Child
111
+ * Node to search for.
112
+ * @template {Uint} [Max=10]
113
+ * Max; searches up to this depth.
114
+ * @template {Uint} [Depth=0]
115
+ * Current depth.
116
+ */
117
+
118
+ /**
119
+ * @typedef {InternalAncestor<InclusiveDescendant<Tree>, Child>} Ancestor
120
+ * Collect nodes in `Tree` that can be ancestors of `Child`.
121
+ * @template {UnistNode} Tree
122
+ * All node types in a tree.
123
+ * @template {UnistNode} Child
124
+ * Node to search for.
125
+ */
126
+
127
+ /**
128
+ * @typedef {(
129
+ * Tree extends UnistParent
130
+ * ? Depth extends Max
131
+ * ? Tree
132
+ * : Tree | InclusiveDescendant<Tree['children'][number], Max, Increment<Depth>>
133
+ * : Tree
134
+ * )} InclusiveDescendant
135
+ * Collect all (inclusive) descendants of `Tree`.
136
+ *
137
+ * > 👉 **Note**: for performance reasons, this seems to be the fastest way to
138
+ * > recurse without actually running into an infinite loop, which the
139
+ * > previous version did.
140
+ * >
141
+ * > Practically, a max of `2` is typically enough assuming a `Root` is
142
+ * > passed, but it doesn’t improve performance.
143
+ * > It gets higher with `List > ListItem > Table > TableRow > TableCell`.
144
+ * > Using up to `10` doesn’t hurt or help either.
145
+ * @template {UnistNode} Tree
146
+ * Tree type.
147
+ * @template {Uint} [Max=10]
148
+ * Max; searches up to this depth.
149
+ * @template {Uint} [Depth=0]
150
+ * Current depth.
151
+ */
152
+
153
+ /**
154
+ * @typedef {'skip' | boolean} Action
155
+ * Union of the action types.
156
+ *
157
+ * @typedef {number} Index
158
+ * Move to the sibling at `index` next (after node itself is completely
159
+ * traversed).
160
+ *
161
+ * Useful if mutating the tree, such as removing the node the visitor is
162
+ * currently on, or any of its previous siblings.
163
+ * Results less than 0 or greater than or equal to `children.length` stop
164
+ * traversing the parent.
165
+ *
166
+ * @typedef {[(Action | null | undefined | void)?, (Index | null | undefined)?]} ActionTuple
167
+ * List with one or two values, the first an action, the second an index.
168
+ *
169
+ * @typedef {Action | ActionTuple | Index | null | undefined | void} VisitorResult
170
+ * Any value that can be returned from a visitor.
171
+ */
172
+
173
+ /**
174
+ * @callback Visitor
175
+ * Handle a node (matching `test`, if given).
176
+ *
177
+ * Visitors are free to transform `node`.
178
+ * They can also transform the parent of node (the last of `ancestors`).
179
+ *
180
+ * Replacing `node` itself, if `SKIP` is not returned, still causes its
181
+ * descendants to be walked (which is a bug).
182
+ *
183
+ * When adding or removing previous siblings of `node` (or next siblings, in
184
+ * case of reverse), the `Visitor` should return a new `Index` to specify the
185
+ * sibling to traverse after `node` is traversed.
186
+ * Adding or removing next siblings of `node` (or previous siblings, in case
187
+ * of reverse) is handled as expected without needing to return a new `Index`.
188
+ *
189
+ * Removing the children property of an ancestor still results in them being
190
+ * traversed.
191
+ * @param {Visited} node
192
+ * Found node.
193
+ * @param {Array<VisitedParents>} ancestors
194
+ * Ancestors of `node`.
195
+ * @returns {VisitorResult}
196
+ * What to do next.
197
+ *
198
+ * An `Index` is treated as a tuple of `[CONTINUE, Index]`.
199
+ * An `Action` is treated as a tuple of `[Action]`.
200
+ *
201
+ * Passing a tuple back only makes sense if the `Action` is `SKIP`.
202
+ * When the `Action` is `EXIT`, that action can be returned.
203
+ * When the `Action` is `CONTINUE`, `Index` can be returned.
204
+ * @template {UnistNode} [Visited=UnistNode]
205
+ * Visited node type.
206
+ * @template {UnistParent} [VisitedParents=UnistParent]
207
+ * Ancestor type.
208
+ */
209
+
210
+ /**
211
+ * @typedef {Visitor<Matches<InclusiveDescendant<Tree>, Check>, Ancestor<Tree, Matches<InclusiveDescendant<Tree>, Check>>>} BuildVisitor
212
+ * Build a typed `Visitor` function from a tree and a test.
213
+ *
214
+ * It will infer which values are passed as `node` and which as `parents`.
215
+ * @template {UnistNode} [Tree=UnistNode]
216
+ * Tree type.
217
+ * @template {Test} [Check=Test]
218
+ * Test type.
219
+ */
220
+
221
+ import {convert} from 'unist-util-is'
222
+ import {color} from 'unist-util-visit-parents/do-not-use-color'
223
+
224
+ /** @type {Readonly<ActionTuple>} */
225
+ const empty = []
226
+
227
+ /**
228
+ * Continue traversing as normal.
229
+ */
230
+ export const CONTINUE = true
231
+
232
+ /**
233
+ * Stop traversing immediately.
234
+ */
235
+ export const EXIT = false
236
+
237
+ /**
238
+ * Do not traverse this node’s children.
239
+ */
240
+ export const SKIP = 'skip'
241
+
242
+ /**
243
+ * Visit nodes, with ancestral information.
244
+ *
245
+ * This algorithm performs *depth-first* *tree traversal* in *preorder*
246
+ * (**NLR**) or if `reverse` is given, in *reverse preorder* (**NRL**).
247
+ *
248
+ * You can choose for which nodes `visitor` is called by passing a `test`.
249
+ * For complex tests, you should test yourself in `visitor`, as it will be
250
+ * faster and will have improved type information.
251
+ *
252
+ * Walking the tree is an intensive task.
253
+ * Make use of the return values of the visitor when possible.
254
+ * Instead of walking a tree multiple times, walk it once, use `unist-util-is`
255
+ * to check if a node matches, and then perform different operations.
256
+ *
257
+ * You can change the tree.
258
+ * See `Visitor` for more info.
259
+ *
260
+ * @overload
261
+ * @param {Tree} tree
262
+ * @param {Check} check
263
+ * @param {BuildVisitor<Tree, Check>} visitor
264
+ * @param {boolean | null | undefined} [reverse]
265
+ * @returns {undefined}
266
+ *
267
+ * @overload
268
+ * @param {Tree} tree
269
+ * @param {BuildVisitor<Tree>} visitor
270
+ * @param {boolean | null | undefined} [reverse]
271
+ * @returns {undefined}
272
+ *
273
+ * @param {UnistNode} tree
274
+ * Tree to traverse.
275
+ * @param {Visitor | Test} test
276
+ * `unist-util-is`-compatible test
277
+ * @param {Visitor | boolean | null | undefined} [visitor]
278
+ * Handle each node.
279
+ * @param {boolean | null | undefined} [reverse]
280
+ * Traverse in reverse preorder (NRL) instead of the default preorder (NLR).
281
+ * @returns {undefined}
282
+ * Nothing.
283
+ *
284
+ * @template {UnistNode} Tree
285
+ * Node type.
286
+ * @template {Test} Check
287
+ * `unist-util-is`-compatible test.
288
+ */
289
+ export function visitParents(tree, test, visitor, reverse) {
290
+ /** @type {Test} */
291
+ let check
292
+
293
+ if (typeof test === 'function' && typeof visitor !== 'function') {
294
+ reverse = visitor
295
+ // @ts-expect-error no visitor given, so `visitor` is test.
296
+ visitor = test
297
+ } else {
298
+ // @ts-expect-error visitor given, so `test` isn’t a visitor.
299
+ check = test
300
+ }
301
+
302
+ const is = convert(check)
303
+ const step = reverse ? -1 : 1
304
+
305
+ factory(tree, undefined, [])()
306
+
307
+ /**
308
+ * @param {UnistNode} node
309
+ * @param {number | undefined} index
310
+ * @param {Array<UnistParent>} parents
311
+ */
312
+ function factory(node, index, parents) {
313
+ const value = /** @type {Record<string, unknown>} */ (
314
+ node && typeof node === 'object' ? node : {}
315
+ )
316
+
317
+ if (typeof value.type === 'string') {
318
+ const name =
319
+ // `hast`
320
+ typeof value.tagName === 'string'
321
+ ? value.tagName
322
+ : // `xast`
323
+ typeof value.name === 'string'
324
+ ? value.name
325
+ : undefined
326
+
327
+ Object.defineProperty(visit, 'name', {
328
+ value:
329
+ 'node (' + color(node.type + (name ? '<' + name + '>' : '')) + ')'
330
+ })
331
+ }
332
+
333
+ return visit
334
+
335
+ function visit() {
336
+ /** @type {Readonly<ActionTuple>} */
337
+ let result = empty
338
+ /** @type {Readonly<ActionTuple>} */
339
+ let subresult
340
+ /** @type {number} */
341
+ let offset
342
+ /** @type {Array<UnistParent>} */
343
+ let grandparents
344
+
345
+ if (!test || is(node, index, parents[parents.length - 1] || undefined)) {
346
+ // @ts-expect-error: `visitor` is now a visitor.
347
+ result = toResult(visitor(node, parents))
348
+
349
+ if (result[0] === EXIT) {
350
+ return result
351
+ }
352
+ }
353
+
354
+ if ('children' in node && node.children) {
355
+ const nodeAsParent = /** @type {UnistParent} */ (node)
356
+
357
+ if (nodeAsParent.children && result[0] !== SKIP) {
358
+ offset = (reverse ? nodeAsParent.children.length : -1) + step
359
+ grandparents = parents.concat(nodeAsParent)
360
+
361
+ while (offset > -1 && offset < nodeAsParent.children.length) {
362
+ const child = nodeAsParent.children[offset]
363
+
364
+ subresult = factory(child, offset, grandparents)()
365
+
366
+ if (subresult[0] === EXIT) {
367
+ return subresult
368
+ }
369
+
370
+ offset =
371
+ typeof subresult[1] === 'number' ? subresult[1] : offset + step
372
+ }
373
+ }
374
+ }
375
+
376
+ return result
377
+ }
378
+ }
379
+ }
380
+
381
+ /**
382
+ * Turn a return value into a clean result.
383
+ *
384
+ * @param {VisitorResult} value
385
+ * Valid return values from visitors.
386
+ * @returns {Readonly<ActionTuple>}
387
+ * Clean result.
388
+ */
389
+ function toResult(value) {
390
+ if (Array.isArray(value)) {
391
+ return value
392
+ }
393
+
394
+ if (typeof value === 'number') {
395
+ return [CONTINUE, value]
396
+ }
397
+
398
+ return value === null || value === undefined ? empty : [value]
399
+ }
@@ -0,0 +1,22 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2016 Titus Wormer <tituswormer@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,106 @@
1
+ {
2
+ "name": "unist-util-visit-parents",
3
+ "version": "6.0.2",
4
+ "description": "unist utility to recursively walk over nodes, with ancestral information",
5
+ "license": "MIT",
6
+ "keywords": [
7
+ "unist",
8
+ "unist-util",
9
+ "util",
10
+ "utility",
11
+ "tree",
12
+ "ast",
13
+ "visit",
14
+ "traverse",
15
+ "walk",
16
+ "check",
17
+ "parent",
18
+ "parents"
19
+ ],
20
+ "repository": "syntax-tree/unist-util-visit-parents",
21
+ "bugs": "https://github.com/syntax-tree/unist-util-visit-parents/issues",
22
+ "funding": {
23
+ "type": "opencollective",
24
+ "url": "https://opencollective.com/unified"
25
+ },
26
+ "author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
27
+ "contributors": [
28
+ "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
29
+ ],
30
+ "sideEffects": false,
31
+ "type": "module",
32
+ "exports": {
33
+ ".": "./index.js",
34
+ "./do-not-use-color": {
35
+ "node": "./lib/color.node.js",
36
+ "default": "./lib/color.js"
37
+ }
38
+ },
39
+ "types": "index.d.ts",
40
+ "files": [
41
+ "lib/",
42
+ "index.d.ts.map",
43
+ "index.d.ts",
44
+ "index.js"
45
+ ],
46
+ "dependencies": {
47
+ "@types/unist": "^3.0.0",
48
+ "unist-util-is": "^6.0.0"
49
+ },
50
+ "devDependencies": {
51
+ "@types/hast": "^3.0.0",
52
+ "@types/mdast": "^4.0.0",
53
+ "@types/node": "^24.0.0",
54
+ "@types/xast": "^2.0.0",
55
+ "c8": "^10.0.0",
56
+ "mdast-util-from-markdown": "^2.0.0",
57
+ "mdast-util-gfm": "^3.0.0",
58
+ "micromark-extension-gfm": "^3.0.0",
59
+ "prettier": "^3.0.0",
60
+ "remark-cli": "^12.0.0",
61
+ "remark-preset-wooorm": "^10.0.0",
62
+ "strip-ansi": "^7.0.0",
63
+ "tsd": "^0.33.0",
64
+ "type-coverage": "^2.0.0",
65
+ "typescript": "^5.0.0",
66
+ "xo": "^0.58.0"
67
+ },
68
+ "scripts": {
69
+ "prepack": "npm run build && npm run format",
70
+ "build": "tsc --build --clean && tsc --build && tsd && type-coverage",
71
+ "format": "remark . -qfo && prettier . -w --log-level warn && xo --fix",
72
+ "test-api": "node --conditions development test.js",
73
+ "test-coverage": "c8 --100 --reporter lcov npm run test-api",
74
+ "test": "npm run build && npm run format && npm run test-coverage"
75
+ },
76
+ "prettier": {
77
+ "bracketSpacing": false,
78
+ "semi": false,
79
+ "singleQuote": true,
80
+ "tabWidth": 2,
81
+ "trailingComma": "none",
82
+ "useTabs": false
83
+ },
84
+ "remarkConfig": {
85
+ "plugins": [
86
+ "remark-preset-wooorm"
87
+ ]
88
+ },
89
+ "typeCoverage": {
90
+ "atLeast": 100,
91
+ "detail": true,
92
+ "#": "needed `any`s",
93
+ "ignoreFiles": [
94
+ "lib/index.d.ts"
95
+ ],
96
+ "ignoreCatch": true,
97
+ "strict": true
98
+ },
99
+ "xo": {
100
+ "prettier": true,
101
+ "rules": {
102
+ "unicorn/prefer-at": "off",
103
+ "unicorn/prefer-string-replace-all": "off"
104
+ }
105
+ }
106
+ }