/// Test: Module System - Helper Module
/// Tests: pub exports, module-private functions
// Public struct (exported)
pub struct ComponentInfo {
pub name: Str,
pub props: Vec<Str>,
pub is_functional: bool,
}
// Public enum (exported)
pub enum ComponentType {
Functional,
Class,
ForwardRef,
Memo,
}
// Public function (exported)
pub fn get_component_name(node: &FunctionDeclaration) -> Str {
node.id.name.clone()
}
// Public function with Option return
pub fn extract_first_param(node: &FunctionDeclaration) -> Option<Str> {
if node.params.len() > 0 {
if let Pattern::Identifier(id) = &node.params[0] {
return Some(id.name.clone());
}
}
None
}
// Public function to check component
pub fn is_react_component(name: &Str) -> bool {
if name.is_empty() {
return false;
}
let first = name.chars().next().unwrap();
first.is_uppercase()
}
// Public function to create info
pub fn create_component_info(name: Str) -> ComponentInfo {
ComponentInfo {
name: name,
props: vec![],
is_functional: true,
}
}
// Private function (not exported)
fn internal_validate(name: &Str) -> bool {
name.len() > 1 && !name.contains("$")
}
// Private helper
fn sanitize_name(name: &Str) -> Str {
if internal_validate(name) {
name.clone()
} else {
"InvalidComponent".into()
}
}
// Public function using private helpers
pub fn safe_component_name(name: &Str) -> Str {
sanitize_name(name)
}