@mdsvex/parse 1.0.0-next.0 → 1.0.0-next.1

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 (329) hide show
  1. package/CHANGELOG.md +213 -0
  2. package/WIRE_FORMAT.md +5 -1
  3. package/dist/buf-utils.js +23 -23
  4. package/dist/buf_utils.d.ts +1 -1
  5. package/dist/cursor.d.ts +17 -13
  6. package/dist/cursor.js +118 -31
  7. package/dist/main.d.ts +362 -26
  8. package/dist/main.js +5841 -3420
  9. package/dist/node_view-bvM0i0-p.js +407 -0
  10. package/dist/node_view.d.ts +11 -12
  11. package/dist/opcodes.d.ts +23 -6
  12. package/dist/plugin_dispatch.d.ts +22 -8
  13. package/dist/tree-builder.js +185 -66
  14. package/dist/tree_builder.d.ts +42 -11
  15. package/dist/undo_log.d.ts +11 -1
  16. package/dist/utils.d.ts +77 -51
  17. package/dist/utils.js +687 -209
  18. package/dist/wire-tree-builder.js +69 -71
  19. package/dist/wire_tree_builder.d.ts +4 -7
  20. package/package.json +1 -1
  21. package/src/buf_utils.ts +10 -14
  22. package/src/cursor.ts +74 -57
  23. package/src/main.ts +9898 -5593
  24. package/src/node_view.ts +159 -140
  25. package/src/opcodes.ts +39 -7
  26. package/src/plugin_dispatch.ts +328 -219
  27. package/src/tree_builder.ts +278 -98
  28. package/src/undo_log.ts +58 -24
  29. package/src/utils.spec.ts +86 -9
  30. package/src/utils.ts +769 -392
  31. package/src/wire_emitter.ts +6 -0
  32. package/src/wire_tree_builder.ts +39 -52
  33. package/test/block_quotes.spec.ts +78 -7
  34. package/test/code_spans.spec.ts +158 -6
  35. package/test/crlf.spec.ts +49 -1
  36. package/test/directives.spec.ts +530 -1
  37. package/test/emphasis.spec.ts +10 -4
  38. package/test/fixtures/pfm/block_quotes/pfm_fence_close.md +4 -0
  39. package/test/fixtures/pfm/block_quotes/pfm_fence_close_compact.md +4 -0
  40. package/test/fixtures/pfm/block_quotes/pfm_fence_close_end_quote.md +5 -0
  41. package/test/fixtures/pfm/block_quotes/pfm_fence_close_info.md +5 -0
  42. package/test/fixtures/pfm/block_quotes/pfm_fence_close_longer.md +4 -0
  43. package/test/fixtures/pfm/block_quotes/pfm_fence_close_nested.md +3 -0
  44. package/test/fixtures/pfm/block_quotes/pfm_fence_close_twice.md +6 -0
  45. package/test/fixtures/pfm/block_quotes/pfm_fence_info_eof.md +1 -0
  46. package/test/fixtures/pfm/block_quotes/pfm_fence_unclosed.md +2 -0
  47. package/test/fixtures/pfm/code_spans/pfm_328_5.md +1 -0
  48. package/test/fixtures/pfm/code_spans/pfm_328_6.md +1 -0
  49. package/test/fixtures/pfm/code_spans/pfm_328_7.md +1 -0
  50. package/test/fixtures/pfm/code_spans/pfm_328_8.md +1 -0
  51. package/test/fixtures/pfm/code_spans/pfm_328_9.md +2 -0
  52. package/test/fixtures/pfm/fenced_code_blocks/pfm_info_eof.md +1 -0
  53. package/test/fixtures/pfm/fenced_code_blocks/pfm_info_eof_no_lf.md +1 -0
  54. package/test/fixtures/pfm/generic_directives/106.md +1 -0
  55. package/test/fixtures/pfm/generic_directives/107.md +3 -0
  56. package/test/fixtures/pfm/generic_directives/108.md +1 -0
  57. package/test/fixtures/pfm/generic_directives/109.md +1 -0
  58. package/test/fixtures/pfm/generic_directives/110.md +1 -0
  59. package/test/fixtures/pfm/generic_directives/111.md +1 -0
  60. package/test/fixtures/pfm/generic_directives/112.md +1 -0
  61. package/test/fixtures/pfm/generic_directives/113.md +1 -0
  62. package/test/fixtures/pfm/generic_directives/114.md +2 -0
  63. package/test/fixtures/pfm/generic_directives/115.md +1 -0
  64. package/test/fixtures/pfm/generic_directives/116.md +6 -0
  65. package/test/fixtures/pfm/generic_directives/117.md +3 -0
  66. package/test/fixtures/pfm/generic_directives/118.md +6 -0
  67. package/test/fixtures/pfm/generic_directives/119.md +3 -0
  68. package/test/fixtures/pfm/generic_directives/120.md +5 -0
  69. package/test/fixtures/pfm/generic_directives/121.md +3 -0
  70. package/test/fixtures/pfm/generic_directives/122.md +4 -0
  71. package/test/fixtures/pfm/generic_directives/123.md +2 -0
  72. package/test/html.spec.ts +44 -1
  73. package/test/html_block_containers.spec.ts +445 -0
  74. package/test/incremental.spec.ts +271 -0
  75. package/test/lists.spec.ts +107 -1
  76. package/test/parser_reuse.spec.ts +40 -0
  77. package/test/plugins.spec.ts +196 -226
  78. package/test/print.ts +2 -3
  79. package/test/run_bytecode.spec.ts +36 -0
  80. package/test/snapshots/hybrid/component-children.snap.ast +9 -16
  81. package/test/snapshots/hybrid/component-simple-00.snap.ast +1 -2
  82. package/test/snapshots/hybrid/component-simple-01.snap.ast +1 -2
  83. package/test/snapshots/hybrid/component-simple-03.snap.ast +13 -13
  84. package/test/snapshots/hybrid/component-simple-04.snap.ast +1 -2
  85. package/test/snapshots/hybrid/error.snap.ast +1 -2
  86. package/test/snapshots/markdown/blockquote-nested-markdown.snap.ast +2 -1
  87. package/test/snapshots/markdown/emphasis.snap.ast +2 -2
  88. package/test/snapshots/markdown/encodeHTMLCodeTags.snap.ast +1 -2
  89. package/test/snapshots/markdown/github-style-codeblock-inside-quote.snap.ast +8 -1
  90. package/test/snapshots/markdown/html-comments.snap.ast +11 -13
  91. package/test/snapshots/markdown/html5-strutural-tags.snap.ast +16 -31
  92. package/test/snapshots/markdown/line-starts-with-html.snap.ast +5 -6
  93. package/test/snapshots/markdown/literal-html-tags.snap.ast +11 -14
  94. package/test/snapshots/markdown/nested-blockquote.snap.ast +3 -3
  95. package/test/snapshots/markdown/pre-code-tags.snap.ast +5 -8
  96. package/test/snapshots/pfm/block_quotes/237.snap.ast +1 -2
  97. package/test/snapshots/pfm/block_quotes/251.snap.ast +5 -5
  98. package/test/snapshots/pfm/block_quotes/pfm_fence_close.snap.ast +6 -0
  99. package/test/snapshots/pfm/block_quotes/pfm_fence_close_compact.snap.ast +6 -0
  100. package/test/snapshots/pfm/block_quotes/pfm_fence_close_end_quote.snap.ast +8 -0
  101. package/test/snapshots/pfm/block_quotes/pfm_fence_close_info.snap.ast +4 -0
  102. package/test/snapshots/pfm/block_quotes/pfm_fence_close_longer.snap.ast +6 -0
  103. package/test/snapshots/pfm/block_quotes/pfm_fence_close_nested.snap.ast +5 -0
  104. package/test/snapshots/pfm/block_quotes/pfm_fence_close_twice.snap.ast +5 -0
  105. package/test/snapshots/pfm/block_quotes/pfm_fence_info_eof.snap.ast +3 -0
  106. package/test/snapshots/pfm/block_quotes/pfm_fence_unclosed.snap.ast +3 -0
  107. package/test/snapshots/pfm/code_spans/344.snap.ast +1 -1
  108. package/test/snapshots/pfm/code_spans/347.snap.ast +1 -2
  109. package/test/snapshots/pfm/code_spans/pfm_328_5.snap.ast +6 -0
  110. package/test/snapshots/pfm/code_spans/pfm_328_6.snap.ast +6 -0
  111. package/test/snapshots/pfm/code_spans/pfm_328_7.snap.ast +6 -0
  112. package/test/snapshots/pfm/code_spans/pfm_328_8.snap.ast +8 -0
  113. package/test/snapshots/pfm/code_spans/pfm_328_9.snap.ast +10 -0
  114. package/test/snapshots/pfm/emphasis_and_strong_emphasis/417.snap.ast +2 -2
  115. package/test/snapshots/pfm/emphasis_and_strong_emphasis/438.snap.ast +1 -1
  116. package/test/snapshots/pfm/emphasis_and_strong_emphasis/441.snap.ast +1 -1
  117. package/test/snapshots/pfm/emphasis_and_strong_emphasis/444.snap.ast +1 -1
  118. package/test/snapshots/pfm/emphasis_and_strong_emphasis/445.snap.ast +1 -1
  119. package/test/snapshots/pfm/emphasis_and_strong_emphasis/450.snap.ast +1 -1
  120. package/test/snapshots/pfm/emphasis_and_strong_emphasis/453.snap.ast +1 -1
  121. package/test/snapshots/pfm/emphasis_and_strong_emphasis/456.snap.ast +1 -1
  122. package/test/snapshots/pfm/emphasis_and_strong_emphasis/457.snap.ast +1 -1
  123. package/test/snapshots/pfm/emphasis_and_strong_emphasis/473.snap.ast +1 -1
  124. package/test/snapshots/pfm/emphasis_and_strong_emphasis/475.snap.ast +1 -1
  125. package/test/snapshots/pfm/emphasis_and_strong_emphasis/476.snap.ast +1 -1
  126. package/test/snapshots/pfm/emphasis_and_strong_emphasis/477.snap.ast +1 -1
  127. package/test/snapshots/pfm/emphasis_and_strong_emphasis/478.snap.ast +3 -4
  128. package/test/snapshots/pfm/emphasis_and_strong_emphasis/479.snap.ast +3 -4
  129. package/test/snapshots/pfm/fenced_code_blocks/126.snap.ast +1 -2
  130. package/test/snapshots/pfm/fenced_code_blocks/pfm_info_eof.snap.ast +2 -0
  131. package/test/snapshots/pfm/fenced_code_blocks/pfm_info_eof_no_lf.snap.ast +2 -0
  132. package/test/snapshots/pfm/generic_directives/011.snap.ast +3 -1
  133. package/test/snapshots/pfm/generic_directives/015.snap.ast +3 -1
  134. package/test/snapshots/pfm/generic_directives/016.snap.ast +3 -1
  135. package/test/snapshots/pfm/generic_directives/017.snap.ast +3 -1
  136. package/test/snapshots/pfm/generic_directives/019.snap.ast +3 -1
  137. package/test/snapshots/pfm/generic_directives/020.snap.ast +3 -1
  138. package/test/snapshots/pfm/generic_directives/030.snap.ast +4 -6
  139. package/test/snapshots/pfm/generic_directives/034.snap.ast +6 -2
  140. package/test/snapshots/pfm/generic_directives/036.snap.ast +5 -1
  141. package/test/snapshots/pfm/generic_directives/038.snap.ast +6 -2
  142. package/test/snapshots/pfm/generic_directives/039.snap.ast +3 -1
  143. package/test/snapshots/pfm/generic_directives/040.snap.ast +3 -1
  144. package/test/snapshots/pfm/generic_directives/044.snap.ast +3 -1
  145. package/test/snapshots/pfm/generic_directives/046.snap.ast +3 -1
  146. package/test/snapshots/pfm/generic_directives/089.snap.ast +1 -1
  147. package/test/snapshots/pfm/generic_directives/103.snap.ast +6 -2
  148. package/test/snapshots/pfm/generic_directives/106.snap.ast +9 -0
  149. package/test/snapshots/pfm/generic_directives/107.snap.ast +9 -0
  150. package/test/snapshots/pfm/generic_directives/108.snap.ast +5 -0
  151. package/test/snapshots/pfm/generic_directives/109.snap.ast +4 -0
  152. package/test/snapshots/pfm/generic_directives/110.snap.ast +10 -0
  153. package/test/snapshots/pfm/generic_directives/111.snap.ast +7 -0
  154. package/test/snapshots/pfm/generic_directives/112.snap.ast +18 -0
  155. package/test/snapshots/pfm/generic_directives/113.snap.ast +7 -0
  156. package/test/snapshots/pfm/generic_directives/114.snap.ast +12 -0
  157. package/test/snapshots/pfm/generic_directives/115.snap.ast +10 -0
  158. package/test/snapshots/pfm/generic_directives/116.snap.ast +13 -0
  159. package/test/snapshots/pfm/generic_directives/117.snap.ast +9 -0
  160. package/test/snapshots/pfm/generic_directives/118.snap.ast +10 -0
  161. package/test/snapshots/pfm/generic_directives/119.snap.ast +9 -0
  162. package/test/snapshots/pfm/generic_directives/120.snap.ast +12 -0
  163. package/test/snapshots/pfm/generic_directives/121.snap.ast +3 -0
  164. package/test/snapshots/pfm/generic_directives/122.snap.ast +3 -0
  165. package/test/snapshots/pfm/generic_directives/123.snap.ast +3 -0
  166. package/test/snapshots/pfm/hard_line_breaks/642.snap.ast +1 -1
  167. package/test/snapshots/pfm/hard_line_breaks/643.snap.ast +1 -1
  168. package/test/snapshots/pfm/html/148.snap.ast +1 -1
  169. package/test/snapshots/pfm/html/150.snap.ast +1 -1
  170. package/test/snapshots/pfm/html/159.snap.ast +2 -3
  171. package/test/snapshots/pfm/html/162.snap.ast +3 -4
  172. package/test/snapshots/pfm/html/163.snap.ast +1 -1
  173. package/test/snapshots/pfm/html/164.snap.ast +3 -4
  174. package/test/snapshots/pfm/html/166.snap.ast +1 -1
  175. package/test/snapshots/pfm/html/168.snap.ast +2 -3
  176. package/test/snapshots/pfm/html/169.snap.ast +5 -7
  177. package/test/snapshots/pfm/html/174.snap.ast +3 -3
  178. package/test/snapshots/pfm/html/182.snap.ast +1 -1
  179. package/test/snapshots/pfm/html/613.snap.ast +2 -2
  180. package/test/snapshots/pfm/html/615.snap.ast +2 -2
  181. package/test/snapshots/pfm/images/585.snap.ast +1 -1
  182. package/test/snapshots/pfm/images/589.snap.ast +1 -1
  183. package/test/snapshots/pfm/link_reference_definitions/201.snap.ast +1 -1
  184. package/test/snapshots/pfm/link_reference_definitions/208.snap.ast +1 -1
  185. package/test/snapshots/pfm/links/491.snap.ast +1 -1
  186. package/test/snapshots/pfm/links/494.snap.ast +2 -2
  187. package/test/snapshots/pfm/links/516.snap.ast +8 -9
  188. package/test/snapshots/pfm/links/521.snap.ast +1 -1
  189. package/test/snapshots/pfm/links/530.snap.ast +8 -12
  190. package/test/snapshots/pfm/links/534.snap.ast +1 -1
  191. package/test/snapshots/pfm/links/552.snap.ast +2 -2
  192. package/test/snapshots/pfm/links/559.snap.ast +1 -1
  193. package/test/snapshots/pfm/links/564.snap.ast +1 -1
  194. package/test/snapshots/pfm/list_items/260.snap.ast +3 -4
  195. package/test/snapshots/pfm/list_items/293.snap.ast +2 -2
  196. package/test/snapshots/pfm/tabs/16.snap.ast +2 -3
  197. package/test/snapshots/pfm/tabs/4.snap.ast +6 -5
  198. package/test/snapshots/svelte/00-introduction/00-hello-world/App.snap.ast +3 -4
  199. package/test/snapshots/svelte/00-introduction/02-styling/App.snap.ast +2 -3
  200. package/test/snapshots/svelte/00-introduction/03-nested-components/App.snap.ast +2 -3
  201. package/test/snapshots/svelte/00-introduction/03-nested-components/Nested.snap.ast +1 -2
  202. package/test/snapshots/svelte/00-introduction/04-html-tags/App.snap.ast +1 -2
  203. package/test/snapshots/svelte/01-reactivity/00-reactive-assignments/App.snap.ast +5 -6
  204. package/test/snapshots/svelte/01-reactivity/01-reactive-declarations/App.snap.ast +11 -14
  205. package/test/snapshots/svelte/01-reactivity/02-reactive-statements/App.snap.ast +5 -6
  206. package/test/snapshots/svelte/02-props/00-declaring-props/Nested.snap.ast +2 -3
  207. package/test/snapshots/svelte/02-props/01-default-values/App.snap.ast +1 -1
  208. package/test/snapshots/svelte/02-props/01-default-values/Nested.snap.ast +2 -3
  209. package/test/snapshots/svelte/02-props/02-spread-props/Info.snap.ast +16 -17
  210. package/test/snapshots/svelte/03-logic/00-if-blocks/App.snap.ast +4 -8
  211. package/test/snapshots/svelte/03-logic/01-else-blocks/App.snap.ast +4 -8
  212. package/test/snapshots/svelte/03-logic/02-else-if-blocks/App.snap.ast +6 -9
  213. package/test/snapshots/svelte/03-logic/03-each-blocks/App.snap.ast +5 -8
  214. package/test/snapshots/svelte/03-logic/04-keyed-each-blocks/App.snap.ast +4 -7
  215. package/test/snapshots/svelte/03-logic/04-keyed-each-blocks/Thing.snap.ast +4 -5
  216. package/test/snapshots/svelte/04-events/02-event-modifiers/App.snap.ast +2 -3
  217. package/test/snapshots/svelte/04-events/03-component-events/Inner.snap.ast +2 -3
  218. package/test/snapshots/svelte/04-events/04-event-forwarding/Inner.snap.ast +2 -3
  219. package/test/snapshots/svelte/04-events/05-dom-event-forwarding/FancyButton.snap.ast +2 -3
  220. package/test/snapshots/svelte/05-bindings/00-text-inputs/App.snap.ast +3 -4
  221. package/test/snapshots/svelte/05-bindings/01-numeric-inputs/App.snap.ast +9 -8
  222. package/test/snapshots/svelte/05-bindings/02-checkbox-inputs/App.snap.ast +7 -11
  223. package/test/snapshots/svelte/05-bindings/03-group-inputs/App.snap.ast +21 -30
  224. package/test/snapshots/svelte/05-bindings/04-textarea-inputs/App.snap.ast +1 -2
  225. package/test/snapshots/svelte/05-bindings/05-select-bindings/App.snap.ast +5 -9
  226. package/test/snapshots/svelte/05-bindings/06-multiple-select-bindings/App.snap.ast +18 -26
  227. package/test/snapshots/svelte/05-bindings/07-each-block-bindings/App.snap.ast +7 -11
  228. package/test/snapshots/svelte/05-bindings/08-media-elements/App.snap.ast +15 -19
  229. package/test/snapshots/svelte/05-bindings/09-dimensions/App.snap.ast +7 -9
  230. package/test/snapshots/svelte/05-bindings/11-component-bindings/App.snap.ast +1 -2
  231. package/test/snapshots/svelte/05-bindings/11-component-bindings/Keypad.snap.ast +32 -34
  232. package/test/snapshots/svelte/06-lifecycle/00-onmount/App.snap.ast +3 -6
  233. package/test/snapshots/svelte/06-lifecycle/01-ondestroy/App.snap.ast +6 -7
  234. package/test/snapshots/svelte/06-lifecycle/02-update/App.snap.ast +2 -4
  235. package/test/snapshots/svelte/07-stores/00-writable-stores/App.snap.ast +4 -5
  236. package/test/snapshots/svelte/07-stores/00-writable-stores/Decrementer.snap.ast +2 -3
  237. package/test/snapshots/svelte/07-stores/00-writable-stores/Incrementer.snap.ast +2 -3
  238. package/test/snapshots/svelte/07-stores/00-writable-stores/Resetter.snap.ast +2 -3
  239. package/test/snapshots/svelte/07-stores/01-auto-subscriptions/App.snap.ast +4 -5
  240. package/test/snapshots/svelte/07-stores/01-auto-subscriptions/Decrementer.snap.ast +2 -3
  241. package/test/snapshots/svelte/07-stores/01-auto-subscriptions/Incrementer.snap.ast +2 -3
  242. package/test/snapshots/svelte/07-stores/01-auto-subscriptions/Resetter.snap.ast +2 -3
  243. package/test/snapshots/svelte/07-stores/02-readable-stores/App.snap.ast +2 -3
  244. package/test/snapshots/svelte/07-stores/03-derived-stores/App.snap.ast +8 -10
  245. package/test/snapshots/svelte/07-stores/04-custom-stores/App.snap.ast +7 -11
  246. package/test/snapshots/svelte/08-motion/00-tweened/App.snap.ast +10 -15
  247. package/test/snapshots/svelte/08-motion/01-spring/App.snap.ast +10 -10
  248. package/test/snapshots/svelte/09-transitions/00-transition/App.snap.ast +3 -5
  249. package/test/snapshots/svelte/09-transitions/01-adding-parameters-to-transitions/App.snap.ast +3 -5
  250. package/test/snapshots/svelte/09-transitions/02-in-and-out/App.snap.ast +3 -5
  251. package/test/snapshots/svelte/09-transitions/03-custom-css-transitions/App.snap.ast +4 -6
  252. package/test/snapshots/svelte/09-transitions/04-custom-js-transitions/App.snap.ast +3 -5
  253. package/test/snapshots/svelte/09-transitions/05-transition-events/App.snap.ast +5 -8
  254. package/test/snapshots/svelte/10-animations/00-animate/App.snap.ast +16 -20
  255. package/test/snapshots/svelte/11-easing/00-easing/App.snap.ast +16 -11
  256. package/test/snapshots/svelte/11-easing/00-easing/Controls.snap.ast +11 -16
  257. package/test/snapshots/svelte/11-easing/00-easing/Grid.snap.ast +2 -2
  258. package/test/snapshots/svelte/12-svg/01-clock/App.snap.ast +2 -1
  259. package/test/snapshots/svelte/12-svg/02-bar-chart/App.snap.ast +7 -9
  260. package/test/snapshots/svelte/12-svg/03-area-chart/App.snap.ast +14 -15
  261. package/test/snapshots/svelte/12-svg/04-scatterplot/App.snap.ast +7 -5
  262. package/test/snapshots/svelte/12-svg/04-scatterplot/Scatterplot.snap.ast +6 -6
  263. package/test/snapshots/svelte/12-svg/05-svg-transitions/App.snap.ast +5 -6
  264. package/test/snapshots/svelte/13-actions/01-adding-parameters-to-actions/App.snap.ast +2 -3
  265. package/test/snapshots/svelte/14-classes/00-classes/App.snap.ast +3 -6
  266. package/test/snapshots/svelte/14-classes/01-class-shorthand/App.snap.ast +2 -3
  267. package/test/snapshots/svelte/15-composition/00-slots/App.snap.ast +3 -5
  268. package/test/snapshots/svelte/15-composition/01-slot-fallbacks/App.snap.ast +3 -5
  269. package/test/snapshots/svelte/15-composition/01-slot-fallbacks/Box.snap.ast +1 -2
  270. package/test/snapshots/svelte/15-composition/02-named-slots/App.snap.ast +7 -11
  271. package/test/snapshots/svelte/15-composition/02-named-slots/ContactCard.snap.ast +3 -6
  272. package/test/snapshots/svelte/15-composition/03-slot-props/App.snap.ast +9 -15
  273. package/test/snapshots/svelte/15-composition/04-modal/App.snap.ast +17 -26
  274. package/test/snapshots/svelte/15-composition/04-modal/Modal.snap.ast +3 -3
  275. package/test/snapshots/svelte/16-context/00-context-api/App.snap.ast +10 -5
  276. package/test/snapshots/svelte/17-special-elements/00-svelte-self/File.snap.ast +1 -2
  277. package/test/snapshots/svelte/17-special-elements/00-svelte-self/Folder.snap.ast +1 -2
  278. package/test/snapshots/svelte/17-special-elements/01-svelte-component/App.snap.ast +1 -2
  279. package/test/snapshots/svelte/17-special-elements/01-svelte-component/BlueThing.snap.ast +1 -2
  280. package/test/snapshots/svelte/17-special-elements/01-svelte-component/GreenThing.snap.ast +1 -2
  281. package/test/snapshots/svelte/17-special-elements/01-svelte-component/RedThing.snap.ast +1 -2
  282. package/test/snapshots/svelte/17-special-elements/02-svelte-window/App.snap.ast +3 -6
  283. package/test/snapshots/svelte/17-special-elements/03-svelte-window-bindings/App.snap.ast +2 -4
  284. package/test/snapshots/svelte/17-special-elements/05-svelte-head/App.snap.ast +6 -12
  285. package/test/snapshots/svelte/18-module-context/01-module-exports/App.snap.ast +2 -3
  286. package/test/snapshots/svelte/18-module-context/01-module-exports/AudioPlayer.snap.ast +4 -7
  287. package/test/snapshots/svelte/19-debugging/00-debug/App.snap.ast +5 -7
  288. package/test/snapshots/svelte/19-debugging/00-debug/Test.snap.ast +7 -11
  289. package/test/snapshots/svelte/20-7guis/01-7guis-counter/App.snap.ast +2 -3
  290. package/test/snapshots/svelte/20-7guis/02-7guis-temperature/App.snap.ast +2 -2
  291. package/test/snapshots/svelte/20-7guis/03-7guis-flight-booker/App.snap.ast +4 -7
  292. package/test/snapshots/svelte/20-7guis/04-7guis-timer/App.snap.ast +13 -17
  293. package/test/snapshots/svelte/20-7guis/05-7guis-crud/App.snap.ast +11 -13
  294. package/test/snapshots/svelte/20-7guis/06-7guis-circles/App.snap.ast +10 -11
  295. package/test/snapshots/svelte/21-miscellaneous/01-hacker-news/Comment.snap.ast +4 -6
  296. package/test/snapshots/svelte/21-miscellaneous/01-hacker-news/Item.snap.ast +9 -13
  297. package/test/snapshots/svelte/21-miscellaneous/01-hacker-news/List.snap.ast +3 -5
  298. package/test/snapshots/svelte/21-miscellaneous/01-hacker-news/Summary.snap.ast +7 -11
  299. package/test/snapshots/svelte/21-miscellaneous/02-immutable-data/App.snap.ast +2 -4
  300. package/test/snapshots/svelte/99-embeds/20181225-blog-svelte-css-in-js/App.snap.ast +6 -7
  301. package/test/snapshots/svelte/99-embeds/20181225-blog-svelte-css-in-js/Hero.snap.ast +3 -5
  302. package/test/snapshots/svelte/99-embeds/20190420-blog-write-less-code/App.snap.ast +6 -7
  303. package/test/svelte_expressions.spec.ts +93 -4
  304. package/test/svelte_tags.spec.ts +27 -12
  305. package/test/tables.spec.ts +347 -0
  306. package/test/tree_builder.spec.ts +286 -1
  307. package/test/unclosed_delimiters.spec.ts +529 -0
  308. package/tsc/buf_utils.d.ts +1 -1
  309. package/tsc/buf_utils.js +9 -9
  310. package/tsc/cursor.d.ts +17 -13
  311. package/tsc/cursor.js +60 -43
  312. package/tsc/main.d.ts +362 -26
  313. package/tsc/main.js +8955 -4891
  314. package/tsc/node_view.d.ts +11 -12
  315. package/tsc/node_view.js +134 -102
  316. package/tsc/opcodes.d.ts +23 -6
  317. package/tsc/plugin_dispatch.d.ts +22 -8
  318. package/tsc/plugin_dispatch.js +292 -170
  319. package/tsc/tree_builder.d.ts +42 -11
  320. package/tsc/tree_builder.js +237 -82
  321. package/tsc/undo_log.d.ts +11 -1
  322. package/tsc/undo_log.js +54 -19
  323. package/tsc/utils.d.ts +77 -51
  324. package/tsc/utils.js +687 -344
  325. package/tsc/utils.spec.js +83 -9
  326. package/tsc/wire_emitter.js +6 -0
  327. package/tsc/wire_tree_builder.d.ts +4 -7
  328. package/tsc/wire_tree_builder.js +34 -37
  329. package/dist/node_view-BEh2-H86.js +0 -373
@@ -0,0 +1,529 @@
1
+ import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
2
+
3
+ import { PFMParser, parse_markdown_svelte } from '../src/main';
4
+ import { TreeBuilder } from '../src/tree_builder';
5
+ import type { NodeBuffer } from '../src/utils';
6
+ import { print_ast } from './print';
7
+
8
+ function parse_incremental(source: string, chunk_size: number): NodeBuffer {
9
+ const tree = new TreeBuilder(source.length);
10
+ const parser = new PFMParser(tree);
11
+ parser.init();
12
+ for (let i = 0; i < source.length; i += chunk_size) {
13
+ parser.feed(source.slice(i, i + chunk_size));
14
+ }
15
+ parser.finish();
16
+ return tree.get_buffer();
17
+ }
18
+
19
+ function expect_incremental_matches(input: string): void {
20
+ const batch = print_ast(parse_markdown_svelte(input).nodes, input);
21
+ for (const size of [1, 2, 3]) {
22
+ expect(print_ast(parse_incremental(input, size), input)).toBe(batch);
23
+ }
24
+ }
25
+
26
+ function kinds(nodes: NodeBuffer, parent: number = 0): string[] {
27
+ return nodes
28
+ .get_node(parent)
29
+ .children.map((i) => nodes.get_node(i).kind)
30
+ .filter((k) => k !== 'line_break');
31
+ }
32
+
33
+ function print_batch(input: string): string {
34
+ return print_ast(parse_markdown_svelte(input).nodes, input);
35
+ }
36
+
37
+ function print_incremental(input: string, chunk_size: number): string {
38
+ return print_ast(parse_incremental(input, chunk_size), input);
39
+ }
40
+
41
+ let error_spy: ReturnType<typeof vi.spyOn>;
42
+ beforeEach(() => {
43
+ error_spy = vi.spyOn(console, 'error').mockImplementation(() => {});
44
+ });
45
+ afterEach(() => {
46
+ error_spy.mockRestore();
47
+ });
48
+
49
+ describe('unclosed delimiter before a block interrupt', () => {
50
+ test('ordered list: `1. ~1\\n2. *`', () => {
51
+ const input = '1. ~1\n2. *';
52
+ const { nodes } = parse_markdown_svelte(input);
53
+
54
+ expect(error_spy).not.toHaveBeenCalled();
55
+ expect(print_ast(nodes, input)).toBe(
56
+ [
57
+ 'root',
58
+ ' list ordered=true start=1 tight=true',
59
+ ' list_item',
60
+ ' text "~1"',
61
+ ' list_item',
62
+ ' text "*"',
63
+ ].join('\n')
64
+ );
65
+ });
66
+
67
+ test('nested list marker: `- *a\\n - b`', () => {
68
+ const input = '- *a\n - b';
69
+ const { nodes } = parse_markdown_svelte(input);
70
+
71
+ expect(error_spy).not.toHaveBeenCalled();
72
+ expect(print_ast(nodes, input)).toBe(
73
+ [
74
+ 'root',
75
+ ' list ordered=false start=0 tight=true',
76
+ ' list_item',
77
+ ' text "*a"',
78
+ ' list ordered=false start=0 tight=true',
79
+ ' list_item',
80
+ ' text "b"',
81
+ ].join('\n')
82
+ );
83
+ });
84
+
85
+ const openers = ['*a', '_a', '~~a', '~a', '^a'];
86
+ const interrupts: [string, string][] = [
87
+ ['- b', 'list'],
88
+ ['1. b', 'list'],
89
+ ['> b', 'block_quote'],
90
+ ['```\nb\n```', 'code_fence'],
91
+ ['<div>\n</div>', 'html'],
92
+ ];
93
+
94
+ for (const opener of openers) {
95
+ for (const [interrupt, kind] of interrupts) {
96
+ const input = `${opener}\n${interrupt}`;
97
+ test(JSON.stringify(input), () => {
98
+ const { nodes } = parse_markdown_svelte(input);
99
+
100
+ expect(error_spy).not.toHaveBeenCalled();
101
+ expect(kinds(nodes)).toEqual(['paragraph', kind]);
102
+ const para = nodes.get_node(0).children[0];
103
+ expect(kinds(nodes, para).every((k) => k === 'text')).toBe(true);
104
+ });
105
+ }
106
+
107
+ const input = `- ${opener}\n- b`;
108
+ test(JSON.stringify(input), () => {
109
+ const { nodes } = parse_markdown_svelte(input);
110
+
111
+ expect(error_spy).not.toHaveBeenCalled();
112
+ const list = nodes.get_node(0).children[0];
113
+ expect(kinds(nodes)).toEqual(['list']);
114
+ expect(kinds(nodes, list)).toEqual(['list_item', 'list_item']);
115
+ });
116
+ }
117
+ });
118
+
119
+ describe('unclosed delimiter in a heading', () => {
120
+ const openers = ['*a', '_)', '**)', '~~a', '~a', '^a', '[a', ':x[a', '<b>a'];
121
+
122
+ for (const opener of openers) {
123
+ for (const [prefix, outer] of [
124
+ ['# ', ['heading', 'paragraph']],
125
+ ['## a ', ['heading', 'paragraph']],
126
+ ['- # ', ['list', 'paragraph']],
127
+ ] as const) {
128
+ const input = `${prefix}${opener}\nfoo`;
129
+ test(JSON.stringify(input), () => {
130
+ const { nodes } = parse_markdown_svelte(input);
131
+ expect(error_spy).not.toHaveBeenCalled();
132
+ expect(kinds(nodes)).toEqual(outer);
133
+ expect_incremental_matches(input);
134
+ });
135
+ }
136
+ }
137
+
138
+ test('heading in a block quote ends at the line end: `> # *a\\n> foo`', () => {
139
+ const input = '> # *a\n> foo';
140
+ const { nodes } = parse_markdown_svelte(input);
141
+
142
+ expect(print_ast(nodes, input)).toBe(
143
+ [
144
+ 'root',
145
+ ' block_quote',
146
+ ' heading depth=1 "*a"',
147
+ ' text "*a"',
148
+ ' paragraph',
149
+ ' text "foo"',
150
+ ].join('\n')
151
+ );
152
+ expect_incremental_matches(input);
153
+ });
154
+ });
155
+
156
+ describe('unclosed link text at a linefeed', () => {
157
+ for (const [input, outer] of [
158
+ ['[a\n# h', ['paragraph', 'heading']],
159
+ ['[a\n---', ['paragraph', 'thematic_break']],
160
+ ['[a\n> q', ['paragraph', 'block_quote']],
161
+ ['[a\n```\nx\n```', ['paragraph', 'code_fence']],
162
+ [':x[a\n# h', ['paragraph', 'heading']],
163
+ ['> [a\nfoo', ['block_quote', 'paragraph']],
164
+ ['> :x[a\nfoo', ['block_quote', 'paragraph']],
165
+ ] as const) {
166
+ test(JSON.stringify(input), () => {
167
+ const { nodes } = parse_markdown_svelte(input);
168
+ expect(error_spy).not.toHaveBeenCalled();
169
+ expect(kinds(nodes)).toEqual(outer);
170
+ expect_incremental_matches(input);
171
+ });
172
+ }
173
+
174
+ test('list item marker ends the link text: `- [a\\n- b`', () => {
175
+ const input = '- [a\n- b';
176
+ const { nodes } = parse_markdown_svelte(input);
177
+
178
+ expect(error_spy).not.toHaveBeenCalled();
179
+ expect(print_ast(nodes, input)).toBe(
180
+ [
181
+ 'root',
182
+ ' list ordered=false start=0 tight=true',
183
+ ' list_item',
184
+ ' text "[a"',
185
+ ' list_item',
186
+ ' text "b"',
187
+ ].join('\n')
188
+ );
189
+ expect_incremental_matches(input);
190
+ });
191
+
192
+ test('link spans block quote lines: `> a [b\\n> c](d) e`', () => {
193
+ const input = '> a [b\n> c](d) e';
194
+ const { nodes } = parse_markdown_svelte(input);
195
+
196
+ expect(error_spy).not.toHaveBeenCalled();
197
+ expect(print_ast(nodes, input)).toBe(
198
+ [
199
+ 'root',
200
+ ' block_quote',
201
+ ' paragraph',
202
+ ' text "a "',
203
+ ' link href="d"',
204
+ ' text "b"',
205
+ ' soft_break',
206
+ ' text "c"',
207
+ ' text " e"',
208
+ ].join('\n')
209
+ );
210
+ expect_incremental_matches(input);
211
+ });
212
+ });
213
+
214
+ describe('unclosed delimiter before a linefeed', () => {
215
+ const cases: [string, string[]][] = [
216
+ ['[\n_', ['text "["', 'soft_break', 'text "_"']],
217
+ ['![\n_', ['text "!["', 'soft_break', 'text "_"']],
218
+ ['^\n_', ['text "^"', 'soft_break', 'text "_"']],
219
+ ['^\na', ['text "^"', 'soft_break', 'text "a"']],
220
+ ['^\n*', ['text "^"', 'soft_break', 'text "*"']],
221
+ ['~~\n_', ['text "~"', 'text "~"', 'soft_break', 'text "_"']],
222
+ ['a ^\n_b', ['text "a "', 'text "^"', 'soft_break', 'text "_b"']],
223
+ ['*\n_', ['text "*"', 'soft_break', 'text "_"']],
224
+ ['_\n_', ['text "_"', 'soft_break', 'text "_"']],
225
+ ['~\n_', ['text "~"', 'soft_break', 'text "_"']],
226
+ ];
227
+
228
+ for (const [input, children] of cases) {
229
+ test(JSON.stringify(input), () => {
230
+ const expected = ['root', ' paragraph']
231
+ .concat(children.map((c) => ` ${c}`))
232
+ .join('\n');
233
+
234
+ expect(print_batch(input)).toBe(expected);
235
+ for (const chunk_size of [1, 2, 3]) {
236
+ expect(
237
+ print_incremental(input, chunk_size),
238
+ `chunk ${chunk_size}`
239
+ ).toBe(expected);
240
+ }
241
+ });
242
+ }
243
+ });
244
+
245
+ describe('tilde closer split across chunks', () => {
246
+ const inputs = [
247
+ '~a~~',
248
+ '~-~~-',
249
+ 'h~2~o',
250
+ '~a~ b',
251
+ '~~~~a',
252
+ '~~>~~a',
253
+ '~~a~~',
254
+ '~~a~~b',
255
+ '~~a~~ b',
256
+ ];
257
+
258
+ for (const input of inputs) {
259
+ test(JSON.stringify(input), () => {
260
+ expect_incremental_matches(input);
261
+ });
262
+ }
263
+ });
264
+
265
+ describe('thematic break at the end of a fed chunk', () => {
266
+ const inputs = [
267
+ '<b>---',
268
+ '<b>\n---',
269
+ '<b>\n\n---',
270
+ '<b>\n***',
271
+ '<div>\n- - -',
272
+ '<div>\n- a',
273
+ '<div>\n-a',
274
+ '{#if x}\n---',
275
+ '{#if x}\n---\n{/if}',
276
+ ':::x[]\n___',
277
+ ':::x[]\n---\n:::',
278
+ ];
279
+
280
+ for (const input of inputs) {
281
+ test(JSON.stringify(input), () => {
282
+ expect_incremental_matches(input);
283
+ });
284
+ }
285
+ });
286
+
287
+ describe('heading marker at the end of a fed chunk', () => {
288
+ const inputs = [
289
+ 'a\n##](',
290
+ 'a\n##b',
291
+ 'a\n## b',
292
+ 'a\n ##b',
293
+ 'a\n######x',
294
+ 'a\n#######',
295
+ '*a\n##b',
296
+ '~~a\n##b',
297
+ '[a\n##b',
298
+ ];
299
+
300
+ for (const input of inputs) {
301
+ test(JSON.stringify(input), () => {
302
+ expect_incremental_matches(input);
303
+ });
304
+ }
305
+ });
306
+
307
+ describe('unclosed inline directive', () => {
308
+ const cases: [string, string[]][] = [
309
+ [
310
+ ':x[\n#',
311
+ [
312
+ ' paragraph',
313
+ ' text name="x" ":x["',
314
+ ' line_break',
315
+ ' heading depth=1',
316
+ ],
317
+ ],
318
+ [
319
+ ':abc[\n> a',
320
+ [
321
+ ' paragraph',
322
+ ' text name="abc" ":abc["',
323
+ ' line_break',
324
+ ' block_quote',
325
+ ' paragraph',
326
+ ' text "a"',
327
+ ],
328
+ ],
329
+ [
330
+ 'a :x[\n\nb',
331
+ [
332
+ ' paragraph',
333
+ ' text "a "',
334
+ ' text name="x" ":x["',
335
+ ' line_break',
336
+ ' line_break',
337
+ ' paragraph',
338
+ ' text "b"',
339
+ ],
340
+ ],
341
+ ];
342
+
343
+ for (const [input, lines] of cases) {
344
+ test(JSON.stringify(input), () => {
345
+ expect(print_batch(input)).toBe(['root', ...lines].join('\n'));
346
+ expect_incremental_matches(input);
347
+ });
348
+ }
349
+
350
+ for (const input of [':x[\n#a', '[~~*:x[\n#[']) {
351
+ test(JSON.stringify(input), () => {
352
+ expect_incremental_matches(input);
353
+ });
354
+ }
355
+ });
356
+
357
+ describe('linefeed in link text at the end of a fed chunk', () => {
358
+ const inputs = ['[\n##b', '![\n##b', '*:x[\n#]', '[<b>\n#]', ':x[<b>\n#]#'];
359
+
360
+ for (const input of inputs) {
361
+ test(JSON.stringify(input), () => {
362
+ expect_incremental_matches(input);
363
+ });
364
+ }
365
+ });
366
+
367
+ describe('linefeed after a closed element in an unclosed delimiter', () => {
368
+ const inputs = [
369
+ '*:x[a]\n#b',
370
+ '*<b>a</b>\n#b',
371
+ '~<b></b>\n#b',
372
+ '~~a<b></b>\n#b',
373
+ '^a<b></b>\n#b',
374
+ '> ~<b></b>\n> #b',
375
+ ];
376
+
377
+ for (const input of inputs) {
378
+ test(JSON.stringify(input), () => {
379
+ expect_incremental_matches(input);
380
+ });
381
+ }
382
+ });
383
+
384
+ describe('list marker with no content at the end of a fed chunk', () => {
385
+ const cases: [string, string[]][] = [
386
+ ['+ ', [' paragraph', ' text "+ "']],
387
+ ['1. ', [' paragraph', ' text "1. "']],
388
+ ['12) ', [' paragraph', ' text "12) "']],
389
+ ];
390
+
391
+ for (const [input, lines] of cases) {
392
+ test(JSON.stringify(input), () => {
393
+ expect(print_batch(input)).toBe(['root', ...lines].join('\n'));
394
+ expect_incremental_matches(input);
395
+ });
396
+ }
397
+
398
+ const inputs = [
399
+ '+ a',
400
+ '1. a',
401
+ '> + ',
402
+ '<div>\n1. ',
403
+ '{#if x}\n+ ',
404
+ '- a\n+ ',
405
+ '- a\n 1. ',
406
+ '+ a\n\n+ ',
407
+ '1. a\n\n1. ',
408
+ '1. >\n\n1. ',
409
+ ];
410
+ for (const input of inputs) {
411
+ test(JSON.stringify(input), () => {
412
+ expect_incremental_matches(input);
413
+ });
414
+ }
415
+ });
416
+
417
+ describe('trailing whitespace in a heading', () => {
418
+ const cases: [string, string[]][] = [
419
+ ['# <b> ', [' heading depth=1 "<b>"', ' text tag="b" "<b>"']],
420
+ [
421
+ '# <b> \t\na',
422
+ [
423
+ ' heading depth=1 "<b>"',
424
+ ' text tag="b" "<b>"',
425
+ ' line_break',
426
+ ' paragraph',
427
+ ' text "a"',
428
+ ],
429
+ ],
430
+ [
431
+ '# ^<http://a> ',
432
+ [
433
+ ' heading depth=1 "^<http://a>"',
434
+ ' text "^"',
435
+ ' link href="http://a"',
436
+ ' text "http://a"',
437
+ ],
438
+ ],
439
+ [
440
+ '# a <b> b',
441
+ [
442
+ ' heading depth=1 "a <b> b"',
443
+ ' text "a "',
444
+ ' text tag="b" "<b>"',
445
+ ' text " b"',
446
+ ],
447
+ ],
448
+ ];
449
+
450
+ for (const [input, lines] of cases) {
451
+ test(JSON.stringify(input), () => {
452
+ expect(print_batch(input)).toBe(['root', ...lines].join('\n'));
453
+ expect_incremental_matches(input);
454
+ });
455
+ }
456
+ });
457
+
458
+ describe('backtick and space at the end of the input', () => {
459
+ const cases: [string, string[]][] = [
460
+ ['` ', [' paragraph', ' text "`"', ' text " "']],
461
+ ['a ` ', [' paragraph', ' text "a "', ' text "`"', ' text " "']],
462
+ ['# ` ', [' heading depth=1 "`"', ' text "`"']],
463
+ ['`` ', [' paragraph', ' text "``"', ' text " "']],
464
+ ];
465
+
466
+ for (const [input, lines] of cases) {
467
+ test(JSON.stringify(input), () => {
468
+ expect(print_batch(input)).toBe(['root', ...lines].join('\n'));
469
+ expect_incremental_matches(input);
470
+ });
471
+ }
472
+ });
473
+
474
+ describe('batch and incremental parity', () => {
475
+ const atoms = [
476
+ '*',
477
+ '_',
478
+ '~',
479
+ '~~',
480
+ '^',
481
+ '[',
482
+ ']',
483
+ '](',
484
+ ':x[',
485
+ '<b>',
486
+ '</b>',
487
+ '\n',
488
+ '\n\n',
489
+ 'a',
490
+ ' ',
491
+ '#',
492
+ '-',
493
+ '>',
494
+ '---',
495
+ '`',
496
+ ];
497
+
498
+ function mulberry32(seed: number): () => number {
499
+ return () => {
500
+ seed = (seed + 0x6d2b79f5) | 0;
501
+ let t = Math.imul(seed ^ (seed >>> 15), 1 | seed);
502
+ t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
503
+ return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
504
+ };
505
+ }
506
+
507
+ test('seeded inputs parse the same in any chunk size', () => {
508
+ const random = mulberry32(1);
509
+ const mismatched: string[] = [];
510
+
511
+ for (let i = 0; i < 2000; i++) {
512
+ const len = 1 + Math.floor(random() * 8);
513
+ let input = '';
514
+ for (let j = 0; j < len; j++) {
515
+ input += atoms[Math.floor(random() * atoms.length)];
516
+ }
517
+
518
+ const batch = print_batch(input);
519
+ for (const chunk_size of [1, 2, 3]) {
520
+ if (print_incremental(input, chunk_size) !== batch) {
521
+ mismatched.push(input);
522
+ break;
523
+ }
524
+ }
525
+ }
526
+
527
+ expect(mismatched).toEqual([]);
528
+ });
529
+ });
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * buffer utilities for svelte components.
3
3
  *
4
- * pure functions that read from NodeBuffer typed arrays.
4
+ * pure functions that read from NodeBuffer accessors.
5
5
  * no cursor state, no allocations beyond the returned arrays.
6
6
  */
7
7
  import type { NodeBuffer } from './utils';
package/tsc/buf_utils.js CHANGED
@@ -1,18 +1,18 @@
1
1
  /**
2
2
  * buffer utilities for svelte components.
3
3
  *
4
- * pure functions that read from NodeBuffer typed arrays.
4
+ * pure functions that read from NodeBuffer accessors.
5
5
  * no cursor state, no allocations beyond the returned arrays.
6
6
  */
7
7
  const NONE = 0xffffffff;
8
8
  /** get child indices for a node. */
9
9
  export function buf_children(buf, idx) {
10
10
  const result = [];
11
- let child = buf._children_starts[idx];
11
+ let child = buf.first_child_at(idx);
12
12
  while (child !== NONE) {
13
13
  result.push(child);
14
- const next = buf._next_siblings[child];
15
- if (next === NONE || buf._parents[next] !== idx)
14
+ const next = buf.next_at(child);
15
+ if (next === NONE || buf.parent_at(next) !== idx)
16
16
  break;
17
17
  child = next;
18
18
  }
@@ -23,8 +23,8 @@ export function buf_text(buf, idx, source) {
23
23
  const s = buf._strings[idx];
24
24
  if (s !== undefined)
25
25
  return s;
26
- const vs = buf._value_starts[idx];
27
- const ve = buf._value_ends[idx];
26
+ const vs = buf.value_start_at(idx);
27
+ const ve = buf.value_end_at(idx);
28
28
  if (vs === NONE || ve === NONE || ve <= vs)
29
29
  return '';
30
30
  return source.slice(vs, ve);
@@ -37,11 +37,11 @@ export function buf_text_content(buf, idx, source) {
37
37
  return own;
38
38
  // Walk children
39
39
  let text = '';
40
- let child = buf._children_starts[idx];
40
+ let child = buf.first_child_at(idx);
41
41
  while (child !== NONE) {
42
42
  text += buf_text_content(buf, child, source);
43
- const next = buf._next_siblings[child];
44
- if (next === NONE || buf._parents[next] !== idx)
43
+ const next = buf.next_at(child);
44
+ if (next === NONE || buf.parent_at(next) !== idx)
45
45
  break;
46
46
  child = next;
47
47
  }
package/tsc/cursor.d.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * single reusable object that provides tree-traversal semantics
5
5
  * (gotofirstchild / gotonextsibling / gotoparent) while reading
6
- * directly from the soa typed arrays underneath. no per-node
6
+ * directly from the node words underneath. no per-node
7
7
  * objects are created, text is lazily sliced from the source
8
8
  * string only when requested.
9
9
  *
@@ -22,24 +22,17 @@
22
22
  * cursor.gotoparent();
23
23
  * }
24
24
  */
25
- import type { NodeBuffer } from "./utils";
25
+ import { type NodeBuffer } from './utils';
26
26
  export declare class Cursor {
27
- /** the backing soa buffer. */
28
27
  private buf;
29
28
  /** the full source string for lazy text slicing. */
30
29
  private src;
31
30
  /** current node index into the buffer. */
32
31
  private idx;
33
- private _kinds;
34
- private _extras;
35
- private _starts;
36
- private _ends;
37
- private _value_starts;
38
- private _value_ends;
39
- private _parents;
40
- private _next_siblings;
41
- private _children_starts;
42
- private _pending_nodes;
32
+ /** idx times NodeField.stride */
33
+ private b;
34
+ /** cached buf._n */
35
+ private n;
43
36
  constructor(buf: NodeBuffer, source: string);
44
37
  /** numeric kind of current node. */
45
38
  get kind(): number;
@@ -64,6 +57,9 @@ export declare class Cursor {
64
57
  /** get text content for the current node. prebuilt strings
65
58
  (from wiretreebuilder) are returned directly; otherwise sliced lazily. */
66
59
  text(): string;
60
+ get source(): string;
61
+ /** undefined when text slices the source */
62
+ get prebuilt(): string | undefined;
67
63
  /** get metadata for the current node, or undefined if none. */
68
64
  meta(): Record<string, unknown> | undefined;
69
65
  /** slice the source string by byte offsets. for resolving metadata offset pairs. */
@@ -71,9 +67,17 @@ export declare class Cursor {
71
67
  goto_first_child(): boolean;
72
68
  goto_next_sibling(): boolean;
73
69
  goto_parent(): boolean;
70
+ /** @internal */
71
+ get words(): Uint32Array;
72
+ /** @internal undefined when text slices the source */
73
+ prebuilt_at(idx: number): string | undefined;
74
+ /** @internal no bounds checks */
75
+ move_to(idx: number): void;
74
76
  reset(): void;
75
77
  /** get child indices as an array (for svelte {#each} iteration). */
76
78
  children(): number[];
79
+ /** a cursor kept for reuse must not pin the source */
80
+ release(): void;
77
81
  /** re-inits cursor with a (potentially grown) buffer and new source. */
78
82
  reinit(buf: NodeBuffer, source: string): void;
79
83
  }