diff --git a/yew-macro/src/html_tree/html_component.rs b/yew-macro/src/html_tree/html_component.rs index 6efdd87d764..ecbbc014c66 100644 --- a/yew-macro/src/html_tree/html_component.rs +++ b/yew-macro/src/html_tree/html_component.rs @@ -398,7 +398,9 @@ impl Parse for Props { input.parse::()?; props = Props::With(Box::new(WithProps { - props: input.parse::()?, + props: input.parse::().map_err(|_| { + syn::Error::new_spanned(&token, "`with` must be followed by an identifier") + })?, node_ref: None, key: None, })); diff --git a/yew-macro/src/html_tree/html_prop.rs b/yew-macro/src/html_tree/html_prop.rs index 1744f710854..538b146186c 100644 --- a/yew-macro/src/html_tree/html_prop.rs +++ b/yew-macro/src/html_tree/html_prop.rs @@ -1,6 +1,5 @@ use crate::html_tree::HtmlDashedName as HtmlPropLabel; use crate::{Peek, PeekValue}; -use boolinator::Boolinator; use proc_macro::TokenStream; use proc_macro2::TokenTree; use syn::buffer::Cursor; @@ -14,16 +13,16 @@ pub struct HtmlProp { impl PeekValue<()> for HtmlProp { fn peek(cursor: Cursor) -> Option<()> { - let (_, cursor) = HtmlPropLabel::peek(cursor)?; - let (punct, _) = cursor.punct()?; - (punct.as_char() == '=').as_option() + HtmlPropLabel::peek(cursor).map(|_| ()) } } impl Parse for HtmlProp { fn parse(input: ParseStream) -> ParseResult { let label = input.parse::()?; - input.parse::()?; + input + .parse::() + .map_err(|_| syn::Error::new_spanned(&label, "this prop doesn't have a value"))?; let value = input.parse::()?; // backwards compat let _ = input.parse::(); diff --git a/yew-macro/tests/macro/html-component-fail.stderr b/yew-macro/tests/macro/html-component-fail.stderr index 39dd21f9478..1a978df97cc 100644 --- a/yew-macro/tests/macro/html-component-fail.stderr +++ b/yew-macro/tests/macro/html-component-fail.stderr @@ -14,15 +14,15 @@ error: expected identifier | = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) -error: unexpected end of input, expected identifier - --> $DIR/html-component-fail.rs:81:5 +error: `with` must be followed by an identifier + --> $DIR/html-component-fail.rs:81:20 | 81 | html! { }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^ | = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) -error: unexpected token +error: this prop doesn't have a value --> $DIR/html-component-fail.rs:82:20 | 82 | html! { };