From 3f1d5257344bbd06f9be1e923f3a9e15660604e6 Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Sat, 11 Mar 2023 18:27:50 -0600 Subject: [PATCH 1/4] make trailing commas in components optional --- packages/rsx/src/component.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/rsx/src/component.rs b/packages/rsx/src/component.rs index 5dc18e0e6..508209adc 100644 --- a/packages/rsx/src/component.rs +++ b/packages/rsx/src/component.rs @@ -243,16 +243,12 @@ impl Parse for ComponentField { 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) { + if is_literal_foramtted(&t) { let content = ContentField::Formatted(input.parse()?); return Ok(Self { name, content }); } } - if input.peek(LitStr) && input.peek2(LitStr) { - missing_trailing_comma!(input.span()); - } - let content = ContentField::ManExpr(input.parse()?); Ok(Self { name, content }) } From 3655e7c89e2353907e6fcd39a056a5d45c2004d6 Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Tue, 21 Mar 2023 07:55:36 -0500 Subject: [PATCH 2/4] 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 }) } } From c04ce2901e5812dfb7cf80655d26c6e2fc1ab3b7 Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Tue, 21 Mar 2023 07:59:25 -0500 Subject: [PATCH 3/4] fix the span the error reports under --- packages/rsx/src/component.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/rsx/src/component.rs b/packages/rsx/src/component.rs index ad3f62d1a..45078b65f 100644 --- a/packages/rsx/src/component.rs +++ b/packages/rsx/src/component.rs @@ -250,7 +250,7 @@ impl Parse for ComponentField { } }; if input.peek(LitStr) || input.peek(Ident) { - missing_trailing_comma!(input.span()); + missing_trailing_comma!(content.span()); } Ok(Self { name, content }) } From 71b5689b1ed65b8e36105d242b2701511c80a9c5 Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Tue, 21 Mar 2023 08:22:40 -0500 Subject: [PATCH 4/4] fix web router test build --- packages/router/tests/web_router.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/router/tests/web_router.rs b/packages/router/tests/web_router.rs index 9c4ed9712..13e2847a4 100644 --- a/packages/router/tests/web_router.rs +++ b/packages/router/tests/web_router.rs @@ -22,7 +22,7 @@ fn simple_test() { onchange: move |router: RouterContext| log::trace!("route changed to {:?}", router.current_location()), active_class: "is-active", Route { to: "/", Home {} } - Route { to: "blog" + Route { to: "blog", Route { to: "/", BlogList {} } Route { to: ":id", BlogPost {} } }