@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
@@ -1,9 +1,9 @@
1
- import { string_to_kind } from "./utils";
2
- import { UndoLog } from "./undo_log";
3
- import { ViewCache, } from "./node_view";
1
+ import { string_to_kind, } from './utils';
2
+ import { UndoLog } from './undo_log';
3
+ import { ViewCache, } from './node_view';
4
4
  const NONE = 0xffffffff;
5
5
  /** total number of node kinds in the enum. */
6
- const NODE_KIND_COUNT = 35;
6
+ const NODE_KIND_COUNT = 36;
7
7
  /** first synthetic id. high bit flag partitions id space from parser ids. */
8
8
  const SYNTHETIC_ID_BASE = 0x40000000;
9
9
  /** single handler: no wrapper needed, just normalize return type. */
@@ -82,6 +82,8 @@ function compose(handlers) {
82
82
  return compose_n(handlers);
83
83
  }
84
84
  }
85
+ /** open_wants once a redirect exists, any open may need retargeting */
86
+ const ALL_WANTS = new Uint8Array(64).fill(1);
85
87
  function register_plugins(plugins) {
86
88
  const fused_plugins = [];
87
89
  const sequential_plugins = [];
@@ -97,13 +99,13 @@ function register_plugins(plugins) {
97
99
  const per_kind = new Array(NODE_KIND_COUNT).fill(null);
98
100
  for (const plugin of fused_plugins) {
99
101
  for (const key of Object.keys(plugin)) {
100
- if (key === "sequential")
102
+ if (key === 'sequential')
101
103
  continue;
102
104
  const kind = string_to_kind(key);
103
105
  if (kind === undefined)
104
106
  continue;
105
107
  const entry = plugin[key];
106
- if (!entry || typeof entry !== "object" || !("parse" in entry))
108
+ if (!entry || typeof entry !== 'object' || !('parse' in entry))
107
109
  continue;
108
110
  if (!per_kind[kind])
109
111
  per_kind[kind] = [];
@@ -112,7 +114,7 @@ function register_plugins(plugins) {
112
114
  }
113
115
  // compose fused handlers
114
116
  const fused = new Array(NODE_KIND_COUNT).fill(null);
115
- const has_handler = new Uint32Array(2); // 64 bits, need 35
117
+ const has_handler = new Uint32Array(2); // 64 bits, need 36
116
118
  for (let i = 0; i < NODE_KIND_COUNT; i++) {
117
119
  const list = per_kind[i];
118
120
  if (list && list.length > 0) {
@@ -124,212 +126,236 @@ function register_plugins(plugins) {
124
126
  const sequential = sequential_plugins.map((plugin) => {
125
127
  const table = new Array(NODE_KIND_COUNT).fill(null);
126
128
  for (const key of Object.keys(plugin)) {
127
- if (key === "sequential")
129
+ if (key === 'sequential')
128
130
  continue;
129
131
  const kind = string_to_kind(key);
130
132
  if (kind === undefined)
131
133
  continue;
132
134
  const entry = plugin[key];
133
- if (!entry || typeof entry !== "object" || !("parse" in entry))
135
+ if (!entry || typeof entry !== 'object' || !('parse' in entry))
134
136
  continue;
135
137
  table[kind] = compose_1(entry);
136
138
  }
137
139
  return { plugin, handlers: table };
138
140
  });
139
- return { fused, sequential, has_handler };
141
+ // a pass with no handler would do nothing
142
+ return {
143
+ fused,
144
+ sequential: sequential.filter((pass) => pass.handlers.some((h) => h !== null)),
145
+ has_handler,
146
+ open_wants: wants_of(has_handler),
147
+ };
148
+ }
149
+ function wants_of(has_handler) {
150
+ const wants = new Uint8Array(64);
151
+ for (let k = 0; k < 64; k++) {
152
+ if (has_handler[k >> 5] & (1 << (k & 31)))
153
+ wants[k] = 1;
154
+ }
155
+ return wants;
156
+ }
157
+ /** parse_of for an entry the registration skips */
158
+ const NO_PARSE = {};
159
+ function parse_of(entry) {
160
+ return entry && typeof entry === 'object' && 'parse' in entry
161
+ ? entry.parse
162
+ : NO_PARSE;
163
+ }
164
+ /** everything register_plugins reads, in the order it reads it */
165
+ function snapshot_plugins(plugins) {
166
+ const snap = [plugins.length];
167
+ for (let i = 0; i < plugins.length; i++) {
168
+ const p = plugins[i];
169
+ const keys = Object.keys(p);
170
+ snap.push(p, !!p.sequential, keys.length);
171
+ for (let k = 0; k < keys.length; k++) {
172
+ const entry = p[keys[k]];
173
+ snap.push(keys[k], entry, parse_of(entry));
174
+ }
175
+ }
176
+ return snap;
177
+ }
178
+ function snapshot_matches(plugins, snap) {
179
+ let j = 0;
180
+ if (snap[j++] !== plugins.length)
181
+ return false;
182
+ for (let i = 0; i < plugins.length; i++) {
183
+ const p = plugins[i];
184
+ if (snap[j++] !== p)
185
+ return false;
186
+ if (snap[j++] !== !!p.sequential)
187
+ return false;
188
+ // inherited enumerable keys change the count or a key, so an exact match
189
+ // means the same own keys without allocating Object.keys
190
+ const count = snap[j++];
191
+ const keys_end = j + count * 3;
192
+ for (const key in p) {
193
+ if (j === keys_end || snap[j++] !== key)
194
+ return false;
195
+ const entry = p[key];
196
+ if (snap[j++] !== entry)
197
+ return false;
198
+ if (snap[j++] !== parse_of(entry))
199
+ return false;
200
+ }
201
+ if (j !== keys_end)
202
+ return false;
203
+ }
204
+ return true;
205
+ }
206
+ // nothing writes a registration after register_plugins, so documents whose
207
+ // plugins hold the same objects, keys and handlers can share one
208
+ let last_snapshot = null;
209
+ let last_registration = null;
210
+ function registration_for(plugins) {
211
+ if (last_snapshot !== null && snapshot_matches(plugins, last_snapshot)) {
212
+ return last_registration;
213
+ }
214
+ const reg = register_plugins(plugins);
215
+ last_snapshot = snapshot_plugins(plugins);
216
+ last_registration = reg;
217
+ return reg;
140
218
  }
141
219
  /**
142
- * stores close callbacks indexed by buffer index.
143
- * flat array gives O(1) access since buffer indices are sequential.
220
+ * a Map since handled nodes can sit over 1024 indices apart, and an array
221
+ * written past such a gap falls back to dictionary elements
144
222
  */
145
223
  class CloseCallbackStore {
146
224
  constructor() {
147
- this.store = [];
225
+ this.store = null;
226
+ // entries still set, most nodes close with none so the lookup is skipped
227
+ this.live = 0;
148
228
  }
149
229
  set(idx, callbacks) {
150
- this.store[idx] = callbacks;
230
+ let store = this.store;
231
+ if (store === null)
232
+ store = this.store = new Map();
233
+ store.set(idx, callbacks);
234
+ this.live = store.size;
151
235
  }
152
236
  /** take close callbacks for a node, removing the entry. returns undefined if none. */
153
237
  take(idx) {
154
- const cbs = this.store[idx];
155
- if (cbs !== undefined)
156
- this.store[idx] = undefined;
238
+ if (this.live === 0)
239
+ return undefined;
240
+ const store = this.store;
241
+ const cbs = store.get(idx);
242
+ if (cbs !== undefined) {
243
+ store.delete(idx);
244
+ this.live = store.size;
245
+ }
157
246
  return cbs;
158
247
  }
159
248
  /** fire close callbacks for a node, removing the entry. */
160
249
  fire(idx) {
161
- const cbs = this.store[idx];
250
+ const cbs = this.take(idx);
162
251
  if (cbs === undefined)
163
252
  return;
164
253
  for (let i = 0; i < cbs.length; i++) {
165
254
  cbs[i]();
166
255
  }
167
- this.store[idx] = undefined;
168
256
  }
169
257
  /** discard callbacks without firing (for revocation). */
170
258
  discard(idx) {
171
- this.store[idx] = undefined;
259
+ this.take(idx);
172
260
  }
173
261
  reset() {
174
- this.store.length = 0;
262
+ if (this.store !== null)
263
+ this.store.clear();
264
+ this.live = 0;
175
265
  }
176
266
  }
177
267
  /**
178
268
  * dispatch plugin handlers for a node open event.
179
269
  *
180
- * the switch destructures the handlers table into 35 locals at the top.
181
- * each arm calls its own local, giving the jit a monomorphic call site
182
- * per kind.
270
+ * each switch arm is a monomorphic call site for its own kind
183
271
  */
184
272
  function dispatch_open(kind, view, ctx, fused, has_handler) {
185
273
  // bitmask fast path: no handler for this kind
186
274
  if (!(has_handler[kind >> 5] & (1 << (kind & 31))))
187
275
  return null;
188
- // destructure into monomorphic locals
189
- const h_0 = fused[0];
190
- const h_1 = fused[1];
191
- const h_2 = fused[2];
192
- const h_3 = fused[3];
193
- const h_4 = fused[4];
194
- const h_5 = fused[5];
195
- const h_6 = fused[6];
196
- const h_7 = fused[7];
197
- const h_8 = fused[8];
198
- const h_9 = fused[9];
199
- const h_10 = fused[10];
200
- const h_11 = fused[11];
201
- const h_12 = fused[12];
202
- const h_13 = fused[13];
203
- const h_14 = fused[14];
204
- const h_15 = fused[15];
205
- const h_16 = fused[16];
206
- const h_17 = fused[17];
207
- const h_18 = fused[18];
208
- const h_19 = fused[19];
209
- const h_20 = fused[20];
210
- const h_21 = fused[21];
211
- const h_22 = fused[22];
212
- const h_23 = fused[23];
213
- const h_24 = fused[24];
214
- const h_25 = fused[25];
215
- const h_26 = fused[26];
216
- const h_27 = fused[27];
217
- const h_28 = fused[28];
218
- const h_29 = fused[29];
219
- const h_30 = fused[30];
220
- const h_31 = fused[31];
221
- const h_32 = fused[32];
222
- const h_33 = fused[33];
223
- const h_34 = fused[34];
224
276
  switch (kind) {
225
277
  case 0:
226
- return h_0(view, ctx);
278
+ return fused[0](view, ctx);
227
279
  case 1:
228
- return h_1(view, ctx);
280
+ return fused[1](view, ctx);
229
281
  case 2:
230
- return h_2(view, ctx);
282
+ return fused[2](view, ctx);
231
283
  case 3:
232
- return h_3(view, ctx);
284
+ return fused[3](view, ctx);
233
285
  case 4:
234
- return h_4(view, ctx);
286
+ return fused[4](view, ctx);
235
287
  case 5:
236
- return h_5(view, ctx);
288
+ return fused[5](view, ctx);
237
289
  case 6:
238
- return h_6(view, ctx);
290
+ return fused[6](view, ctx);
239
291
  case 7:
240
- return h_7(view, ctx);
292
+ return fused[7](view, ctx);
241
293
  case 8:
242
- return h_8(view, ctx);
294
+ return fused[8](view, ctx);
243
295
  case 9:
244
- return h_9(view, ctx);
296
+ return fused[9](view, ctx);
245
297
  case 10:
246
- return h_10(view, ctx);
298
+ return fused[10](view, ctx);
247
299
  case 11:
248
- return h_11(view, ctx);
300
+ return fused[11](view, ctx);
249
301
  case 12:
250
- return h_12(view, ctx);
302
+ return fused[12](view, ctx);
251
303
  case 13:
252
- return h_13(view, ctx);
304
+ return fused[13](view, ctx);
253
305
  case 14:
254
- return h_14(view, ctx);
306
+ return fused[14](view, ctx);
255
307
  case 15:
256
- return h_15(view, ctx);
308
+ return fused[15](view, ctx);
257
309
  case 16:
258
- return h_16(view, ctx);
310
+ return fused[16](view, ctx);
259
311
  case 17:
260
- return h_17(view, ctx);
312
+ return fused[17](view, ctx);
261
313
  case 18:
262
- return h_18(view, ctx);
314
+ return fused[18](view, ctx);
263
315
  case 19:
264
- return h_19(view, ctx);
316
+ return fused[19](view, ctx);
265
317
  case 20:
266
- return h_20(view, ctx);
318
+ return fused[20](view, ctx);
267
319
  case 21:
268
- return h_21(view, ctx);
320
+ return fused[21](view, ctx);
269
321
  case 22:
270
- return h_22(view, ctx);
322
+ return fused[22](view, ctx);
271
323
  case 23:
272
- return h_23(view, ctx);
324
+ return fused[23](view, ctx);
273
325
  case 24:
274
- return h_24(view, ctx);
326
+ return fused[24](view, ctx);
275
327
  case 25:
276
- return h_25(view, ctx);
328
+ return fused[25](view, ctx);
277
329
  case 26:
278
- return h_26(view, ctx);
330
+ return fused[26](view, ctx);
279
331
  case 27:
280
- return h_27(view, ctx);
332
+ return fused[27](view, ctx);
281
333
  case 28:
282
- return h_28(view, ctx);
334
+ return fused[28](view, ctx);
283
335
  case 29:
284
- return h_29(view, ctx);
336
+ return fused[29](view, ctx);
285
337
  case 30:
286
- return h_30(view, ctx);
338
+ return fused[30](view, ctx);
287
339
  case 31:
288
- return h_31(view, ctx);
340
+ return fused[31](view, ctx);
289
341
  case 32:
290
- return h_32(view, ctx);
342
+ return fused[32](view, ctx);
291
343
  case 33:
292
- return h_33(view, ctx);
344
+ return fused[33](view, ctx);
293
345
  case 34:
294
- return h_34(view, ctx);
346
+ return fused[34](view, ctx);
347
+ case 35:
348
+ return fused[35](view, ctx);
295
349
  default:
296
350
  return null;
297
351
  }
298
352
  }
299
- /**
300
- * depth-first walk over the soa buffer.
301
- * calls visitor(idx, kind, false) on open, visitor(idx, kind, true) on close.
302
- */
303
- function walk_tree(buf, visitor) {
304
- const children_starts = buf._children_starts;
305
- const next_siblings = buf._next_siblings;
306
- const parents = buf._parents;
307
- const kinds = buf._kinds;
308
- let idx = children_starts[0]; // first child of root
309
- if (idx === NONE)
310
- return;
311
- const stack = [];
312
- while (true) {
313
- visitor(idx, kinds[idx], false);
314
- const child = children_starts[idx];
315
- if (child !== NONE) {
316
- stack.push(idx);
317
- idx = child;
318
- continue;
319
- }
320
- visitor(idx, kinds[idx], true);
321
- let next = next_siblings[idx];
322
- while ((next === NONE || parents[next] !== parents[idx]) &&
323
- stack.length > 0) {
324
- idx = stack.pop();
325
- visitor(idx, kinds[idx], true);
326
- next = next_siblings[idx];
327
- }
328
- if (next === NONE || parents[next] !== parents[idx])
329
- break;
330
- idx = next;
331
- }
332
- }
353
+ /** shared undo log until a view or a kind rewrite needs one, never written */
354
+ const NO_UNDO = new UndoLog();
355
+ /** shared close callbacks until the first is set, never written */
356
+ const NO_CLOSE_CBS = new CloseCallbackStore();
357
+ /** shared redirects until the first wrap_inner, never written */
358
+ const NO_REDIRECTS = new Map();
333
359
  /**
334
360
  * orchestrates plugin dispatch for both TreeBuilder and WireTreeBuilder.
335
361
  *
@@ -338,20 +364,56 @@ function walk_tree(buf, visitor) {
338
364
  */
339
365
  export class PluginDispatcher {
340
366
  constructor(plugins, text_source) {
341
- this.undo = new UndoLog();
342
- this.close_cbs = new CloseCallbackStore();
343
- this.ctx = {};
367
+ this.undo = NO_UNDO;
368
+ this.close_cbs = NO_CLOSE_CBS;
369
+ this.ctx = null;
344
370
  /**
345
371
  * redirect map: when wrap_inner is called, subsequent children
346
372
  * targeting the parent should land in the wrapper instead.
347
373
  */
348
- this.redirects = new Map();
374
+ this.redirects = NO_REDIRECTS;
349
375
  this.next_synthetic_id = SYNTHETIC_ID_BASE;
350
- const reg = register_plugins(plugins);
376
+ /** one cache serves every dispatch, a view only holds an index */
377
+ this.cache = null;
378
+ const reg = registration_for(plugins);
351
379
  this.fused = reg.fused;
352
380
  this.has_handler = reg.has_handler;
353
381
  this.sequential = reg.sequential;
354
382
  this.text_source = text_source;
383
+ this.open_wants = reg.open_wants;
384
+ }
385
+ /** cleared since a callback view may have filled it after the last dispatch */
386
+ views(buf) {
387
+ const cache = this.cache;
388
+ if (cache === null) {
389
+ let undo = this.undo;
390
+ if (undo === NO_UNDO)
391
+ undo = this.undo = new UndoLog();
392
+ return (this.cache = new ViewCache(buf, this.text_source, undo));
393
+ }
394
+ cache.clear();
395
+ cache.rebind(buf, this.text_source);
396
+ return cache;
397
+ }
398
+ /** buffer index and prior kind of each kind rewrite, see UndoLog */
399
+ kind_log() {
400
+ return this.undo.kind_changes;
401
+ }
402
+ /** a kind rewrite outside the plugins, such as a revoke repair */
403
+ log_kind(buf_idx, prior_kind) {
404
+ let undo = this.undo;
405
+ if (undo === NO_UNDO)
406
+ undo = this.undo = new UndoLog();
407
+ undo.log_kind(buf_idx, prior_kind);
408
+ }
409
+ /** an open of this kind needs a handler call or a redirect lookup */
410
+ wants_open(kind) {
411
+ return ((this.has_handler[kind >> 5] & (1 << (kind & 31))) !== 0 ||
412
+ this.redirects.size !== 0);
413
+ }
414
+ /** a close needs no dispatch */
415
+ quiet() {
416
+ return (this.close_cbs.live === 0 && this.redirects.size === 0 && this.undo.empty);
355
417
  }
356
418
  /** check whether any fused handlers exist for this kind. */
357
419
  has_handlers(kind) {
@@ -359,15 +421,17 @@ export class PluginDispatcher {
359
421
  }
360
422
  /** check if a parent index has a redirect (wrap_inner). */
361
423
  get_redirect(parent_idx) {
424
+ if (this.redirects.size === 0)
425
+ return undefined;
362
426
  return this.redirects.get(parent_idx);
363
427
  }
364
- /** register a wrap_inner redirect. */
365
- set_redirect(parent_idx, wrapper_idx) {
366
- this.redirects.set(parent_idx, wrapper_idx);
367
- }
368
- /** clear a redirect (on parent close). */
369
- clear_redirect(parent_idx) {
370
- this.redirects.delete(parent_idx);
428
+ own_redirects() {
429
+ let redirects = this.redirects;
430
+ if (redirects === NO_REDIRECTS) {
431
+ redirects = this.redirects = new Map();
432
+ this.open_wants = ALL_WANTS;
433
+ }
434
+ return redirects;
371
435
  }
372
436
  /** allocate a new synthetic node id. */
373
437
  allocate_synthetic_id() {
@@ -381,11 +445,11 @@ export class PluginDispatcher {
381
445
  * dispatch fused plugin handlers on node open.
382
446
  * creates a ViewCache, runs handlers, stores close callbacks.
383
447
  */
384
- dispatch_open(buf_idx, kind, buf, id_register) {
385
- const cache = new ViewCache(buf, this.text_source, this.undo, buf_idx);
448
+ dispatch_open(buf_idx, kind, buf) {
449
+ const cache = this.views(buf);
386
450
  const view = cache.get(buf_idx);
387
451
  this.undo.set_active_node(buf_idx);
388
- const callbacks = dispatch_open(kind, view, this.ctx, this.fused, this.has_handler);
452
+ const callbacks = dispatch_open(kind, view, this.ctx ?? (this.ctx = {}), this.fused, this.has_handler);
389
453
  this.undo.clear_active_node();
390
454
  // check if the handler called wrap_inner and register redirects.
391
455
  // the wrapped node may be the handler's own node or a node
@@ -395,12 +459,15 @@ export class PluginDispatcher {
395
459
  for (let i = 0; i < entries.length; i++) {
396
460
  const e = entries[i];
397
461
  if (e.kind === 3 /* UndoEntryKind.WrapInner */) {
398
- this.redirects.set(e.parent, e.wrapper);
462
+ this.own_redirects().set(e.parent, e.wrapper);
399
463
  }
400
464
  }
401
465
  }
402
466
  if (callbacks) {
403
- this.close_cbs.set(buf_idx, callbacks);
467
+ let close_cbs = this.close_cbs;
468
+ if (close_cbs === NO_CLOSE_CBS)
469
+ close_cbs = this.close_cbs = new CloseCallbackStore();
470
+ close_cbs.set(buf_idx, callbacks);
404
471
  }
405
472
  cache.clear();
406
473
  }
@@ -412,21 +479,25 @@ export class PluginDispatcher {
412
479
  * speculation, inline emphasis).
413
480
  */
414
481
  dispatch_close(buf_idx, buf) {
415
- this.redirects.delete(buf_idx);
482
+ if (this.redirects.size !== 0)
483
+ this.redirects.delete(buf_idx);
416
484
  // take and fire close callbacks with undo attribution
417
485
  const cbs = this.close_cbs.take(buf_idx);
486
+ // callbacks cannot change the pending flag
487
+ const pending = buf.pending_at(buf_idx) !== 0;
418
488
  if (cbs) {
419
- const cache = new ViewCache(buf, this.text_source, this.undo, buf_idx);
420
- this.undo.set_active_node(buf_idx);
489
+ // a node no longer pending commits right after its callbacks, so
490
+ // anything they recorded would be dropped unread
491
+ if (pending)
492
+ this.undo.set_active_node(buf_idx);
421
493
  for (let i = 0; i < cbs.length; i++) {
422
494
  cbs[i]();
423
495
  }
424
496
  this.undo.clear_active_node();
425
- cache.clear();
426
497
  }
427
498
  // only commit if the node is no longer pending.
428
499
  // pending nodes can still be revoked after close.
429
- if (buf._pending_nodes[buf_idx] === 0) {
500
+ if (!pending) {
430
501
  this.undo.commit(buf_idx);
431
502
  }
432
503
  }
@@ -443,6 +514,11 @@ export class PluginDispatcher {
443
514
  * must be called BEFORE handle_repair().
444
515
  */
445
516
  dispatch_revoke(buf_idx, buf) {
517
+ // nothing recorded, so nothing to undo
518
+ if (this.redirects.size === 0 &&
519
+ this.close_cbs.live === 0 &&
520
+ this.undo.empty)
521
+ return;
446
522
  this.redirects.delete(buf_idx);
447
523
  this.close_cbs.discard(buf_idx);
448
524
  // clean up redirects from any cross-node WrapInner entries
@@ -458,10 +534,10 @@ export class PluginDispatcher {
458
534
  }
459
535
  this.undo.revoke(buf_idx, buf);
460
536
  // recurse into children to revoke their plugin state too
461
- let child = buf._children_starts[buf_idx];
462
- while (child !== NONE && buf._parents[child] === buf_idx) {
537
+ let child = buf.first_child_at(buf_idx);
538
+ while (child !== NONE && buf.parent_at(child) === buf_idx) {
463
539
  this.dispatch_revoke(child, buf);
464
- child = buf._next_siblings[child];
540
+ child = buf.next_at(child);
465
541
  }
466
542
  }
467
543
  /**
@@ -470,30 +546,76 @@ export class PluginDispatcher {
470
546
  */
471
547
  run_sequential(buf) {
472
548
  for (const pass of this.sequential) {
549
+ const handlers = pass.handlers;
550
+ // reread after plugin code runs, growing the buffer moves it to new storage
551
+ let n = buf._n;
552
+ let idx = n[8 /* NodeField.first_child */];
553
+ if (idx === NONE)
554
+ continue;
555
+ // with no handled kind anywhere in the buffer, linked or not, the walk does nothing
556
+ const size = buf._size;
557
+ let handled = false;
558
+ for (let b = 0, end = size * 12 /* NodeField.stride */; b < end; b += 12 /* NodeField.stride */) {
559
+ if (handlers[n[b] & 0xff] != null) {
560
+ handled = true;
561
+ break;
562
+ }
563
+ }
564
+ if (!handled)
565
+ continue;
473
566
  const close_store = new CloseCallbackStore();
474
- walk_tree(buf, (idx, kind, is_close) => {
475
- if (is_close) {
567
+ const ctx = this.ctx ?? (this.ctx = {});
568
+ const stack = [];
569
+ while (true) {
570
+ const b = idx * 12 /* NodeField.stride */;
571
+ const handler = handlers[n[b] & 0xff];
572
+ if (handler != null) {
573
+ const cache = this.views(buf);
574
+ const view = cache.get(idx);
575
+ // the tree is complete so nothing revokes a sequential write, no
576
+ // active node means none is recorded
577
+ const callbacks = handler(view, ctx);
578
+ if (callbacks)
579
+ close_store.set(idx, callbacks);
580
+ cache.clear();
581
+ n = buf._n;
582
+ }
583
+ const child = n[b + 8 /* NodeField.first_child */];
584
+ if (child !== NONE) {
585
+ stack.push(idx);
586
+ idx = child;
587
+ continue;
588
+ }
589
+ if (close_store.live !== 0) {
476
590
  close_store.fire(idx);
477
- return;
591
+ n = buf._n;
478
592
  }
479
- const handler = pass.handlers[kind];
480
- if (handler === null)
481
- return;
482
- const cache = new ViewCache(buf, this.text_source, this.undo, idx);
483
- const view = cache.get(idx);
484
- this.undo.set_active_node(idx);
485
- const callbacks = handler(view, this.ctx);
486
- this.undo.clear_active_node();
487
- if (callbacks) {
488
- close_store.set(idx, callbacks);
593
+ // read after the callbacks, which may relink the node
594
+ let next = n[b + 6 /* NodeField.next */];
595
+ let parent = n[b + 5 /* NodeField.parent */];
596
+ while ((next === NONE ||
597
+ n[next * 12 /* NodeField.stride */ + 5 /* NodeField.parent */] !== parent) &&
598
+ stack.length > 0) {
599
+ idx = stack.pop();
600
+ if (close_store.live !== 0) {
601
+ close_store.fire(idx);
602
+ n = buf._n;
603
+ }
604
+ const bi = idx * 12 /* NodeField.stride */;
605
+ next = n[bi + 6 /* NodeField.next */];
606
+ parent = n[bi + 5 /* NodeField.parent */];
489
607
  }
490
- cache.clear();
491
- });
608
+ if (next === NONE ||
609
+ n[next * 12 /* NodeField.stride */ + 5 /* NodeField.parent */] !== parent)
610
+ break;
611
+ idx = next;
612
+ }
492
613
  }
493
614
  }
494
615
  /** reset all state. */
495
616
  reset() {
496
- this.undo.clear();
617
+ if (this.undo !== NO_UNDO)
618
+ this.undo.clear();
497
619
  this.close_cbs.reset();
498
620
  this.redirects.clear();
499
621
  this.next_synthetic_id = SYNTHETIC_ID_BASE;