@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
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
import { NodeBuffer as a } from "./utils.js";
|
|
2
|
-
import { Cursor as
|
|
3
|
-
import { W as
|
|
4
|
-
const
|
|
5
|
-
class
|
|
6
|
-
constructor(
|
|
7
|
-
this.
|
|
8
|
-
this.id_to_index[t] = e;
|
|
9
|
-
}, this.buf = new a(s), this.id_to_index = [0], this.schema = null, this.dispatcher = i ?? null, this.dispatcher && this.dispatcher.set_text_source(new o(this.buf._strings));
|
|
1
|
+
import { NodeBuffer as a, merge_meta as u, make_meta as o } from "./utils.js";
|
|
2
|
+
import { Cursor as b } from "./cursor.js";
|
|
3
|
+
import { W as p } from "./node_view-bvM0i0-p.js";
|
|
4
|
+
const d = 4294967295;
|
|
5
|
+
class k {
|
|
6
|
+
constructor(e = 128, i) {
|
|
7
|
+
this.buf = new a(e), this.buf.own_strings(), this.id_to_index = [0], this.schema = null, this.dispatcher = i ?? null, this.dispatcher && this.dispatcher.set_text_source(new p(this.buf._strings));
|
|
10
8
|
}
|
|
11
9
|
/**
|
|
12
10
|
* apply a batch of wire opcodes to the buffer.
|
|
13
11
|
* call after each sse/websocket message.
|
|
14
12
|
*/
|
|
15
|
-
apply(
|
|
16
|
-
this.buf.ensure_capacity(this.buf.size + (
|
|
17
|
-
for (let i = 0; i <
|
|
18
|
-
const t =
|
|
13
|
+
apply(e) {
|
|
14
|
+
this.buf.ensure_capacity(this.buf.size + (e.length >> 1));
|
|
15
|
+
for (let i = 0; i < e.length; i++) {
|
|
16
|
+
const t = e[i];
|
|
19
17
|
switch (t[0]) {
|
|
20
18
|
case "S":
|
|
21
19
|
this.schema = t[1];
|
|
@@ -46,7 +44,7 @@ class m {
|
|
|
46
44
|
}
|
|
47
45
|
/** get a cursor over the current buffer state. */
|
|
48
46
|
cursor() {
|
|
49
|
-
return new
|
|
47
|
+
return new b(this.buf, "");
|
|
50
48
|
}
|
|
51
49
|
/** get the underlying NodeBuffer. */
|
|
52
50
|
get_buffer() {
|
|
@@ -57,114 +55,114 @@ class m {
|
|
|
57
55
|
this.buf = new a(128), this.id_to_index = [0], this.schema = null;
|
|
58
56
|
}
|
|
59
57
|
// internal opcode handlers
|
|
60
|
-
_open(
|
|
61
|
-
if (
|
|
58
|
+
_open(e, i, t, s, n) {
|
|
59
|
+
if (e === 0)
|
|
62
60
|
return;
|
|
63
|
-
let
|
|
64
|
-
if (this.dispatcher &&
|
|
65
|
-
const h = this.dispatcher.get_redirect(
|
|
66
|
-
h !== void 0 && (
|
|
61
|
+
let r = t === -1 ? d : this.id_to_index[t] ?? d;
|
|
62
|
+
if (this.dispatcher && r !== d) {
|
|
63
|
+
const h = this.dispatcher.get_redirect(r);
|
|
64
|
+
h !== void 0 && (r = h);
|
|
67
65
|
}
|
|
68
|
-
const
|
|
69
|
-
this.id_to_index[
|
|
66
|
+
const f = s ? this.buf.push_pending(i, 0, r, n) : this.buf.push(i, 0, r, n);
|
|
67
|
+
this.id_to_index[e] = f, this.dispatcher && this.dispatcher.has_handlers(i) && this.dispatcher.dispatch_open(f, i, this.buf);
|
|
70
68
|
}
|
|
71
|
-
_close(
|
|
72
|
-
const i = this.id_to_index[
|
|
69
|
+
_close(e) {
|
|
70
|
+
const i = this.id_to_index[e];
|
|
73
71
|
if (i === void 0)
|
|
74
72
|
return;
|
|
75
73
|
this.buf.set_end(i, 1);
|
|
76
|
-
const t = this.buf.
|
|
74
|
+
const t = this.buf.pending_at(i) === 1;
|
|
77
75
|
this.dispatcher && this.dispatcher.dispatch_close(i, this.buf);
|
|
78
|
-
const
|
|
79
|
-
if (
|
|
80
|
-
const
|
|
81
|
-
if (
|
|
82
|
-
let
|
|
83
|
-
for (;
|
|
84
|
-
const h = this.buf.
|
|
85
|
-
let
|
|
86
|
-
for (;
|
|
87
|
-
const c = this.buf.
|
|
88
|
-
this.buf.
|
|
76
|
+
const s = this.buf.kind_at(i), n = this.buf.kind_at(this.buf.parent_at(i));
|
|
77
|
+
if (s === 7 && n === 16 && this.buf.pending_at(i) === 1 || (this.buf.commit_node(i), this.dispatcher && !t && this.dispatcher.dispatch_commit(i)), s === 15) {
|
|
78
|
+
const r = this.buf.metadata_at(i);
|
|
79
|
+
if (r && r.tight) {
|
|
80
|
+
let f = this.buf.first_child_at(i);
|
|
81
|
+
for (; f !== d; ) {
|
|
82
|
+
const h = this.buf.next_at(f);
|
|
83
|
+
let _ = this.buf.first_child_at(f);
|
|
84
|
+
for (; _ !== d; ) {
|
|
85
|
+
const c = this.buf.next_at(_);
|
|
86
|
+
this.buf.kind_at(_) === 7 && this.buf.unwrap_node(_), _ = c;
|
|
89
87
|
}
|
|
90
|
-
|
|
88
|
+
f = h;
|
|
91
89
|
}
|
|
92
90
|
}
|
|
93
91
|
}
|
|
94
92
|
}
|
|
95
|
-
_text(
|
|
96
|
-
let t = this.id_to_index[
|
|
93
|
+
_text(e, i) {
|
|
94
|
+
let t = this.id_to_index[e];
|
|
97
95
|
if (t === void 0)
|
|
98
96
|
return;
|
|
99
97
|
if (this.dispatcher) {
|
|
100
98
|
const h = this.dispatcher.get_redirect(t);
|
|
101
99
|
h !== void 0 && (t = h);
|
|
102
100
|
}
|
|
103
|
-
const
|
|
104
|
-
if (
|
|
101
|
+
const s = this.buf.kind_at(t), n = this.buf._strings;
|
|
102
|
+
if (s === 5 || s === 8 || s === 26) {
|
|
105
103
|
const h = n[t];
|
|
106
104
|
n[t] = h !== void 0 ? h + i : i;
|
|
107
105
|
return;
|
|
108
106
|
}
|
|
109
|
-
if (
|
|
107
|
+
if (s === 2) {
|
|
110
108
|
const h = this.buf.metadata_at(t);
|
|
111
109
|
if (h && (h.tag === "script" || h.tag === "style")) {
|
|
112
|
-
const
|
|
113
|
-
n[t] =
|
|
110
|
+
const _ = n[t];
|
|
111
|
+
n[t] = _ !== void 0 ? _ + i : i;
|
|
114
112
|
return;
|
|
115
113
|
}
|
|
116
114
|
}
|
|
117
|
-
const
|
|
118
|
-
if (
|
|
119
|
-
const h = n[
|
|
120
|
-
n[
|
|
115
|
+
const r = this._last_text_child(t);
|
|
116
|
+
if (r !== d) {
|
|
117
|
+
const h = n[r];
|
|
118
|
+
n[r] = h !== void 0 ? h + i : i;
|
|
121
119
|
return;
|
|
122
120
|
}
|
|
123
|
-
const
|
|
124
|
-
n[
|
|
121
|
+
const f = this.buf.push(1, 0, t);
|
|
122
|
+
n[f] = i, this.buf.set_end(f, 1);
|
|
125
123
|
}
|
|
126
124
|
/**
|
|
127
125
|
* return the buffer index of the last child of `idx` if and only if that
|
|
128
126
|
* child is a text node. returns none otherwise. used by _text (coalesce)
|
|
129
127
|
* and _clear (discard in-progress text).
|
|
130
128
|
*/
|
|
131
|
-
_last_text_child(
|
|
132
|
-
let i = this.buf.
|
|
133
|
-
if (i ===
|
|
134
|
-
return
|
|
129
|
+
_last_text_child(e) {
|
|
130
|
+
let i = this.buf.first_child_at(e);
|
|
131
|
+
if (i === d)
|
|
132
|
+
return d;
|
|
135
133
|
let t = i;
|
|
136
134
|
for (; ; ) {
|
|
137
|
-
const
|
|
138
|
-
if (
|
|
135
|
+
const s = this.buf.next_at(t);
|
|
136
|
+
if (s === d || this.buf.parent_at(s) !== e)
|
|
139
137
|
break;
|
|
140
|
-
t =
|
|
138
|
+
t = s;
|
|
141
139
|
}
|
|
142
|
-
return this.buf.
|
|
140
|
+
return this.buf.kind_at(t) === 1 ? t : d;
|
|
143
141
|
}
|
|
144
|
-
_attr(
|
|
145
|
-
const
|
|
146
|
-
if (
|
|
142
|
+
_attr(e, i, t) {
|
|
143
|
+
const s = this.id_to_index[e];
|
|
144
|
+
if (s === void 0)
|
|
147
145
|
return;
|
|
148
|
-
const n = this.buf.metadata_at(
|
|
149
|
-
n ? (n
|
|
146
|
+
const n = this.buf.metadata_at(s);
|
|
147
|
+
n ? u(n, i, t) : this.buf.set_metadata(s, o(i, t));
|
|
150
148
|
}
|
|
151
|
-
_revoke(
|
|
152
|
-
const t = this.id_to_index[
|
|
149
|
+
_revoke(e, i) {
|
|
150
|
+
const t = this.id_to_index[e];
|
|
153
151
|
t !== void 0 && (this.dispatcher && this.dispatcher.dispatch_revoke(t, this.buf), this.buf.handle_repair(t, i || void 0));
|
|
154
152
|
}
|
|
155
|
-
_commit(
|
|
156
|
-
const i = this.id_to_index[
|
|
153
|
+
_commit(e) {
|
|
154
|
+
const i = this.id_to_index[e];
|
|
157
155
|
i !== void 0 && (this.buf.commit_node(i), this.dispatcher && this.dispatcher.dispatch_commit(i));
|
|
158
156
|
}
|
|
159
|
-
_clear(
|
|
160
|
-
const i = this.id_to_index[
|
|
157
|
+
_clear(e) {
|
|
158
|
+
const i = this.id_to_index[e];
|
|
161
159
|
if (i === void 0)
|
|
162
160
|
return;
|
|
163
161
|
delete this.buf._strings[i];
|
|
164
162
|
const t = this._last_text_child(i);
|
|
165
|
-
t !==
|
|
163
|
+
t !== d && (delete this.buf._strings[t], this.buf.unwrap_node(t));
|
|
166
164
|
}
|
|
167
165
|
}
|
|
168
166
|
export {
|
|
169
|
-
|
|
167
|
+
k as WireTreeBuilder
|
|
170
168
|
};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* WireTreeBuilder, populates a NodeBuffer from wire format batches.
|
|
3
3
|
*
|
|
4
4
|
* client-side counterpart to TreeBuilder. consumes the same json
|
|
5
|
-
* opcode batches that WireEmitter produces and builds the same
|
|
5
|
+
* opcode batches that WireEmitter produces and builds the same
|
|
6
6
|
* NodeBuffer structure. the resulting buffer is walkable by Cursor
|
|
7
7
|
* with identical semantics.
|
|
8
8
|
*
|
|
@@ -16,11 +16,10 @@
|
|
|
16
16
|
* const cursor = builder.cursor(); // reusable cursor over the buffer
|
|
17
17
|
* const html = renderCursor(cursor);
|
|
18
18
|
*/
|
|
19
|
-
import { NodeBuffer } from
|
|
20
|
-
import { Cursor } from
|
|
21
|
-
import type { PluginDispatcher } from
|
|
19
|
+
import { NodeBuffer } from './utils';
|
|
20
|
+
import { Cursor } from './cursor';
|
|
21
|
+
import type { PluginDispatcher } from './plugin_dispatch';
|
|
22
22
|
export declare class WireTreeBuilder {
|
|
23
|
-
/** the soa buffer. */
|
|
24
23
|
private buf;
|
|
25
24
|
/** maps wire node id -> buffer index. */
|
|
26
25
|
private id_to_index;
|
|
@@ -28,8 +27,6 @@ export declare class WireTreeBuilder {
|
|
|
28
27
|
private schema;
|
|
29
28
|
/** optional plugin dispatcher. null when no plugins registered. */
|
|
30
29
|
private dispatcher;
|
|
31
|
-
/** callback for dispatcher to register synthetic node ids. */
|
|
32
|
-
private register_id;
|
|
33
30
|
constructor(capacity?: number, dispatcher?: PluginDispatcher);
|
|
34
31
|
/**
|
|
35
32
|
* apply a batch of wire opcodes to the buffer.
|
package/package.json
CHANGED
package/src/buf_utils.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* buffer utilities for svelte components.
|
|
3
3
|
*
|
|
4
|
-
* pure functions that read from NodeBuffer
|
|
4
|
+
* pure functions that read from NodeBuffer accessors.
|
|
5
5
|
* no cursor state, no allocations beyond the returned arrays.
|
|
6
6
|
*/
|
|
7
7
|
|
|
@@ -12,26 +12,22 @@ const NONE = 0xffffffff;
|
|
|
12
12
|
/** get child indices for a node. */
|
|
13
13
|
export function buf_children(buf: NodeBuffer, idx: number): number[] {
|
|
14
14
|
const result: number[] = [];
|
|
15
|
-
let child = buf.
|
|
15
|
+
let child = buf.first_child_at(idx);
|
|
16
16
|
while (child !== NONE) {
|
|
17
17
|
result.push(child);
|
|
18
|
-
const next = buf.
|
|
19
|
-
if (next === NONE || buf.
|
|
18
|
+
const next = buf.next_at(child);
|
|
19
|
+
if (next === NONE || buf.parent_at(next) !== idx) break;
|
|
20
20
|
child = next;
|
|
21
21
|
}
|
|
22
22
|
return result;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
/** get text content for a node (value range or pre-materialized string). */
|
|
26
|
-
export function buf_text(
|
|
27
|
-
buf: NodeBuffer,
|
|
28
|
-
idx: number,
|
|
29
|
-
source: string
|
|
30
|
-
): string {
|
|
26
|
+
export function buf_text(buf: NodeBuffer, idx: number, source: string): string {
|
|
31
27
|
const s = buf._strings[idx];
|
|
32
28
|
if (s !== undefined) return s;
|
|
33
|
-
const vs = buf.
|
|
34
|
-
const ve = buf.
|
|
29
|
+
const vs = buf.value_start_at(idx);
|
|
30
|
+
const ve = buf.value_end_at(idx);
|
|
35
31
|
if (vs === NONE || ve === NONE || ve <= vs) return '';
|
|
36
32
|
return source.slice(vs, ve);
|
|
37
33
|
}
|
|
@@ -47,11 +43,11 @@ export function buf_text_content(
|
|
|
47
43
|
if (own) return own;
|
|
48
44
|
// Walk children
|
|
49
45
|
let text = '';
|
|
50
|
-
let child = buf.
|
|
46
|
+
let child = buf.first_child_at(idx);
|
|
51
47
|
while (child !== NONE) {
|
|
52
48
|
text += buf_text_content(buf, child, source);
|
|
53
|
-
const next = buf.
|
|
54
|
-
if (next === NONE || buf.
|
|
49
|
+
const next = buf.next_at(child);
|
|
50
|
+
if (next === NONE || buf.parent_at(next) !== idx) break;
|
|
55
51
|
child = next;
|
|
56
52
|
}
|
|
57
53
|
return text;
|
package/src/cursor.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
|
|
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
|
*
|
|
@@ -23,55 +23,37 @@
|
|
|
23
23
|
* }
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
-
import type
|
|
26
|
+
import { NodeField, type NodeBuffer } from './utils';
|
|
27
27
|
|
|
28
28
|
const NONE = 0xffffffff;
|
|
29
29
|
|
|
30
30
|
export class Cursor {
|
|
31
|
-
/** the backing soa buffer. */
|
|
32
31
|
private buf: NodeBuffer;
|
|
33
32
|
/** the full source string for lazy text slicing. */
|
|
34
33
|
private src: string;
|
|
35
34
|
/** current node index into the buffer. */
|
|
36
35
|
private idx: number;
|
|
37
|
-
|
|
38
|
-
private
|
|
39
|
-
|
|
40
|
-
private
|
|
41
|
-
private _ends: Uint32Array;
|
|
42
|
-
private _value_starts: Uint32Array;
|
|
43
|
-
private _value_ends: Uint32Array;
|
|
44
|
-
private _parents: Uint32Array;
|
|
45
|
-
private _next_siblings: Uint32Array;
|
|
46
|
-
private _children_starts: Uint32Array;
|
|
47
|
-
private _pending_nodes: Uint32Array;
|
|
36
|
+
/** idx times NodeField.stride */
|
|
37
|
+
private b: number;
|
|
38
|
+
/** cached buf._n */
|
|
39
|
+
private n: Uint32Array;
|
|
48
40
|
|
|
49
41
|
constructor(buf: NodeBuffer, source: string) {
|
|
50
42
|
this.buf = buf;
|
|
51
43
|
this.src = source;
|
|
52
44
|
this.idx = 0; // root
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
this._kinds = buf._kinds;
|
|
56
|
-
this._extras = buf._extras;
|
|
57
|
-
this._starts = buf._starts;
|
|
58
|
-
this._ends = buf._ends;
|
|
59
|
-
this._value_starts = buf._value_starts;
|
|
60
|
-
this._value_ends = buf._value_ends;
|
|
61
|
-
this._parents = buf._parents;
|
|
62
|
-
this._next_siblings = buf._next_siblings;
|
|
63
|
-
this._children_starts = buf._children_starts;
|
|
64
|
-
this._pending_nodes = buf._pending_nodes;
|
|
45
|
+
this.b = 0;
|
|
46
|
+
this.n = buf._n;
|
|
65
47
|
}
|
|
66
48
|
|
|
67
49
|
/** numeric kind of current node. */
|
|
68
50
|
get kind(): number {
|
|
69
|
-
return this.
|
|
51
|
+
return this.n[this.b] & 0xff;
|
|
70
52
|
}
|
|
71
53
|
|
|
72
54
|
/** kind-specific extra value (eg heading depth). */
|
|
73
55
|
get extra(): number {
|
|
74
|
-
return this.
|
|
56
|
+
return this.n[this.b] >>> 8;
|
|
75
57
|
}
|
|
76
58
|
|
|
77
59
|
/** current node index (for external id tracking / keyed lists). */
|
|
@@ -81,38 +63,38 @@ export class Cursor {
|
|
|
81
63
|
|
|
82
64
|
/** if the current node is closed (end offset has been set). */
|
|
83
65
|
get closed(): boolean {
|
|
84
|
-
return this.
|
|
66
|
+
return this.n[this.b + NodeField.end] !== NONE;
|
|
85
67
|
}
|
|
86
68
|
|
|
87
69
|
/** if the current node is pending (speculative, may be revoked). */
|
|
88
70
|
get pending(): boolean {
|
|
89
|
-
return this.
|
|
71
|
+
return this.n[this.b + NodeField.pending] === 1;
|
|
90
72
|
}
|
|
91
73
|
|
|
92
74
|
/** parent kind of the current node, -1 if at root. */
|
|
93
75
|
get parent_kind(): number {
|
|
94
|
-
const p = this.
|
|
95
|
-
return p === NONE ? -1 : this.
|
|
76
|
+
const p = this.n[this.b + NodeField.parent];
|
|
77
|
+
return p === NONE ? -1 : this.n[p * NodeField.stride] & 0xff;
|
|
96
78
|
}
|
|
97
79
|
|
|
98
80
|
/** byte offset where the current node starts in source. */
|
|
99
81
|
get start(): number {
|
|
100
|
-
return this.
|
|
82
|
+
return this.n[this.b + NodeField.start];
|
|
101
83
|
}
|
|
102
84
|
|
|
103
85
|
/** byte offset where the current node ends in source. */
|
|
104
86
|
get end(): number {
|
|
105
|
-
return this.
|
|
87
|
+
return this.n[this.b + NodeField.end];
|
|
106
88
|
}
|
|
107
89
|
|
|
108
90
|
/** byte offset where the current node's value content starts. */
|
|
109
91
|
get value_start(): number {
|
|
110
|
-
return this.
|
|
92
|
+
return this.n[this.b + NodeField.value_start];
|
|
111
93
|
}
|
|
112
94
|
|
|
113
95
|
/** byte offset where the current node's value content ends. */
|
|
114
96
|
get value_end(): number {
|
|
115
|
-
return this.
|
|
97
|
+
return this.n[this.b + NodeField.value_end];
|
|
116
98
|
}
|
|
117
99
|
|
|
118
100
|
/** get text content for the current node. prebuilt strings
|
|
@@ -120,15 +102,25 @@ export class Cursor {
|
|
|
120
102
|
text(): string {
|
|
121
103
|
const s = this.buf._strings[this.idx];
|
|
122
104
|
if (s !== undefined) return s;
|
|
123
|
-
const vs = this.
|
|
124
|
-
const ve = this.
|
|
125
|
-
if (vs === NONE || ve === NONE || ve <= vs) return
|
|
105
|
+
const vs = this.n[this.b + NodeField.value_start];
|
|
106
|
+
const ve = this.n[this.b + NodeField.value_end];
|
|
107
|
+
if (vs === NONE || ve === NONE || ve <= vs) return '';
|
|
126
108
|
return this.src.slice(vs, ve);
|
|
127
109
|
}
|
|
128
110
|
|
|
111
|
+
get source(): string {
|
|
112
|
+
return this.src;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** undefined when text slices the source */
|
|
116
|
+
get prebuilt(): string | undefined {
|
|
117
|
+
return this.buf._strings[this.idx];
|
|
118
|
+
}
|
|
119
|
+
|
|
129
120
|
/** get metadata for the current node, or undefined if none. */
|
|
130
121
|
meta(): Record<string, unknown> | undefined {
|
|
131
|
-
|
|
122
|
+
const slot = this.n[this.b + NodeField.meta];
|
|
123
|
+
return slot === 0 ? undefined : this.buf._meta[slot - 1];
|
|
132
124
|
}
|
|
133
125
|
|
|
134
126
|
/** slice the source string by byte offsets. for resolving metadata offset pairs. */
|
|
@@ -137,59 +129,84 @@ export class Cursor {
|
|
|
137
129
|
}
|
|
138
130
|
|
|
139
131
|
goto_first_child(): boolean {
|
|
140
|
-
const child = this.
|
|
132
|
+
const child = this.n[this.b + NodeField.first_child];
|
|
141
133
|
if (child === NONE) return false;
|
|
142
134
|
this.idx = child;
|
|
135
|
+
this.b = child * NodeField.stride;
|
|
143
136
|
return true;
|
|
144
137
|
}
|
|
145
138
|
|
|
146
139
|
goto_next_sibling(): boolean {
|
|
147
|
-
const
|
|
140
|
+
const n = this.n;
|
|
141
|
+
const next = n[this.b + NodeField.next];
|
|
148
142
|
if (next === NONE) return false;
|
|
149
143
|
// verify it's actually a sibling (same parent)
|
|
150
|
-
|
|
144
|
+
const b = next * NodeField.stride;
|
|
145
|
+
if (n[b + NodeField.parent] !== n[this.b + NodeField.parent]) return false;
|
|
151
146
|
this.idx = next;
|
|
147
|
+
this.b = b;
|
|
152
148
|
return true;
|
|
153
149
|
}
|
|
154
150
|
|
|
155
151
|
goto_parent(): boolean {
|
|
156
|
-
const parent = this.
|
|
152
|
+
const parent = this.n[this.b + NodeField.parent];
|
|
157
153
|
if (parent === NONE) return false;
|
|
158
154
|
this.idx = parent;
|
|
155
|
+
this.b = parent * NodeField.stride;
|
|
159
156
|
return true;
|
|
160
157
|
}
|
|
161
158
|
|
|
159
|
+
/** @internal */
|
|
160
|
+
get words(): Uint32Array {
|
|
161
|
+
return this.n;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** @internal undefined when text slices the source */
|
|
165
|
+
prebuilt_at(idx: number): string | undefined {
|
|
166
|
+
return this.buf._strings[idx];
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** @internal no bounds checks */
|
|
170
|
+
move_to(idx: number): void {
|
|
171
|
+
this.idx = idx;
|
|
172
|
+
this.b = idx * NodeField.stride;
|
|
173
|
+
}
|
|
174
|
+
|
|
162
175
|
reset(): void {
|
|
163
176
|
this.idx = 0;
|
|
177
|
+
this.b = 0;
|
|
164
178
|
}
|
|
165
179
|
|
|
166
180
|
/** get child indices as an array (for svelte {#each} iteration). */
|
|
167
181
|
children(): number[] {
|
|
182
|
+
const n = this.n;
|
|
168
183
|
const result: number[] = [];
|
|
169
|
-
let child =
|
|
184
|
+
let child = n[this.b + NodeField.first_child];
|
|
170
185
|
while (child !== NONE) {
|
|
171
186
|
result.push(child);
|
|
172
|
-
const next =
|
|
173
|
-
if (
|
|
187
|
+
const next = n[child * NodeField.stride + NodeField.next];
|
|
188
|
+
if (
|
|
189
|
+
next === NONE ||
|
|
190
|
+
n[next * NodeField.stride + NodeField.parent] !==
|
|
191
|
+
n[child * NodeField.stride + NodeField.parent]
|
|
192
|
+
)
|
|
193
|
+
break;
|
|
174
194
|
child = next;
|
|
175
195
|
}
|
|
176
196
|
return result;
|
|
177
197
|
}
|
|
178
198
|
|
|
199
|
+
/** a cursor kept for reuse must not pin the source */
|
|
200
|
+
release(): void {
|
|
201
|
+
this.src = '';
|
|
202
|
+
}
|
|
203
|
+
|
|
179
204
|
/** re-inits cursor with a (potentially grown) buffer and new source. */
|
|
180
205
|
reinit(buf: NodeBuffer, source: string): void {
|
|
181
206
|
this.buf = buf;
|
|
182
207
|
this.src = source;
|
|
183
208
|
this.idx = 0;
|
|
184
|
-
this.
|
|
185
|
-
this.
|
|
186
|
-
this._starts = buf._starts;
|
|
187
|
-
this._ends = buf._ends;
|
|
188
|
-
this._value_starts = buf._value_starts;
|
|
189
|
-
this._value_ends = buf._value_ends;
|
|
190
|
-
this._parents = buf._parents;
|
|
191
|
-
this._next_siblings = buf._next_siblings;
|
|
192
|
-
this._children_starts = buf._children_starts;
|
|
193
|
-
this._pending_nodes = buf._pending_nodes;
|
|
209
|
+
this.b = 0;
|
|
210
|
+
this.n = buf._n;
|
|
194
211
|
}
|
|
195
212
|
}
|