Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[yew-macro] Improve error message #1219

Merged
merged 1 commit into from
May 13, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion yew-macro/src/html_tree/html_component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,9 @@ impl Parse for Props {

input.parse::<Ident>()?;
props = Props::With(Box::new(WithProps {
props: input.parse::<Ident>()?,
props: input.parse::<Ident>().map_err(|_| {
syn::Error::new_spanned(&token, "`with` must be followed by an identifier")
})?,
node_ref: None,
key: None,
}));
Expand Down
9 changes: 4 additions & 5 deletions yew-macro/src/html_tree/html_prop.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<Self> {
let label = input.parse::<HtmlPropLabel>()?;
input.parse::<Token![=]>()?;
input
.parse::<Token![=]>()
.map_err(|_| syn::Error::new_spanned(&label, "this prop doesn't have a value"))?;
let value = input.parse::<Expr>()?;
// backwards compat
let _ = input.parse::<Token![,]>();
Expand Down
8 changes: 4 additions & 4 deletions yew-macro/tests/macro/html-component-fail.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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! { <Child with /> };
| ^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^
|
= 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! { <Child props /> };
Expand Down