mirror of
https://github.com/DioxusLabs/dioxus
synced 2025-03-01 05:47:23 +00:00
refactor: simplify and organize the errors
This commit is contained in:
parent
b8573bc4dd
commit
1f065acb4c
4 changed files with 23 additions and 35 deletions
|
@ -199,8 +199,7 @@ impl Parse for ComponentField {
|
||||||
}
|
}
|
||||||
|
|
||||||
if input.peek(LitStr) && input.peek2(LitStr) {
|
if input.peek(LitStr) && input.peek2(LitStr) {
|
||||||
let item = input.parse::<LitStr>().unwrap();
|
attr_after_element!(input.span());
|
||||||
proc_macro_error::emit_error!(item, "this attribute is missing a trailing comma")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let content = ContentField::ManExpr(input.parse()?);
|
let content = ContentField::ManExpr(input.parse()?);
|
||||||
|
|
|
@ -63,12 +63,8 @@ impl Parse for Element {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo: add a message saying you need to include commas between fields
|
|
||||||
if content.parse::<Token![,]>().is_err() {
|
if content.parse::<Token![,]>().is_err() {
|
||||||
proc_macro_error::emit_error!(
|
missing_trailing_comma!(ident);
|
||||||
ident,
|
|
||||||
"this attribute is missing a trailing comma"
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -126,10 +122,7 @@ impl Parse for Element {
|
||||||
|
|
||||||
// todo: add a message saying you need to include commas between fields
|
// todo: add a message saying you need to include commas between fields
|
||||||
if content.parse::<Token![,]>().is_err() {
|
if content.parse::<Token![,]>().is_err() {
|
||||||
proc_macro_error::emit_error!(
|
missing_trailing_comma!(ident);
|
||||||
ident,
|
|
||||||
"this attribute is missing a trailing comma"
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -139,33 +132,11 @@ impl Parse for Element {
|
||||||
|
|
||||||
while !content.is_empty() {
|
while !content.is_empty() {
|
||||||
if (content.peek(LitStr) && content.peek2(Token![:])) && !content.peek3(Token![:]) {
|
if (content.peek(LitStr) && content.peek2(Token![:])) && !content.peek3(Token![:]) {
|
||||||
let ident = content.parse::<LitStr>().unwrap();
|
attr_after_element!(content.span());
|
||||||
let name = ident.value();
|
|
||||||
proc_macro_error::emit_error!(
|
|
||||||
ident, "this attribute `{}` is in the wrong place", name;
|
|
||||||
help =
|
|
||||||
"all attribute fields must be placed above children elements
|
|
||||||
|
|
||||||
div {
|
|
||||||
attr: \"...\", <---- attribute is above children
|
|
||||||
div { } <---- children are below attributes
|
|
||||||
}";
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (content.peek(Ident) && content.peek2(Token![:])) && !content.peek3(Token![:]) {
|
if (content.peek(Ident) && content.peek2(Token![:])) && !content.peek3(Token![:]) {
|
||||||
let ident = content.parse::<Ident>().unwrap();
|
attr_after_element!(content.span());
|
||||||
let name = ident.to_string();
|
|
||||||
proc_macro_error::emit_error!(
|
|
||||||
ident, "this attribute `{}` is in the wrong place", name;
|
|
||||||
help =
|
|
||||||
"all attribute fields must be placed above children elements
|
|
||||||
|
|
||||||
div {
|
|
||||||
attr: \"...\", <---- attribute is above children
|
|
||||||
div { } <---- children are below attributes
|
|
||||||
}";
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
children.push(content.parse::<BodyNode>()?);
|
children.push(content.parse::<BodyNode>()?);
|
||||||
|
|
15
packages/core-macro/src/rsx/errors.rs
Normal file
15
packages/core-macro/src/rsx/errors.rs
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
macro_rules! missing_trailing_comma {
|
||||||
|
($span:expr) => {
|
||||||
|
proc_macro_error::emit_error!($span, "missing trailing comma")
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! attr_after_element {
|
||||||
|
($span:expr) => {
|
||||||
|
proc_macro_error::emit_error!(
|
||||||
|
$span,
|
||||||
|
"expected element";
|
||||||
|
help = "move the attribute above all the children and text elements"
|
||||||
|
)
|
||||||
|
};
|
||||||
|
}
|
|
@ -11,6 +11,9 @@
|
||||||
//!
|
//!
|
||||||
//! Any errors in using rsx! will likely occur when people start using it, so the first errors must be really helpful.
|
//! Any errors in using rsx! will likely occur when people start using it, so the first errors must be really helpful.
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
mod errors;
|
||||||
|
|
||||||
mod component;
|
mod component;
|
||||||
mod element;
|
mod element;
|
||||||
mod node;
|
mod node;
|
||||||
|
|
Loading…
Add table
Reference in a new issue