Skip to content

Commit

Permalink
Fix view! to handle dashed attributes with Rust keywords (#624)
Browse files Browse the repository at this point in the history
Switches view! AttributeName parser to Ident::parse_any to handle keywords in extended attribute names.

Fixes #620
  • Loading branch information
mekanoe authored Sep 6, 2023
1 parent abce04f commit 6bb700b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/sycamore-macro/src/view/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ impl Parse for AttributeName {
let tag = input.call(Ident::parse_any)?;
let mut extended = Vec::new();
while input.peek(Token![-]) {
extended.push((input.parse()?, input.parse()?));
extended.push((input.parse()?, input.call(Ident::parse_any)?));
}

Ok(Self { tag, extended })
Expand Down
3 changes: 3 additions & 0 deletions packages/sycamore-macro/tests/view/element-pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ fn compile_pass<G: Html>() {

// view! should correctly parenthesize the (1 + 2) when borrowing.
let _: View<G> = view! { cx, p { (1 + 2) } };

// view! should accept the pattern "-ref-" in an attribute name.
let _: View<G> = view! { cx, p(class="my-class", data-ref-me="my-value") };
});
}

Expand Down

0 comments on commit 6bb700b

Please sign in to comment.