~repos /tide-jsx

#rust#proc-macro#jsx

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

Tide + JSX


02548be3 Naitik Shah

5 years ago
Eliminate unused brace errors & unused import (#25)
render/src/text_element.rs CHANGED
@@ -1,6 +1,6 @@
1
+ use crate::html_escaping::escape_html;
1
2
  use crate::Render;
2
3
  use std::fmt::{Result, Write};
3
- use crate::html_escaping::escape_html;
4
4
 
5
5
  impl Render for String {
6
6
  fn render_into<W: Write>(self, writer: &mut W) -> Result {
render_macros/src/child.rs CHANGED
@@ -12,7 +12,12 @@ impl ToTokens for Child {
12
12
  match self {
13
13
  Self::Element(element) => element.to_tokens(tokens),
14
14
  Self::RawBlock(block) => {
15
+ let ts = if block.stmts.len() == 1 {
16
+ let first = &block.stmts[0];
17
+ quote!(#first)
18
+ } else {
15
- let ts = quote! { #block };
19
+ quote!(#block)
20
+ };
16
21
  ts.to_tokens(tokens);
17
22
  }
18
23
  }
render_macros/src/children.rs CHANGED
@@ -30,7 +30,7 @@ impl Children {
30
30
  1 => quote! { Some(#(#children_quotes),*) },
31
31
  _ => {
32
32
  let mut iter = children_quotes.iter();
33
-
33
+
34
34
  let first = iter.next().unwrap();
35
35
  let second = iter.next().unwrap();
36
36
 
render_macros/src/element_attribute.rs CHANGED
@@ -23,7 +23,14 @@ impl ElementAttribute {
23
23
 
24
24
  pub fn value_tokens(&self) -> proc_macro2::TokenStream {
25
25
  match self {
26
- Self::WithValue(_, value) => quote!(#value),
26
+ Self::WithValue(_, value) => {
27
+ if value.stmts.len() == 1 {
28
+ let first = &value.stmts[0];
29
+ quote!(#first)
30
+ } else {
31
+ quote!(#value)
32
+ }
33
+ }
27
34
  Self::Punned(ident) => quote!(#ident),
28
35
  }
29
36
  }
render_macros/src/function_component.rs CHANGED
@@ -10,9 +10,7 @@ pub fn create_function_component(f: syn::ItemFn) -> TokenStream {
10
10
  let vis = f.vis;
11
11
 
12
12
  let inputs_block = if inputs.len() > 0 {
13
- let input_names: Vec<_> = inputs
13
+ let input_names: Vec<_> = inputs.iter().collect();
14
- .iter()
15
- .collect();
16
14
 
17
15
  quote!({ #(#vis #input_names),* })
18
16
  } else {
render_tests/src/lib.rs CHANGED
@@ -33,8 +33,8 @@ pub fn works_with_raw_ident() {
33
33
 
34
34
  #[test]
35
35
  pub fn element_ordering() {
36
- use pretty_assertions::assert_eq;
36
+ use pretty_assertions::assert_eq;
37
- use render::{html, raw};
37
+ use render::html;
38
38
 
39
39
  let actual = html! {
40
40
  <ul>
@@ -58,7 +58,10 @@ pub fn element_ordering() {
58
58
  </div>
59
59
  };
60
60
 
61
+ assert_eq!(
62
+ deep,
61
- assert_eq!(deep, "<div><h1>A list</h1><hr/><ul><li>1</li><li>2</li><li>3</li></ul></div>");
63
+ "<div><h1>A list</h1><hr/><ul><li>1</li><li>2</li><li>3</li></ul></div>"
64
+ );
62
65
  }
63
66
 
64
67
  mod kaki {
@@ -111,8 +114,8 @@ mod kaki {
111
114
 
112
115
  #[test]
113
116
  fn externals_test() {
114
- use pretty_assertions::assert_eq;
115
117
  use crate::other::ExternalPage;
118
+ use pretty_assertions::assert_eq;
116
119
 
117
120
  let actual = render::html! {
118
121
  <ExternalPage title={"Home"} subtitle={"Foo"}>
@@ -135,30 +138,30 @@ mod kaki {
135
138
  }
136
139
 
137
140
  /// ## Other
138
- ///
141
+ ///
139
142
  /// Module for testing component visibility when imported from other modules.
140
143
 
141
144
  mod other {
142
- use render::html::HTML5Doctype;
145
+ use render::html::HTML5Doctype;
143
- use render::{ component, rsx, Render };
146
+ use render::{component, rsx, Render};
144
-
147
+
145
- #[component]
148
+ #[component]
146
- pub fn ExternalPage<'title, 'subtitle, Children: Render>(
149
+ pub fn ExternalPage<'title, 'subtitle, Children: Render>(
147
- title: &'title str,
150
+ title: &'title str,
148
- subtitle: &'subtitle str,
151
+ subtitle: &'subtitle str,
149
- children: Children
152
+ children: Children,
150
- ) {
153
+ ) {
151
- rsx! {
154
+ rsx! {
152
- <>
155
+ <>
153
- <HTML5Doctype />
156
+ <HTML5Doctype />
154
- <html>
157
+ <html>
155
- <head><title>{title}</title></head>
158
+ <head><title>{title}</title></head>
156
- <body>
159
+ <body>
157
- <h1>{subtitle}</h1>
160
+ <h1>{subtitle}</h1>
158
- {children}
161
+ {children}
159
- </body>
162
+ </body>
160
- </html>
163
+ </html>
161
- </>
164
+ </>
162
- }
165
+ }
163
- }
166
+ }
164
- }
167
+ }