瀏覽代碼

Expand to a partial Component if a shorthand attribute starts with a capital letter (#2652)

Evan Almloff 11 月之前
父節點
當前提交
163d66e9d7
共有 1 個文件被更改,包括 13 次插入2 次删除
  1. 13 2
      packages/rsx/src/rsx_block.rs

+ 13 - 2
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::<Ident>() {
+                // 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