sycamore-rs / sycamore

A library for creating reactive web apps in Rust and WebAssembly
https://sycamore-rs.netlify.app
MIT License
2.79k stars 148 forks source link

Refactor view! by extracting parsing logic from codegen into a new crate #649

Closed lukechu10 closed 10 months ago

lukechu10 commented 10 months ago

This PR adds the sycamore-view-parser crate which contains all the parsing logic for the view! ~and node!~ macros.

This new sycamore-view-parser crate is completely backend-agnostic and contains no knowledge of HTML and SVG tags whatsoever. In fact, it does not even distinguish between elements and components.

The macros view! ~and node!~ are now implemented using this new crate and are HTML/SVG specific for codegen.

For creating custom backends, it will be expected to provide a proc-macro crate which uses sycamore-view-parser and which produces the appropriate codegen for the backend with the same familiar sycamore DSL syntax.

Finally, this also unifies the syntax for elements and components since no distinction is made between the two during parsing.

Update: The node! macro has also been removed by this PR. There has never really been an use-case for node! and it can simply be replaced by View::as_node.

codecov[bot] commented 10 months ago

Codecov Report

Attention: 37 lines in your changes are missing coverage. Please review.

Comparison is base (16acf8e) 61.12% compared to head (93e15ed) 61.06%.

Files Patch % Lines
packages/sycamore-macro/src/view.rs 93.20% 35 Missing :warning:
packages/sycamore-view-parser/src/ir.rs 80.00% 1 Missing :warning:
packages/sycamore-view-parser/src/parse.rs 99.10% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #649 +/- ## ========================================== - Coverage 61.12% 61.06% -0.06% ========================================== Files 55 54 -1 Lines 9059 8985 -74 ========================================== - Hits 5537 5487 -50 + Misses 3522 3498 -24 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.