@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/plugin_dispatch.ts
CHANGED
|
@@ -1,35 +1,39 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
type NodeBuffer,
|
|
3
|
+
NodeField,
|
|
4
|
+
NodeKind,
|
|
5
|
+
kind_to_string,
|
|
6
|
+
string_to_kind,
|
|
7
|
+
} from './utils';
|
|
8
|
+
import { UndoLog, UndoEntryKind } from './undo_log';
|
|
3
9
|
import {
|
|
4
10
|
NodeView,
|
|
5
11
|
ViewCache,
|
|
6
12
|
type TextSource,
|
|
7
13
|
SourceTextSource,
|
|
8
14
|
WireTextSource,
|
|
9
|
-
} from
|
|
15
|
+
} from './node_view';
|
|
10
16
|
import type {
|
|
11
17
|
ParsePlugin,
|
|
12
18
|
NodeHandler,
|
|
13
19
|
ComposedHandler,
|
|
14
20
|
PluginContext,
|
|
15
|
-
|
|
16
|
-
} from "./plugin_types";
|
|
21
|
+
} from './plugin_types';
|
|
17
22
|
|
|
18
23
|
const NONE = 0xffffffff;
|
|
19
24
|
|
|
20
25
|
/** total number of node kinds in the enum. */
|
|
21
|
-
const NODE_KIND_COUNT =
|
|
26
|
+
const NODE_KIND_COUNT = 36;
|
|
22
27
|
|
|
23
28
|
/** first synthetic id. high bit flag partitions id space from parser ids. */
|
|
24
29
|
const SYNTHETIC_ID_BASE = 0x40000000;
|
|
25
30
|
|
|
26
|
-
|
|
27
31
|
/** single handler: no wrapper needed, just normalize return type. */
|
|
28
32
|
function compose_1(h: NodeHandler): ComposedHandler {
|
|
29
33
|
const parse = h.parse;
|
|
30
34
|
return function handler_1(
|
|
31
35
|
view: NodeView,
|
|
32
|
-
ctx: PluginContext
|
|
36
|
+
ctx: PluginContext
|
|
33
37
|
): (() => void)[] | null {
|
|
34
38
|
const cb = parse(view, ctx);
|
|
35
39
|
if (cb) return [cb];
|
|
@@ -43,7 +47,7 @@ function compose_2(a: NodeHandler, b: NodeHandler): ComposedHandler {
|
|
|
43
47
|
const pb = b.parse;
|
|
44
48
|
return function handler_2(
|
|
45
49
|
view: NodeView,
|
|
46
|
-
ctx: PluginContext
|
|
50
|
+
ctx: PluginContext
|
|
47
51
|
): (() => void)[] | null {
|
|
48
52
|
const ca = pa(view, ctx);
|
|
49
53
|
const cb = pb(view, ctx);
|
|
@@ -60,14 +64,14 @@ function compose_2(a: NodeHandler, b: NodeHandler): ComposedHandler {
|
|
|
60
64
|
function compose_3(
|
|
61
65
|
a: NodeHandler,
|
|
62
66
|
b: NodeHandler,
|
|
63
|
-
c: NodeHandler
|
|
67
|
+
c: NodeHandler
|
|
64
68
|
): ComposedHandler {
|
|
65
69
|
const pa = a.parse;
|
|
66
70
|
const pb = b.parse;
|
|
67
71
|
const pc = c.parse;
|
|
68
72
|
return function handler_3(
|
|
69
73
|
view: NodeView,
|
|
70
|
-
ctx: PluginContext
|
|
74
|
+
ctx: PluginContext
|
|
71
75
|
): (() => void)[] | null {
|
|
72
76
|
const ca = pa(view, ctx);
|
|
73
77
|
const cb = pb(view, ctx);
|
|
@@ -92,7 +96,7 @@ function compose_n(handlers: NodeHandler[]): ComposedHandler {
|
|
|
92
96
|
const len = parses.length;
|
|
93
97
|
return function handler_n(
|
|
94
98
|
view: NodeView,
|
|
95
|
-
ctx: PluginContext
|
|
99
|
+
ctx: PluginContext
|
|
96
100
|
): (() => void)[] | null {
|
|
97
101
|
let result: (() => void)[] | null = null;
|
|
98
102
|
for (let i = 0; i < len; i++) {
|
|
@@ -118,16 +122,20 @@ function compose(handlers: NodeHandler[]): ComposedHandler {
|
|
|
118
122
|
}
|
|
119
123
|
}
|
|
120
124
|
|
|
121
|
-
|
|
122
|
-
/** 35 slots, one per NodeKind. null means no handlers. */
|
|
125
|
+
/** 36 slots, one per NodeKind, null means no handlers */
|
|
123
126
|
type HandlersTable = (ComposedHandler | null)[];
|
|
124
127
|
|
|
125
128
|
interface RegistrationResult {
|
|
126
129
|
fused: HandlersTable;
|
|
127
130
|
sequential: { plugin: ParsePlugin; handlers: HandlersTable }[];
|
|
128
131
|
has_handler: Uint32Array;
|
|
132
|
+
/** 1 for each kind with a fused handler, shared, never written */
|
|
133
|
+
open_wants: Uint8Array;
|
|
129
134
|
}
|
|
130
135
|
|
|
136
|
+
/** open_wants once a redirect exists, any open may need retargeting */
|
|
137
|
+
const ALL_WANTS = new Uint8Array(64).fill(1);
|
|
138
|
+
|
|
131
139
|
function register_plugins(plugins: ParsePlugin[]): RegistrationResult {
|
|
132
140
|
const fused_plugins: ParsePlugin[] = [];
|
|
133
141
|
const sequential_plugins: ParsePlugin[] = [];
|
|
@@ -142,17 +150,16 @@ function register_plugins(plugins: ParsePlugin[]): RegistrationResult {
|
|
|
142
150
|
|
|
143
151
|
// build per-kind handler lists for fused plugins
|
|
144
152
|
const per_kind: (NodeHandler[] | null)[] = new Array(NODE_KIND_COUNT).fill(
|
|
145
|
-
null
|
|
153
|
+
null
|
|
146
154
|
);
|
|
147
155
|
|
|
148
156
|
for (const plugin of fused_plugins) {
|
|
149
157
|
for (const key of Object.keys(plugin)) {
|
|
150
|
-
if (key ===
|
|
158
|
+
if (key === 'sequential') continue;
|
|
151
159
|
const kind = string_to_kind(key);
|
|
152
160
|
if (kind === undefined) continue;
|
|
153
161
|
const entry = plugin[key];
|
|
154
|
-
if (!entry || typeof entry !==
|
|
155
|
-
continue;
|
|
162
|
+
if (!entry || typeof entry !== 'object' || !('parse' in entry)) continue;
|
|
156
163
|
if (!per_kind[kind]) per_kind[kind] = [];
|
|
157
164
|
per_kind[kind]!.push(entry as NodeHandler);
|
|
158
165
|
}
|
|
@@ -160,7 +167,7 @@ function register_plugins(plugins: ParsePlugin[]): RegistrationResult {
|
|
|
160
167
|
|
|
161
168
|
// compose fused handlers
|
|
162
169
|
const fused: HandlersTable = new Array(NODE_KIND_COUNT).fill(null);
|
|
163
|
-
const has_handler = new Uint32Array(2); // 64 bits, need
|
|
170
|
+
const has_handler = new Uint32Array(2); // 64 bits, need 36
|
|
164
171
|
|
|
165
172
|
for (let i = 0; i < NODE_KIND_COUNT; i++) {
|
|
166
173
|
const list = per_kind[i];
|
|
@@ -174,236 +181,245 @@ function register_plugins(plugins: ParsePlugin[]): RegistrationResult {
|
|
|
174
181
|
const sequential = sequential_plugins.map((plugin) => {
|
|
175
182
|
const table: HandlersTable = new Array(NODE_KIND_COUNT).fill(null);
|
|
176
183
|
for (const key of Object.keys(plugin)) {
|
|
177
|
-
if (key ===
|
|
184
|
+
if (key === 'sequential') continue;
|
|
178
185
|
const kind = string_to_kind(key);
|
|
179
186
|
if (kind === undefined) continue;
|
|
180
187
|
const entry = plugin[key];
|
|
181
|
-
if (!entry || typeof entry !==
|
|
182
|
-
continue;
|
|
188
|
+
if (!entry || typeof entry !== 'object' || !('parse' in entry)) continue;
|
|
183
189
|
table[kind] = compose_1(entry as NodeHandler);
|
|
184
190
|
}
|
|
185
191
|
return { plugin, handlers: table };
|
|
186
192
|
});
|
|
187
193
|
|
|
188
|
-
|
|
194
|
+
// a pass with no handler would do nothing
|
|
195
|
+
return {
|
|
196
|
+
fused,
|
|
197
|
+
sequential: sequential.filter((pass) =>
|
|
198
|
+
pass.handlers.some((h) => h !== null)
|
|
199
|
+
),
|
|
200
|
+
has_handler,
|
|
201
|
+
open_wants: wants_of(has_handler),
|
|
202
|
+
};
|
|
189
203
|
}
|
|
190
204
|
|
|
205
|
+
function wants_of(has_handler: Uint32Array): Uint8Array {
|
|
206
|
+
const wants = new Uint8Array(64);
|
|
207
|
+
for (let k = 0; k < 64; k++) {
|
|
208
|
+
if (has_handler[k >> 5] & (1 << (k & 31))) wants[k] = 1;
|
|
209
|
+
}
|
|
210
|
+
return wants;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** parse_of for an entry the registration skips */
|
|
214
|
+
const NO_PARSE = {};
|
|
215
|
+
|
|
216
|
+
function parse_of(entry: unknown): unknown {
|
|
217
|
+
return entry && typeof entry === 'object' && 'parse' in entry
|
|
218
|
+
? (entry as NodeHandler).parse
|
|
219
|
+
: NO_PARSE;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** everything register_plugins reads, in the order it reads it */
|
|
223
|
+
function snapshot_plugins(plugins: ParsePlugin[]): unknown[] {
|
|
224
|
+
const snap: unknown[] = [plugins.length];
|
|
225
|
+
for (let i = 0; i < plugins.length; i++) {
|
|
226
|
+
const p = plugins[i];
|
|
227
|
+
const keys = Object.keys(p);
|
|
228
|
+
snap.push(p, !!p.sequential, keys.length);
|
|
229
|
+
for (let k = 0; k < keys.length; k++) {
|
|
230
|
+
const entry = p[keys[k]];
|
|
231
|
+
snap.push(keys[k], entry, parse_of(entry));
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return snap;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function snapshot_matches(plugins: ParsePlugin[], snap: unknown[]): boolean {
|
|
238
|
+
let j = 0;
|
|
239
|
+
if (snap[j++] !== plugins.length) return false;
|
|
240
|
+
for (let i = 0; i < plugins.length; i++) {
|
|
241
|
+
const p = plugins[i];
|
|
242
|
+
if (snap[j++] !== p) return false;
|
|
243
|
+
if (snap[j++] !== !!p.sequential) return false;
|
|
244
|
+
// inherited enumerable keys change the count or a key, so an exact match
|
|
245
|
+
// means the same own keys without allocating Object.keys
|
|
246
|
+
const count = snap[j++] as number;
|
|
247
|
+
const keys_end = j + count * 3;
|
|
248
|
+
for (const key in p) {
|
|
249
|
+
if (j === keys_end || snap[j++] !== key) return false;
|
|
250
|
+
const entry = p[key];
|
|
251
|
+
if (snap[j++] !== entry) return false;
|
|
252
|
+
if (snap[j++] !== parse_of(entry)) return false;
|
|
253
|
+
}
|
|
254
|
+
if (j !== keys_end) return false;
|
|
255
|
+
}
|
|
256
|
+
return true;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// nothing writes a registration after register_plugins, so documents whose
|
|
260
|
+
// plugins hold the same objects, keys and handlers can share one
|
|
261
|
+
let last_snapshot: unknown[] | null = null;
|
|
262
|
+
let last_registration: RegistrationResult | null = null;
|
|
263
|
+
|
|
264
|
+
function registration_for(plugins: ParsePlugin[]): RegistrationResult {
|
|
265
|
+
if (last_snapshot !== null && snapshot_matches(plugins, last_snapshot)) {
|
|
266
|
+
return last_registration!;
|
|
267
|
+
}
|
|
268
|
+
const reg = register_plugins(plugins);
|
|
269
|
+
last_snapshot = snapshot_plugins(plugins);
|
|
270
|
+
last_registration = reg;
|
|
271
|
+
return reg;
|
|
272
|
+
}
|
|
191
273
|
|
|
192
274
|
/**
|
|
193
|
-
*
|
|
194
|
-
*
|
|
275
|
+
* a Map since handled nodes can sit over 1024 indices apart, and an array
|
|
276
|
+
* written past such a gap falls back to dictionary elements
|
|
195
277
|
*/
|
|
196
278
|
class CloseCallbackStore {
|
|
197
|
-
private store: ((
|
|
279
|
+
private store: Map<number, (() => void)[]> | null = null;
|
|
280
|
+
// entries still set, most nodes close with none so the lookup is skipped
|
|
281
|
+
live = 0;
|
|
198
282
|
|
|
199
283
|
set(idx: number, callbacks: (() => void)[]): void {
|
|
200
|
-
|
|
284
|
+
let store = this.store;
|
|
285
|
+
if (store === null) store = this.store = new Map();
|
|
286
|
+
store.set(idx, callbacks);
|
|
287
|
+
this.live = store.size;
|
|
201
288
|
}
|
|
202
289
|
|
|
203
290
|
/** take close callbacks for a node, removing the entry. returns undefined if none. */
|
|
204
291
|
take(idx: number): (() => void)[] | undefined {
|
|
205
|
-
|
|
206
|
-
|
|
292
|
+
if (this.live === 0) return undefined;
|
|
293
|
+
const store = this.store!;
|
|
294
|
+
const cbs = store.get(idx);
|
|
295
|
+
if (cbs !== undefined) {
|
|
296
|
+
store.delete(idx);
|
|
297
|
+
this.live = store.size;
|
|
298
|
+
}
|
|
207
299
|
return cbs;
|
|
208
300
|
}
|
|
209
301
|
|
|
210
302
|
/** fire close callbacks for a node, removing the entry. */
|
|
211
303
|
fire(idx: number): void {
|
|
212
|
-
const cbs = this.
|
|
304
|
+
const cbs = this.take(idx);
|
|
213
305
|
if (cbs === undefined) return;
|
|
214
306
|
for (let i = 0; i < cbs.length; i++) {
|
|
215
307
|
cbs[i]();
|
|
216
308
|
}
|
|
217
|
-
this.store[idx] = undefined;
|
|
218
309
|
}
|
|
219
310
|
|
|
220
311
|
/** discard callbacks without firing (for revocation). */
|
|
221
312
|
discard(idx: number): void {
|
|
222
|
-
this.
|
|
313
|
+
this.take(idx);
|
|
223
314
|
}
|
|
224
315
|
|
|
225
316
|
reset(): void {
|
|
226
|
-
this.store
|
|
317
|
+
if (this.store !== null) this.store.clear();
|
|
318
|
+
this.live = 0;
|
|
227
319
|
}
|
|
228
320
|
}
|
|
229
321
|
|
|
230
|
-
|
|
231
322
|
/**
|
|
232
323
|
* dispatch plugin handlers for a node open event.
|
|
233
324
|
*
|
|
234
|
-
*
|
|
235
|
-
* each arm calls its own local, giving the jit a monomorphic call site
|
|
236
|
-
* per kind.
|
|
325
|
+
* each switch arm is a monomorphic call site for its own kind
|
|
237
326
|
*/
|
|
238
327
|
function dispatch_open(
|
|
239
328
|
kind: NodeKind,
|
|
240
329
|
view: NodeView,
|
|
241
330
|
ctx: PluginContext,
|
|
242
331
|
fused: HandlersTable,
|
|
243
|
-
has_handler: Uint32Array
|
|
332
|
+
has_handler: Uint32Array
|
|
244
333
|
): (() => void)[] | null {
|
|
245
334
|
// bitmask fast path: no handler for this kind
|
|
246
335
|
if (!(has_handler[kind >> 5] & (1 << (kind & 31)))) return null;
|
|
247
336
|
|
|
248
|
-
// destructure into monomorphic locals
|
|
249
|
-
const h_0 = fused[0];
|
|
250
|
-
const h_1 = fused[1];
|
|
251
|
-
const h_2 = fused[2];
|
|
252
|
-
const h_3 = fused[3];
|
|
253
|
-
const h_4 = fused[4];
|
|
254
|
-
const h_5 = fused[5];
|
|
255
|
-
const h_6 = fused[6];
|
|
256
|
-
const h_7 = fused[7];
|
|
257
|
-
const h_8 = fused[8];
|
|
258
|
-
const h_9 = fused[9];
|
|
259
|
-
const h_10 = fused[10];
|
|
260
|
-
const h_11 = fused[11];
|
|
261
|
-
const h_12 = fused[12];
|
|
262
|
-
const h_13 = fused[13];
|
|
263
|
-
const h_14 = fused[14];
|
|
264
|
-
const h_15 = fused[15];
|
|
265
|
-
const h_16 = fused[16];
|
|
266
|
-
const h_17 = fused[17];
|
|
267
|
-
const h_18 = fused[18];
|
|
268
|
-
const h_19 = fused[19];
|
|
269
|
-
const h_20 = fused[20];
|
|
270
|
-
const h_21 = fused[21];
|
|
271
|
-
const h_22 = fused[22];
|
|
272
|
-
const h_23 = fused[23];
|
|
273
|
-
const h_24 = fused[24];
|
|
274
|
-
const h_25 = fused[25];
|
|
275
|
-
const h_26 = fused[26];
|
|
276
|
-
const h_27 = fused[27];
|
|
277
|
-
const h_28 = fused[28];
|
|
278
|
-
const h_29 = fused[29];
|
|
279
|
-
const h_30 = fused[30];
|
|
280
|
-
const h_31 = fused[31];
|
|
281
|
-
const h_32 = fused[32];
|
|
282
|
-
const h_33 = fused[33];
|
|
283
|
-
const h_34 = fused[34];
|
|
284
|
-
|
|
285
337
|
switch (kind) {
|
|
286
338
|
case 0:
|
|
287
|
-
return
|
|
339
|
+
return fused[0]!(view, ctx);
|
|
288
340
|
case 1:
|
|
289
|
-
return
|
|
341
|
+
return fused[1]!(view, ctx);
|
|
290
342
|
case 2:
|
|
291
|
-
return
|
|
343
|
+
return fused[2]!(view, ctx);
|
|
292
344
|
case 3:
|
|
293
|
-
return
|
|
345
|
+
return fused[3]!(view, ctx);
|
|
294
346
|
case 4:
|
|
295
|
-
return
|
|
347
|
+
return fused[4]!(view, ctx);
|
|
296
348
|
case 5:
|
|
297
|
-
return
|
|
349
|
+
return fused[5]!(view, ctx);
|
|
298
350
|
case 6:
|
|
299
|
-
return
|
|
351
|
+
return fused[6]!(view, ctx);
|
|
300
352
|
case 7:
|
|
301
|
-
return
|
|
353
|
+
return fused[7]!(view, ctx);
|
|
302
354
|
case 8:
|
|
303
|
-
return
|
|
355
|
+
return fused[8]!(view, ctx);
|
|
304
356
|
case 9:
|
|
305
|
-
return
|
|
357
|
+
return fused[9]!(view, ctx);
|
|
306
358
|
case 10:
|
|
307
|
-
return
|
|
359
|
+
return fused[10]!(view, ctx);
|
|
308
360
|
case 11:
|
|
309
|
-
return
|
|
361
|
+
return fused[11]!(view, ctx);
|
|
310
362
|
case 12:
|
|
311
|
-
return
|
|
363
|
+
return fused[12]!(view, ctx);
|
|
312
364
|
case 13:
|
|
313
|
-
return
|
|
365
|
+
return fused[13]!(view, ctx);
|
|
314
366
|
case 14:
|
|
315
|
-
return
|
|
367
|
+
return fused[14]!(view, ctx);
|
|
316
368
|
case 15:
|
|
317
|
-
return
|
|
369
|
+
return fused[15]!(view, ctx);
|
|
318
370
|
case 16:
|
|
319
|
-
return
|
|
371
|
+
return fused[16]!(view, ctx);
|
|
320
372
|
case 17:
|
|
321
|
-
return
|
|
373
|
+
return fused[17]!(view, ctx);
|
|
322
374
|
case 18:
|
|
323
|
-
return
|
|
375
|
+
return fused[18]!(view, ctx);
|
|
324
376
|
case 19:
|
|
325
|
-
return
|
|
377
|
+
return fused[19]!(view, ctx);
|
|
326
378
|
case 20:
|
|
327
|
-
return
|
|
379
|
+
return fused[20]!(view, ctx);
|
|
328
380
|
case 21:
|
|
329
|
-
return
|
|
381
|
+
return fused[21]!(view, ctx);
|
|
330
382
|
case 22:
|
|
331
|
-
return
|
|
383
|
+
return fused[22]!(view, ctx);
|
|
332
384
|
case 23:
|
|
333
|
-
return
|
|
385
|
+
return fused[23]!(view, ctx);
|
|
334
386
|
case 24:
|
|
335
|
-
return
|
|
387
|
+
return fused[24]!(view, ctx);
|
|
336
388
|
case 25:
|
|
337
|
-
return
|
|
389
|
+
return fused[25]!(view, ctx);
|
|
338
390
|
case 26:
|
|
339
|
-
return
|
|
391
|
+
return fused[26]!(view, ctx);
|
|
340
392
|
case 27:
|
|
341
|
-
return
|
|
393
|
+
return fused[27]!(view, ctx);
|
|
342
394
|
case 28:
|
|
343
|
-
return
|
|
395
|
+
return fused[28]!(view, ctx);
|
|
344
396
|
case 29:
|
|
345
|
-
return
|
|
397
|
+
return fused[29]!(view, ctx);
|
|
346
398
|
case 30:
|
|
347
|
-
return
|
|
399
|
+
return fused[30]!(view, ctx);
|
|
348
400
|
case 31:
|
|
349
|
-
return
|
|
401
|
+
return fused[31]!(view, ctx);
|
|
350
402
|
case 32:
|
|
351
|
-
return
|
|
403
|
+
return fused[32]!(view, ctx);
|
|
352
404
|
case 33:
|
|
353
|
-
return
|
|
405
|
+
return fused[33]!(view, ctx);
|
|
354
406
|
case 34:
|
|
355
|
-
return
|
|
407
|
+
return fused[34]!(view, ctx);
|
|
408
|
+
case 35:
|
|
409
|
+
return fused[35]!(view, ctx);
|
|
356
410
|
default:
|
|
357
411
|
return null;
|
|
358
412
|
}
|
|
359
413
|
}
|
|
360
414
|
|
|
415
|
+
/** shared undo log until a view or a kind rewrite needs one, never written */
|
|
416
|
+
const NO_UNDO = new UndoLog();
|
|
361
417
|
|
|
362
|
-
/**
|
|
363
|
-
|
|
364
|
-
* calls visitor(idx, kind, false) on open, visitor(idx, kind, true) on close.
|
|
365
|
-
*/
|
|
366
|
-
function walk_tree(
|
|
367
|
-
buf: NodeBuffer,
|
|
368
|
-
visitor: (idx: number, kind: NodeKind, is_close: boolean) => void,
|
|
369
|
-
): void {
|
|
370
|
-
const children_starts = buf._children_starts;
|
|
371
|
-
const next_siblings = buf._next_siblings;
|
|
372
|
-
const parents = buf._parents;
|
|
373
|
-
const kinds = buf._kinds;
|
|
374
|
-
|
|
375
|
-
let idx = children_starts[0]; // first child of root
|
|
376
|
-
if (idx === NONE) return;
|
|
377
|
-
|
|
378
|
-
const stack: number[] = [];
|
|
379
|
-
|
|
380
|
-
while (true) {
|
|
381
|
-
visitor(idx, kinds[idx] as NodeKind, false);
|
|
382
|
-
|
|
383
|
-
const child = children_starts[idx];
|
|
384
|
-
if (child !== NONE) {
|
|
385
|
-
stack.push(idx);
|
|
386
|
-
idx = child;
|
|
387
|
-
continue;
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
visitor(idx, kinds[idx] as NodeKind, true);
|
|
391
|
-
|
|
392
|
-
let next = next_siblings[idx];
|
|
393
|
-
while (
|
|
394
|
-
(next === NONE || parents[next] !== parents[idx]) &&
|
|
395
|
-
stack.length > 0
|
|
396
|
-
) {
|
|
397
|
-
idx = stack.pop()!;
|
|
398
|
-
visitor(idx, kinds[idx] as NodeKind, true);
|
|
399
|
-
next = next_siblings[idx];
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
if (next === NONE || parents[next] !== parents[idx]) break;
|
|
403
|
-
idx = next;
|
|
404
|
-
}
|
|
405
|
-
}
|
|
418
|
+
/** shared close callbacks until the first is set, never written */
|
|
419
|
+
const NO_CLOSE_CBS = new CloseCallbackStore();
|
|
406
420
|
|
|
421
|
+
/** shared redirects until the first wrap_inner, never written */
|
|
422
|
+
const NO_REDIRECTS: Map<number, number> = new Map();
|
|
407
423
|
|
|
408
424
|
/**
|
|
409
425
|
* orchestrates plugin dispatch for both TreeBuilder and WireTreeBuilder.
|
|
@@ -415,25 +431,75 @@ export class PluginDispatcher {
|
|
|
415
431
|
private fused: HandlersTable;
|
|
416
432
|
private has_handler: Uint32Array;
|
|
417
433
|
private sequential: { plugin: ParsePlugin; handlers: HandlersTable }[];
|
|
418
|
-
private undo: UndoLog =
|
|
419
|
-
private close_cbs: CloseCallbackStore =
|
|
420
|
-
private ctx: PluginContext =
|
|
434
|
+
private undo: UndoLog = NO_UNDO;
|
|
435
|
+
private close_cbs: CloseCallbackStore = NO_CLOSE_CBS;
|
|
436
|
+
private ctx: PluginContext | null = null;
|
|
421
437
|
private text_source: TextSource;
|
|
422
438
|
|
|
423
439
|
/**
|
|
424
440
|
* redirect map: when wrap_inner is called, subsequent children
|
|
425
441
|
* targeting the parent should land in the wrapper instead.
|
|
426
442
|
*/
|
|
427
|
-
private redirects: Map<number, number> =
|
|
443
|
+
private redirects: Map<number, number> = NO_REDIRECTS;
|
|
428
444
|
|
|
429
445
|
private next_synthetic_id = SYNTHETIC_ID_BASE;
|
|
430
446
|
|
|
447
|
+
/** one cache serves every dispatch, a view only holds an index */
|
|
448
|
+
private cache: ViewCache | null = null;
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* 1 for each kind whose open needs the dispatcher, every kind once a redirect
|
|
452
|
+
* exists, redirects only start in dispatch_open so builders reread it after one
|
|
453
|
+
*/
|
|
454
|
+
open_wants: Uint8Array;
|
|
455
|
+
|
|
431
456
|
constructor(plugins: ParsePlugin[], text_source: TextSource) {
|
|
432
|
-
const reg =
|
|
457
|
+
const reg = registration_for(plugins);
|
|
433
458
|
this.fused = reg.fused;
|
|
434
459
|
this.has_handler = reg.has_handler;
|
|
435
460
|
this.sequential = reg.sequential;
|
|
436
461
|
this.text_source = text_source;
|
|
462
|
+
this.open_wants = reg.open_wants;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/** cleared since a callback view may have filled it after the last dispatch */
|
|
466
|
+
private views(buf: NodeBuffer): ViewCache {
|
|
467
|
+
const cache = this.cache;
|
|
468
|
+
if (cache === null) {
|
|
469
|
+
let undo = this.undo;
|
|
470
|
+
if (undo === NO_UNDO) undo = this.undo = new UndoLog();
|
|
471
|
+
return (this.cache = new ViewCache(buf, this.text_source, undo));
|
|
472
|
+
}
|
|
473
|
+
cache.clear();
|
|
474
|
+
cache.rebind(buf, this.text_source);
|
|
475
|
+
return cache;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
/** buffer index and prior kind of each kind rewrite, see UndoLog */
|
|
479
|
+
kind_log(): number[] | null {
|
|
480
|
+
return this.undo.kind_changes;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
/** a kind rewrite outside the plugins, such as a revoke repair */
|
|
484
|
+
log_kind(buf_idx: number, prior_kind: number): void {
|
|
485
|
+
let undo = this.undo;
|
|
486
|
+
if (undo === NO_UNDO) undo = this.undo = new UndoLog();
|
|
487
|
+
undo.log_kind(buf_idx, prior_kind);
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/** an open of this kind needs a handler call or a redirect lookup */
|
|
491
|
+
wants_open(kind: NodeKind): boolean {
|
|
492
|
+
return (
|
|
493
|
+
(this.has_handler[kind >> 5] & (1 << (kind & 31))) !== 0 ||
|
|
494
|
+
this.redirects.size !== 0
|
|
495
|
+
);
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
/** a close needs no dispatch */
|
|
499
|
+
quiet(): boolean {
|
|
500
|
+
return (
|
|
501
|
+
this.close_cbs.live === 0 && this.redirects.size === 0 && this.undo.empty
|
|
502
|
+
);
|
|
437
503
|
}
|
|
438
504
|
|
|
439
505
|
/** check whether any fused handlers exist for this kind. */
|
|
@@ -443,17 +509,17 @@ export class PluginDispatcher {
|
|
|
443
509
|
|
|
444
510
|
/** check if a parent index has a redirect (wrap_inner). */
|
|
445
511
|
get_redirect(parent_idx: number): number | undefined {
|
|
512
|
+
if (this.redirects.size === 0) return undefined;
|
|
446
513
|
return this.redirects.get(parent_idx);
|
|
447
514
|
}
|
|
448
515
|
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
this.redirects.delete(parent_idx);
|
|
516
|
+
private own_redirects(): Map<number, number> {
|
|
517
|
+
let redirects = this.redirects;
|
|
518
|
+
if (redirects === NO_REDIRECTS) {
|
|
519
|
+
redirects = this.redirects = new Map();
|
|
520
|
+
this.open_wants = ALL_WANTS;
|
|
521
|
+
}
|
|
522
|
+
return redirects;
|
|
457
523
|
}
|
|
458
524
|
|
|
459
525
|
/** allocate a new synthetic node id. */
|
|
@@ -470,27 +536,17 @@ export class PluginDispatcher {
|
|
|
470
536
|
* dispatch fused plugin handlers on node open.
|
|
471
537
|
* creates a ViewCache, runs handlers, stores close callbacks.
|
|
472
538
|
*/
|
|
473
|
-
dispatch_open(
|
|
474
|
-
|
|
475
|
-
kind: NodeKind,
|
|
476
|
-
buf: NodeBuffer,
|
|
477
|
-
id_register: IdRegister,
|
|
478
|
-
): void {
|
|
479
|
-
const cache = new ViewCache(
|
|
480
|
-
buf,
|
|
481
|
-
this.text_source,
|
|
482
|
-
this.undo,
|
|
483
|
-
buf_idx,
|
|
484
|
-
);
|
|
539
|
+
dispatch_open(buf_idx: number, kind: NodeKind, buf: NodeBuffer): void {
|
|
540
|
+
const cache = this.views(buf);
|
|
485
541
|
const view = cache.get(buf_idx)!;
|
|
486
542
|
|
|
487
543
|
this.undo.set_active_node(buf_idx);
|
|
488
544
|
const callbacks = dispatch_open(
|
|
489
545
|
kind,
|
|
490
546
|
view,
|
|
491
|
-
this.ctx,
|
|
547
|
+
this.ctx ?? (this.ctx = {}),
|
|
492
548
|
this.fused,
|
|
493
|
-
this.has_handler
|
|
549
|
+
this.has_handler
|
|
494
550
|
);
|
|
495
551
|
this.undo.clear_active_node();
|
|
496
552
|
|
|
@@ -502,13 +558,16 @@ export class PluginDispatcher {
|
|
|
502
558
|
for (let i = 0; i < entries.length; i++) {
|
|
503
559
|
const e = entries[i];
|
|
504
560
|
if (e.kind === UndoEntryKind.WrapInner) {
|
|
505
|
-
this.
|
|
561
|
+
this.own_redirects().set(e.parent, e.wrapper);
|
|
506
562
|
}
|
|
507
563
|
}
|
|
508
564
|
}
|
|
509
565
|
|
|
510
566
|
if (callbacks) {
|
|
511
|
-
this.close_cbs
|
|
567
|
+
let close_cbs = this.close_cbs;
|
|
568
|
+
if (close_cbs === NO_CLOSE_CBS)
|
|
569
|
+
close_cbs = this.close_cbs = new CloseCallbackStore();
|
|
570
|
+
close_cbs.set(buf_idx, callbacks);
|
|
512
571
|
}
|
|
513
572
|
|
|
514
573
|
cache.clear();
|
|
@@ -522,28 +581,25 @@ export class PluginDispatcher {
|
|
|
522
581
|
* speculation, inline emphasis).
|
|
523
582
|
*/
|
|
524
583
|
dispatch_close(buf_idx: number, buf: NodeBuffer): void {
|
|
525
|
-
this.redirects.delete(buf_idx);
|
|
584
|
+
if (this.redirects.size !== 0) this.redirects.delete(buf_idx);
|
|
526
585
|
|
|
527
586
|
// take and fire close callbacks with undo attribution
|
|
528
587
|
const cbs = this.close_cbs.take(buf_idx);
|
|
588
|
+
// callbacks cannot change the pending flag
|
|
589
|
+
const pending = buf.pending_at(buf_idx) !== 0;
|
|
529
590
|
if (cbs) {
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
this.undo,
|
|
534
|
-
buf_idx,
|
|
535
|
-
);
|
|
536
|
-
this.undo.set_active_node(buf_idx);
|
|
591
|
+
// a node no longer pending commits right after its callbacks, so
|
|
592
|
+
// anything they recorded would be dropped unread
|
|
593
|
+
if (pending) this.undo.set_active_node(buf_idx);
|
|
537
594
|
for (let i = 0; i < cbs.length; i++) {
|
|
538
595
|
cbs[i]();
|
|
539
596
|
}
|
|
540
597
|
this.undo.clear_active_node();
|
|
541
|
-
cache.clear();
|
|
542
598
|
}
|
|
543
599
|
|
|
544
600
|
// only commit if the node is no longer pending.
|
|
545
601
|
// pending nodes can still be revoked after close.
|
|
546
|
-
if (
|
|
602
|
+
if (!pending) {
|
|
547
603
|
this.undo.commit(buf_idx);
|
|
548
604
|
}
|
|
549
605
|
}
|
|
@@ -562,6 +618,13 @@ export class PluginDispatcher {
|
|
|
562
618
|
* must be called BEFORE handle_repair().
|
|
563
619
|
*/
|
|
564
620
|
dispatch_revoke(buf_idx: number, buf: NodeBuffer): void {
|
|
621
|
+
// nothing recorded, so nothing to undo
|
|
622
|
+
if (
|
|
623
|
+
this.redirects.size === 0 &&
|
|
624
|
+
this.close_cbs.live === 0 &&
|
|
625
|
+
this.undo.empty
|
|
626
|
+
)
|
|
627
|
+
return;
|
|
565
628
|
this.redirects.delete(buf_idx);
|
|
566
629
|
this.close_cbs.discard(buf_idx);
|
|
567
630
|
|
|
@@ -580,10 +643,10 @@ export class PluginDispatcher {
|
|
|
580
643
|
this.undo.revoke(buf_idx, buf);
|
|
581
644
|
|
|
582
645
|
// recurse into children to revoke their plugin state too
|
|
583
|
-
let child = buf.
|
|
584
|
-
while (child !== NONE && buf.
|
|
646
|
+
let child = buf.first_child_at(buf_idx);
|
|
647
|
+
while (child !== NONE && buf.parent_at(child) === buf_idx) {
|
|
585
648
|
this.dispatch_revoke(child, buf);
|
|
586
|
-
child = buf.
|
|
649
|
+
child = buf.next_at(child);
|
|
587
650
|
}
|
|
588
651
|
}
|
|
589
652
|
|
|
@@ -593,41 +656,87 @@ export class PluginDispatcher {
|
|
|
593
656
|
*/
|
|
594
657
|
run_sequential(buf: NodeBuffer): void {
|
|
595
658
|
for (const pass of this.sequential) {
|
|
659
|
+
const handlers = pass.handlers;
|
|
660
|
+
|
|
661
|
+
// reread after plugin code runs, growing the buffer moves it to new storage
|
|
662
|
+
let n = buf._n;
|
|
663
|
+
let idx = n[NodeField.first_child];
|
|
664
|
+
if (idx === NONE) continue;
|
|
665
|
+
// with no handled kind anywhere in the buffer, linked or not, the walk does nothing
|
|
666
|
+
const size = buf._size;
|
|
667
|
+
let handled = false;
|
|
668
|
+
for (
|
|
669
|
+
let b = 0, end = size * NodeField.stride;
|
|
670
|
+
b < end;
|
|
671
|
+
b += NodeField.stride
|
|
672
|
+
) {
|
|
673
|
+
if (handlers[n[b] & 0xff] != null) {
|
|
674
|
+
handled = true;
|
|
675
|
+
break;
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
if (!handled) continue;
|
|
596
679
|
const close_store = new CloseCallbackStore();
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
680
|
+
const ctx = this.ctx ?? (this.ctx = {});
|
|
681
|
+
const stack: number[] = [];
|
|
682
|
+
|
|
683
|
+
while (true) {
|
|
684
|
+
const b = idx * NodeField.stride;
|
|
685
|
+
const handler = handlers[n[b] & 0xff];
|
|
686
|
+
if (handler != null) {
|
|
687
|
+
const cache = this.views(buf);
|
|
688
|
+
const view = cache.get(idx)!;
|
|
689
|
+
// the tree is complete so nothing revokes a sequential write, no
|
|
690
|
+
// active node means none is recorded
|
|
691
|
+
const callbacks = handler(view, ctx);
|
|
692
|
+
if (callbacks) close_store.set(idx, callbacks);
|
|
693
|
+
cache.clear();
|
|
694
|
+
n = buf._n;
|
|
602
695
|
}
|
|
603
696
|
|
|
604
|
-
const
|
|
605
|
-
if (
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
this.undo,
|
|
611
|
-
idx,
|
|
612
|
-
);
|
|
613
|
-
const view = cache.get(idx)!;
|
|
697
|
+
const child = n[b + NodeField.first_child];
|
|
698
|
+
if (child !== NONE) {
|
|
699
|
+
stack.push(idx);
|
|
700
|
+
idx = child;
|
|
701
|
+
continue;
|
|
702
|
+
}
|
|
614
703
|
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
704
|
+
if (close_store.live !== 0) {
|
|
705
|
+
close_store.fire(idx);
|
|
706
|
+
n = buf._n;
|
|
707
|
+
}
|
|
618
708
|
|
|
619
|
-
|
|
620
|
-
|
|
709
|
+
// read after the callbacks, which may relink the node
|
|
710
|
+
let next = n[b + NodeField.next];
|
|
711
|
+
let parent = n[b + NodeField.parent];
|
|
712
|
+
while (
|
|
713
|
+
(next === NONE ||
|
|
714
|
+
n[next * NodeField.stride + NodeField.parent] !== parent) &&
|
|
715
|
+
stack.length > 0
|
|
716
|
+
) {
|
|
717
|
+
idx = stack.pop()!;
|
|
718
|
+
if (close_store.live !== 0) {
|
|
719
|
+
close_store.fire(idx);
|
|
720
|
+
n = buf._n;
|
|
721
|
+
}
|
|
722
|
+
const bi = idx * NodeField.stride;
|
|
723
|
+
next = n[bi + NodeField.next];
|
|
724
|
+
parent = n[bi + NodeField.parent];
|
|
621
725
|
}
|
|
622
726
|
|
|
623
|
-
|
|
624
|
-
|
|
727
|
+
if (
|
|
728
|
+
next === NONE ||
|
|
729
|
+
n[next * NodeField.stride + NodeField.parent] !== parent
|
|
730
|
+
)
|
|
731
|
+
break;
|
|
732
|
+
idx = next;
|
|
733
|
+
}
|
|
625
734
|
}
|
|
626
735
|
}
|
|
627
736
|
|
|
628
737
|
/** reset all state. */
|
|
629
738
|
reset(): void {
|
|
630
|
-
this.undo.clear();
|
|
739
|
+
if (this.undo !== NO_UNDO) this.undo.clear();
|
|
631
740
|
this.close_cbs.reset();
|
|
632
741
|
this.redirects.clear();
|
|
633
742
|
this.next_synthetic_id = SYNTHETIC_ID_BASE;
|