From 3655e7c89e2353907e6fcd39a056a5d45c2004d6 Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Tue, 21 Mar 2023 07:55:36 -0500 Subject: [PATCH] throw an error instead of accepting attributes without commas --- packages/rsx/src/component.rs | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/packages/rsx/src/component.rs b/packages/rsx/src/component.rs index 508209adc..ad3f62d1a 100644 --- a/packages/rsx/src/component.rs +++ b/packages/rsx/src/component.rs @@ -230,26 +230,28 @@ impl Parse for ComponentField { let name = Ident::parse_any(input)?; input.parse::()?; - if name.to_string().starts_with("on") { - let content = ContentField::OnHandlerRaw(input.parse()?); - return Ok(Self { name, content }); - } - - if name == "key" { - let content = ContentField::Formatted(input.parse()?); - return Ok(Self { name, content }); - } - if input.peek(LitStr) { - let forked = input.fork(); - let t: LitStr = forked.parse()?; - // the string literal must either be the end of the input or a followed by a comma - if is_literal_foramtted(&t) { + let content = { + if name.to_string().starts_with("on") { + ContentField::OnHandlerRaw(input.parse()?) + } else if name == "key" { let content = ContentField::Formatted(input.parse()?); return Ok(Self { name, content }); + } else if input.peek(LitStr) { + let forked = input.fork(); + let t: LitStr = forked.parse()?; + // the string literal must either be the end of the input or a followed by a comma + if (forked.is_empty() || forked.peek(Token![,])) && is_literal_foramtted(&t) { + ContentField::Formatted(input.parse()?) + } 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 }) } }