Skip to content

Commit 2c12256

Browse files
authored
feat: allow component names to be paths (#1725)
1 parent a821abf commit 2c12256

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

leptos_hot_reload/src/parsing.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rstml::node::NodeElement;
1+
use rstml::node::{NodeElement, NodeName};
22

33
///
44
/// Converts `syn::Block` to simple expression
@@ -42,10 +42,24 @@ pub fn value_to_string(value: &syn::Expr) -> Option<String> {
4242
}
4343
}
4444

45-
pub fn is_component_tag_name(name: &str) -> bool {
46-
name.starts_with(|c: char| c.is_ascii_uppercase())
45+
pub fn is_component_tag_name(name: &NodeName) -> bool {
46+
match name {
47+
NodeName::Path(path) => {
48+
!path.path.segments.is_empty()
49+
&& path
50+
.path
51+
.segments
52+
.last()
53+
.unwrap()
54+
.ident
55+
.to_string()
56+
.starts_with(|c: char| c.is_ascii_uppercase())
57+
}
58+
NodeName::Block(_) => false,
59+
NodeName::Punctuated(_) => false,
60+
}
4761
}
4862

4963
pub fn is_component_node(node: &NodeElement) -> bool {
50-
is_component_tag_name(&node.name().to_string())
64+
is_component_tag_name(node.name())
5165
}

leptos_macro/src/view/ide_helper.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ impl IdeTagHelper {
2424
/// Save stmts for tag name.
2525
/// Emit warning if tag is component.
2626
pub fn save_tag_completion(&mut self, name: &NodeName) {
27-
let tag_name = name.to_string();
28-
if is_component_tag_name(&tag_name) {
27+
if is_component_tag_name(name) {
2928
proc_macro_error::emit_warning!(
3029
name.span(),
3130
"BUG: Component tag is used in regular tag completion."

0 commit comments

Comments
 (0)