Avoid the accidental removal of comments inside expressions by dx fmt (#4410)
* Avoid the accidental removal of comments inside expressions by dx fmt * Rewrite the logic to pass failed tests * Removed unnecessary call to write_inline_comments * add failing test case * alter parsing a bit to handle more test cases * almost there... * fix * use threadlocal --------- Co-authored-by: Jonathan Kelley <jkelleyrtp@gmail.com>
This commit is contained in:
1 parent
88c693b2e4
commit
54d465a7b5
7 files changed
+213
-21
No files matched your search
@@ -9,8 +9,9 @@ impl Writer<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
const MARKER: &str = "dioxus_autofmt_block__________";
|
||||
const MARKER_REPLACE: &str = "dioxus_autofmt_block__________! {}";
|
||||
// we use weird unicode alternatives to avoid conflicts with the actual rsx! macro
|
||||
const MARKER: &str = "𝕣𝕤𝕩";
|
||||
const MARKER_REPLACE: &str = "𝕣𝕤𝕩! {}";
|
||||
|
||||
pub fn unparse_expr(expr: &Expr, src: &str, cfg: &IndentOptions) -> String {
|
||||
struct ReplaceMacros<'a> {
|
||||
@@ -42,7 +43,6 @@ pub fn unparse_expr(expr: &Expr, src: &str, cfg: &IndentOptions) -> String {
|
||||
}
|
||||
.unwrap();
|
||||
|
||||
// always push out the rsx to require a new line
|
||||
i.path = syn::parse_str(MARKER).unwrap();
|
||||
i.tokens = Default::default();
|
||||
|
||||
@@ -84,7 +84,7 @@ pub fn unparse_expr(expr: &Expr, src: &str, cfg: &IndentOptions) -> String {
|
||||
|
||||
// now we can replace the macros with the formatted blocks
|
||||
for fmted in replacer.formatted_stack.drain(..) {
|
||||
let is_multiline = fmted.contains('{');
|
||||
let is_multiline = fmted.ends_with('}') || fmted.contains('\n');
|
||||
let is_empty = fmted.trim().is_empty();
|
||||
|
||||
let mut out_fmt = String::from("rsx! {");
|
||||
|
||||
Reference in new issue
Block a user