breaking: gate 'styly!(const scope...' behind the const-scoping feature.\nFor some reason it did only become a problem recently, but it appears that having lightningcss/grass unconditionally will break WASM builds by having getrandom dependency
This commit is contained in:
parent
aa0f426ecb
commit
4259330925
3 changed files with 150 additions and 97 deletions
|
|
@ -9,15 +9,20 @@ authors.workspace = true
|
|||
license.workspace = true
|
||||
|
||||
[dependencies]
|
||||
sabry_intrnl = { workspace = true }
|
||||
syn = { version = "^2", features = ["parsing"] }
|
||||
quote = { version = "^1" }
|
||||
proc-macro2 = { version = "^1", features = ["span-locations"] }
|
||||
regex = { version = "^1" }
|
||||
itertools = { version = "^0.14" }
|
||||
sabry_intrnl.workspace = true
|
||||
sabry_intrnl.features = ["scope"]
|
||||
syn.workspace = true
|
||||
syn.features = ["parsing"]
|
||||
quote.workspace = true
|
||||
proc-macro2.workspace = true
|
||||
proc-macro2.features = ["span-locations"]
|
||||
regex.workspace = true
|
||||
itertools.workspace = true
|
||||
cfg-if.workspace = true
|
||||
|
||||
[features]
|
||||
nightly = []
|
||||
const-compile = ["sabry_intrnl/compile"]
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
all-features = true
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ pub fn scssy_macro_impl(input: TokenStream, source_path: Option<PathBuf>) -> Tok
|
|||
}
|
||||
|
||||
let sourcesass = code.to_string();
|
||||
let macro_doc = format!("Arbitrary {:?} code declared with `scssy!`. Pretty usable in tandem with `usey!` and `buildy` at build time", syntax);
|
||||
let macro_doc = format!("Arbitrary {syntax:?} code declared with `scssy!`. Pretty usable in tandem with `usey!` and `buildy` at build time");
|
||||
|
||||
quote! {
|
||||
#[doc = #macro_doc]
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
use cfg_if::cfg_if;
|
||||
use itertools::Itertools;
|
||||
use proc_macro2::{Span, TokenStream};
|
||||
use quote::quote;
|
||||
use sabry_intrnl::{
|
||||
compiler::CompilerAdapter,
|
||||
config::SabryConfig,
|
||||
scoper::{apply_basic_rusty_member_gen_rules, ArbitraryScope, ScopedSelector},
|
||||
};
|
||||
|
|
@ -38,10 +38,7 @@ pub fn styly_macro_impl(input: TokenStream, source_path: Option<PathBuf>) -> Tok
|
|||
Err(e) => {
|
||||
return syn::Error::new(
|
||||
Span::call_site(),
|
||||
format!(
|
||||
"Could not read sabry configuration required by this macro: {:?}",
|
||||
e
|
||||
),
|
||||
format!("Could not read sabry configuration required by this macro: {e:?}",),
|
||||
)
|
||||
.to_compile_error()
|
||||
}
|
||||
|
|
@ -63,7 +60,7 @@ pub fn styly_macro_impl(input: TokenStream, source_path: Option<PathBuf>) -> Tok
|
|||
Err(e) => {
|
||||
return syn::Error::new(
|
||||
Span::call_site(),
|
||||
format!("Could not generate scope: {:?}", e),
|
||||
format!("Could not generate scope: {e:?}"),
|
||||
)
|
||||
.to_compile_error()
|
||||
}
|
||||
|
|
@ -127,7 +124,7 @@ pub fn styly_macro_impl(input: TokenStream, source_path: Option<PathBuf>) -> Tok
|
|||
})
|
||||
})
|
||||
.map(|(name, ident, html, css)| {
|
||||
let docs = format!("'{:?}' {}. CSS selector '{}'", ident, name, css);
|
||||
let docs = format!("'{ident:?}' {name}. CSS selector '{css}'");
|
||||
quote! {
|
||||
#[doc = #docs]
|
||||
#[allow(non_upper_case_globals)]
|
||||
|
|
@ -142,33 +139,44 @@ pub fn styly_macro_impl(input: TokenStream, source_path: Option<PathBuf>) -> Tok
|
|||
let wrp_docs = format!("wrapper class for '{}' scope. If you have any tagname selectors - they should live as children of element with this class applied.", &scope_ident);
|
||||
|
||||
if constant {
|
||||
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:?}"),
|
||||
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(),
|
||||
)
|
||||
.to_compile_error()
|
||||
}
|
||||
};
|
||||
.expect("BUG: We just converted valid Ident to string and uppercased");
|
||||
|
||||
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)*
|
||||
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 {
|
||||
return syn::Error::new(
|
||||
Span::call_site(),
|
||||
"`styly!(const scope...` requires `experimental-const-scoping` feature flag",
|
||||
)
|
||||
.to_compile_error();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in a new issue