Skip to content

Commit

Permalink
fix: formatting empty tags with prop spreading (#152)
Browse files Browse the repository at this point in the history
This commit addresses the issue where leptosfmt incorrectly removed
the '..' from empty tags with prop spreading, causing compilation
errors. The formatter now correctly preserves the '..' in expressions
like `<{..} class="foo" />.`

Fixes #151
  • Loading branch information
osmano807 authored Oct 25, 2024
1 parent 456ae04 commit 915d991
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
12 changes: 12 additions & 0 deletions formatter/src/formatter/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,16 @@ mod tests {
let f = format_attribute! { let(Item { name, value }) };
assert_snapshot!(f, @r#"let(Item { name, value })"#)
}

#[test]
fn prop_spreading_unnamed() {
let f = format_attribute! { {..} };
assert_snapshot!(f, @r#"{..}"#)
}

#[test]
fn prop_spreading_named() {
let f = format_attribute! { { ..some_props } };
assert_snapshot!(f, @r#"{..some_props}"#)
}
}
12 changes: 12 additions & 0 deletions formatter/src/formatter/mac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,16 @@ mod tests {
}
"#);
}

#[test]
fn unnamed_element_empty_props_spreading() {
let formatted = view_macro!(view! { <{..} class="foo" /> });
insta::assert_snapshot!(formatted, @r#"view! { <{..} class="foo" /> }"#);
}

#[test]
fn unnamed_element_named_props_spreading() {
let formatted = view_macro!(view! { <{..some_props} class="foo" /> });
insta::assert_snapshot!(formatted, @r#"view! { <{..some_props} class="foo" /> }"#);
}
}
6 changes: 5 additions & 1 deletion formatter/src/formatter/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ impl Formatter<'_> {
}

pub fn node_name(&mut self, name: &NodeName) {
self.printer.word(name.to_string());
if let NodeName::Block(block) = name {
self.node_value_block_expr(block, false, false);
} else {
self.printer.word(name.to_string());
}
}

pub fn node_block(&mut self, block: &NodeBlock) {
Expand Down

0 comments on commit 915d991

Please sign in to comment.