@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/utils.ts
CHANGED
|
@@ -1,6 +1,114 @@
|
|
|
1
1
|
/** default number of token entries to preallocate. */
|
|
2
2
|
const DEFAULT_TOKEN_CAPACITY = 128;
|
|
3
3
|
|
|
4
|
+
/** under 2 kb of slab, cheaper than a resize for a slightly larger document */
|
|
5
|
+
const MIN_NODE_CAPACITY = 32;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* a buffer past the carve cap is its own ArrayBuffer, far costlier than a
|
|
9
|
+
* carve, so small documents should fit the slab
|
|
10
|
+
*/
|
|
11
|
+
const SLAB_BYTES = 1048576;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* caps the tail a full slab can waste at a quarter, high since a one shot
|
|
15
|
+
* parse gives back what it does not use
|
|
16
|
+
*/
|
|
17
|
+
const SLAB_MAX_CARVE = 262144;
|
|
18
|
+
|
|
19
|
+
const EMPTY_U32 = new Uint32Array(0);
|
|
20
|
+
|
|
21
|
+
/** most documents set no metadata, the first set_metadata swaps in a real array */
|
|
22
|
+
const NO_META: any[] = Object.freeze([]) as unknown as any[];
|
|
23
|
+
|
|
24
|
+
/** push writes and the cursor reads fields together, so they share one stride */
|
|
25
|
+
export const enum NodeField {
|
|
26
|
+
/** kind in the low byte, extra in the sixteen bits above it */
|
|
27
|
+
kind = 0,
|
|
28
|
+
start = 1,
|
|
29
|
+
end = 2,
|
|
30
|
+
value_start = 3,
|
|
31
|
+
value_end = 4,
|
|
32
|
+
parent = 5,
|
|
33
|
+
next = 6,
|
|
34
|
+
prev = 7,
|
|
35
|
+
first_child = 8,
|
|
36
|
+
last_child = 9,
|
|
37
|
+
/** one while the node may still be revoked */
|
|
38
|
+
pending = 10,
|
|
39
|
+
/** one plus the slot in NodeBuffer._meta, zero without metadata */
|
|
40
|
+
meta = 11,
|
|
41
|
+
stride = 12,
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const NODE_BYTES = NodeField.stride * 4;
|
|
45
|
+
|
|
46
|
+
/** shared empty strings until own_strings, never written */
|
|
47
|
+
const NO_STRINGS: (string | undefined)[] = [];
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* uninitialized where the host allows, the template and a push write every
|
|
51
|
+
* word of a node before anything reads it
|
|
52
|
+
*/
|
|
53
|
+
const host_buffer: any = (globalThis as any).Buffer;
|
|
54
|
+
const unzeroed =
|
|
55
|
+
host_buffer !== undefined &&
|
|
56
|
+
typeof host_buffer.allocUnsafeSlow === 'function';
|
|
57
|
+
function new_storage(bytes: number): ArrayBuffer {
|
|
58
|
+
return unzeroed
|
|
59
|
+
? (host_buffer.allocUnsafeSlow(bytes).buffer as ArrayBuffer)
|
|
60
|
+
: new ArrayBuffer(bytes);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** a template copy repeats at most this many nodes, a longer source falls out of cache */
|
|
64
|
+
const TEMPLATE_BLOCK = 512;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* template slots from up to to, no end, value, links, pending or meta, so a
|
|
68
|
+
* push writes only kind, start, parent and the links it makes
|
|
69
|
+
*/
|
|
70
|
+
function fill_template(n: Uint32Array, from: number, to: number): void {
|
|
71
|
+
// a copy is a runtime call, stores beat it for the few nodes a small document has
|
|
72
|
+
const short = to - from <= 64 ? to : from + 64;
|
|
73
|
+
for (let b = from * NodeField.stride; b < short * NodeField.stride; ) {
|
|
74
|
+
n[b + NodeField.end] = 0xffffffff;
|
|
75
|
+
n[b + NodeField.value_start] = 0;
|
|
76
|
+
n[b + NodeField.value_end] = 0;
|
|
77
|
+
n[b + NodeField.next] = 0xffffffff;
|
|
78
|
+
n[b + NodeField.prev] = 0xffffffff;
|
|
79
|
+
n[b + NodeField.first_child] = 0xffffffff;
|
|
80
|
+
n[b + NodeField.last_child] = 0xffffffff;
|
|
81
|
+
n[b + NodeField.pending] = 0;
|
|
82
|
+
n[b + NodeField.meta] = 0;
|
|
83
|
+
b += NodeField.stride;
|
|
84
|
+
}
|
|
85
|
+
let done = short;
|
|
86
|
+
while (done < to) {
|
|
87
|
+
let count = done - from;
|
|
88
|
+
if (count > TEMPLATE_BLOCK) count = TEMPLATE_BLOCK;
|
|
89
|
+
if (count > to - done) count = to - done;
|
|
90
|
+
n.copyWithin(
|
|
91
|
+
done * NodeField.stride,
|
|
92
|
+
from * NodeField.stride,
|
|
93
|
+
(from + count) * NodeField.stride
|
|
94
|
+
);
|
|
95
|
+
done += count;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const SLAB_NODES = (SLAB_BYTES / NODE_BYTES) | 0;
|
|
100
|
+
|
|
101
|
+
const FILL_CHUNK = 4096;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* a carve costs one view not a backing store but keeps its whole slab alive,
|
|
105
|
+
* a slab holds the template from slab_used on, a trim returns only unwritten slots
|
|
106
|
+
*/
|
|
107
|
+
let slab = new ArrayBuffer(0);
|
|
108
|
+
let slab_used = SLAB_BYTES;
|
|
109
|
+
/** the view whose region ends at slab_used, it can grow in place or shrink */
|
|
110
|
+
let last_carve: Uint32Array | null = null;
|
|
111
|
+
|
|
4
112
|
/** default number of error entries to preallocate. */
|
|
5
113
|
const DEFAULT_ERROR_CAPACITY = 32;
|
|
6
114
|
|
|
@@ -40,6 +148,7 @@ export const enum NodeKind {
|
|
|
40
148
|
directive_container = 32,
|
|
41
149
|
frontmatter = 33,
|
|
42
150
|
import_statement = 34,
|
|
151
|
+
directive_label = 35,
|
|
43
152
|
}
|
|
44
153
|
|
|
45
154
|
/**
|
|
@@ -63,81 +172,83 @@ function next_power_of_two(value: number): number {
|
|
|
63
172
|
export const kind_to_string = (kind: NodeKind): string => {
|
|
64
173
|
switch (kind) {
|
|
65
174
|
case NodeKind.root:
|
|
66
|
-
return
|
|
175
|
+
return 'root';
|
|
67
176
|
case NodeKind.text:
|
|
68
|
-
return
|
|
177
|
+
return 'text';
|
|
69
178
|
case NodeKind.html:
|
|
70
|
-
return
|
|
179
|
+
return 'html';
|
|
71
180
|
case NodeKind.heading:
|
|
72
|
-
return
|
|
181
|
+
return 'heading';
|
|
73
182
|
case NodeKind.mustache:
|
|
74
|
-
return
|
|
183
|
+
return 'mustache';
|
|
75
184
|
case NodeKind.code_fence:
|
|
76
|
-
return
|
|
185
|
+
return 'code_fence';
|
|
77
186
|
case NodeKind.line_break:
|
|
78
|
-
return
|
|
187
|
+
return 'line_break';
|
|
79
188
|
case NodeKind.paragraph:
|
|
80
|
-
return
|
|
189
|
+
return 'paragraph';
|
|
81
190
|
case NodeKind.code_span:
|
|
82
|
-
return
|
|
191
|
+
return 'code_span';
|
|
83
192
|
case NodeKind.emphasis:
|
|
84
|
-
return
|
|
193
|
+
return 'emphasis';
|
|
85
194
|
case NodeKind.strong_emphasis:
|
|
86
|
-
return
|
|
195
|
+
return 'strong_emphasis';
|
|
87
196
|
case NodeKind.thematic_break:
|
|
88
|
-
return
|
|
197
|
+
return 'thematic_break';
|
|
89
198
|
case NodeKind.link:
|
|
90
|
-
return
|
|
199
|
+
return 'link';
|
|
91
200
|
case NodeKind.image:
|
|
92
|
-
return
|
|
201
|
+
return 'image';
|
|
93
202
|
case NodeKind.block_quote:
|
|
94
|
-
return
|
|
203
|
+
return 'block_quote';
|
|
95
204
|
case NodeKind.list:
|
|
96
|
-
return
|
|
205
|
+
return 'list';
|
|
97
206
|
case NodeKind.list_item:
|
|
98
|
-
return
|
|
207
|
+
return 'list_item';
|
|
99
208
|
case NodeKind.hard_break:
|
|
100
|
-
return
|
|
209
|
+
return 'hard_break';
|
|
101
210
|
case NodeKind.soft_break:
|
|
102
|
-
return
|
|
211
|
+
return 'soft_break';
|
|
103
212
|
case NodeKind.strikethrough:
|
|
104
|
-
return
|
|
213
|
+
return 'strikethrough';
|
|
105
214
|
case NodeKind.superscript:
|
|
106
|
-
return
|
|
215
|
+
return 'superscript';
|
|
107
216
|
case NodeKind.subscript:
|
|
108
|
-
return
|
|
217
|
+
return 'subscript';
|
|
109
218
|
case NodeKind.table:
|
|
110
|
-
return
|
|
219
|
+
return 'table';
|
|
111
220
|
case NodeKind.table_header:
|
|
112
|
-
return
|
|
221
|
+
return 'table_header';
|
|
113
222
|
case NodeKind.table_row:
|
|
114
|
-
return
|
|
223
|
+
return 'table_row';
|
|
115
224
|
case NodeKind.table_cell:
|
|
116
|
-
return
|
|
225
|
+
return 'table_cell';
|
|
117
226
|
case NodeKind.html_comment:
|
|
118
|
-
return
|
|
227
|
+
return 'html_comment';
|
|
119
228
|
case NodeKind.svelte_tag:
|
|
120
|
-
return
|
|
229
|
+
return 'svelte_tag';
|
|
121
230
|
case NodeKind.svelte_block:
|
|
122
|
-
return
|
|
231
|
+
return 'svelte_block';
|
|
123
232
|
case NodeKind.svelte_branch:
|
|
124
|
-
return
|
|
233
|
+
return 'svelte_branch';
|
|
125
234
|
case NodeKind.directive_inline:
|
|
126
|
-
return
|
|
235
|
+
return 'directive_inline';
|
|
127
236
|
case NodeKind.directive_leaf:
|
|
128
|
-
return
|
|
237
|
+
return 'directive_leaf';
|
|
129
238
|
case NodeKind.directive_container:
|
|
130
|
-
return
|
|
239
|
+
return 'directive_container';
|
|
131
240
|
case NodeKind.frontmatter:
|
|
132
|
-
return
|
|
241
|
+
return 'frontmatter';
|
|
133
242
|
case NodeKind.import_statement:
|
|
134
|
-
return
|
|
243
|
+
return 'import_statement';
|
|
244
|
+
case NodeKind.directive_label:
|
|
245
|
+
return 'directive_label';
|
|
135
246
|
}
|
|
136
247
|
};
|
|
137
248
|
|
|
138
249
|
/** reverse mapping from string name to numeric NodeKind. built once at module load. */
|
|
139
250
|
const _string_to_kind = new Map<string, NodeKind>();
|
|
140
|
-
for (let i = 0; i <=
|
|
251
|
+
for (let i = 0; i <= 35; i++) {
|
|
141
252
|
_string_to_kind.set(kind_to_string(i as NodeKind), i as NodeKind);
|
|
142
253
|
}
|
|
143
254
|
|
|
@@ -158,90 +269,226 @@ export const string_to_kind = (name: string): NodeKind | undefined => {
|
|
|
158
269
|
const extra_to_string = (kind: NodeKind): string | undefined => {
|
|
159
270
|
switch (kind) {
|
|
160
271
|
case NodeKind.heading:
|
|
161
|
-
return
|
|
272
|
+
return 'depth';
|
|
162
273
|
}
|
|
163
274
|
};
|
|
164
275
|
|
|
165
276
|
/**
|
|
166
|
-
*
|
|
277
|
+
* a computed key literal takes a slow generic define, so known keys get
|
|
278
|
+
* constant key literals and other keys a store into an empty literal
|
|
167
279
|
*/
|
|
280
|
+
export function make_meta(key: string, value: any): Record<string, any> {
|
|
281
|
+
switch (key) {
|
|
282
|
+
case 'tag':
|
|
283
|
+
return { tag: value };
|
|
284
|
+
case 'href':
|
|
285
|
+
return { href: value };
|
|
286
|
+
case 'src':
|
|
287
|
+
return { src: value };
|
|
288
|
+
case 'ordered':
|
|
289
|
+
return { ordered: value };
|
|
290
|
+
case 'info_start':
|
|
291
|
+
return { info_start: value };
|
|
292
|
+
case 'name':
|
|
293
|
+
return { name: value };
|
|
294
|
+
case 'alignments':
|
|
295
|
+
return { alignments: value };
|
|
296
|
+
case 'attributes':
|
|
297
|
+
return { attributes: value };
|
|
298
|
+
case 'self_closing':
|
|
299
|
+
return { self_closing: value };
|
|
300
|
+
case 'title':
|
|
301
|
+
return { title: value };
|
|
302
|
+
case 'start':
|
|
303
|
+
return { start: value };
|
|
304
|
+
case 'tight':
|
|
305
|
+
return { tight: value };
|
|
306
|
+
case 'info_end':
|
|
307
|
+
return { info_end: value };
|
|
308
|
+
case 'args':
|
|
309
|
+
return { args: value };
|
|
310
|
+
case 'col_count':
|
|
311
|
+
return { col_count: value };
|
|
312
|
+
default: {
|
|
313
|
+
// a set would change the prototype, a literal defines an own property
|
|
314
|
+
if (key === '__proto__') return { [key]: value };
|
|
315
|
+
const meta: Record<string, any> = {};
|
|
316
|
+
meta[key] = value;
|
|
317
|
+
return meta;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/** named stores stay monomorphic, a keyed store goes megamorphic across shapes */
|
|
323
|
+
export function merge_meta(
|
|
324
|
+
meta: Record<string, any>,
|
|
325
|
+
key: string,
|
|
326
|
+
value: any
|
|
327
|
+
): void {
|
|
328
|
+
switch (key) {
|
|
329
|
+
case 'attributes':
|
|
330
|
+
meta.attributes = value;
|
|
331
|
+
return;
|
|
332
|
+
case 'start':
|
|
333
|
+
meta.start = value;
|
|
334
|
+
return;
|
|
335
|
+
case 'tight':
|
|
336
|
+
meta.tight = value;
|
|
337
|
+
return;
|
|
338
|
+
case 'title':
|
|
339
|
+
meta.title = value;
|
|
340
|
+
return;
|
|
341
|
+
case 'self_closing':
|
|
342
|
+
meta.self_closing = value;
|
|
343
|
+
return;
|
|
344
|
+
case 'info_end':
|
|
345
|
+
meta.info_end = value;
|
|
346
|
+
return;
|
|
347
|
+
case 'col_count':
|
|
348
|
+
meta.col_count = value;
|
|
349
|
+
return;
|
|
350
|
+
case 'args':
|
|
351
|
+
meta.args = value;
|
|
352
|
+
return;
|
|
353
|
+
case 'tag':
|
|
354
|
+
meta.tag = value;
|
|
355
|
+
return;
|
|
356
|
+
case 'href':
|
|
357
|
+
meta.href = value;
|
|
358
|
+
return;
|
|
359
|
+
case 'src':
|
|
360
|
+
meta.src = value;
|
|
361
|
+
return;
|
|
362
|
+
case 'ordered':
|
|
363
|
+
meta.ordered = value;
|
|
364
|
+
return;
|
|
365
|
+
case 'info_start':
|
|
366
|
+
meta.info_start = value;
|
|
367
|
+
return;
|
|
368
|
+
case 'name':
|
|
369
|
+
meta.name = value;
|
|
370
|
+
return;
|
|
371
|
+
case 'alignments':
|
|
372
|
+
meta.alignments = value;
|
|
373
|
+
return;
|
|
374
|
+
default:
|
|
375
|
+
meta[key] = value;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
168
379
|
export class NodeBuffer {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
_kinds: Uint8Array;
|
|
172
|
-
/** @internal exposed for cursor access. do not mutate externally. */
|
|
173
|
-
_starts: Uint32Array;
|
|
380
|
+
// v8 sizes in-object slots from constructor stores, so every field is
|
|
381
|
+
// initialized here, not only in alloc, or the tail fields spill out of line
|
|
174
382
|
/** @internal */
|
|
175
|
-
|
|
383
|
+
_capacity = 0;
|
|
384
|
+
/** @internal do not mutate externally */
|
|
385
|
+
_n: Uint32Array = EMPTY_U32;
|
|
176
386
|
/** @internal */
|
|
177
|
-
|
|
178
|
-
/** @internal */
|
|
179
|
-
_value_starts: Uint32Array;
|
|
180
|
-
/** @internal */
|
|
181
|
-
_value_ends: Uint32Array;
|
|
182
|
-
private has_metadata: Uint8Array;
|
|
183
|
-
private metadata: Map<number, any>;
|
|
387
|
+
_meta: any[] = NO_META;
|
|
184
388
|
/** @internal pre-materialized text strings (used by wiretreebuilder). index -> string. */
|
|
185
|
-
_strings: (string | undefined)[];
|
|
186
|
-
/** @internal */
|
|
187
|
-
_parents: Uint32Array;
|
|
188
|
-
/** @internal */
|
|
189
|
-
_next_siblings: Uint32Array;
|
|
190
|
-
/** @internal */
|
|
191
|
-
_prev_siblings: Uint32Array;
|
|
192
|
-
/** @internal */
|
|
193
|
-
_children_starts: Uint32Array;
|
|
194
|
-
/** @internal */
|
|
195
|
-
_children_ends: Uint32Array;
|
|
196
|
-
/** @internal */
|
|
197
|
-
_pending_nodes: Uint32Array;
|
|
389
|
+
_strings: (string | undefined)[] = NO_STRINGS;
|
|
198
390
|
|
|
199
|
-
|
|
391
|
+
/** @internal read by TreeBuilder to check ids against indices */
|
|
392
|
+
_size = 0;
|
|
393
|
+
/** slots from _size up to here hold the template */
|
|
394
|
+
private _filled = 0;
|
|
200
395
|
|
|
201
|
-
/**
|
|
202
|
-
* create a buffer that stores token metadata with typed arrays.
|
|
203
|
-
* @param initial_capacity requested starting capacity for tokens.
|
|
204
|
-
*/
|
|
205
396
|
constructor(initial_capacity = DEFAULT_TOKEN_CAPACITY) {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
this.
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
this.
|
|
221
|
-
|
|
222
|
-
this._pending_nodes = new Uint32Array(capacity);
|
|
397
|
+
// the comparison also sends a nan capacity to the floor
|
|
398
|
+
let n = this.alloc(
|
|
399
|
+
next_power_of_two(
|
|
400
|
+
initial_capacity > MIN_NODE_CAPACITY
|
|
401
|
+
? initial_capacity
|
|
402
|
+
: MIN_NODE_CAPACITY
|
|
403
|
+
)
|
|
404
|
+
);
|
|
405
|
+
// the root push by hand, an inlined push_node would count against the
|
|
406
|
+
// inlining budget of every new TreeBuilder caller
|
|
407
|
+
if (this._filled === 0) n = this.fill(0);
|
|
408
|
+
n[0] = NodeKind.root;
|
|
409
|
+
n[NodeField.start] = 0;
|
|
410
|
+
n[NodeField.parent] = 0xffffffff;
|
|
411
|
+
this._size = 1;
|
|
412
|
+
}
|
|
223
413
|
|
|
224
|
-
|
|
414
|
+
private alloc(capacity: number): Uint32Array {
|
|
415
|
+
// a node is a whole number of words, so every carve stays word aligned
|
|
416
|
+
const bytes = capacity * NODE_BYTES;
|
|
417
|
+
let buffer: ArrayBuffer;
|
|
418
|
+
let base = 0;
|
|
419
|
+
if (bytes <= SLAB_MAX_CARVE) {
|
|
420
|
+
if (slab_used + bytes > SLAB_BYTES) {
|
|
421
|
+
slab = new_storage(SLAB_BYTES);
|
|
422
|
+
slab_used = 0;
|
|
423
|
+
fill_template(new Uint32Array(slab), 0, SLAB_NODES);
|
|
424
|
+
}
|
|
425
|
+
buffer = slab;
|
|
426
|
+
base = slab_used;
|
|
427
|
+
slab_used = base + bytes;
|
|
428
|
+
} else {
|
|
429
|
+
buffer = new_storage(bytes);
|
|
430
|
+
}
|
|
431
|
+
const n = new Uint32Array(buffer, base, capacity * NodeField.stride);
|
|
432
|
+
if (buffer === slab) {
|
|
433
|
+
last_carve = n;
|
|
434
|
+
this._filled = capacity;
|
|
435
|
+
} else this._filled = 0;
|
|
436
|
+
this._capacity = capacity;
|
|
437
|
+
this._n = n;
|
|
438
|
+
return n;
|
|
439
|
+
}
|
|
225
440
|
|
|
226
|
-
|
|
441
|
+
/** @internal */
|
|
442
|
+
own_strings(): (string | undefined)[] {
|
|
443
|
+
const strings = this._strings;
|
|
444
|
+
return strings === NO_STRINGS ? (this._strings = []) : strings;
|
|
227
445
|
}
|
|
228
446
|
|
|
229
|
-
/**
|
|
447
|
+
/** gives the unused tail of the last slab carve back, a later push resizes */
|
|
448
|
+
trim(): void {
|
|
449
|
+
if (this._n !== last_carve) return;
|
|
450
|
+
slab_used -= (this._capacity - this._size) * NODE_BYTES;
|
|
451
|
+
this._capacity = this._size;
|
|
452
|
+
this._filled = this._size;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/** clear nodes without reallocating storage */
|
|
230
456
|
reset(): void {
|
|
231
|
-
|
|
457
|
+
// push writes every word of a node, so stale words need no clearing
|
|
458
|
+
// a length store is a runtime call even when already empty
|
|
459
|
+
if (this._meta.length !== 0) this._meta.length = 0;
|
|
460
|
+
if (this._strings.length !== 0) this._strings.length = 0;
|
|
461
|
+
// make the pushed slots template again, copying the template above them
|
|
462
|
+
// when there is enough, one copy costs about what stores for eight nodes do
|
|
463
|
+
const size = this._size;
|
|
464
|
+
if (size !== 0) {
|
|
465
|
+
if (size > 8 && size << 1 <= this._filled) {
|
|
466
|
+
const n = this._n;
|
|
467
|
+
for (let done = 0; done < size; ) {
|
|
468
|
+
let count = size - done;
|
|
469
|
+
if (count > TEMPLATE_BLOCK) count = TEMPLATE_BLOCK;
|
|
470
|
+
n.copyWithin(
|
|
471
|
+
done * NodeField.stride,
|
|
472
|
+
size * NodeField.stride,
|
|
473
|
+
(size + count) * NodeField.stride
|
|
474
|
+
);
|
|
475
|
+
done += count;
|
|
476
|
+
}
|
|
477
|
+
} else fill_template(this._n, 0, size);
|
|
478
|
+
this._size = 0;
|
|
479
|
+
}
|
|
232
480
|
}
|
|
233
481
|
|
|
234
|
-
/** number of tokens currently stored. */
|
|
235
482
|
get size(): number {
|
|
236
483
|
return this._size;
|
|
237
484
|
}
|
|
238
485
|
|
|
239
486
|
/**
|
|
240
|
-
* push a
|
|
241
|
-
* @param kind
|
|
487
|
+
* push a node as the last child of parent
|
|
488
|
+
* @param kind node category.
|
|
242
489
|
* @param cursor cursor position
|
|
243
|
-
* @param parent index of the parent node, or
|
|
244
|
-
* @param extra extra metadata stored alongside the
|
|
490
|
+
* @param parent index of the parent node, or 0xffffffff for none.
|
|
491
|
+
* @param extra extra metadata stored alongside the node.
|
|
245
492
|
* @param metadata optional metadata associated with the node.
|
|
246
493
|
*/
|
|
247
494
|
push(
|
|
@@ -249,61 +496,138 @@ export class NodeBuffer {
|
|
|
249
496
|
cursor: number,
|
|
250
497
|
parent = 0xffffffff,
|
|
251
498
|
extra = 0,
|
|
252
|
-
metadata?: any
|
|
499
|
+
metadata?: any
|
|
253
500
|
): number {
|
|
254
|
-
const index = this.
|
|
255
|
-
if (
|
|
256
|
-
|
|
257
|
-
|
|
501
|
+
const index = this.push_node(kind, cursor, parent, extra, false);
|
|
502
|
+
if (metadata !== undefined) this.set_metadata(index, metadata);
|
|
503
|
+
return index;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
push_pending(
|
|
507
|
+
kind: NodeKind,
|
|
508
|
+
cursor: number,
|
|
509
|
+
parent = 0xffffffff,
|
|
510
|
+
extra = 0,
|
|
511
|
+
metadata?: any
|
|
512
|
+
): number {
|
|
513
|
+
const index = this.push_node(kind, cursor, parent, extra, true);
|
|
514
|
+
if (metadata !== undefined) this.set_metadata(index, metadata);
|
|
515
|
+
return index;
|
|
516
|
+
}
|
|
258
517
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
518
|
+
/** one body for every open so the builder inlines a single copy */
|
|
519
|
+
push_node(
|
|
520
|
+
kind: NodeKind,
|
|
521
|
+
cursor: number,
|
|
522
|
+
parent: number,
|
|
523
|
+
extra: number,
|
|
524
|
+
pending: boolean
|
|
525
|
+
): number {
|
|
526
|
+
const index = this._size;
|
|
527
|
+
let n = this._n;
|
|
528
|
+
if (index >= this._filled) n = this.fill(index);
|
|
529
|
+
|
|
530
|
+
// the template holds every other word
|
|
531
|
+
const b = index * NodeField.stride;
|
|
532
|
+
n[b] = (kind & 0xff) | ((extra & 0xffff) << 8);
|
|
533
|
+
n[b + NodeField.start] = cursor;
|
|
534
|
+
n[b + NodeField.parent] = parent;
|
|
535
|
+
if (pending) n[b + NodeField.pending] = 1;
|
|
263
536
|
this._size = index + 1;
|
|
264
|
-
this._parents[index] = parent;
|
|
265
|
-
this._next_siblings[index] = 0xffffffff;
|
|
266
|
-
this._prev_siblings[index] = 0xffffffff;
|
|
267
|
-
this._children_starts[index] = 0xffffffff;
|
|
268
|
-
this._children_ends[index] = 0xffffffff;
|
|
269
537
|
|
|
270
538
|
if (parent !== 0xffffffff) {
|
|
271
|
-
const
|
|
539
|
+
const p = parent * NodeField.stride;
|
|
540
|
+
const last = n[p + NodeField.last_child];
|
|
272
541
|
if (last === 0xffffffff) {
|
|
273
542
|
// first child
|
|
274
|
-
|
|
543
|
+
n[p + NodeField.first_child] = index;
|
|
275
544
|
} else {
|
|
276
545
|
// append after last child, o(1)
|
|
277
|
-
|
|
278
|
-
|
|
546
|
+
n[last * NodeField.stride + NodeField.next] = index;
|
|
547
|
+
n[b + NodeField.prev] = last;
|
|
279
548
|
}
|
|
280
|
-
|
|
549
|
+
n[p + NodeField.last_child] = index;
|
|
281
550
|
}
|
|
551
|
+
return index;
|
|
552
|
+
}
|
|
282
553
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
554
|
+
/** parent must be a node, not 0xffffffff */
|
|
555
|
+
push_text(start: number, end: number, parent: number): number {
|
|
556
|
+
const index = this._size;
|
|
557
|
+
let n = this._n;
|
|
558
|
+
if (index >= this._filled) n = this.fill(index);
|
|
559
|
+
|
|
560
|
+
const b = index * NodeField.stride;
|
|
561
|
+
n[b] = NodeKind.text;
|
|
562
|
+
n[b + NodeField.start] = start;
|
|
563
|
+
n[b + NodeField.end] = end;
|
|
564
|
+
n[b + NodeField.value_start] = start;
|
|
565
|
+
n[b + NodeField.value_end] = end;
|
|
566
|
+
n[b + NodeField.parent] = parent;
|
|
567
|
+
this._size = index + 1;
|
|
288
568
|
|
|
569
|
+
const p = parent * NodeField.stride;
|
|
570
|
+
const last = n[p + NodeField.last_child];
|
|
571
|
+
if (last === 0xffffffff) {
|
|
572
|
+
n[p + NodeField.first_child] = index;
|
|
573
|
+
} else {
|
|
574
|
+
n[last * NodeField.stride + NodeField.next] = index;
|
|
575
|
+
n[b + NodeField.prev] = last;
|
|
576
|
+
}
|
|
577
|
+
n[p + NodeField.last_child] = index;
|
|
289
578
|
return index;
|
|
290
579
|
}
|
|
291
580
|
|
|
292
|
-
|
|
581
|
+
/** a closed node with no extra and a value range, as open, value and close would leave it */
|
|
582
|
+
push_leaf(
|
|
293
583
|
kind: NodeKind,
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
584
|
+
start: number,
|
|
585
|
+
value_start: number,
|
|
586
|
+
value_end: number,
|
|
587
|
+
end: number,
|
|
588
|
+
parent: number
|
|
298
589
|
): number {
|
|
299
|
-
const index = this.
|
|
300
|
-
|
|
590
|
+
const index = this._size;
|
|
591
|
+
let n = this._n;
|
|
592
|
+
if (index >= this._filled) n = this.fill(index);
|
|
593
|
+
|
|
594
|
+
const b = index * NodeField.stride;
|
|
595
|
+
n[b] = kind;
|
|
596
|
+
n[b + NodeField.start] = start;
|
|
597
|
+
n[b + NodeField.end] = end;
|
|
598
|
+
n[b + NodeField.value_start] = value_start;
|
|
599
|
+
n[b + NodeField.value_end] = value_end;
|
|
600
|
+
n[b + NodeField.parent] = parent;
|
|
601
|
+
this._size = index + 1;
|
|
602
|
+
|
|
603
|
+
const p = parent * NodeField.stride;
|
|
604
|
+
const last = n[p + NodeField.last_child];
|
|
605
|
+
if (last === 0xffffffff) {
|
|
606
|
+
n[p + NodeField.first_child] = index;
|
|
607
|
+
} else {
|
|
608
|
+
n[last * NodeField.stride + NodeField.next] = index;
|
|
609
|
+
n[b + NodeField.prev] = last;
|
|
610
|
+
}
|
|
611
|
+
n[p + NodeField.last_child] = index;
|
|
301
612
|
return index;
|
|
302
613
|
}
|
|
303
614
|
|
|
615
|
+
private fill(index: number): Uint32Array {
|
|
616
|
+
let n = this._n;
|
|
617
|
+
if (index >= this._capacity) n = this.grow();
|
|
618
|
+
let filled = this._filled;
|
|
619
|
+
if (index >= filled) {
|
|
620
|
+
let to = filled + (filled > FILL_CHUNK ? filled : FILL_CHUNK);
|
|
621
|
+
if (to > this._capacity) to = this._capacity;
|
|
622
|
+
fill_template(n, filled, to);
|
|
623
|
+
this._filled = filled = to;
|
|
624
|
+
}
|
|
625
|
+
return n;
|
|
626
|
+
}
|
|
627
|
+
|
|
304
628
|
/**
|
|
305
629
|
* allocate a node slot without linking it into any parent's child list.
|
|
306
|
-
* the caller is responsible for setting
|
|
630
|
+
* the caller is responsible for setting the parent and linking into the
|
|
307
631
|
* sibling chain manually. used by plugin structural mutations (prepend).
|
|
308
632
|
* @param kind node kind.
|
|
309
633
|
* @param cursor source position.
|
|
@@ -315,30 +639,9 @@ export class NodeBuffer {
|
|
|
315
639
|
kind: NodeKind,
|
|
316
640
|
cursor: number,
|
|
317
641
|
extra = 0,
|
|
318
|
-
metadata?: any
|
|
642
|
+
metadata?: any
|
|
319
643
|
): number {
|
|
320
|
-
|
|
321
|
-
if (index >= this.capacity) {
|
|
322
|
-
this.grow();
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
this._kinds[index] = kind;
|
|
326
|
-
this._starts[index] = cursor >>> 0;
|
|
327
|
-
this._ends[index] = 0xffffffff;
|
|
328
|
-
this._extras[index] = extra & 0xffff;
|
|
329
|
-
this._size = index + 1;
|
|
330
|
-
this._parents[index] = 0xffffffff;
|
|
331
|
-
this._next_siblings[index] = 0xffffffff;
|
|
332
|
-
this._prev_siblings[index] = 0xffffffff;
|
|
333
|
-
this._children_starts[index] = 0xffffffff;
|
|
334
|
-
this._children_ends[index] = 0xffffffff;
|
|
335
|
-
|
|
336
|
-
if (metadata !== undefined) {
|
|
337
|
-
this.metadata.set(index, metadata);
|
|
338
|
-
this.has_metadata[index >> 3] |= 1 << (index & 7);
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
return index;
|
|
644
|
+
return this.push(kind, cursor, 0xffffffff, extra, metadata);
|
|
342
645
|
}
|
|
343
646
|
|
|
344
647
|
/**
|
|
@@ -356,28 +659,28 @@ export class NodeBuffer {
|
|
|
356
659
|
parent_idx: number,
|
|
357
660
|
new_kind: NodeKind,
|
|
358
661
|
extra = 0,
|
|
359
|
-
metadata?: any
|
|
662
|
+
metadata?: any
|
|
360
663
|
): number {
|
|
361
|
-
const first_child = this.
|
|
362
|
-
const last_child = this.
|
|
664
|
+
const first_child = this.first_child_at(parent_idx);
|
|
665
|
+
const last_child = this.last_child_at(parent_idx);
|
|
363
666
|
|
|
364
667
|
// detach children from parent
|
|
365
|
-
this.
|
|
366
|
-
this.
|
|
668
|
+
this.set_first_child(parent_idx, 0xffffffff);
|
|
669
|
+
this.set_last_child(parent_idx, 0xffffffff);
|
|
367
670
|
|
|
368
671
|
// push wrapper as sole child of parent (auto-links via push)
|
|
369
672
|
const wrapper_idx = this.push(new_kind, 0, parent_idx, extra, metadata);
|
|
370
673
|
|
|
371
674
|
// reattach old children to wrapper
|
|
372
675
|
if (first_child !== 0xffffffff) {
|
|
373
|
-
this.
|
|
374
|
-
this.
|
|
676
|
+
this.set_first_child(wrapper_idx, first_child);
|
|
677
|
+
this.set_last_child(wrapper_idx, last_child);
|
|
375
678
|
|
|
376
679
|
// update parent pointers on all moved children
|
|
377
680
|
let child = first_child;
|
|
378
|
-
while (child !== 0xffffffff && this.
|
|
379
|
-
this.
|
|
380
|
-
child = this.
|
|
681
|
+
while (child !== 0xffffffff && this.parent_at(child) === parent_idx) {
|
|
682
|
+
this.set_parent(child, wrapper_idx);
|
|
683
|
+
child = this.next_at(child);
|
|
381
684
|
}
|
|
382
685
|
}
|
|
383
686
|
|
|
@@ -385,13 +688,14 @@ export class NodeBuffer {
|
|
|
385
688
|
}
|
|
386
689
|
|
|
387
690
|
commit_node(index: number): void {
|
|
388
|
-
this.
|
|
691
|
+
this._n[index * NodeField.stride + NodeField.pending] = 0;
|
|
389
692
|
}
|
|
390
693
|
|
|
391
694
|
get_pending(): number[] {
|
|
392
695
|
const result: number[] = [];
|
|
696
|
+
const n = this._n;
|
|
393
697
|
for (let i = 0; i < this._size; i++) {
|
|
394
|
-
if (
|
|
698
|
+
if (n[i * NodeField.stride + NodeField.pending] !== 0) {
|
|
395
699
|
result.push(i);
|
|
396
700
|
}
|
|
397
701
|
}
|
|
@@ -415,18 +719,22 @@ export class NodeBuffer {
|
|
|
415
719
|
* @param delimiter_text optional pre-resolved delimiter string (wire path).
|
|
416
720
|
* if provided, stored in _strings. if absent, value range is set from
|
|
417
721
|
* the node's start position.
|
|
722
|
+
* @param text_start source offset of delimiter_text, at the node start the
|
|
723
|
+
* repaired range slices the same text so it is not stored
|
|
418
724
|
*/
|
|
419
|
-
handle_repair(
|
|
420
|
-
|
|
421
|
-
|
|
725
|
+
handle_repair(
|
|
726
|
+
index: number,
|
|
727
|
+
delimiter_text?: string,
|
|
728
|
+
text_start?: number
|
|
729
|
+
): void {
|
|
730
|
+
const parent = this.parent_at(index);
|
|
731
|
+
const kind = this.kind_at(index);
|
|
422
732
|
const parent_kind =
|
|
423
|
-
parent !== 0xffffffff ?
|
|
733
|
+
parent !== 0xffffffff ? this.kind_at(parent) : undefined;
|
|
424
734
|
|
|
425
|
-
// tight
|
|
426
|
-
// a
|
|
427
|
-
|
|
428
|
-
// the wrapper and reparents children to the list_item.
|
|
429
|
-
if (kind === NodeKind.paragraph && parent_kind === NodeKind.list_item) {
|
|
735
|
+
// a revoked paragraph is a wrapper a tight list item or a paragraph of only tags does not need
|
|
736
|
+
// a revoked table cell was a merge marker, the cell it joined spans its column
|
|
737
|
+
if (kind === NodeKind.paragraph || kind === NodeKind.table_cell) {
|
|
430
738
|
this.unwrap_node(index);
|
|
431
739
|
return;
|
|
432
740
|
}
|
|
@@ -441,7 +749,7 @@ export class NodeBuffer {
|
|
|
441
749
|
parent_kind === NodeKind.block_quote ||
|
|
442
750
|
parent_kind === NodeKind.list_item
|
|
443
751
|
) {
|
|
444
|
-
const start = this.
|
|
752
|
+
const start = this.start_at(index);
|
|
445
753
|
let end: number;
|
|
446
754
|
|
|
447
755
|
if (delimiter_text !== undefined) {
|
|
@@ -450,17 +758,17 @@ export class NodeBuffer {
|
|
|
450
758
|
} else {
|
|
451
759
|
// source path: prefer the node's recorded end; fall back to the
|
|
452
760
|
// nearest meaningful child position so we never collapse to start.
|
|
453
|
-
end = this.
|
|
761
|
+
end = this.end_at(index);
|
|
454
762
|
if (end === 0xffffffff) {
|
|
455
|
-
let child = this.
|
|
456
|
-
while (child !== 0xffffffff && this.
|
|
457
|
-
if (this.
|
|
458
|
-
const lb_start = this.
|
|
763
|
+
let child = this.first_child_at(index);
|
|
764
|
+
while (child !== 0xffffffff && this.parent_at(child) === index) {
|
|
765
|
+
if (this.kind_at(child) === NodeKind.line_break) {
|
|
766
|
+
const lb_start = this.start_at(child);
|
|
459
767
|
if (lb_start > 0 && (end === 0xffffffff || lb_start > end)) {
|
|
460
768
|
end = lb_start;
|
|
461
769
|
}
|
|
462
770
|
} else {
|
|
463
|
-
const child_end = this.
|
|
771
|
+
const child_end = this.end_at(child);
|
|
464
772
|
if (
|
|
465
773
|
child_end !== 0xffffffff &&
|
|
466
774
|
(end === 0xffffffff || child_end > end)
|
|
@@ -468,7 +776,7 @@ export class NodeBuffer {
|
|
|
468
776
|
end = child_end;
|
|
469
777
|
}
|
|
470
778
|
}
|
|
471
|
-
child = this.
|
|
779
|
+
child = this.next_at(child);
|
|
472
780
|
}
|
|
473
781
|
}
|
|
474
782
|
if (end === 0xffffffff || end <= start) {
|
|
@@ -479,48 +787,50 @@ export class NodeBuffer {
|
|
|
479
787
|
|
|
480
788
|
// reparent children to the grandparent so trailing parsed content
|
|
481
789
|
// (e.g. block elements that followed the unclosed open tag) is kept.
|
|
482
|
-
const child_chain = this.
|
|
483
|
-
this.
|
|
484
|
-
this.
|
|
790
|
+
const child_chain = this.first_child_at(index);
|
|
791
|
+
this.set_first_child(index, 0xffffffff);
|
|
792
|
+
this.set_last_child(index, 0xffffffff);
|
|
485
793
|
|
|
486
794
|
// convert this node into a paragraph holding the literal open-tag text.
|
|
487
795
|
this.set_kind(index, NodeKind.paragraph);
|
|
488
|
-
this.
|
|
489
|
-
this.
|
|
796
|
+
this.delete_metadata(index);
|
|
797
|
+
this.set_end(index, end);
|
|
490
798
|
|
|
491
799
|
const text_idx = this.push(NodeKind.text, start, index);
|
|
492
|
-
this.
|
|
493
|
-
this.
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
this._strings[text_idx] = delimiter_text;
|
|
800
|
+
this.set_value(text_idx, start, end);
|
|
801
|
+
this.set_end(text_idx, end);
|
|
802
|
+
if (delimiter_text !== undefined && text_start !== start) {
|
|
803
|
+
this.own_strings()[text_idx] = delimiter_text;
|
|
497
804
|
}
|
|
498
805
|
|
|
499
806
|
// splice the original children in after the rewritten node so they
|
|
500
807
|
// appear as siblings under the parent.
|
|
501
808
|
if (child_chain !== 0xffffffff) {
|
|
502
|
-
const original_next = this.
|
|
809
|
+
const original_next = this.next_at(index);
|
|
503
810
|
let last_child = child_chain;
|
|
504
811
|
let scan = child_chain;
|
|
505
|
-
while (scan !== 0xffffffff && this.
|
|
506
|
-
this.
|
|
812
|
+
while (scan !== 0xffffffff && this.parent_at(scan) === index) {
|
|
813
|
+
this.set_parent(scan, parent);
|
|
507
814
|
last_child = scan;
|
|
508
|
-
scan = this.
|
|
815
|
+
scan = this.next_at(scan);
|
|
509
816
|
}
|
|
510
|
-
this.
|
|
817
|
+
this.set_next(last_child, original_next);
|
|
511
818
|
if (original_next !== 0xffffffff) {
|
|
512
|
-
this.
|
|
513
|
-
} else if (
|
|
514
|
-
|
|
819
|
+
this.set_prev(original_next, last_child);
|
|
820
|
+
} else if (
|
|
821
|
+
parent !== 0xffffffff &&
|
|
822
|
+
this.last_child_at(parent) === index
|
|
823
|
+
) {
|
|
824
|
+
this.set_last_child(parent, last_child);
|
|
515
825
|
}
|
|
516
|
-
this.
|
|
517
|
-
this.
|
|
826
|
+
this.set_next(index, child_chain);
|
|
827
|
+
this.set_prev(child_chain, index);
|
|
518
828
|
}
|
|
519
829
|
return;
|
|
520
830
|
}
|
|
521
831
|
|
|
522
832
|
// inline repair
|
|
523
|
-
const first_child = this.
|
|
833
|
+
const first_child = this.first_child_at(index);
|
|
524
834
|
|
|
525
835
|
// convert the wrapper to a plain text node whose value is the
|
|
526
836
|
// literal delimiter (e.g. "~" for subscript, "<div>" for an
|
|
@@ -530,55 +840,58 @@ export class NodeBuffer {
|
|
|
530
840
|
this.set_kind(index, NodeKind.text);
|
|
531
841
|
|
|
532
842
|
if (delimiter_text !== undefined) {
|
|
533
|
-
this.
|
|
534
|
-
|
|
843
|
+
const start = this.start_at(index);
|
|
844
|
+
if (text_start !== start) this.own_strings()[index] = delimiter_text;
|
|
535
845
|
const end = start + delimiter_text.length;
|
|
536
|
-
this.
|
|
537
|
-
this.
|
|
538
|
-
this._ends[index] = end;
|
|
846
|
+
this.set_value(index, start, end);
|
|
847
|
+
this.set_end(index, end);
|
|
539
848
|
|
|
540
849
|
if (first_child === 0xffffffff) {
|
|
541
|
-
this.
|
|
542
|
-
this.
|
|
850
|
+
this.set_first_child(index, 0xffffffff);
|
|
851
|
+
this.set_last_child(index, 0xffffffff);
|
|
543
852
|
return;
|
|
544
853
|
}
|
|
545
854
|
|
|
546
855
|
// reparent children and splice them in after this text node.
|
|
547
856
|
let child = first_child;
|
|
548
857
|
let last_child = first_child;
|
|
549
|
-
while (child !== 0xffffffff && this.
|
|
550
|
-
this.
|
|
858
|
+
while (child !== 0xffffffff && this.parent_at(child) === index) {
|
|
859
|
+
this.set_parent(child, parent);
|
|
551
860
|
last_child = child;
|
|
552
|
-
child = this.
|
|
861
|
+
child = this.next_at(child);
|
|
553
862
|
}
|
|
554
|
-
const node_next = this.
|
|
555
|
-
this.
|
|
556
|
-
this.
|
|
557
|
-
if (node_next !== 0xffffffff && this.
|
|
558
|
-
this.
|
|
559
|
-
this.
|
|
863
|
+
const node_next = this.next_at(index);
|
|
864
|
+
this.set_next(index, first_child);
|
|
865
|
+
this.set_prev(first_child, index);
|
|
866
|
+
if (node_next !== 0xffffffff && this.parent_at(node_next) === parent) {
|
|
867
|
+
this.set_next(last_child, node_next);
|
|
868
|
+
this.set_prev(node_next, last_child);
|
|
560
869
|
} else {
|
|
561
|
-
this.
|
|
870
|
+
this.set_next(last_child, 0xffffffff);
|
|
562
871
|
}
|
|
563
|
-
if (this.
|
|
564
|
-
this.
|
|
872
|
+
if (this.last_child_at(parent) === index) {
|
|
873
|
+
this.set_last_child(parent, last_child);
|
|
565
874
|
}
|
|
566
|
-
this.
|
|
567
|
-
this.
|
|
875
|
+
this.set_first_child(index, 0xffffffff);
|
|
876
|
+
this.set_last_child(index, 0xffffffff);
|
|
568
877
|
return;
|
|
569
878
|
}
|
|
570
879
|
|
|
571
880
|
// source-based fallback, derive the delimiter byte range from
|
|
572
881
|
// the node's own start offset.
|
|
573
882
|
if (first_child === 0xffffffff) {
|
|
574
|
-
this.
|
|
575
|
-
this.
|
|
576
|
-
|
|
577
|
-
if (this.
|
|
578
|
-
|
|
579
|
-
|
|
883
|
+
this.set_first_child(index, 0xffffffff);
|
|
884
|
+
this.set_last_child(index, 0xffffffff);
|
|
885
|
+
const start = this.start_at(index);
|
|
886
|
+
if (this.end_at(index) === 0xffffffff) {
|
|
887
|
+
// an opener that records where its content starts ends there
|
|
888
|
+
const content_start = this.value_start_at(index);
|
|
889
|
+
const end = content_start > start ? content_start : start + 1;
|
|
890
|
+
this.set_value(index, start, end);
|
|
891
|
+
this.set_end(index, end);
|
|
580
892
|
} else {
|
|
581
|
-
this.
|
|
893
|
+
this.set_value_start(index, start);
|
|
894
|
+
this.set_value_end(index, this.end_at(index));
|
|
582
895
|
}
|
|
583
896
|
return;
|
|
584
897
|
}
|
|
@@ -587,66 +900,75 @@ export class NodeBuffer {
|
|
|
587
900
|
let child = first_child;
|
|
588
901
|
let last_child = first_child;
|
|
589
902
|
|
|
590
|
-
while (child !== 0xffffffff && this.
|
|
591
|
-
this.
|
|
903
|
+
while (child !== 0xffffffff && this.parent_at(child) === index) {
|
|
904
|
+
this.set_parent(child, parent);
|
|
592
905
|
last_child = child;
|
|
593
|
-
child = this.
|
|
906
|
+
child = this.next_at(child);
|
|
594
907
|
}
|
|
595
908
|
|
|
596
|
-
//
|
|
909
|
+
// merge a lone text child into the delimiter, a cell text ends at the pipe past its value
|
|
597
910
|
if (
|
|
598
911
|
last_child === first_child &&
|
|
599
|
-
this.
|
|
912
|
+
this.kind_at(first_child) === NodeKind.text
|
|
600
913
|
) {
|
|
601
|
-
this.
|
|
602
|
-
|
|
603
|
-
|
|
914
|
+
this.set_value(
|
|
915
|
+
index,
|
|
916
|
+
this.start_at(index),
|
|
917
|
+
this.value_end_at(first_child)
|
|
918
|
+
);
|
|
919
|
+
this.set_end(index, this.end_at(first_child));
|
|
604
920
|
|
|
605
921
|
// skip the child in the sibling chain
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
922
|
+
const after = this.next_at(first_child);
|
|
923
|
+
this.set_next(index, after);
|
|
924
|
+
if (after !== 0xffffffff) {
|
|
925
|
+
this.set_prev(after, index);
|
|
609
926
|
}
|
|
610
927
|
|
|
611
|
-
this.
|
|
612
|
-
this.
|
|
928
|
+
this.set_first_child(index, 0xffffffff);
|
|
929
|
+
this.set_last_child(index, 0xffffffff);
|
|
613
930
|
return;
|
|
614
931
|
}
|
|
615
932
|
|
|
616
933
|
// insert converted node as sibling before first_child, reparent rest
|
|
617
|
-
const first_child_prev = this.
|
|
934
|
+
const first_child_prev = this.prev_at(first_child);
|
|
618
935
|
|
|
619
|
-
this.
|
|
620
|
-
this.
|
|
936
|
+
this.set_next(index, first_child);
|
|
937
|
+
this.set_prev(first_child, index);
|
|
621
938
|
|
|
622
939
|
if (first_child_prev !== 0xffffffff) {
|
|
623
|
-
this.
|
|
624
|
-
this.
|
|
940
|
+
this.set_next(first_child_prev, index);
|
|
941
|
+
this.set_prev(index, first_child_prev);
|
|
625
942
|
}
|
|
626
943
|
|
|
627
|
-
if (this.
|
|
628
|
-
this.
|
|
944
|
+
if (this.last_child_at(parent) === index) {
|
|
945
|
+
this.set_last_child(parent, last_child);
|
|
629
946
|
}
|
|
630
947
|
|
|
631
948
|
// clear children references
|
|
632
|
-
this.
|
|
633
|
-
this.
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
949
|
+
this.set_first_child(index, 0xffffffff);
|
|
950
|
+
this.set_last_child(index, 0xffffffff);
|
|
951
|
+
|
|
952
|
+
// use start, a soft_break child has no value range
|
|
953
|
+
const value_start = this.start_at(index);
|
|
954
|
+
const value_end = this.start_at(first_child);
|
|
955
|
+
this.set_value(index, value_start, value_end);
|
|
956
|
+
this.set_end(index, value_end);
|
|
638
957
|
}
|
|
639
958
|
|
|
640
959
|
repair(): void {
|
|
641
|
-
const
|
|
642
|
-
|
|
643
|
-
|
|
960
|
+
const n = this._n;
|
|
961
|
+
for (let i = 0; i < this._size; i++) {
|
|
962
|
+
if (n[i * NodeField.stride + NodeField.pending] !== 0) {
|
|
963
|
+
this.handle_repair(i);
|
|
644
964
|
}
|
|
645
|
-
}
|
|
965
|
+
}
|
|
646
966
|
}
|
|
647
967
|
|
|
648
968
|
pop(): void {
|
|
649
|
-
this._size
|
|
969
|
+
const i = --this._size;
|
|
970
|
+
// the popped slot is the template again, as a push expects
|
|
971
|
+
fill_template(this._n, i, i + 1);
|
|
650
972
|
}
|
|
651
973
|
|
|
652
974
|
/**
|
|
@@ -655,24 +977,24 @@ export class NodeBuffer {
|
|
|
655
977
|
* in the parent's child list.
|
|
656
978
|
*/
|
|
657
979
|
unwrap_node(index: number): void {
|
|
658
|
-
const parent = this.
|
|
659
|
-
const first_child = this.
|
|
980
|
+
const parent = this.parent_at(index);
|
|
981
|
+
const first_child = this.first_child_at(index);
|
|
660
982
|
|
|
661
983
|
if (first_child === 0xffffffff) {
|
|
662
984
|
// no children, remove from sibling chain
|
|
663
|
-
const prev_sib = this.
|
|
664
|
-
const next_sib = this.
|
|
985
|
+
const prev_sib = this.prev_at(index);
|
|
986
|
+
const next_sib = this.next_at(index);
|
|
665
987
|
if (prev_sib !== 0xffffffff) {
|
|
666
|
-
this.
|
|
988
|
+
this.set_next(prev_sib, next_sib);
|
|
667
989
|
} else if (parent !== 0xffffffff) {
|
|
668
|
-
this.
|
|
990
|
+
this.set_first_child(parent, next_sib);
|
|
669
991
|
}
|
|
670
992
|
if (next_sib !== 0xffffffff) {
|
|
671
|
-
this.
|
|
993
|
+
this.set_prev(next_sib, prev_sib);
|
|
672
994
|
}
|
|
673
995
|
// update parent's last child if we removed the tail
|
|
674
|
-
if (parent !== 0xffffffff && this.
|
|
675
|
-
this.
|
|
996
|
+
if (parent !== 0xffffffff && this.last_child_at(parent) === index) {
|
|
997
|
+
this.set_last_child(parent, prev_sib); // 0xffffffff if was only child
|
|
676
998
|
}
|
|
677
999
|
return;
|
|
678
1000
|
}
|
|
@@ -680,71 +1002,63 @@ export class NodeBuffer {
|
|
|
680
1002
|
// reparent all children and find last child
|
|
681
1003
|
let child = first_child;
|
|
682
1004
|
let last_child = first_child;
|
|
683
|
-
while (child !== 0xffffffff && this.
|
|
684
|
-
this.
|
|
1005
|
+
while (child !== 0xffffffff && this.parent_at(child) === index) {
|
|
1006
|
+
this.set_parent(child, parent);
|
|
685
1007
|
last_child = child;
|
|
686
|
-
child = this.
|
|
1008
|
+
child = this.next_at(child);
|
|
687
1009
|
}
|
|
688
1010
|
|
|
689
1011
|
// splice children into parent's child list where this node was
|
|
690
|
-
const prev_sib = this.
|
|
691
|
-
const next_sib =
|
|
692
|
-
this._next_siblings[last_child] !== 0xffffffff &&
|
|
693
|
-
this._parents[this._next_siblings[last_child]] === index
|
|
694
|
-
? 0xffffffff
|
|
695
|
-
: this._next_siblings[last_child];
|
|
1012
|
+
const prev_sib = this.prev_at(index);
|
|
696
1013
|
|
|
697
1014
|
// the actual next sibling of the unwrapped node (not of last_child)
|
|
698
|
-
const node_next = this.
|
|
1015
|
+
const node_next = this.next_at(index);
|
|
699
1016
|
|
|
700
1017
|
if (prev_sib !== 0xffffffff) {
|
|
701
|
-
this.
|
|
702
|
-
this.
|
|
1018
|
+
this.set_next(prev_sib, first_child);
|
|
1019
|
+
this.set_prev(first_child, prev_sib);
|
|
703
1020
|
} else if (parent !== 0xffffffff) {
|
|
704
|
-
this.
|
|
705
|
-
this.
|
|
1021
|
+
this.set_first_child(parent, first_child);
|
|
1022
|
+
this.set_prev(first_child, 0xffffffff);
|
|
706
1023
|
}
|
|
707
1024
|
|
|
708
1025
|
// link last child to the unwrapped node's next sibling
|
|
709
1026
|
if (node_next !== 0xffffffff && node_next !== first_child) {
|
|
710
|
-
this.
|
|
711
|
-
this.
|
|
1027
|
+
this.set_next(last_child, node_next);
|
|
1028
|
+
this.set_prev(node_next, last_child);
|
|
712
1029
|
} else {
|
|
713
|
-
this.
|
|
1030
|
+
this.set_next(last_child, 0xffffffff);
|
|
714
1031
|
}
|
|
715
1032
|
|
|
716
1033
|
// update parent's last child if we replaced the tail
|
|
717
|
-
if (parent !== 0xffffffff && this.
|
|
718
|
-
this.
|
|
1034
|
+
if (parent !== 0xffffffff && this.last_child_at(parent) === index) {
|
|
1035
|
+
this.set_last_child(parent, last_child);
|
|
719
1036
|
}
|
|
720
1037
|
|
|
721
1038
|
// clear the unwrapped node's links
|
|
722
|
-
this.
|
|
723
|
-
this.
|
|
1039
|
+
this.set_first_child(index, 0xffffffff);
|
|
1040
|
+
this.set_last_child(index, 0xffffffff);
|
|
724
1041
|
}
|
|
725
1042
|
|
|
726
1043
|
set_parent_kind(index: number, kind: NodeKind): void {
|
|
727
|
-
const parent_index = this.
|
|
1044
|
+
const parent_index = this.parent_at(index);
|
|
728
1045
|
if (parent_index !== 0xffffffff) {
|
|
729
|
-
this.
|
|
1046
|
+
this.set_kind(parent_index, kind);
|
|
730
1047
|
}
|
|
731
1048
|
}
|
|
732
1049
|
|
|
733
1050
|
/** return indices of all nodes matching the given kind (lazy scan). */
|
|
734
1051
|
get_kinds(kind: NodeKind): number[] {
|
|
735
1052
|
const result: number[] = [];
|
|
1053
|
+
const n = this._n;
|
|
736
1054
|
for (let i = 0; i < this._size; i++) {
|
|
737
|
-
if (
|
|
1055
|
+
if ((n[i * NodeField.stride] & 0xff) === kind) result.push(i);
|
|
738
1056
|
}
|
|
739
1057
|
return result;
|
|
740
1058
|
}
|
|
741
1059
|
|
|
742
|
-
/**
|
|
743
|
-
* get the token kind recorded at the supplied index.
|
|
744
|
-
* @param index token index.
|
|
745
|
-
*/
|
|
746
1060
|
kind_at(index: number): NodeKind {
|
|
747
|
-
return this.
|
|
1061
|
+
return (this._n[index * NodeField.stride] & 0xff) as NodeKind;
|
|
748
1062
|
}
|
|
749
1063
|
|
|
750
1064
|
/**
|
|
@@ -753,17 +1067,13 @@ export class NodeBuffer {
|
|
|
753
1067
|
* @param kind new kind
|
|
754
1068
|
*/
|
|
755
1069
|
set_kind(index: number, kind: NodeKind): void {
|
|
756
|
-
|
|
1070
|
+
const n = this._n;
|
|
1071
|
+
const b = index * NodeField.stride;
|
|
1072
|
+
n[b] = (n[b] & 0xffff00) | (kind & 0xff);
|
|
757
1073
|
}
|
|
758
1074
|
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
this._prev_siblings[index] = value;
|
|
762
|
-
}
|
|
763
|
-
|
|
764
|
-
/** @internal set children_ends for wiretreebuilder revoke. */
|
|
765
|
-
children_ends_set(index: number, value: number): void {
|
|
766
|
-
this._children_ends[index] = value;
|
|
1075
|
+
extra_at(index: number): number {
|
|
1076
|
+
return this._n[index * NodeField.stride] >>> 8;
|
|
767
1077
|
}
|
|
768
1078
|
|
|
769
1079
|
/**
|
|
@@ -772,7 +1082,18 @@ export class NodeBuffer {
|
|
|
772
1082
|
* @param extra new extra
|
|
773
1083
|
*/
|
|
774
1084
|
set_extra(index: number, extra: number): void {
|
|
775
|
-
|
|
1085
|
+
const n = this._n;
|
|
1086
|
+
const b = index * NodeField.stride;
|
|
1087
|
+
n[b] = (n[b] & 0xff) | ((extra & 0xffff) << 8);
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
start_at(index: number): number {
|
|
1091
|
+
return this._n[index * NodeField.stride + NodeField.start];
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
/** 0xffffffff while open */
|
|
1095
|
+
end_at(index: number): number {
|
|
1096
|
+
return this._n[index * NodeField.stride + NodeField.end];
|
|
776
1097
|
}
|
|
777
1098
|
|
|
778
1099
|
/**
|
|
@@ -781,95 +1102,153 @@ export class NodeBuffer {
|
|
|
781
1102
|
* @param end new end position
|
|
782
1103
|
*/
|
|
783
1104
|
set_end(index: number, end: number): void {
|
|
784
|
-
this.
|
|
1105
|
+
this._n[index * NodeField.stride + NodeField.end] = end >>> 0;
|
|
785
1106
|
}
|
|
786
1107
|
|
|
787
1108
|
gently_set_end(index: number, end: number): void {
|
|
788
|
-
|
|
789
|
-
this.
|
|
1109
|
+
const i = index * NodeField.stride + NodeField.end;
|
|
1110
|
+
if (this._n[i] !== 0xffffffff) return;
|
|
1111
|
+
this._n[i] = end >>> 0;
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
value_start_at(index: number): number {
|
|
1115
|
+
return this._n[index * NodeField.stride + NodeField.value_start];
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
value_end_at(index: number): number {
|
|
1119
|
+
return this._n[index * NodeField.stride + NodeField.value_end];
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
set_value(index: number, value_start: number, value_end: number): void {
|
|
1123
|
+
const n = this._n;
|
|
1124
|
+
const b = index * NodeField.stride;
|
|
1125
|
+
n[b + NodeField.value_start] = value_start;
|
|
1126
|
+
n[b + NodeField.value_end] = value_end;
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
set_value_start(index: number, value_start: number): void {
|
|
1130
|
+
this._n[index * NodeField.stride + NodeField.value_start] = value_start;
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1133
|
+
set_value_end(index: number, value_end: number): void {
|
|
1134
|
+
this._n[index * NodeField.stride + NodeField.value_end] = value_end;
|
|
790
1135
|
}
|
|
791
1136
|
|
|
792
1137
|
gently_set_value_end(index: number, end: number): void {
|
|
793
|
-
|
|
794
|
-
this.
|
|
1138
|
+
const i = index * NodeField.stride + NodeField.value_end;
|
|
1139
|
+
if (this._n[i] !== 0xffffffff) return;
|
|
1140
|
+
this._n[i] = end >>> 0;
|
|
795
1141
|
}
|
|
796
1142
|
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
while (this.capacity < needed) this.grow();
|
|
1143
|
+
parent_at(index: number): number {
|
|
1144
|
+
return this._n[index * NodeField.stride + NodeField.parent];
|
|
800
1145
|
}
|
|
801
1146
|
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
const next_kinds = new Uint8Array(next);
|
|
806
|
-
const next_starts = new Uint32Array(next);
|
|
807
|
-
const next_ends = new Uint32Array(next);
|
|
808
|
-
const next_extras = new Uint16Array(next);
|
|
809
|
-
const next_value_starts = new Uint32Array(next);
|
|
810
|
-
const next_value_ends = new Uint32Array(next);
|
|
811
|
-
const next_parents = new Uint32Array(next);
|
|
812
|
-
const next_next_siblings = new Uint32Array(next);
|
|
813
|
-
const next_prev_siblings = new Uint32Array(next);
|
|
814
|
-
const next_children_starts = new Uint32Array(next);
|
|
815
|
-
const next_children_ends = new Uint32Array(next);
|
|
816
|
-
const next_pending_nodes = new Uint32Array(next);
|
|
817
|
-
const next_has_metadata = new Uint8Array(Math.max(1, next >> 3));
|
|
818
|
-
|
|
819
|
-
next_kinds.set(this._kinds);
|
|
820
|
-
next_starts.set(this._starts);
|
|
821
|
-
next_ends.set(this._ends);
|
|
822
|
-
next_extras.set(this._extras);
|
|
823
|
-
next_value_starts.set(this._value_starts);
|
|
824
|
-
next_value_ends.set(this._value_ends);
|
|
825
|
-
next_parents.set(this._parents);
|
|
826
|
-
next_next_siblings.set(this._next_siblings);
|
|
827
|
-
next_prev_siblings.set(this._prev_siblings);
|
|
828
|
-
next_children_starts.set(this._children_starts);
|
|
829
|
-
next_children_ends.set(this._children_ends);
|
|
830
|
-
next_pending_nodes.set(this._pending_nodes);
|
|
831
|
-
next_has_metadata.set(this.has_metadata);
|
|
1147
|
+
set_parent(index: number, parent: number): void {
|
|
1148
|
+
this._n[index * NodeField.stride + NodeField.parent] = parent;
|
|
1149
|
+
}
|
|
832
1150
|
|
|
833
|
-
|
|
834
|
-
this.
|
|
835
|
-
this._starts = next_starts;
|
|
836
|
-
this._ends = next_ends;
|
|
837
|
-
this._extras = next_extras;
|
|
838
|
-
this._value_starts = next_value_starts;
|
|
839
|
-
this._value_ends = next_value_ends;
|
|
840
|
-
this._parents = next_parents;
|
|
841
|
-
this._next_siblings = next_next_siblings;
|
|
842
|
-
this._prev_siblings = next_prev_siblings;
|
|
843
|
-
this._children_starts = next_children_starts;
|
|
844
|
-
this._children_ends = next_children_ends;
|
|
845
|
-
this._pending_nodes = next_pending_nodes;
|
|
846
|
-
this.has_metadata = next_has_metadata;
|
|
1151
|
+
next_at(index: number): number {
|
|
1152
|
+
return this._n[index * NodeField.stride + NodeField.next];
|
|
847
1153
|
}
|
|
848
1154
|
|
|
849
|
-
|
|
850
|
-
this.
|
|
851
|
-
this.has_metadata[index >> 3] |= 1 << (index & 7);
|
|
1155
|
+
set_next(index: number, next: number): void {
|
|
1156
|
+
this._n[index * NodeField.stride + NodeField.next] = next;
|
|
852
1157
|
}
|
|
853
1158
|
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
1159
|
+
prev_at(index: number): number {
|
|
1160
|
+
return this._n[index * NodeField.stride + NodeField.prev];
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
set_prev(index: number, prev: number): void {
|
|
1164
|
+
this._n[index * NodeField.stride + NodeField.prev] = prev;
|
|
1165
|
+
}
|
|
1166
|
+
|
|
1167
|
+
first_child_at(index: number): number {
|
|
1168
|
+
return this._n[index * NodeField.stride + NodeField.first_child];
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
set_first_child(index: number, child: number): void {
|
|
1172
|
+
this._n[index * NodeField.stride + NodeField.first_child] = child;
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
last_child_at(index: number): number {
|
|
1176
|
+
return this._n[index * NodeField.stride + NodeField.last_child];
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
set_last_child(index: number, child: number): void {
|
|
1180
|
+
this._n[index * NodeField.stride + NodeField.last_child] = child;
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
pending_at(index: number): number {
|
|
1184
|
+
return this._n[index * NodeField.stride + NodeField.pending];
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
/** pre-grow to avoid repeated resizes when the final size is estimable. */
|
|
1188
|
+
ensure_capacity(needed: number): void {
|
|
1189
|
+
let next = this._capacity;
|
|
1190
|
+
if (next >= needed) return;
|
|
1191
|
+
while (next < needed) next <<= 1;
|
|
1192
|
+
this.resize(next);
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
/** double the backing storage when capacity is exhausted. */
|
|
1196
|
+
private grow(): Uint32Array {
|
|
1197
|
+
return this.resize(this._capacity << 1);
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
private resize(next: number): Uint32Array {
|
|
1201
|
+
const old = this._n;
|
|
1202
|
+
const words = this._capacity * NodeField.stride;
|
|
1203
|
+
if (old === last_carve) {
|
|
1204
|
+
// nothing was carved since, so extend the region in place
|
|
1205
|
+
const base = slab_used - words * 4;
|
|
1206
|
+
const bytes = next * NODE_BYTES;
|
|
1207
|
+
if (bytes <= SLAB_MAX_CARVE && base + bytes <= SLAB_BYTES) {
|
|
1208
|
+
const n = new Uint32Array(slab, base, next * NodeField.stride);
|
|
1209
|
+
slab_used = base + bytes;
|
|
1210
|
+
last_carve = n;
|
|
1211
|
+
this._capacity = next;
|
|
1212
|
+
this._filled = next;
|
|
1213
|
+
this._n = n;
|
|
1214
|
+
return n;
|
|
1215
|
+
}
|
|
858
1216
|
}
|
|
859
|
-
|
|
1217
|
+
const n = this.alloc(next);
|
|
1218
|
+
// slots from _size on are template in both, a carve has it already
|
|
1219
|
+
const size = this._size;
|
|
1220
|
+
n.set(
|
|
1221
|
+
old.length === size * NodeField.stride
|
|
1222
|
+
? old
|
|
1223
|
+
: old.subarray(0, size * NodeField.stride)
|
|
1224
|
+
);
|
|
1225
|
+
if (this._filled < size) this._filled = size;
|
|
1226
|
+
return n;
|
|
860
1227
|
}
|
|
861
1228
|
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
1229
|
+
set_metadata(index: number, metadata: any): void {
|
|
1230
|
+
const n = this._n;
|
|
1231
|
+
const i = index * NodeField.stride + NodeField.meta;
|
|
1232
|
+
const slot = n[i];
|
|
1233
|
+
if (slot !== 0) this._meta[slot - 1] = metadata;
|
|
1234
|
+
else {
|
|
1235
|
+
const meta = this._meta;
|
|
1236
|
+
// a literal holds one slot, a push onto an empty array reserves seventeen
|
|
1237
|
+
if (meta === NO_META) {
|
|
1238
|
+
this._meta = [metadata];
|
|
1239
|
+
n[i] = 1;
|
|
1240
|
+
} else n[i] = meta.push(metadata);
|
|
1241
|
+
}
|
|
865
1242
|
}
|
|
866
1243
|
|
|
867
|
-
|
|
868
|
-
this.
|
|
1244
|
+
metadata_at(index: number): any | undefined {
|
|
1245
|
+
const slot = this._n[index * NodeField.stride + NodeField.meta];
|
|
1246
|
+
// an index past the storage reads undefined, which indexes _meta at nan
|
|
1247
|
+
return slot === 0 ? undefined : this._meta[slot - 1];
|
|
869
1248
|
}
|
|
870
1249
|
|
|
871
|
-
|
|
872
|
-
this.
|
|
1250
|
+
delete_metadata(index: number): void {
|
|
1251
|
+
this._n[index * NodeField.stride + NodeField.meta] = 0;
|
|
873
1252
|
}
|
|
874
1253
|
|
|
875
1254
|
/**
|
|
@@ -889,38 +1268,36 @@ export class NodeBuffer {
|
|
|
889
1268
|
value: [number, number];
|
|
890
1269
|
index: number;
|
|
891
1270
|
} {
|
|
892
|
-
const
|
|
1271
|
+
const kind = this.kind_at(index);
|
|
1272
|
+
const extra_string = extra_to_string(kind);
|
|
893
1273
|
const extras_object = extra_string
|
|
894
|
-
? { [extra_string]: this.
|
|
1274
|
+
? { [extra_string]: this.extra_at(index) }
|
|
895
1275
|
: {};
|
|
896
1276
|
|
|
897
1277
|
const _children = [];
|
|
898
1278
|
|
|
899
1279
|
// walk sibling chain to get all direct children
|
|
900
|
-
let child = this.
|
|
901
|
-
while (child !== 0xffffffff && this.
|
|
1280
|
+
let child = this.first_child_at(index);
|
|
1281
|
+
while (child !== 0xffffffff && this.parent_at(child) === index) {
|
|
902
1282
|
_children.push(child);
|
|
903
|
-
child = this.
|
|
1283
|
+
child = this.next_at(child);
|
|
904
1284
|
}
|
|
905
1285
|
|
|
1286
|
+
const parent = this.parent_at(index);
|
|
1287
|
+
const next = this.next_at(index);
|
|
1288
|
+
const prev = this.prev_at(index);
|
|
906
1289
|
return {
|
|
907
|
-
kind: kind_to_string(
|
|
908
|
-
start: this.
|
|
909
|
-
end: this.
|
|
1290
|
+
kind: kind_to_string(kind),
|
|
1291
|
+
start: this.start_at(index),
|
|
1292
|
+
end: this.end_at(index),
|
|
910
1293
|
metadata: {
|
|
911
1294
|
...this.metadata_at(index),
|
|
912
1295
|
...extras_object,
|
|
913
1296
|
},
|
|
914
|
-
parent:
|
|
915
|
-
next:
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
: this._next_siblings[index],
|
|
919
|
-
prev:
|
|
920
|
-
this._prev_siblings[index] === 0xffffffff
|
|
921
|
-
? null
|
|
922
|
-
: this._prev_siblings[index],
|
|
923
|
-
value: [this._value_starts[index], this._value_ends[index]],
|
|
1297
|
+
parent: parent === 0xffffffff ? null : parent,
|
|
1298
|
+
next: next === 0xffffffff ? null : next,
|
|
1299
|
+
prev: prev === 0xffffffff ? null : prev,
|
|
1300
|
+
value: [this.value_start_at(index), this.value_end_at(index)],
|
|
924
1301
|
children: _children,
|
|
925
1302
|
index: index,
|
|
926
1303
|
};
|