Closed qrilka closed 9 months ago
And related error, after applying this workaround I get
// leptosfmt addes a space between dot and a brace
let skills = format!("{skills}.");
view! {
formatted as
let skills = format!("{skills}.");
view! {
// leptosfmt addes a space between dot and a brace
what could be the reason to move around comments?
And another thing: if I switch to /* */
for this comment it just gets stripped away altogether :(
Actually the odd thing about comment is even weirder than I described: this comment was also copied into a view!
which is below the closure the cited 3 lines are in :-\
And related error, after applying this workaround I get
// leptosfmt addes a space between dot and a brace let skills = format!("{skills}."); view! {
formatted as
let skills = format!("{skills}."); view! { // leptosfmt addes a space between dot and a brace
what could be the reason to move around comments?
syn
does not parse non-doc comments, they are treated (per specification) as whitespace.
In order to still provide (limited) support for non-doc comments, leptosfmt
tries to collect the whitespace between different the spans of each consecutive token. This currently only works for comments placed around rstml
nodes and not for comments placed inside rust code blocks that reside inside a view macro. (See the note about non-doc comments on the readme.md
for more info)
In your specific example, is this a view!
macro call that is nested inside a parent view?
Simple example:
$ echo 'view!{<p>Something: {something}.</p>}' | leptosfmt -s view! { <p>Something: {something} .</p> }
This extra space doesn't look good in the resulting HTML and I need to do
let something = format!{"{something}.");
as a workaround
Thanks for the bug report. This is indeed incorrect behaviour.
When this library was created, there was no support for unquoted text inside the view!
macro yet, which means it would format into:
view! { <p>"Something:" {something} "."</p> }
but with unquoted text, as you reported, this is problematic. I am currently traveling, but will try to push a fix soon!
In your specific example, is this a view! macro call that is nested inside a parent view?
Yes, it is
In your specific example, is this a view! macro call that is nested inside a parent view?
Yes, it is
Could you provide a minimal reproducible example and create a separate issue for it?
Simple example:
This extra space doesn't look good in the resulting HTML and I need to do
let something = format!{"{something}.");
as a workaround