feat: implement comments in zero children nodes

This commit is contained in:
Jonathan Kelley committed 2023-01-10 17:47:58 -08:00
1 parent 6500a6d490
commit 1940855e39
9 files changed
+379 -336

No files matched your search

+7 -10
View File
@@ -19,8 +19,7 @@ use syn::{
ext::IdentExt,
parse::{Parse, ParseBuffer, ParseStream},
spanned::Spanned,
token, AngleBracketedGenericArguments, Error, Expr, Ident, LitStr, PathArguments, Result,
Token,
AngleBracketedGenericArguments, Error, Expr, Ident, LitStr, PathArguments, Result, Token,
};
#[derive(PartialEq, Eq, Clone, Debug, Hash)]
@@ -30,6 +29,7 @@ pub struct Component {
pub fields: Vec<ComponentField>,
pub children: Vec<BodyNode>,
pub manual_props: Option<Expr>,
pub brace: syn::token::Brace,
}
impl Component {
@@ -88,13 +88,9 @@ impl Parse for Component {
// if we see a `{` then we have a block
// else parse as a function-like call
if stream.peek(token::Brace) {
syn::braced!(content in stream);
} else {
syn::parenthesized!(content in stream);
}
let brace = syn::braced!(content in stream);
let mut body = Vec::new();
let mut fields = Vec::new();
let mut children = Vec::new();
let mut manual_props = None;
@@ -104,7 +100,7 @@ impl Parse for Component {
content.parse::<Token![..]>()?;
manual_props = Some(content.parse::<Expr>()?);
} else if content.peek(Ident) && content.peek2(Token![:]) && !content.peek3(Token![:]) {
body.push(content.parse::<ComponentField>()?);
fields.push(content.parse::<ComponentField>()?);
} else {
children.push(content.parse::<BodyNode>()?);
}
@@ -117,9 +113,10 @@ impl Parse for Component {
Ok(Self {
name,
prop_gen_args,
fields: body,
fields,
children,
manual_props,
brace,
})
}
}