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:
yiffyrusdev 2025-05-08 19:42:06 +05:00 • committed by spushk
commit 355465e8cf
Signed by: spushk
GPG key ID: 7797B761E105E8AA
2 changed files with 150 additions and 97 deletions

View file

@ -1,15 +1,14 @@
use base64::Engine;
use crate::config::SabryHashConfig;
use super::{apply_basic_rusty_member_gen_rules, ArbitraryScope};
/// Convenience wrapper for String-being-a-hash
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ScopeHash(String);
impl ScopeHash {
pub fn new(scope: &ArbitraryScope, config: &SabryHashConfig) -> Self {
#[cfg(feature = "scope")]
pub fn new(scope: &super::ArbitraryScope, config: &crate::config::SabryHashConfig) -> Self {
use base64::Engine;
use crate::scoper::apply_basic_rusty_member_gen_rules;
let mut hasher = blake3::Hasher::new();
if config.use_scope_name {

View file

@ -3,12 +3,8 @@ use std::fmt::Debug;
use cfg_if::cfg_if;
use hash::ScopeHash;
use raffia::{Span, Spanned};
use regex::Regex;
use crate::{
config::SabryHashConfig,
syntax::{ostrta::OneSyntaxToRuleThemAll, StylesheetAdapter},
};
use crate::syntax::{ostrta::OneSyntaxToRuleThemAll, StylesheetAdapter};
pub mod hash;
@ -56,7 +52,11 @@ impl<'s> ArbitraryScope<'s> {
/// Consume arbitrary scope and create a [HashedScope] in its basis
///
/// This function calls [HashedScope::new] under the hood
pub fn hashed(self, config: &SabryHashConfig) -> Result<HashedScope<'s>, ScopeError> {
#[cfg(feature = "scope")]
pub fn hashed(
self,
config: &crate::config::SabryHashConfig,
) -> Result<HashedScope<'s>, ScopeError> {
let hash = ScopeHash::new(&self, config);
HashedScope::new(hash, self)
}
@ -332,6 +332,7 @@ impl ScopedSelector {
}
/// Generate rusty member ident based on selector type and CSS ident
#[cfg(feature = "scope")]
pub fn gen_rusty_ident(&self) -> Option<syn::Ident> {
let arb = &self.as_arbitrary().ident;
let basic = apply_basic_rusty_member_gen_rules(arb);
@ -401,8 +402,9 @@ impl ScopedSelector {
}
}
#[cfg(feature = "scope")]
pub fn apply_basic_rusty_member_gen_rules(source: &str) -> String {
let omit_regex = Regex::new(r"(^\-)|(\-$)|[^a-zA-Z0-9\-\_]")
let omit_regex = regex::Regex::new(r"(^\-)|(\-$)|[^a-zA-Z0-9\-\_]")
.expect("BUG: can not build omition regex for rusty member generation");
// omit forbidden chars