bram209 / leptosfmt

A formatter for the leptos view! macro
Apache License 2.0
271 stars 29 forks source link

Empty tag with properties doesn't compile after formatting #151

Closed osmano807 closed 4 weeks ago

osmano807 commented 1 month ago

Leptosfmt removes necessary formatting for prop spreading (new in Leptos 0.7). When trying to format <{..} class="a" /> it removes the .., formatting as <{} class="a" /> and the file doesn't compile anymore:

let form_control = view! { <{..} class="form-control" /> };
let size_class = view! { <{..} class="w-40" /> };

view! {
    <label {..form_control.clone()} {..size_class.clone()}>
    </label>
}

becomes

let form_control = view! { <{} class="form-control" /> };
let size_class = view! { <{} class="w-40" /> };

view! {
    <label {..form_control.clone()} {..size_class.clone()}>
    </label>
}
error: expected identifier, found `{`
 --> file.rs:5:33
  |
5 |     let form_control = view! { <{} class="form-control" /> };
  |                                 ^^ expected identifier

See also https://github.com/leptos-rs/leptos/blob/eba08ad5927478b1d600959abb5513119bccdb26/examples/spread/src/lib.rs for some examples of prop spreading using empty tags.

osmano807 commented 1 month ago

I've added a PR, I don't know if it's the correct approach to special case this in node_name but it appears to be working.