feat(build): emit checked param tokens
Generate ParamName constants for handle data parameters so public code can refer to checked param metadata instead of stringly typed names. req: codegen/003
This commit is contained in:
@@ -186,6 +186,35 @@ impl core::fmt::Display for CssClass {
|
||||
}
|
||||
}
|
||||
|
||||
/// A generated, checked parameter token.
|
||||
/// req: codegen/003
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
|
||||
pub struct ParamName {
|
||||
name: &'static str,
|
||||
}
|
||||
|
||||
impl ParamName {
|
||||
pub const fn new(name: &'static str) -> Self {
|
||||
Self { name }
|
||||
}
|
||||
|
||||
pub const fn as_str(self) -> &'static str {
|
||||
self.name
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<str> for ParamName {
|
||||
fn as_ref(&self) -> &str {
|
||||
self.name
|
||||
}
|
||||
}
|
||||
|
||||
impl core::fmt::Display for ParamName {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
f.write_str(self.name)
|
||||
}
|
||||
}
|
||||
|
||||
/// A generated, checked component token.
|
||||
/// req: component/003
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use slhx_core::{
|
||||
event, navigate, redirect, replace, Atom, AtomSnapshot, AtomState, BuildFingerprint,
|
||||
ComponentRef, CssClass, CssClasses, Effect, EffectBatch, Form, Handle, IntoEffect, KeyedSlot,
|
||||
NavigateMode, Payload, ResourceKind, SafeHtml, ScopeKey, Slot,
|
||||
NavigateMode, ParamName, Payload, ResourceKind, SafeHtml, ScopeKey, Slot,
|
||||
};
|
||||
|
||||
#[test]
|
||||
@@ -93,6 +93,14 @@ fn slot_html_requires_explicit_safe_html() {
|
||||
assert_eq!(payload, Payload::Html(String::from("<strong>ok</strong>")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn param_names_format_generated_param_names() {
|
||||
// req: codegen/003
|
||||
let param = ParamName::new("todo_id");
|
||||
assert_eq!(param.as_str(), "todo_id");
|
||||
assert_eq!(param.to_string(), "todo_id");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn component_refs_format_generated_component_names() {
|
||||
// req: component/003
|
||||
|
||||
Reference in New Issue
Block a user