Skip to content

Commit

Permalink
Merge #564
Browse files Browse the repository at this point in the history
564: html!: fix explicit return types in callbacks r=jstarry a=totorigolo

### Problem (see #560)
The html! macro didn't properly handle explicit return types in
callbacks, considering the '>' in '->' as the end of the HTML tag.

```rust
html! {
    <div onblur=|_| -> u32 0 />
    //               ^ here
}
```

Fixes: #560

Co-authored-by: Thomas Lacroix <toto.rigolo@free.fr>
  • Loading branch information
bors[bot] and totorigolo committed Aug 7, 2019
2 parents eafe4be + c6e1a39 commit 6cca6fe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 10 additions & 2 deletions crates/macro/src/html_tree/html_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ impl Parse for HtmlProp {
}

pub struct HtmlPropSuffix {
pub stream: TokenStream,
pub div: Option<Token![/]>,
pub gt: Token![>],
pub stream: TokenStream,
}

impl Parse for HtmlPropSuffix {
Expand Down Expand Up @@ -67,6 +67,14 @@ impl Parse for HtmlPropSuffix {
break;
}
}
'-' => {
if input.peek(Token![>]) {
// Handle explicit return types in callbacks (#560)
// We increase angle_count here in order to ignore
// the following >.
angle_count += 1;
}
}
_ => {}
};
}
Expand All @@ -77,6 +85,6 @@ impl Parse for HtmlPropSuffix {
let stream: proc_macro2::TokenStream = trees.into_iter().collect();
let stream = TokenStream::from(stream);

Ok(HtmlPropSuffix { div, gt, stream })
Ok(HtmlPropSuffix { stream, div, gt })
}
}
4 changes: 4 additions & 0 deletions tests/vtag_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,10 @@ fn it_checks_mixed_closing_tags() {
let b: VNode<CompInt> = html! { <div> <div onblur=|_| 3></div> </div> };
assert_eq!(a, b); // NB: assert_eq! doesn't (cannot) compare the closures

let b: VNode<CompInt> = html! { <div> <a onblur=|_| 0></a> </div> };
let a: VNode<CompInt> = html! { <div> <a onblur=|_| -> u32 { 0 } /> </div> };
assert_eq!(a, b); // NB: assert_eq! doesn't (cannot) compare the closures

// This is a known limitation of the html! macro:
//
// html! { <div> <img onblur=|_| 2 > 1 /> </div> }
Expand Down

0 comments on commit 6cca6fe

Please sign in to comment.