fix!: bring const scopes back
Some checks failed
cargo basic build-test / Sabry - latest (push) Has been cancelled
cargo basic build-test / Sabry - latset - examples (push) Has been cancelled
cargo basic build-test / Sabry - latset - examples-1 (push) Has been cancelled
cargo basic build-test / Sabry - latset - examples-2 (push) Has been cancelled
Some checks failed
cargo basic build-test / Sabry - latest (push) Has been cancelled
cargo basic build-test / Sabry - latset - examples (push) Has been cancelled
cargo basic build-test / Sabry - latset - examples-1 (push) Has been cancelled
cargo basic build-test / Sabry - latset - examples-2 (push) Has been cancelled
- replace grass with sasso - drop lightningcss - rearrange crate and workspace hierarchy & features
This commit is contained in:
parent
1c7ccc58fe
commit
0a0cbeee1a
4 changed files with 2614 additions and 768 deletions
|
|
@ -13,18 +13,21 @@ all-features = true
|
|||
rustdoc-args = ["--cfg", "docsrs"]
|
||||
|
||||
[dependencies]
|
||||
cfg-if.workspace = true
|
||||
## Workspace
|
||||
sabry_intrnl.workspace = true
|
||||
sabry_intrnl.features = ["config-manifest", "style-compiler"]
|
||||
## Css
|
||||
raffia.workspace = true
|
||||
## Util
|
||||
itertools.workspace = true
|
||||
regex.workspace = true
|
||||
## Codegen
|
||||
thiserror.workspace = true
|
||||
proc-macro2.workspace = true
|
||||
proc-macro2.features = ["span-locations"]
|
||||
quote.workspace = true
|
||||
raffia.workspace = true
|
||||
regex.workspace = true
|
||||
sabry_intrnl.workspace = true
|
||||
sabry_intrnl.features = ["scope"]
|
||||
syn.workspace = true
|
||||
syn.features = ["parsing"]
|
||||
|
||||
[features]
|
||||
const-compile = ["sabry_intrnl/compile"]
|
||||
nightly = []
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use std::{fmt::Debug, fs, path::PathBuf, str::FromStr};
|
|||
use proc_macro2::{Span, TokenStream};
|
||||
use quote::{ToTokens, TokenStreamExt, quote};
|
||||
use regex::Regex;
|
||||
use sabry_intrnl::syntax::ostrta::OneSyntaxToRuleThemAll;
|
||||
use sabry_intrnl::style::syntax::SyntaxKind;
|
||||
use syn::{Ident, LitStr, Token, braced, parse::Parse};
|
||||
|
||||
pub mod scssy;
|
||||
|
|
@ -96,9 +96,9 @@ impl ToString for ArbitraryStyleBlock {
|
|||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, Copy)]
|
||||
pub struct ArbitraryStyleSyntax(OneSyntaxToRuleThemAll);
|
||||
pub struct ArbitraryStyleSyntax(SyntaxKind);
|
||||
|
||||
impl From<ArbitraryStyleSyntax> for OneSyntaxToRuleThemAll {
|
||||
impl From<ArbitraryStyleSyntax> for SyntaxKind {
|
||||
fn from(value: ArbitraryStyleSyntax) -> Self {
|
||||
value.0
|
||||
}
|
||||
|
|
@ -107,8 +107,9 @@ impl From<ArbitraryStyleSyntax> for OneSyntaxToRuleThemAll {
|
|||
impl ToTokens for ArbitraryStyleSyntax {
|
||||
fn to_tokens(&self, tokens: &mut TokenStream) {
|
||||
match self.0 {
|
||||
OneSyntaxToRuleThemAll::Sass => tokens.append_all(quote! {"sass"}),
|
||||
OneSyntaxToRuleThemAll::Scss => tokens.append_all(quote! {"scss"}),
|
||||
SyntaxKind::Sass => tokens.append_all(quote! {"sass"}),
|
||||
SyntaxKind::Scss => tokens.append_all(quote! {"scss"}),
|
||||
SyntaxKind::Css => tokens.append_all(quote! {"css"}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -116,7 +117,7 @@ impl ToTokens for ArbitraryStyleSyntax {
|
|||
impl TryFrom<&str> for ArbitraryStyleSyntax {
|
||||
type Error = ();
|
||||
fn try_from(value: &str) -> Result<Self, Self::Error> {
|
||||
Ok(Self(OneSyntaxToRuleThemAll::try_from(value)?))
|
||||
Ok(Self(SyntaxKind::try_from(value)?))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use std::path::PathBuf;
|
|||
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::quote;
|
||||
use sabry_intrnl::scoper::ArbitraryScope;
|
||||
use sabry_intrnl::style::scope::ArbitraryScope;
|
||||
use syn::{Ident, parse::ParseStream};
|
||||
|
||||
use super::{ArbitraryStyleBlock, ArbitraryStyleSyntax};
|
||||
|
|
@ -67,12 +67,3 @@ impl MacroSyntax {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
// impl Parse for MacroSyntax {
|
||||
// fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
|
||||
// Self::parse_syn(input, None)
|
||||
// }
|
||||
// }
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
use cfg_if::cfg_if;
|
||||
use itertools::Itertools;
|
||||
use proc_macro2::{Span, TokenStream};
|
||||
use quote::quote;
|
||||
use sabry_intrnl::{
|
||||
config::SabryConfig,
|
||||
scoper::{ArbitraryScope, ScopedSelector, sanitize_css_member},
|
||||
conf::SabryConfig,
|
||||
style::{
|
||||
compiler::CompilerAdapter,
|
||||
scope::{ArbitraryScope, ScopedSelector, sanitize_css_member},
|
||||
},
|
||||
};
|
||||
use syn::{
|
||||
Ident, Token,
|
||||
|
|
@ -102,7 +104,7 @@ pub fn styly_macro_impl(input: TokenStream, source_path: PathBuf) -> TokenStream
|
|||
let ident = sanitize_css_member(&s);
|
||||
let fnident = syn::parse_str::<Ident>(format!("_{ident}").as_str())
|
||||
.expect("BUG: invalid ident for nesting selector formed");
|
||||
let formatstr = format!("{{c}}{}", &s);
|
||||
let formatstr = format!("{{c}}{}", s);
|
||||
let doc = format!("Nesting selector. Originated from '&{s}'");
|
||||
|
||||
quote! {
|
||||
|
|
@ -152,53 +154,42 @@ pub fn styly_macro_impl(input: TokenStream, source_path: PathBuf) -> TokenStream
|
|||
|
||||
let mod_docs = format!(
|
||||
"'{}' style scope. The hash class is `{}`",
|
||||
&scope_ident, &scope_wrapper_ident
|
||||
scope_ident, scope_wrapper_ident
|
||||
);
|
||||
let wrp_docs = format!(
|
||||
"hash class for '{}' scope. All HTML elements should have this class applied",
|
||||
&scope_ident
|
||||
scope_ident
|
||||
);
|
||||
|
||||
if constant {
|
||||
cfg_if! {
|
||||
if #[cfg(feature = "const-compile")] {
|
||||
use sabry_intrnl::compiler::CompilerAdapter;
|
||||
let compiler = CompilerAdapter::new(config.clone());
|
||||
let css = match compiler.compile_module(ms.syntax.0, &scope.hashed_code) {
|
||||
Ok(c) => c,
|
||||
Err(e) => {
|
||||
return syn::Error::new(
|
||||
ms.code.span,
|
||||
format!("Could not compile const inline: {e:?}"),
|
||||
)
|
||||
.to_compile_error()
|
||||
}
|
||||
};
|
||||
|
||||
let const_docs = format!("The compiled CSS style for {} scope", &scope_ident);
|
||||
let const_wrapper_ident = syn::parse_str::<Ident>(
|
||||
format!("{}_CSS", &scope_ident.to_string().to_uppercase()).as_str(),
|
||||
)
|
||||
.expect("BUG: We just converted valid Ident to string and uppercased");
|
||||
|
||||
quote! {
|
||||
#[doc = #const_docs]
|
||||
#scope_vis const #const_wrapper_ident: &str = #css ;
|
||||
#[doc = #wrp_docs]
|
||||
#scope_vis const #scope_wrapper_ident : &str = #scope_hash ;
|
||||
#[doc = #mod_docs]
|
||||
#scope_vis mod #scope_ident {
|
||||
#(#scope_members)*
|
||||
#(#special_nesting_members)*
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let compiler = CompilerAdapter::new(config.clone());
|
||||
let css = match compiler.compile_module(ms.syntax.0, &scope.hashed_code) {
|
||||
Ok(c) => c,
|
||||
Err(e) => {
|
||||
return syn::Error::new(
|
||||
Span::call_site(),
|
||||
"`styly!(const scope...` requires `experimental-const-scoping` feature flag",
|
||||
ms.code.span,
|
||||
format!("Could not compile const inline: {e:?}"),
|
||||
)
|
||||
.to_compile_error();
|
||||
}
|
||||
};
|
||||
|
||||
let const_docs = format!("The compiled CSS style for {} scope", scope_ident);
|
||||
let const_wrapper_ident = syn::parse_str::<Ident>(
|
||||
format!("{}_CSS", scope_ident.to_string().to_uppercase()).as_str(),
|
||||
)
|
||||
.expect("BUG: We just converted valid Ident to string and uppercased");
|
||||
|
||||
quote! {
|
||||
#[doc = #const_docs]
|
||||
#scope_vis const #const_wrapper_ident: &str = #css ;
|
||||
#[doc = #wrp_docs]
|
||||
#scope_vis const #scope_wrapper_ident : &str = #scope_hash ;
|
||||
#[doc = #mod_docs]
|
||||
#scope_vis mod #scope_ident {
|
||||
#(#scope_members)*
|
||||
#(#special_nesting_members)*
|
||||
}
|
||||
}
|
||||
} else {
|
||||
quote! {
|
||||
|
|
|
|||
Loading…
Reference in a new issue