Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leptosfmt is removing or replacing some characters #84

Closed
svieujot opened this issue Oct 7, 2023 · 4 comments · Fixed by #85
Closed

Leptosfmt is removing or replacing some characters #84

svieujot opened this issue Oct 7, 2023 · 4 comments · Fixed by #85

Comments

@svieujot
Copy link

svieujot commented Oct 7, 2023

Running leptosfmt on the following file:

use leptos::*;

#[component]
pub fn FormatingGoneWrong() -> impl IntoView {

    view! {
        <div>
        // <span>{{ (position.course.correction > 0 ? "+" : "") + formattedNumber(radiansToDegrees(position.course.correction), 0, "?", false) }}°</span>
        </div>
        <div>
            Switch
        </div>
        <span class="mx-1">@</span>
        <span class="ms-3">Manœuvering aid</span>
    }
}

Generates this:

use leptos::*;

#[component]
pub fn FormatingGoneWrong() -> impl IntoView {

    view! {
        <div>// <span>{{ (position.course.correction > 0 ? "+" : "") + formattedNumber(radiansToDegrees(position.course.correction), 0, "?", false) }}°</span>
        </div>
        <div> Switc</div>
        <span class="mx-1">></span>
        <span class="ms-3">>Manœuvering a</span>
    }
}
  1. The word Switch has become Switc (and looses one more character at every subsequent run).
  2. The @ has been replaced with a >
  3. The word aid has been replaced by a

It looks like this is due to the use of UTF-8 characters: The ° in the span, and the œ in Manœuvering.
I have no explanation for the @ however.

@bram209
Copy link
Owner

bram209 commented Oct 8, 2023

It looks like this is due to the use of UTF-8 characters: The ° in the span, and the œ in Manœuvering.

That is indeed the cause

I have no explanation for the @ however.

The issue is that it uses proc_macro2's get_source_text which impl comes down to source[lo..hi], where lo and hi are character indexes but are used as byte indexes here... So multibyte characters anywhere in the source file will cause issues with unquoted text at the moment.

Also from proc_macros docs (https://docs.rs/proc-macro2/latest/proc_macro2/struct.Span.html#method.source_text):

Note: The observable result of a macro should only rely on the tokens and not on this source text. The result of this function is a best effort to be used for diagnostics only.

@bram209
Copy link
Owner

bram209 commented Oct 8, 2023

Ah I see now that the author of proc_macro2 pushed a fix 2 days ago :D

dtolnay/proc-macro2@7f5533d

@bram209
Copy link
Owner

bram209 commented Oct 8, 2023

ok, so the proc_macro2 crate is still having a bug, issue here: dtolnay/proc-macro2#410
will implement a workaround for now

@svieujot
Copy link
Author

svieujot commented Oct 8, 2023

@bram209 Works perfectly. Thank you !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants