Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/yew-macro/src/props/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ impl Parse for WithProps {
while !input.is_empty() {
// no need to check if it's followed by `=` because `with` isn't a special prop
if input.peek(kw::with) {
if let Some((with, expr)) = with_expr {
return Err(syn::Error::new_spanned(
{
let mut res = with.into_token_stream();
expr.to_tokens(&mut res);
res
},
"there are two `with <props>` definitions for this component (note: you can only define `with <props>` once)"
));
}
let with = input.parse::<kw::with>()?;
if input.is_empty() {
return Err(syn::Error::new_spanned(
Expand Down
2 changes: 2 additions & 0 deletions packages/yew-macro/tests/html_macro/html-component-fail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ fn compile_fail() {
html! { <Child with /> };
html! { <Child props /> };
html! { <Child with props > };
let (p1, p2);
html! { <Child with p1 with p2 /> };
html! { <Child with props ref=() ref=() /> };
html! { <Child with props ref=() ref=() value=1 /> };
html! { <Child with props ref=() value=1 ref=() /> };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ error: this opening tag has no corresponding closing tag
82 | html! { <Child with props > };
| ^^^^^^^^^^^^^^^^^^^

error: there are two `with <props>` definitions for this component (note: you can only define `with <props>` once)
--> $DIR/html-component-fail.rs:84:20
|
84 | html! { <Child with p1 with p2 /> };
| ^^^^^^^

error: `ref` can only be set once
--> $DIR/html-component-fail.rs:83:38
|
Expand Down