From 163d66e9d75691f995634011663ffa22f3e0bfd9 Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Tue, 23 Jul 2024 19:57:15 +0200 Subject: [PATCH] Expand to a partial Component if a shorthand attribute starts with a capital letter (#2652) --- packages/rsx/src/rsx_block.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/rsx/src/rsx_block.rs b/packages/rsx/src/rsx_block.rs index 6fc507b2d..5aedd834e 100644 --- a/packages/rsx/src/rsx_block.rs +++ b/packages/rsx/src/rsx_block.rs @@ -139,8 +139,19 @@ impl RsxBlock { // Parse shorthand attributes // todo: this might cause complications with partial expansion... think more about the cases - // where we can imagine expansion and what better diagnostics we can providea - if content.peek(Ident) + // where we can imagine expansion and what better diagnostics we can provide + let looks_like_attribute = match content.fork().parse::() { + // If it is an ident, it is only a shorthand attribute if it starts with a lowercase letter + // Otherwise this is the start of a component + Ok(ident) => ident + .to_string() + .chars() + .next() + .unwrap() + .is_ascii_lowercase(), + Err(_) => false, + }; + if looks_like_attribute && !content.peek2(Brace) && !content.peek2(Token![:]) // regular attributes / components with generics && !content.peek2(Token![-]) // web components