Add JSX/XML-like tag syntax to the rsx! macro - #5730
Open
nicoburns wants to merge 2 commits into
Open
Conversation
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
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.
Summary
Adds a JSX/XML-like tag syntax to
rsx!, freely mixable with the existing block syntax (similar to dioxus-html-macro, but integrated into the one macro). A<token switchesBodyNode::parseinto tag mode:The new parser (
packages/rsx/src/jsx.rs) produces the exact sameElement/ComponentAST as the block syntax, so templates, hot-reloading, attribute merging, and diagnostics all behave identically. Element-vs-component tag names, string-literal text nodes,key, shorthand attributes (<div class>), custom/dashed attributes (data-foo="1","custom-attr"="x"), web components (<my-widget />), component paths/generics (<some::Outlet<R>>), and{..spread}all follow the existing rsx rules. Attribute values must be literals or braced expressions (attr={expr}); closing tags must match the opening tag or a spanned error is emitted.Supporting changes:
Element::from_parts/Component::from_partsextracted from the existingParseimpls so the tag parser can construct nodes with the same merge/validation logic (pure refactor).PartialExpr::parsenow also treats{expr}followed by<as a braced expression, so{children}directly before a closing tag parses correctly.Bracespanned to the open tag's>so brace-dependent consumers (completion hints, autofmt) treat the node as complete.Notes/limitations:
<>...</>) are rejected with a dedicated error (children can just be listed directly in rsx).dx fmt(autofmt) will currently rewrite tag syntax into the canonical block syntax, since it prints from the shared AST. If tag syntax should instead be preserved by the formatter, that would be a follow-up indioxus-autofmt.Tests: parser unit tests in
jsx.rs(elements, components, generics, web components, spreads, shorthand, mixing, error cases, codegen) plus end-to-end SSR rendering tests inpackages/ssr/tests/jsx_syntax.rs.Link to Devin session: https://dioxus.staging.devinenterprise.com/sessions/418cbef546c844b6b40c575b1ae28376
Requested by: @nicoburns