Repository navigation
Replace vapor_split with split_template, built on Vize's L2 IR - #8
Merged
Merged
Conversation
split_template/2 lowers a template to Vize's L2 semantic IR, the op family Vize's own SSR compiler builds on, and prints it: static HTML, and a slot for everything that depends on data. It replaces vapor_split, which located elements in Vapor's template HTML with a hand-rolled tag scanner, and so dropped slots after text nodes, placed components before their siblings, rendered a root v-if twice, and lost default slot content beside a named slot. Slots carry source positions. An attribute is a whole slot, so null and false boolean attributes can be left out. Components carry their props, events and slot content, and <slot> outlets are slots. The root_attrs option gathers a component template's root attributes for fallthrough merging. Errors are Vize.Error structs with a positioned Vize.Diagnostic each, and Vize.Diagnostic.to_code_diagnostic/2 converts one to Elixir's diagnostic shape.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For vize 0.17.0. Breaking:
Vize.vapor_split/1is replaced byVize.split_template/2.Why
vapor_splitbuilt the split from Vapor's generated template HTML. A hand-rolled tag scanner inhtml_inject.rslocated each element in that HTML and matched it to the IR throughchild/nextoffsets. Each bug fixed in it so far was the scanner and the IR disagreeing:v-ifrendered twice;<template #x>.Vize already has the right input.
vize_l2, its semantic IR, is the representation Vize's SSR compiler builds its string plan from. It has elements, components, text, interpolations,v-if,v-forand slot outlets, with static attributes and typed bindings in authored order, and a source span on every op.What changed
split_template/2lowers the template withvize_l1andvize_l1_to_l2::lower, then walks the L2 ops, printing static HTML and emitting a slot for everything that depends on data.html_inject.rs,vapor_split.rsand its marker splicing are gone.decode_ssr_static_textanddecode_html_attribute_entities, and escaped withhtml-escape.:position.:attrslot is a whole attribute, so a renderer can leave it out fornulland false boolean attributes, as Vue does. A static attribute of the same name comes with it.<slot>outlets are slots.v-show,v-modelon<input>/<textarea>,v-html,v-text,v-bindobjects and dynamic attribute names are slots.v-models are:on/:modelbindings with where their element's start tag ends.root_attrs: true: gathers a component template's root element attributes into one slot, for fallthrough attribute merging.Vize.Errorwith a positionedVize.Diagnosticeach, such as1:7: can't parse the expression \a +`, and the error message lists them. Warnings, such as custom directives, are in the split's:diagnostics`.Vize.Diagnosticgains:severity.Vize.Diagnostic.to_code_diagnostic/2converts a diagnostic to Elixir'sCode.diagnosticshape for a file, offset to where the template starts in it.atoms::r#if()are deduplicated against{:if, "if"}declarations.Verification
VIZE_EX_BUILD=1 mix cipasses: credo, ex_dna, reach, dialyzer, clippy, and 130 tests.test/vize/split_template_test.exscovers each slot kind, entity round-tripping, attribute merging, slot placement among siblings, component slots includingv-sloton the component,root_attrs, and diagnostics with positions.playgroundbranch renders its test suite (307 tests, e2e included) and demo (14 e2e tests) on this split.