Fix non-brace delimeters in nested macro formatting (#2831)
This commit is contained in:
1 parent
d649b0c54d
commit
851abe82d5
6 files changed
+255
-6
No files matched your search
@@ -1,5 +1,5 @@
|
||||
use dioxus_rsx::CallBody;
|
||||
use syn::{parse::Parser, visit_mut::VisitMut, Expr, File, Item};
|
||||
use syn::{parse::Parser, visit_mut::VisitMut, Expr, File, Item, MacroDelimiter};
|
||||
|
||||
use crate::{IndentOptions, Writer};
|
||||
|
||||
@@ -46,6 +46,11 @@ pub fn unparse_expr(expr: &Expr, src: &str, cfg: &IndentOptions) -> String {
|
||||
i.path = syn::parse_str(MARKER).unwrap();
|
||||
i.tokens = Default::default();
|
||||
|
||||
// make sure to transform the delimiter to a brace so the marker can be found
|
||||
// an alternative approach would be to use multiple different markers that are not
|
||||
// sensitive to the delimiter.
|
||||
i.delimiter = MacroDelimiter::Brace(Default::default());
|
||||
|
||||
// Push out the indent level of the formatted block if it's multiline
|
||||
if multiline || formatted.contains('\n') {
|
||||
formatted = formatted
|
||||
|
||||
@@ -72,9 +72,11 @@ impl<'a> Writer<'a> {
|
||||
|
||||
/// Check if the rsx call is short enough to be inlined
|
||||
pub(crate) fn is_short_rsx_call(roots: &[BodyNode]) -> bool {
|
||||
match roots.len() {
|
||||
0 => true,
|
||||
1 if matches!(roots[0], BodyNode::Text(_)) => true,
|
||||
// eventually I want to use the _text length, so shutup now
|
||||
#[allow(clippy::match_like_matches_macro)]
|
||||
match roots {
|
||||
[] => true,
|
||||
[BodyNode::Text(_text)] => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user