Skip to content

Commit a19f0e3

Browse files
committed
chore: refactor
1 parent beb4e58 commit a19f0e3

File tree

2 files changed

+50
-53
lines changed

2 files changed

+50
-53
lines changed

packages/frender-style/src/style.rs

Lines changed: 21 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//! See [`style!`](crate::style!).
22
3-
pub use frender_const_expr::{array_len, const_marker};
4-
53
/// Styles separated by comma.
64
///
75
/// The macro input will be parsed as [style syntaxes](one) separated by comma.
@@ -23,57 +21,12 @@ pub use style as comma_separated;
2321
#[doc(hidden)]
2422
#[macro_export]
2523
macro_rules! style_const {
26-
(const $($rest:tt)*) => {{
27-
enum HasConstDeclarationList {}
28-
$crate::style::r#const! {
29-
#[const_marker(HasConstDeclarationList)]
30-
const $($rest)*
31-
}
32-
}};
33-
(
34-
#[$const_marker:ident $const_marker_body:tt]
35-
const $s:tt
36-
) => {
37-
$crate::style::r#const! {
38-
#[$const_marker $const_marker_body]
39-
const $s as _
24+
($($t:tt)*) => {
25+
$crate::style::__private::r#const! {
26+
#[const_impl_mod($crate::style::__private::const_impl)]
27+
$($t)*
4028
}
4129
};
42-
(
43-
#[$const_marker:ident $const_marker_body:tt]
44-
const $s:tt as $($const_ty:tt)*
45-
) => {{
46-
const CONST_EXPR: $crate::styles::constness::ConstDeclarationList::<
47-
$crate::style::const_marker::$const_marker!$const_marker_body
48-
> = {
49-
$crate::impl_has_const_declaration_list_for! {
50-
impl $crate::style::const_marker::$const_marker!$const_marker_body {
51-
const _: $crate::__style_infer_const_type![$s $($const_ty)*] = $s;
52-
}
53-
}
54-
55-
$crate::styles::constness::ConstDeclarationList()
56-
};
57-
58-
CONST_EXPR
59-
}};
60-
}
61-
62-
#[doc(hidden)]
63-
#[macro_export]
64-
macro_rules! __style_infer_const_type {
65-
({ [$($array:tt)*] } _) => {
66-
[$crate::styles::constness::StaticStr; $crate::style::array_len!([$($array)*])]
67-
};
68-
({ [$($array:tt)*] } [$item_ty:ty; _]) => {
69-
[$item_ty; $crate::__dom_tokens_array_len!([$($array)*])]
70-
};
71-
($block:tt _) => {
72-
$crate::styles::constness::StaticStr
73-
};
74-
($block:tt $ty:ty) => {
75-
$ty
76-
};
7730
}
7831

7932
/// ### Supported style syntaxes
@@ -150,6 +103,23 @@ pub mod syntax {
150103
}
151104
}
152105

106+
#[doc(hidden)]
107+
pub mod __private {
108+
#[doc(hidden)]
109+
pub use frender_const_expr::{const_marker, r#const};
110+
111+
#[doc(hidden)]
112+
pub mod const_impl {
113+
#[doc(hidden)]
114+
pub use crate::{
115+
impl_has_const_declaration_list_for as impl_marker_for,
116+
styles::constness::{
117+
ConstDeclarationList as ConstValue, HasConstDeclarationList as HasConstValue,
118+
},
119+
};
120+
}
121+
}
122+
153123
#[cfg(test)]
154124
mod tests {
155125
use crate::{

packages/frender-style/src/styles/constness.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,27 @@ impl DeclarationListInfo {
270270
}
271271
}
272272

273+
#[doc(hidden)]
274+
#[macro_export]
275+
macro_rules! __style_infer_const_type {
276+
($Ty:tt {$($braced:tt)*} ;) => {
277+
// unbrace
278+
$crate::__style_infer_const_type![$Ty $($braced)* ;]
279+
};
280+
([_] [$($array:tt)*] ;) => {
281+
[$crate::styles::constness::StaticStr; $crate::styles::constness::__private::array_len!([$($array)*])]
282+
};
283+
([[$item_ty:ty; _]] [$($array:tt)*] ;) => {
284+
[$item_ty; $crate::__dom_tokens_array_len!([$($array)*])]
285+
};
286+
([_] $($unbraced_or_unrecognized_and_semi:tt)*) => {
287+
$crate::styles::constness::StaticStr
288+
};
289+
([$Ty:ty] $($unbraced_and_semi:tt)*) => {
290+
$Ty
291+
};
292+
}
293+
273294
#[macro_export]
274295
macro_rules! impl_has_const_declaration_list_for {
275296
(impl <$(__)?> $($rest:tt)*) => {
@@ -279,12 +300,13 @@ macro_rules! impl_has_const_declaration_list_for {
279300
};
280301
(
281302
impl $for_ty:ty {
282-
const $NAME:tt: _ = $const_expr:expr;
303+
const $NAME:tt: $Ty:tt = $($const_expr_and_semi:tt)*
283304
}
284305
) => {
285306
$crate::impl_has_const_declaration_list_for! {
286307
impl $for_ty {
287-
const $NAME: $crate::styles::constness::StaticStr = $const_expr;
308+
const $NAME: $crate::__style_infer_const_type![[$Ty] $($const_expr_and_semi)*]
309+
= $($const_expr_and_semi)*
288310
}
289311
}
290312
};
@@ -586,8 +608,13 @@ pub type StaticStr = &'static str;
586608

587609
#[doc(hidden)]
588610
pub mod __private {
611+
#[doc(hidden)]
589612
pub use str;
590613

614+
#[doc(hidden)]
615+
pub use frender_const_expr::array_len;
616+
617+
#[doc(hidden)]
591618
pub const fn from_utf8(v: &[u8]) -> &str {
592619
match core::str::from_utf8(v) {
593620
Ok(v) => v,

0 commit comments

Comments
 (0)