@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.
- package/CHANGELOG.md +213 -0
- package/WIRE_FORMAT.md +5 -1
- package/dist/buf-utils.js +23 -23
- package/dist/buf_utils.d.ts +1 -1
- package/dist/cursor.d.ts +17 -13
- package/dist/cursor.js +118 -31
- package/dist/main.d.ts +362 -26
- package/dist/main.js +5841 -3420
- package/dist/node_view-bvM0i0-p.js +407 -0
- package/dist/node_view.d.ts +11 -12
- package/dist/opcodes.d.ts +23 -6
- package/dist/plugin_dispatch.d.ts +22 -8
- package/dist/tree-builder.js +185 -66
- package/dist/tree_builder.d.ts +42 -11
- package/dist/undo_log.d.ts +11 -1
- package/dist/utils.d.ts +77 -51
- package/dist/utils.js +687 -209
- package/dist/wire-tree-builder.js +69 -71
- package/dist/wire_tree_builder.d.ts +4 -7
- package/package.json +1 -1
- package/src/buf_utils.ts +10 -14
- package/src/cursor.ts +74 -57
- package/src/main.ts +9898 -5593
- package/src/node_view.ts +159 -140
- package/src/opcodes.ts +39 -7
- package/src/plugin_dispatch.ts +328 -219
- package/src/tree_builder.ts +278 -98
- package/src/undo_log.ts +58 -24
- package/src/utils.spec.ts +86 -9
- package/src/utils.ts +769 -392
- package/src/wire_emitter.ts +6 -0
- package/src/wire_tree_builder.ts +39 -52
- package/test/block_quotes.spec.ts +78 -7
- package/test/code_spans.spec.ts +158 -6
- package/test/crlf.spec.ts +49 -1
- package/test/directives.spec.ts +530 -1
- package/test/emphasis.spec.ts +10 -4
- package/test/fixtures/pfm/block_quotes/pfm_fence_close.md +4 -0
- package/test/fixtures/pfm/block_quotes/pfm_fence_close_compact.md +4 -0
- package/test/fixtures/pfm/block_quotes/pfm_fence_close_end_quote.md +5 -0
- package/test/fixtures/pfm/block_quotes/pfm_fence_close_info.md +5 -0
- package/test/fixtures/pfm/block_quotes/pfm_fence_close_longer.md +4 -0
- package/test/fixtures/pfm/block_quotes/pfm_fence_close_nested.md +3 -0
- package/test/fixtures/pfm/block_quotes/pfm_fence_close_twice.md +6 -0
- package/test/fixtures/pfm/block_quotes/pfm_fence_info_eof.md +1 -0
- package/test/fixtures/pfm/block_quotes/pfm_fence_unclosed.md +2 -0
- package/test/fixtures/pfm/code_spans/pfm_328_5.md +1 -0
- package/test/fixtures/pfm/code_spans/pfm_328_6.md +1 -0
- package/test/fixtures/pfm/code_spans/pfm_328_7.md +1 -0
- package/test/fixtures/pfm/code_spans/pfm_328_8.md +1 -0
- package/test/fixtures/pfm/code_spans/pfm_328_9.md +2 -0
- package/test/fixtures/pfm/fenced_code_blocks/pfm_info_eof.md +1 -0
- package/test/fixtures/pfm/fenced_code_blocks/pfm_info_eof_no_lf.md +1 -0
- package/test/fixtures/pfm/generic_directives/106.md +1 -0
- package/test/fixtures/pfm/generic_directives/107.md +3 -0
- package/test/fixtures/pfm/generic_directives/108.md +1 -0
- package/test/fixtures/pfm/generic_directives/109.md +1 -0
- package/test/fixtures/pfm/generic_directives/110.md +1 -0
- package/test/fixtures/pfm/generic_directives/111.md +1 -0
- package/test/fixtures/pfm/generic_directives/112.md +1 -0
- package/test/fixtures/pfm/generic_directives/113.md +1 -0
- package/test/fixtures/pfm/generic_directives/114.md +2 -0
- package/test/fixtures/pfm/generic_directives/115.md +1 -0
- package/test/fixtures/pfm/generic_directives/116.md +6 -0
- package/test/fixtures/pfm/generic_directives/117.md +3 -0
- package/test/fixtures/pfm/generic_directives/118.md +6 -0
- package/test/fixtures/pfm/generic_directives/119.md +3 -0
- package/test/fixtures/pfm/generic_directives/120.md +5 -0
- package/test/fixtures/pfm/generic_directives/121.md +3 -0
- package/test/fixtures/pfm/generic_directives/122.md +4 -0
- package/test/fixtures/pfm/generic_directives/123.md +2 -0
- package/test/html.spec.ts +44 -1
- package/test/html_block_containers.spec.ts +445 -0
- package/test/incremental.spec.ts +271 -0
- package/test/lists.spec.ts +107 -1
- package/test/parser_reuse.spec.ts +40 -0
- package/test/plugins.spec.ts +196 -226
- package/test/print.ts +2 -3
- package/test/run_bytecode.spec.ts +36 -0
- package/test/snapshots/hybrid/component-children.snap.ast +9 -16
- package/test/snapshots/hybrid/component-simple-00.snap.ast +1 -2
- package/test/snapshots/hybrid/component-simple-01.snap.ast +1 -2
- package/test/snapshots/hybrid/component-simple-03.snap.ast +13 -13
- package/test/snapshots/hybrid/component-simple-04.snap.ast +1 -2
- package/test/snapshots/hybrid/error.snap.ast +1 -2
- package/test/snapshots/markdown/blockquote-nested-markdown.snap.ast +2 -1
- package/test/snapshots/markdown/emphasis.snap.ast +2 -2
- package/test/snapshots/markdown/encodeHTMLCodeTags.snap.ast +1 -2
- package/test/snapshots/markdown/github-style-codeblock-inside-quote.snap.ast +8 -1
- package/test/snapshots/markdown/html-comments.snap.ast +11 -13
- package/test/snapshots/markdown/html5-strutural-tags.snap.ast +16 -31
- package/test/snapshots/markdown/line-starts-with-html.snap.ast +5 -6
- package/test/snapshots/markdown/literal-html-tags.snap.ast +11 -14
- package/test/snapshots/markdown/nested-blockquote.snap.ast +3 -3
- package/test/snapshots/markdown/pre-code-tags.snap.ast +5 -8
- package/test/snapshots/pfm/block_quotes/237.snap.ast +1 -2
- package/test/snapshots/pfm/block_quotes/251.snap.ast +5 -5
- package/test/snapshots/pfm/block_quotes/pfm_fence_close.snap.ast +6 -0
- package/test/snapshots/pfm/block_quotes/pfm_fence_close_compact.snap.ast +6 -0
- package/test/snapshots/pfm/block_quotes/pfm_fence_close_end_quote.snap.ast +8 -0
- package/test/snapshots/pfm/block_quotes/pfm_fence_close_info.snap.ast +4 -0
- package/test/snapshots/pfm/block_quotes/pfm_fence_close_longer.snap.ast +6 -0
- package/test/snapshots/pfm/block_quotes/pfm_fence_close_nested.snap.ast +5 -0
- package/test/snapshots/pfm/block_quotes/pfm_fence_close_twice.snap.ast +5 -0
- package/test/snapshots/pfm/block_quotes/pfm_fence_info_eof.snap.ast +3 -0
- package/test/snapshots/pfm/block_quotes/pfm_fence_unclosed.snap.ast +3 -0
- package/test/snapshots/pfm/code_spans/344.snap.ast +1 -1
- package/test/snapshots/pfm/code_spans/347.snap.ast +1 -2
- package/test/snapshots/pfm/code_spans/pfm_328_5.snap.ast +6 -0
- package/test/snapshots/pfm/code_spans/pfm_328_6.snap.ast +6 -0
- package/test/snapshots/pfm/code_spans/pfm_328_7.snap.ast +6 -0
- package/test/snapshots/pfm/code_spans/pfm_328_8.snap.ast +8 -0
- package/test/snapshots/pfm/code_spans/pfm_328_9.snap.ast +10 -0
- package/test/snapshots/pfm/emphasis_and_strong_emphasis/417.snap.ast +2 -2
- package/test/snapshots/pfm/emphasis_and_strong_emphasis/438.snap.ast +1 -1
- package/test/snapshots/pfm/emphasis_and_strong_emphasis/441.snap.ast +1 -1
- package/test/snapshots/pfm/emphasis_and_strong_emphasis/444.snap.ast +1 -1
- package/test/snapshots/pfm/emphasis_and_strong_emphasis/445.snap.ast +1 -1
- package/test/snapshots/pfm/emphasis_and_strong_emphasis/450.snap.ast +1 -1
- package/test/snapshots/pfm/emphasis_and_strong_emphasis/453.snap.ast +1 -1
- package/test/snapshots/pfm/emphasis_and_strong_emphasis/456.snap.ast +1 -1
- package/test/snapshots/pfm/emphasis_and_strong_emphasis/457.snap.ast +1 -1
- package/test/snapshots/pfm/emphasis_and_strong_emphasis/473.snap.ast +1 -1
- package/test/snapshots/pfm/emphasis_and_strong_emphasis/475.snap.ast +1 -1
- package/test/snapshots/pfm/emphasis_and_strong_emphasis/476.snap.ast +1 -1
- package/test/snapshots/pfm/emphasis_and_strong_emphasis/477.snap.ast +1 -1
- package/test/snapshots/pfm/emphasis_and_strong_emphasis/478.snap.ast +3 -4
- package/test/snapshots/pfm/emphasis_and_strong_emphasis/479.snap.ast +3 -4
- package/test/snapshots/pfm/fenced_code_blocks/126.snap.ast +1 -2
- package/test/snapshots/pfm/fenced_code_blocks/pfm_info_eof.snap.ast +2 -0
- package/test/snapshots/pfm/fenced_code_blocks/pfm_info_eof_no_lf.snap.ast +2 -0
- package/test/snapshots/pfm/generic_directives/011.snap.ast +3 -1
- package/test/snapshots/pfm/generic_directives/015.snap.ast +3 -1
- package/test/snapshots/pfm/generic_directives/016.snap.ast +3 -1
- package/test/snapshots/pfm/generic_directives/017.snap.ast +3 -1
- package/test/snapshots/pfm/generic_directives/019.snap.ast +3 -1
- package/test/snapshots/pfm/generic_directives/020.snap.ast +3 -1
- package/test/snapshots/pfm/generic_directives/030.snap.ast +4 -6
- package/test/snapshots/pfm/generic_directives/034.snap.ast +6 -2
- package/test/snapshots/pfm/generic_directives/036.snap.ast +5 -1
- package/test/snapshots/pfm/generic_directives/038.snap.ast +6 -2
- package/test/snapshots/pfm/generic_directives/039.snap.ast +3 -1
- package/test/snapshots/pfm/generic_directives/040.snap.ast +3 -1
- package/test/snapshots/pfm/generic_directives/044.snap.ast +3 -1
- package/test/snapshots/pfm/generic_directives/046.snap.ast +3 -1
- package/test/snapshots/pfm/generic_directives/089.snap.ast +1 -1
- package/test/snapshots/pfm/generic_directives/103.snap.ast +6 -2
- package/test/snapshots/pfm/generic_directives/106.snap.ast +9 -0
- package/test/snapshots/pfm/generic_directives/107.snap.ast +9 -0
- package/test/snapshots/pfm/generic_directives/108.snap.ast +5 -0
- package/test/snapshots/pfm/generic_directives/109.snap.ast +4 -0
- package/test/snapshots/pfm/generic_directives/110.snap.ast +10 -0
- package/test/snapshots/pfm/generic_directives/111.snap.ast +7 -0
- package/test/snapshots/pfm/generic_directives/112.snap.ast +18 -0
- package/test/snapshots/pfm/generic_directives/113.snap.ast +7 -0
- package/test/snapshots/pfm/generic_directives/114.snap.ast +12 -0
- package/test/snapshots/pfm/generic_directives/115.snap.ast +10 -0
- package/test/snapshots/pfm/generic_directives/116.snap.ast +13 -0
- package/test/snapshots/pfm/generic_directives/117.snap.ast +9 -0
- package/test/snapshots/pfm/generic_directives/118.snap.ast +10 -0
- package/test/snapshots/pfm/generic_directives/119.snap.ast +9 -0
- package/test/snapshots/pfm/generic_directives/120.snap.ast +12 -0
- package/test/snapshots/pfm/generic_directives/121.snap.ast +3 -0
- package/test/snapshots/pfm/generic_directives/122.snap.ast +3 -0
- package/test/snapshots/pfm/generic_directives/123.snap.ast +3 -0
- package/test/snapshots/pfm/hard_line_breaks/642.snap.ast +1 -1
- package/test/snapshots/pfm/hard_line_breaks/643.snap.ast +1 -1
- package/test/snapshots/pfm/html/148.snap.ast +1 -1
- package/test/snapshots/pfm/html/150.snap.ast +1 -1
- package/test/snapshots/pfm/html/159.snap.ast +2 -3
- package/test/snapshots/pfm/html/162.snap.ast +3 -4
- package/test/snapshots/pfm/html/163.snap.ast +1 -1
- package/test/snapshots/pfm/html/164.snap.ast +3 -4
- package/test/snapshots/pfm/html/166.snap.ast +1 -1
- package/test/snapshots/pfm/html/168.snap.ast +2 -3
- package/test/snapshots/pfm/html/169.snap.ast +5 -7
- package/test/snapshots/pfm/html/174.snap.ast +3 -3
- package/test/snapshots/pfm/html/182.snap.ast +1 -1
- package/test/snapshots/pfm/html/613.snap.ast +2 -2
- package/test/snapshots/pfm/html/615.snap.ast +2 -2
- package/test/snapshots/pfm/images/585.snap.ast +1 -1
- package/test/snapshots/pfm/images/589.snap.ast +1 -1
- package/test/snapshots/pfm/link_reference_definitions/201.snap.ast +1 -1
- package/test/snapshots/pfm/link_reference_definitions/208.snap.ast +1 -1
- package/test/snapshots/pfm/links/491.snap.ast +1 -1
- package/test/snapshots/pfm/links/494.snap.ast +2 -2
- package/test/snapshots/pfm/links/516.snap.ast +8 -9
- package/test/snapshots/pfm/links/521.snap.ast +1 -1
- package/test/snapshots/pfm/links/530.snap.ast +8 -12
- package/test/snapshots/pfm/links/534.snap.ast +1 -1
- package/test/snapshots/pfm/links/552.snap.ast +2 -2
- package/test/snapshots/pfm/links/559.snap.ast +1 -1
- package/test/snapshots/pfm/links/564.snap.ast +1 -1
- package/test/snapshots/pfm/list_items/260.snap.ast +3 -4
- package/test/snapshots/pfm/list_items/293.snap.ast +2 -2
- package/test/snapshots/pfm/tabs/16.snap.ast +2 -3
- package/test/snapshots/pfm/tabs/4.snap.ast +6 -5
- package/test/snapshots/svelte/00-introduction/00-hello-world/App.snap.ast +3 -4
- package/test/snapshots/svelte/00-introduction/02-styling/App.snap.ast +2 -3
- package/test/snapshots/svelte/00-introduction/03-nested-components/App.snap.ast +2 -3
- package/test/snapshots/svelte/00-introduction/03-nested-components/Nested.snap.ast +1 -2
- package/test/snapshots/svelte/00-introduction/04-html-tags/App.snap.ast +1 -2
- package/test/snapshots/svelte/01-reactivity/00-reactive-assignments/App.snap.ast +5 -6
- package/test/snapshots/svelte/01-reactivity/01-reactive-declarations/App.snap.ast +11 -14
- package/test/snapshots/svelte/01-reactivity/02-reactive-statements/App.snap.ast +5 -6
- package/test/snapshots/svelte/02-props/00-declaring-props/Nested.snap.ast +2 -3
- package/test/snapshots/svelte/02-props/01-default-values/App.snap.ast +1 -1
- package/test/snapshots/svelte/02-props/01-default-values/Nested.snap.ast +2 -3
- package/test/snapshots/svelte/02-props/02-spread-props/Info.snap.ast +16 -17
- package/test/snapshots/svelte/03-logic/00-if-blocks/App.snap.ast +4 -8
- package/test/snapshots/svelte/03-logic/01-else-blocks/App.snap.ast +4 -8
- package/test/snapshots/svelte/03-logic/02-else-if-blocks/App.snap.ast +6 -9
- package/test/snapshots/svelte/03-logic/03-each-blocks/App.snap.ast +5 -8
- package/test/snapshots/svelte/03-logic/04-keyed-each-blocks/App.snap.ast +4 -7
- package/test/snapshots/svelte/03-logic/04-keyed-each-blocks/Thing.snap.ast +4 -5
- package/test/snapshots/svelte/04-events/02-event-modifiers/App.snap.ast +2 -3
- package/test/snapshots/svelte/04-events/03-component-events/Inner.snap.ast +2 -3
- package/test/snapshots/svelte/04-events/04-event-forwarding/Inner.snap.ast +2 -3
- package/test/snapshots/svelte/04-events/05-dom-event-forwarding/FancyButton.snap.ast +2 -3
- package/test/snapshots/svelte/05-bindings/00-text-inputs/App.snap.ast +3 -4
- package/test/snapshots/svelte/05-bindings/01-numeric-inputs/App.snap.ast +9 -8
- package/test/snapshots/svelte/05-bindings/02-checkbox-inputs/App.snap.ast +7 -11
- package/test/snapshots/svelte/05-bindings/03-group-inputs/App.snap.ast +21 -30
- package/test/snapshots/svelte/05-bindings/04-textarea-inputs/App.snap.ast +1 -2
- package/test/snapshots/svelte/05-bindings/05-select-bindings/App.snap.ast +5 -9
- package/test/snapshots/svelte/05-bindings/06-multiple-select-bindings/App.snap.ast +18 -26
- package/test/snapshots/svelte/05-bindings/07-each-block-bindings/App.snap.ast +7 -11
- package/test/snapshots/svelte/05-bindings/08-media-elements/App.snap.ast +15 -19
- package/test/snapshots/svelte/05-bindings/09-dimensions/App.snap.ast +7 -9
- package/test/snapshots/svelte/05-bindings/11-component-bindings/App.snap.ast +1 -2
- package/test/snapshots/svelte/05-bindings/11-component-bindings/Keypad.snap.ast +32 -34
- package/test/snapshots/svelte/06-lifecycle/00-onmount/App.snap.ast +3 -6
- package/test/snapshots/svelte/06-lifecycle/01-ondestroy/App.snap.ast +6 -7
- package/test/snapshots/svelte/06-lifecycle/02-update/App.snap.ast +2 -4
- package/test/snapshots/svelte/07-stores/00-writable-stores/App.snap.ast +4 -5
- package/test/snapshots/svelte/07-stores/00-writable-stores/Decrementer.snap.ast +2 -3
- package/test/snapshots/svelte/07-stores/00-writable-stores/Incrementer.snap.ast +2 -3
- package/test/snapshots/svelte/07-stores/00-writable-stores/Resetter.snap.ast +2 -3
- package/test/snapshots/svelte/07-stores/01-auto-subscriptions/App.snap.ast +4 -5
- package/test/snapshots/svelte/07-stores/01-auto-subscriptions/Decrementer.snap.ast +2 -3
- package/test/snapshots/svelte/07-stores/01-auto-subscriptions/Incrementer.snap.ast +2 -3
- package/test/snapshots/svelte/07-stores/01-auto-subscriptions/Resetter.snap.ast +2 -3
- package/test/snapshots/svelte/07-stores/02-readable-stores/App.snap.ast +2 -3
- package/test/snapshots/svelte/07-stores/03-derived-stores/App.snap.ast +8 -10
- package/test/snapshots/svelte/07-stores/04-custom-stores/App.snap.ast +7 -11
- package/test/snapshots/svelte/08-motion/00-tweened/App.snap.ast +10 -15
- package/test/snapshots/svelte/08-motion/01-spring/App.snap.ast +10 -10
- package/test/snapshots/svelte/09-transitions/00-transition/App.snap.ast +3 -5
- package/test/snapshots/svelte/09-transitions/01-adding-parameters-to-transitions/App.snap.ast +3 -5
- package/test/snapshots/svelte/09-transitions/02-in-and-out/App.snap.ast +3 -5
- package/test/snapshots/svelte/09-transitions/03-custom-css-transitions/App.snap.ast +4 -6
- package/test/snapshots/svelte/09-transitions/04-custom-js-transitions/App.snap.ast +3 -5
- package/test/snapshots/svelte/09-transitions/05-transition-events/App.snap.ast +5 -8
- package/test/snapshots/svelte/10-animations/00-animate/App.snap.ast +16 -20
- package/test/snapshots/svelte/11-easing/00-easing/App.snap.ast +16 -11
- package/test/snapshots/svelte/11-easing/00-easing/Controls.snap.ast +11 -16
- package/test/snapshots/svelte/11-easing/00-easing/Grid.snap.ast +2 -2
- package/test/snapshots/svelte/12-svg/01-clock/App.snap.ast +2 -1
- package/test/snapshots/svelte/12-svg/02-bar-chart/App.snap.ast +7 -9
- package/test/snapshots/svelte/12-svg/03-area-chart/App.snap.ast +14 -15
- package/test/snapshots/svelte/12-svg/04-scatterplot/App.snap.ast +7 -5
- package/test/snapshots/svelte/12-svg/04-scatterplot/Scatterplot.snap.ast +6 -6
- package/test/snapshots/svelte/12-svg/05-svg-transitions/App.snap.ast +5 -6
- package/test/snapshots/svelte/13-actions/01-adding-parameters-to-actions/App.snap.ast +2 -3
- package/test/snapshots/svelte/14-classes/00-classes/App.snap.ast +3 -6
- package/test/snapshots/svelte/14-classes/01-class-shorthand/App.snap.ast +2 -3
- package/test/snapshots/svelte/15-composition/00-slots/App.snap.ast +3 -5
- package/test/snapshots/svelte/15-composition/01-slot-fallbacks/App.snap.ast +3 -5
- package/test/snapshots/svelte/15-composition/01-slot-fallbacks/Box.snap.ast +1 -2
- package/test/snapshots/svelte/15-composition/02-named-slots/App.snap.ast +7 -11
- package/test/snapshots/svelte/15-composition/02-named-slots/ContactCard.snap.ast +3 -6
- package/test/snapshots/svelte/15-composition/03-slot-props/App.snap.ast +9 -15
- package/test/snapshots/svelte/15-composition/04-modal/App.snap.ast +17 -26
- package/test/snapshots/svelte/15-composition/04-modal/Modal.snap.ast +3 -3
- package/test/snapshots/svelte/16-context/00-context-api/App.snap.ast +10 -5
- package/test/snapshots/svelte/17-special-elements/00-svelte-self/File.snap.ast +1 -2
- package/test/snapshots/svelte/17-special-elements/00-svelte-self/Folder.snap.ast +1 -2
- package/test/snapshots/svelte/17-special-elements/01-svelte-component/App.snap.ast +1 -2
- package/test/snapshots/svelte/17-special-elements/01-svelte-component/BlueThing.snap.ast +1 -2
- package/test/snapshots/svelte/17-special-elements/01-svelte-component/GreenThing.snap.ast +1 -2
- package/test/snapshots/svelte/17-special-elements/01-svelte-component/RedThing.snap.ast +1 -2
- package/test/snapshots/svelte/17-special-elements/02-svelte-window/App.snap.ast +3 -6
- package/test/snapshots/svelte/17-special-elements/03-svelte-window-bindings/App.snap.ast +2 -4
- package/test/snapshots/svelte/17-special-elements/05-svelte-head/App.snap.ast +6 -12
- package/test/snapshots/svelte/18-module-context/01-module-exports/App.snap.ast +2 -3
- package/test/snapshots/svelte/18-module-context/01-module-exports/AudioPlayer.snap.ast +4 -7
- package/test/snapshots/svelte/19-debugging/00-debug/App.snap.ast +5 -7
- package/test/snapshots/svelte/19-debugging/00-debug/Test.snap.ast +7 -11
- package/test/snapshots/svelte/20-7guis/01-7guis-counter/App.snap.ast +2 -3
- package/test/snapshots/svelte/20-7guis/02-7guis-temperature/App.snap.ast +2 -2
- package/test/snapshots/svelte/20-7guis/03-7guis-flight-booker/App.snap.ast +4 -7
- package/test/snapshots/svelte/20-7guis/04-7guis-timer/App.snap.ast +13 -17
- package/test/snapshots/svelte/20-7guis/05-7guis-crud/App.snap.ast +11 -13
- package/test/snapshots/svelte/20-7guis/06-7guis-circles/App.snap.ast +10 -11
- package/test/snapshots/svelte/21-miscellaneous/01-hacker-news/Comment.snap.ast +4 -6
- package/test/snapshots/svelte/21-miscellaneous/01-hacker-news/Item.snap.ast +9 -13
- package/test/snapshots/svelte/21-miscellaneous/01-hacker-news/List.snap.ast +3 -5
- package/test/snapshots/svelte/21-miscellaneous/01-hacker-news/Summary.snap.ast +7 -11
- package/test/snapshots/svelte/21-miscellaneous/02-immutable-data/App.snap.ast +2 -4
- package/test/snapshots/svelte/99-embeds/20181225-blog-svelte-css-in-js/App.snap.ast +6 -7
- package/test/snapshots/svelte/99-embeds/20181225-blog-svelte-css-in-js/Hero.snap.ast +3 -5
- package/test/snapshots/svelte/99-embeds/20190420-blog-write-less-code/App.snap.ast +6 -7
- package/test/svelte_expressions.spec.ts +93 -4
- package/test/svelte_tags.spec.ts +27 -12
- package/test/tables.spec.ts +347 -0
- package/test/tree_builder.spec.ts +286 -1
- package/test/unclosed_delimiters.spec.ts +529 -0
- package/tsc/buf_utils.d.ts +1 -1
- package/tsc/buf_utils.js +9 -9
- package/tsc/cursor.d.ts +17 -13
- package/tsc/cursor.js +60 -43
- package/tsc/main.d.ts +362 -26
- package/tsc/main.js +8955 -4891
- package/tsc/node_view.d.ts +11 -12
- package/tsc/node_view.js +134 -102
- package/tsc/opcodes.d.ts +23 -6
- package/tsc/plugin_dispatch.d.ts +22 -8
- package/tsc/plugin_dispatch.js +292 -170
- package/tsc/tree_builder.d.ts +42 -11
- package/tsc/tree_builder.js +237 -82
- package/tsc/undo_log.d.ts +11 -1
- package/tsc/undo_log.js +54 -19
- package/tsc/utils.d.ts +77 -51
- package/tsc/utils.js +687 -344
- package/tsc/utils.spec.js +83 -9
- package/tsc/wire_emitter.js +6 -0
- package/tsc/wire_tree_builder.d.ts +4 -7
- package/tsc/wire_tree_builder.js +34 -37
- package/dist/node_view-BEh2-H86.js +0 -373
package/src/node_view.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
type NodeBuffer,
|
|
3
|
+
NodeKind,
|
|
4
|
+
kind_to_string,
|
|
5
|
+
make_meta,
|
|
6
|
+
merge_meta,
|
|
7
|
+
string_to_kind,
|
|
8
|
+
} from './utils';
|
|
9
|
+
import { type UndoLog, ATTR_DID_NOT_EXIST } from './undo_log';
|
|
3
10
|
|
|
4
11
|
const NONE = 0xffffffff;
|
|
5
12
|
|
|
@@ -37,7 +44,7 @@ export class WireTextSource implements TextSource {
|
|
|
37
44
|
this.strings = strings;
|
|
38
45
|
}
|
|
39
46
|
slice(_start: number, _end: number): string {
|
|
40
|
-
return
|
|
47
|
+
return '';
|
|
41
48
|
}
|
|
42
49
|
get_string(index: number): string | undefined {
|
|
43
50
|
return this.strings[index];
|
|
@@ -50,58 +57,139 @@ export class WireTextSource implements TextSource {
|
|
|
50
57
|
* short-lived: created before handler invocation, cleared after.
|
|
51
58
|
*/
|
|
52
59
|
export class ViewCache {
|
|
53
|
-
|
|
60
|
+
// most dispatches only view the handler node, so the map waits for a second view
|
|
61
|
+
private first: NodeView | null = null;
|
|
62
|
+
private views: Map<number, NodeView> | null = null;
|
|
54
63
|
private buf: NodeBuffer;
|
|
55
64
|
private text_source: TextSource;
|
|
56
65
|
private undo: UndoLog;
|
|
57
|
-
private handler_node: number;
|
|
58
66
|
|
|
59
|
-
constructor(
|
|
60
|
-
buf: NodeBuffer,
|
|
61
|
-
text_source: TextSource,
|
|
62
|
-
undo: UndoLog,
|
|
63
|
-
handler_node: number,
|
|
64
|
-
) {
|
|
67
|
+
constructor(buf: NodeBuffer, text_source: TextSource, undo: UndoLog) {
|
|
65
68
|
this.buf = buf;
|
|
66
69
|
this.text_source = text_source;
|
|
67
70
|
this.undo = undo;
|
|
68
|
-
this.handler_node = handler_node;
|
|
69
71
|
}
|
|
70
72
|
|
|
71
73
|
/** get or create a NodeView for the given buffer index. */
|
|
72
74
|
get(index: number): NodeView | null {
|
|
73
75
|
if (index === NONE) return null;
|
|
74
|
-
|
|
76
|
+
const first = this.first;
|
|
77
|
+
if (first === null) {
|
|
78
|
+
return (this.first = this.make(index));
|
|
79
|
+
}
|
|
80
|
+
if (first._index === index) return first;
|
|
81
|
+
let views = this.views;
|
|
82
|
+
if (views === null) views = this.views = new Map();
|
|
83
|
+
let view = views.get(index);
|
|
75
84
|
if (view === undefined) {
|
|
76
|
-
view =
|
|
77
|
-
|
|
78
|
-
this.buf,
|
|
79
|
-
this.text_source,
|
|
80
|
-
this,
|
|
81
|
-
this.undo,
|
|
82
|
-
this.handler_node,
|
|
83
|
-
);
|
|
84
|
-
this.views.set(index, view);
|
|
85
|
+
view = this.make(index);
|
|
86
|
+
views.set(index, view);
|
|
85
87
|
}
|
|
86
88
|
return view;
|
|
87
89
|
}
|
|
88
90
|
|
|
91
|
+
private make(index: number): NodeView {
|
|
92
|
+
return new NodeView(index, this.buf, this.text_source, this, this.undo);
|
|
93
|
+
}
|
|
94
|
+
|
|
89
95
|
/** discard all cached views. */
|
|
90
96
|
clear(): void {
|
|
91
|
-
this.
|
|
97
|
+
this.first = null;
|
|
98
|
+
if (this.views !== null) this.views.clear();
|
|
92
99
|
}
|
|
93
100
|
|
|
94
|
-
/**
|
|
95
|
-
|
|
96
|
-
this.
|
|
101
|
+
/** views made from here on read this buffer and text source */
|
|
102
|
+
rebind(buf: NodeBuffer, text_source: TextSource): void {
|
|
103
|
+
this.buf = buf;
|
|
104
|
+
this.text_source = text_source;
|
|
97
105
|
}
|
|
98
106
|
}
|
|
99
107
|
|
|
100
108
|
/**
|
|
101
|
-
*
|
|
109
|
+
* attrs proxy target fields, symbol keyed so reflection through the traps
|
|
110
|
+
* never meets them, one handler serves every proxy
|
|
111
|
+
*/
|
|
112
|
+
const BUF: unique symbol = Symbol('buf');
|
|
113
|
+
const IDX: unique symbol = Symbol('idx');
|
|
114
|
+
const UNDO: unique symbol = Symbol('undo');
|
|
115
|
+
|
|
116
|
+
class AttrsTarget {
|
|
117
|
+
[BUF]: NodeBuffer;
|
|
118
|
+
[IDX]: number;
|
|
119
|
+
[UNDO]: UndoLog;
|
|
120
|
+
|
|
121
|
+
constructor(buf: NodeBuffer, idx: number, undo: UndoLog) {
|
|
122
|
+
this[BUF] = buf;
|
|
123
|
+
this[IDX] = idx;
|
|
124
|
+
this[UNDO] = undo;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const ATTRS_HANDLER: ProxyHandler<AttrsTarget> = {
|
|
129
|
+
get(target, prop: string): any {
|
|
130
|
+
const meta = target[BUF].metadata_at(target[IDX]);
|
|
131
|
+
return meta ? meta[prop] : undefined;
|
|
132
|
+
},
|
|
133
|
+
|
|
134
|
+
set(target, prop: string, value: any): boolean {
|
|
135
|
+
const buf = target[BUF];
|
|
136
|
+
const idx = target[IDX];
|
|
137
|
+
const meta = buf.metadata_at(idx);
|
|
138
|
+
const undo = target[UNDO];
|
|
139
|
+
if (undo.recording) {
|
|
140
|
+
const prior = meta && prop in meta ? meta[prop] : ATTR_DID_NOT_EXIST;
|
|
141
|
+
undo.record_attr_set(idx, prop, prior);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (meta) {
|
|
145
|
+
merge_meta(meta, prop, value);
|
|
146
|
+
} else {
|
|
147
|
+
buf.set_metadata(idx, make_meta(prop, value));
|
|
148
|
+
}
|
|
149
|
+
return true;
|
|
150
|
+
},
|
|
151
|
+
|
|
152
|
+
deleteProperty(target, prop: string): boolean {
|
|
153
|
+
const buf = target[BUF];
|
|
154
|
+
const idx = target[IDX];
|
|
155
|
+
const meta = buf.metadata_at(idx);
|
|
156
|
+
if (!meta || !(prop in meta)) return true;
|
|
157
|
+
|
|
158
|
+
const prior = meta[prop];
|
|
159
|
+
target[UNDO].record_attr_delete(idx, prop, prior);
|
|
160
|
+
delete meta[prop];
|
|
161
|
+
buf.set_metadata(idx, meta);
|
|
162
|
+
return true;
|
|
163
|
+
},
|
|
164
|
+
|
|
165
|
+
has(target, prop: string): boolean {
|
|
166
|
+
const meta = target[BUF].metadata_at(target[IDX]);
|
|
167
|
+
return meta ? prop in meta : false;
|
|
168
|
+
},
|
|
169
|
+
|
|
170
|
+
ownKeys(target): string[] {
|
|
171
|
+
const meta = target[BUF].metadata_at(target[IDX]);
|
|
172
|
+
return meta ? Object.keys(meta) : [];
|
|
173
|
+
},
|
|
174
|
+
|
|
175
|
+
getOwnPropertyDescriptor(target, prop: string) {
|
|
176
|
+
const meta = target[BUF].metadata_at(target[IDX]);
|
|
177
|
+
if (meta && prop in meta) {
|
|
178
|
+
return {
|
|
179
|
+
configurable: true,
|
|
180
|
+
enumerable: true,
|
|
181
|
+
value: meta[prop],
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
return undefined;
|
|
185
|
+
},
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* a view over a single node in the NodeBuffer.
|
|
102
190
|
*
|
|
103
191
|
* reads are getters that look up the current state of the node
|
|
104
|
-
* in the
|
|
192
|
+
* in the buffer. writes are setters that update the backing store
|
|
105
193
|
* and record in the undo log for revocation.
|
|
106
194
|
*
|
|
107
195
|
* plugin handlers receive node views and interact with the tree
|
|
@@ -110,7 +198,7 @@ export class ViewCache {
|
|
|
110
198
|
export class NodeView {
|
|
111
199
|
/** @internal buffer index of this node. */
|
|
112
200
|
readonly _index: number;
|
|
113
|
-
/** @internal
|
|
201
|
+
/** @internal */
|
|
114
202
|
private _buf: NodeBuffer;
|
|
115
203
|
/** @internal text resolution strategy. */
|
|
116
204
|
private _text_source: TextSource;
|
|
@@ -118,8 +206,6 @@ export class NodeView {
|
|
|
118
206
|
private _cache: ViewCache;
|
|
119
207
|
/** @internal undo log for recording mutations. */
|
|
120
208
|
private _undo: UndoLog;
|
|
121
|
-
/** @internal which handler node's undo log to attribute mutations to. */
|
|
122
|
-
private _handler_node: number;
|
|
123
209
|
/** lazily created attrs proxy. */
|
|
124
210
|
private _attrs: Record<string, any> | null = null;
|
|
125
211
|
|
|
@@ -128,58 +214,53 @@ export class NodeView {
|
|
|
128
214
|
buf: NodeBuffer,
|
|
129
215
|
text_source: TextSource,
|
|
130
216
|
cache: ViewCache,
|
|
131
|
-
undo: UndoLog
|
|
132
|
-
handler_node: number,
|
|
217
|
+
undo: UndoLog
|
|
133
218
|
) {
|
|
134
219
|
this._index = index;
|
|
135
220
|
this._buf = buf;
|
|
136
221
|
this._text_source = text_source;
|
|
137
222
|
this._cache = cache;
|
|
138
223
|
this._undo = undo;
|
|
139
|
-
this._handler_node = handler_node;
|
|
140
224
|
}
|
|
141
225
|
|
|
142
|
-
|
|
143
226
|
get type(): string {
|
|
144
|
-
return kind_to_string(this._buf.
|
|
227
|
+
return kind_to_string(this._buf.kind_at(this._index) as NodeKind);
|
|
145
228
|
}
|
|
146
229
|
|
|
147
230
|
set type(value: string) {
|
|
148
231
|
const numeric = string_to_kind(value);
|
|
149
232
|
if (numeric === undefined) return;
|
|
150
|
-
const prior = this._buf.
|
|
233
|
+
const prior = this._buf.kind_at(this._index);
|
|
151
234
|
this._undo.record_type_change(this._index, prior);
|
|
152
|
-
this._buf.
|
|
235
|
+
this._buf.set_kind(this._index, numeric);
|
|
153
236
|
}
|
|
154
237
|
|
|
155
|
-
|
|
156
238
|
get parent(): NodeView | null {
|
|
157
|
-
return this._cache.get(this._buf.
|
|
239
|
+
return this._cache.get(this._buf.parent_at(this._index));
|
|
158
240
|
}
|
|
159
241
|
|
|
160
242
|
get first_child(): NodeView | null {
|
|
161
|
-
return this._cache.get(this._buf.
|
|
243
|
+
return this._cache.get(this._buf.first_child_at(this._index));
|
|
162
244
|
}
|
|
163
245
|
|
|
164
246
|
get last_child(): NodeView | null {
|
|
165
|
-
return this._cache.get(this._buf.
|
|
247
|
+
return this._cache.get(this._buf.last_child_at(this._index));
|
|
166
248
|
}
|
|
167
249
|
|
|
168
250
|
get next(): NodeView | null {
|
|
169
|
-
const n = this._buf.
|
|
251
|
+
const n = this._buf.next_at(this._index);
|
|
170
252
|
if (n === NONE) return null;
|
|
171
|
-
if (this._buf.
|
|
253
|
+
if (this._buf.parent_at(n) !== this._buf.parent_at(this._index))
|
|
172
254
|
return null;
|
|
173
255
|
return this._cache.get(n);
|
|
174
256
|
}
|
|
175
257
|
|
|
176
258
|
get prev(): NodeView | null {
|
|
177
|
-
const p = this._buf.
|
|
259
|
+
const p = this._buf.prev_at(this._index);
|
|
178
260
|
if (p === NONE) return null;
|
|
179
261
|
return this._cache.get(p);
|
|
180
262
|
}
|
|
181
263
|
|
|
182
|
-
|
|
183
264
|
/**
|
|
184
265
|
* flattened text of all descendants.
|
|
185
266
|
* only guaranteed complete in the close callback.
|
|
@@ -190,15 +271,15 @@ export class NodeView {
|
|
|
190
271
|
|
|
191
272
|
private _collect_text(idx: number): string {
|
|
192
273
|
const buf = this._buf;
|
|
193
|
-
const kind = buf.
|
|
274
|
+
const kind = buf.kind_at(idx) as NodeKind;
|
|
194
275
|
|
|
195
276
|
// leaf text node
|
|
196
277
|
if (kind === NodeKind.text) {
|
|
197
278
|
const s = this._text_source.get_string(idx);
|
|
198
279
|
if (s !== undefined) return s;
|
|
199
|
-
const vs = buf.
|
|
200
|
-
const ve = buf.
|
|
201
|
-
if (vs === NONE || ve === NONE || ve <= vs) return
|
|
280
|
+
const vs = buf.value_start_at(idx);
|
|
281
|
+
const ve = buf.value_end_at(idx);
|
|
282
|
+
if (vs === NONE || ve === NONE || ve <= vs) return '';
|
|
202
283
|
return this._text_source.slice(vs, ve);
|
|
203
284
|
}
|
|
204
285
|
|
|
@@ -212,9 +293,9 @@ export class NodeView {
|
|
|
212
293
|
) {
|
|
213
294
|
const s = this._text_source.get_string(idx);
|
|
214
295
|
if (s !== undefined) return s;
|
|
215
|
-
const vs = buf.
|
|
216
|
-
const ve = buf.
|
|
217
|
-
if (vs === NONE || ve === NONE || ve <= vs) return
|
|
296
|
+
const vs = buf.value_start_at(idx);
|
|
297
|
+
const ve = buf.value_end_at(idx);
|
|
298
|
+
if (vs === NONE || ve === NONE || ve <= vs) return '';
|
|
218
299
|
return this._text_source.slice(vs, ve);
|
|
219
300
|
}
|
|
220
301
|
|
|
@@ -223,8 +304,8 @@ export class NodeView {
|
|
|
223
304
|
if (kind === NodeKind.heading) {
|
|
224
305
|
const s = this._text_source.get_string(idx);
|
|
225
306
|
if (s !== undefined) return s;
|
|
226
|
-
const vs = buf.
|
|
227
|
-
const ve = buf.
|
|
307
|
+
const vs = buf.value_start_at(idx);
|
|
308
|
+
const ve = buf.value_end_at(idx);
|
|
228
309
|
if (vs !== NONE && ve !== NONE && ve > vs) {
|
|
229
310
|
return this._text_source.slice(vs, ve);
|
|
230
311
|
}
|
|
@@ -232,25 +313,24 @@ export class NodeView {
|
|
|
232
313
|
}
|
|
233
314
|
|
|
234
315
|
// container node: walk children, concatenate
|
|
235
|
-
let result =
|
|
236
|
-
let child = buf.
|
|
237
|
-
while (child !== NONE && buf.
|
|
316
|
+
let result = '';
|
|
317
|
+
let child = buf.first_child_at(idx);
|
|
318
|
+
while (child !== NONE && buf.parent_at(child) === idx) {
|
|
238
319
|
result += this._collect_text(child);
|
|
239
|
-
child = buf.
|
|
320
|
+
child = buf.next_at(child);
|
|
240
321
|
}
|
|
241
322
|
return result;
|
|
242
323
|
}
|
|
243
324
|
|
|
244
|
-
|
|
245
325
|
/** heading depth (1-6). only meaningful when type === 'heading'. */
|
|
246
326
|
get depth(): number | undefined {
|
|
247
|
-
if (this._buf.
|
|
248
|
-
return this._buf.
|
|
327
|
+
if (this._buf.kind_at(this._index) !== NodeKind.heading) return undefined;
|
|
328
|
+
return this._buf.extra_at(this._index);
|
|
249
329
|
}
|
|
250
330
|
|
|
251
331
|
/** code block language/info string. */
|
|
252
332
|
get lang(): string | undefined {
|
|
253
|
-
const kind = this._buf.
|
|
333
|
+
const kind = this._buf.kind_at(this._index);
|
|
254
334
|
if (kind !== NodeKind.code_fence) return undefined;
|
|
255
335
|
const meta = this._buf.metadata_at(this._index);
|
|
256
336
|
if (!meta) return undefined;
|
|
@@ -291,72 +371,14 @@ export class NodeView {
|
|
|
291
371
|
return meta?.tight as boolean | undefined;
|
|
292
372
|
}
|
|
293
373
|
|
|
294
|
-
|
|
295
374
|
get attrs(): Record<string, any> {
|
|
296
375
|
if (this._attrs !== null) return this._attrs;
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
this._attrs = new Proxy({} as Record<string, any>, {
|
|
303
|
-
get(_target, prop: string): any {
|
|
304
|
-
const meta = buf.metadata_at(idx);
|
|
305
|
-
return meta ? meta[prop] : undefined;
|
|
306
|
-
},
|
|
307
|
-
|
|
308
|
-
set(_target, prop: string, value: any): boolean {
|
|
309
|
-
const meta = buf.metadata_at(idx);
|
|
310
|
-
const prior =
|
|
311
|
-
meta && prop in meta ? meta[prop] : ATTR_DID_NOT_EXIST;
|
|
312
|
-
undo.record_attr_set(idx, prop, prior);
|
|
313
|
-
|
|
314
|
-
if (meta) {
|
|
315
|
-
meta[prop] = value;
|
|
316
|
-
buf.set_metadata(idx, meta);
|
|
317
|
-
} else {
|
|
318
|
-
buf.set_metadata(idx, { [prop]: value });
|
|
319
|
-
}
|
|
320
|
-
return true;
|
|
321
|
-
},
|
|
322
|
-
|
|
323
|
-
deleteProperty(_target, prop: string): boolean {
|
|
324
|
-
const meta = buf.metadata_at(idx);
|
|
325
|
-
if (!meta || !(prop in meta)) return true;
|
|
326
|
-
|
|
327
|
-
const prior = meta[prop];
|
|
328
|
-
undo.record_attr_delete(idx, prop, prior);
|
|
329
|
-
delete meta[prop];
|
|
330
|
-
buf.set_metadata(idx, meta);
|
|
331
|
-
return true;
|
|
332
|
-
},
|
|
333
|
-
|
|
334
|
-
has(_target, prop: string): boolean {
|
|
335
|
-
const meta = buf.metadata_at(idx);
|
|
336
|
-
return meta ? prop in meta : false;
|
|
337
|
-
},
|
|
338
|
-
|
|
339
|
-
ownKeys(): string[] {
|
|
340
|
-
const meta = buf.metadata_at(idx);
|
|
341
|
-
return meta ? Object.keys(meta) : [];
|
|
342
|
-
},
|
|
343
|
-
|
|
344
|
-
getOwnPropertyDescriptor(_target, prop: string) {
|
|
345
|
-
const meta = buf.metadata_at(idx);
|
|
346
|
-
if (meta && prop in meta) {
|
|
347
|
-
return {
|
|
348
|
-
configurable: true,
|
|
349
|
-
enumerable: true,
|
|
350
|
-
value: meta[prop],
|
|
351
|
-
};
|
|
352
|
-
}
|
|
353
|
-
return undefined;
|
|
354
|
-
},
|
|
355
|
-
});
|
|
356
|
-
return this._attrs;
|
|
376
|
+
return (this._attrs = new Proxy(
|
|
377
|
+
new AttrsTarget(this._buf, this._index, this._undo) as any,
|
|
378
|
+
ATTRS_HANDLER
|
|
379
|
+
));
|
|
357
380
|
}
|
|
358
381
|
|
|
359
|
-
|
|
360
382
|
/**
|
|
361
383
|
* insert a new node between this node and its current children.
|
|
362
384
|
* all current children become children of the new wrapper.
|
|
@@ -364,15 +386,14 @@ export class NodeView {
|
|
|
364
386
|
*/
|
|
365
387
|
wrap_inner(type: string, attrs?: Record<string, any>): NodeView {
|
|
366
388
|
const kind_num = string_to_kind(type);
|
|
367
|
-
if (kind_num === undefined)
|
|
368
|
-
throw new Error(`Unknown node type: ${type}`);
|
|
389
|
+
if (kind_num === undefined) throw new Error(`Unknown node type: ${type}`);
|
|
369
390
|
|
|
370
391
|
const buf = this._buf;
|
|
371
392
|
const idx = this._index;
|
|
372
393
|
|
|
373
394
|
// capture prior state
|
|
374
|
-
const prior_first_child = buf.
|
|
375
|
-
const prior_last_child = buf.
|
|
395
|
+
const prior_first_child = buf.first_child_at(idx);
|
|
396
|
+
const prior_last_child = buf.last_child_at(idx);
|
|
376
397
|
|
|
377
398
|
// wrap_children does the atomic operation
|
|
378
399
|
const wrapper_idx = buf.wrap_children(idx, kind_num, 0, attrs);
|
|
@@ -382,7 +403,7 @@ export class NodeView {
|
|
|
382
403
|
idx,
|
|
383
404
|
wrapper_idx,
|
|
384
405
|
prior_first_child,
|
|
385
|
-
prior_last_child
|
|
406
|
+
prior_last_child
|
|
386
407
|
);
|
|
387
408
|
|
|
388
409
|
return this._cache.get(wrapper_idx)!;
|
|
@@ -394,12 +415,11 @@ export class NodeView {
|
|
|
394
415
|
*/
|
|
395
416
|
prepend(type: string, attrs?: Record<string, any>): NodeView {
|
|
396
417
|
const kind_num = string_to_kind(type);
|
|
397
|
-
if (kind_num === undefined)
|
|
398
|
-
throw new Error(`Unknown node type: ${type}`);
|
|
418
|
+
if (kind_num === undefined) throw new Error(`Unknown node type: ${type}`);
|
|
399
419
|
|
|
400
420
|
const buf = this._buf;
|
|
401
421
|
const idx = this._index;
|
|
402
|
-
const prior_first_child = buf.
|
|
422
|
+
const prior_first_child = buf.first_child_at(idx);
|
|
403
423
|
|
|
404
424
|
if (prior_first_child === NONE) {
|
|
405
425
|
// no existing children: push is equivalent to prepend
|
|
@@ -410,10 +430,10 @@ export class NodeView {
|
|
|
410
430
|
|
|
411
431
|
// allocate unlinked and manually wire as first child
|
|
412
432
|
const new_idx = buf.push_unlinked(kind_num, 0, 0, attrs);
|
|
413
|
-
buf.
|
|
414
|
-
buf.
|
|
415
|
-
buf.
|
|
416
|
-
buf.
|
|
433
|
+
buf.set_parent(new_idx, idx);
|
|
434
|
+
buf.set_next(new_idx, prior_first_child);
|
|
435
|
+
buf.set_prev(prior_first_child, new_idx);
|
|
436
|
+
buf.set_first_child(idx, new_idx);
|
|
417
437
|
|
|
418
438
|
this._undo.record_prepend(idx, new_idx, prior_first_child);
|
|
419
439
|
return this._cache.get(new_idx)!;
|
|
@@ -425,12 +445,11 @@ export class NodeView {
|
|
|
425
445
|
*/
|
|
426
446
|
append(type: string, attrs?: Record<string, any>): NodeView {
|
|
427
447
|
const kind_num = string_to_kind(type);
|
|
428
|
-
if (kind_num === undefined)
|
|
429
|
-
throw new Error(`Unknown node type: ${type}`);
|
|
448
|
+
if (kind_num === undefined) throw new Error(`Unknown node type: ${type}`);
|
|
430
449
|
|
|
431
450
|
const buf = this._buf;
|
|
432
451
|
const idx = this._index;
|
|
433
|
-
const prior_last_child = buf.
|
|
452
|
+
const prior_last_child = buf.last_child_at(idx);
|
|
434
453
|
|
|
435
454
|
// push() already appends as last child
|
|
436
455
|
const new_idx = buf.push(kind_num, 0, idx, 0, attrs);
|
package/src/opcodes.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { NodeKind } from
|
|
1
|
+
import type { NodeKind } from './utils';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* emitter interface for pfm parser opcodes.
|
|
@@ -11,6 +11,9 @@ import type { NodeKind } from "./utils";
|
|
|
11
11
|
export interface Emitter {
|
|
12
12
|
/**
|
|
13
13
|
* open a new node.
|
|
14
|
+
*
|
|
15
|
+
* ids are dense from root 0, each open and each text that creates a child
|
|
16
|
+
* node takes the next id, so a builder can use ids as slot indices
|
|
14
17
|
* @param id monotonic node id (unique within this parse).
|
|
15
18
|
* @param kind node kind (heading, paragraph, emphasis, etc.).
|
|
16
19
|
* @param start source byte offset where this node starts.
|
|
@@ -24,25 +27,49 @@ export interface Emitter {
|
|
|
24
27
|
start: number,
|
|
25
28
|
parent: number,
|
|
26
29
|
extra: number,
|
|
27
|
-
pending: boolean
|
|
30
|
+
pending: boolean
|
|
28
31
|
): void;
|
|
29
32
|
|
|
30
33
|
/**
|
|
31
34
|
* close a previously opened node. implicitly commits pending nodes.
|
|
32
35
|
* @param id id of the node to close.
|
|
33
36
|
* @param end source byte offset where this node ends.
|
|
37
|
+
* @param kind kind at open, a revoke may have rewritten it since, omitting
|
|
38
|
+
* it makes the builder track revokes
|
|
34
39
|
*/
|
|
35
|
-
close(id: number, end: number): void;
|
|
40
|
+
close(id: number, end: number, kind?: NodeKind): void;
|
|
36
41
|
|
|
37
42
|
/**
|
|
38
43
|
* emit leaf text content within a node.
|
|
39
|
-
*
|
|
40
|
-
*
|
|
44
|
+
* paragraphs, emphasis, links and table cells get a child text node, which
|
|
45
|
+
* takes the next id although no open names it
|
|
46
|
+
* headings, code fences, code spans and html comments get a value range and
|
|
47
|
+
* take no id
|
|
41
48
|
* @param parent id of the parent node.
|
|
42
49
|
* @param start source byte offset of text start.
|
|
43
50
|
* @param end source byte offset of text end.
|
|
51
|
+
* @param parent_kind parent kind at open, as for close
|
|
44
52
|
*/
|
|
45
|
-
text(
|
|
53
|
+
text(
|
|
54
|
+
parent: number,
|
|
55
|
+
start: number,
|
|
56
|
+
end: number,
|
|
57
|
+
parent_kind?: NodeKind
|
|
58
|
+
): void;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* open, set_value_start, set_value_end and close of a node with no extra in
|
|
62
|
+
* one call, when it is missing the parser emits those four opcodes
|
|
63
|
+
*/
|
|
64
|
+
leaf?(
|
|
65
|
+
id: number,
|
|
66
|
+
kind: NodeKind,
|
|
67
|
+
start: number,
|
|
68
|
+
parent: number,
|
|
69
|
+
value_start: number,
|
|
70
|
+
value_end: number,
|
|
71
|
+
end: number
|
|
72
|
+
): void;
|
|
46
73
|
|
|
47
74
|
/**
|
|
48
75
|
* set or update an attribute on a node.
|
|
@@ -68,8 +95,10 @@ export interface Emitter {
|
|
|
68
95
|
* @param source_text optional raw source text for the revoked node.
|
|
69
96
|
* used for block-level revocations where the content must be
|
|
70
97
|
* reconstructed (e.g. failed html tags becoming paragraph text).
|
|
98
|
+
* @param text_start source offset of source_text, at the node start a tree
|
|
99
|
+
* that reads the source need not keep source_text
|
|
71
100
|
*/
|
|
72
|
-
revoke(id: number, source_text?: string): void;
|
|
101
|
+
revoke(id: number, source_text?: string, text_start?: number): void;
|
|
73
102
|
|
|
74
103
|
/**
|
|
75
104
|
* clear the pending flag on a node without touching its structure.
|
|
@@ -88,4 +117,7 @@ export interface Emitter {
|
|
|
88
117
|
* @param pos current byte offset in the source.
|
|
89
118
|
*/
|
|
90
119
|
cursor(pos: number): void;
|
|
120
|
+
|
|
121
|
+
/** the incremental finish emitted the last opcode, reserved storage can go */
|
|
122
|
+
end?(): void;
|
|
91
123
|
}
|