~repos /tide-jsx

#rust#proc-macro#jsx

git clone https://pyrossh.dev/repos/tide-jsx.git

Tide + JSX


3f7f7653 Naitik Shah

5 years ago
support keywords like type/for without resorting to raw (#30)
render_macros/src/element_attribute.rs CHANGED
@@ -1,5 +1,6 @@
1
1
  use quote::quote;
2
2
  use std::hash::{Hash, Hasher};
3
+ use syn::ext::IdentExt;
3
4
  use syn::parse::{Parse, ParseStream, Result};
4
5
  use syn::spanned::Spanned;
5
6
 
@@ -93,7 +94,7 @@ impl Hash for ElementAttribute {
93
94
 
94
95
  impl Parse for ElementAttribute {
95
96
  fn parse(input: ParseStream) -> Result<Self> {
96
- let name = AttributeKey::parse_separated_nonempty(input)?;
97
+ let name = AttributeKey::parse_separated_nonempty_with(input, syn::Ident::parse_any)?;
97
98
  let not_punned = input.peek(syn::Token![=]);
98
99
 
99
100
  if !not_punned {
render_macros/src/element_attributes.rs CHANGED
@@ -57,7 +57,7 @@ impl ElementAttributes {
57
57
  impl Parse for ElementAttributes {
58
58
  fn parse(input: ParseStream) -> Result<Self> {
59
59
  let mut attributes: HashSet<ElementAttribute> = HashSet::new();
60
- while input.peek(syn::Ident) {
60
+ while input.peek(syn::Ident::peek_any) {
61
61
  let attribute = input.parse::<ElementAttribute>()?;
62
62
  let ident = attribute.ident();
63
63
  if attributes.contains(&attribute) {
render_tests/src/lib.rs CHANGED
@@ -35,6 +35,15 @@ fn works_with_raw_ident() {
35
35
  assert_eq!(actual, r#"<input type="text"/>"#);
36
36
  }
37
37
 
38
+ #[test]
39
+ fn works_with_keywords() {
40
+ use pretty_assertions::assert_eq;
41
+ use render::html;
42
+
43
+ assert_eq!(html! { <input type={"text"} /> }, r#"<input type="text"/>"#);
44
+ assert_eq!(html! { <label for={"me"} /> }, r#"<label for="me"/>"#);
45
+ }
46
+
38
47
  #[test]
39
48
  fn element_ordering() {
40
49
  use pretty_assertions::assert_eq;