throw an error instead of accepting attributes without commas

This commit is contained in:
Evan Almloff committed 2023-03-21 07:55:36 -05:00
1 parent db79168348
commit 3655e7c89e
1 file changed
+14 -12
+14 -12
View File
@@ -230,26 +230,28 @@ impl Parse for ComponentField {
let name = Ident::parse_any(input)?; let name = Ident::parse_any(input)?;
input.parse::<Token![:]>()?; input.parse::<Token![:]>()?;
let content = {
if name.to_string().starts_with("on") { if name.to_string().starts_with("on") {
let content = ContentField::OnHandlerRaw(input.parse()?); ContentField::OnHandlerRaw(input.parse()?)
return Ok(Self { name, content }); } else if name == "key" {
}
if name == "key" {
let content = ContentField::Formatted(input.parse()?); let content = ContentField::Formatted(input.parse()?);
return Ok(Self { name, content }); return Ok(Self { name, content });
} } else if input.peek(LitStr) {
if input.peek(LitStr) {
let forked = input.fork(); let forked = input.fork();
let t: LitStr = forked.parse()?; let t: LitStr = forked.parse()?;
// the string literal must either be the end of the input or a followed by a comma // the string literal must either be the end of the input or a followed by a comma
if is_literal_foramtted(&t) { if (forked.is_empty() || forked.peek(Token![,])) && is_literal_foramtted(&t) {
let content = ContentField::Formatted(input.parse()?); ContentField::Formatted(input.parse()?)
return Ok(Self { name, content }); } else {
ContentField::ManExpr(input.parse()?)
} }
} else {
ContentField::ManExpr(input.parse()?)
}
};
if input.peek(LitStr) || input.peek(Ident) {
missing_trailing_comma!(input.span());
} }
let content = ContentField::ManExpr(input.parse()?);
Ok(Self { name, content }) Ok(Self { name, content })
} }
} }