Add optional attributes

This commit is contained in:
Evan Almloff committed 2023-09-18 19:50:02 -05:00
1 parent 9f1c735cf1
commit d297e2baa2
6 files changed
+171 -57

No files matched your search

+10 -25
View File
@@ -11,7 +11,7 @@ use syn::{
parse::{Parse, ParseBuffer, ParseStream},
punctuated::Punctuated,
spanned::Spanned,
Expr, Ident, LitStr, Result, Token,
Ident, LitStr, Result, Token,
};
// =======================================
@@ -51,13 +51,7 @@ impl Parse for Element {
content.parse::<Token![:]>()?;
let value = if content.peek(LitStr) {
let value = content.parse()?;
ElementAttrValue::AttrLiteral(value)
} else {
let value = content.parse::<Expr>()?;
ElementAttrValue::AttrExpr(value)
};
let value = content.parse::<ElementAttrValue>()?;
attributes.push(ElementAttrNamed {
el_name: el_name.clone(),
attr: ElementAttr {
@@ -100,23 +94,14 @@ impl Parse for Element {
key = Some(content.parse()?);
}
_ => {
if content.peek(LitStr) {
attributes.push(ElementAttrNamed {
el_name: el_name.clone(),
attr: ElementAttr {
name: ElementAttrName::BuiltIn(name),
value: ElementAttrValue::AttrLiteral(content.parse()?),
},
});
} else {
attributes.push(ElementAttrNamed {
el_name: el_name.clone(),
attr: ElementAttr {
name: ElementAttrName::BuiltIn(name),
value: ElementAttrValue::AttrExpr(content.parse()?),
},
});
}
let value = content.parse::<ElementAttrValue>()?;
attributes.push(ElementAttrNamed {
el_name: el_name.clone(),
attr: ElementAttr {
name: ElementAttrName::BuiltIn(name),
value,
},
});
}
}
}