Skip to content

Commit

Permalink
feat: allow component names to be paths (#1725)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrvillage authored Sep 15, 2023
1 parent a821abf commit 2c12256
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
22 changes: 18 additions & 4 deletions leptos_hot_reload/src/parsing.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rstml::node::NodeElement;
use rstml::node::{NodeElement, NodeName};

///
/// Converts `syn::Block` to simple expression
Expand Down Expand Up @@ -42,10 +42,24 @@ pub fn value_to_string(value: &syn::Expr) -> Option<String> {
}
}

pub fn is_component_tag_name(name: &str) -> bool {
name.starts_with(|c: char| c.is_ascii_uppercase())
pub fn is_component_tag_name(name: &NodeName) -> bool {
match name {
NodeName::Path(path) => {
!path.path.segments.is_empty()
&& path
.path
.segments
.last()
.unwrap()
.ident
.to_string()
.starts_with(|c: char| c.is_ascii_uppercase())
}
NodeName::Block(_) => false,
NodeName::Punctuated(_) => false,
}
}

pub fn is_component_node(node: &NodeElement) -> bool {
is_component_tag_name(&node.name().to_string())
is_component_tag_name(node.name())
}
3 changes: 1 addition & 2 deletions leptos_macro/src/view/ide_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ impl IdeTagHelper {
/// Save stmts for tag name.
/// Emit warning if tag is component.
pub fn save_tag_completion(&mut self, name: &NodeName) {
let tag_name = name.to_string();
if is_component_tag_name(&tag_name) {
if is_component_tag_name(name) {
proc_macro_error::emit_warning!(
name.span(),
"BUG: Component tag is used in regular tag completion."
Expand Down

0 comments on commit 2c12256

Please sign in to comment.