Skip to content

Commit

Permalink
Merge pull request #141 from ChieloNewctle/exclude-cfg-js-sys-from-ex…
Browse files Browse the repository at this point in the history
…pansion
  • Loading branch information
jprochazk authored Jan 10, 2025
2 parents 0c8823f + 584b0bf commit 7f351cb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion garde/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ email = ["regex"]
email-idna = ["dep:idna"]
regex = ["dep:regex", "dep:once_cell", "garde_derive?/regex"]
pattern = ["regex"] # for backward compatibility with <0.14.0
js-sys = ["dep:js-sys"]
js-sys = ["dep:js-sys", "garde_derive?/js-sys"]
rust_decimal = ["dep:rust_decimal"]

[dependencies]
Expand Down
1 change: 1 addition & 0 deletions garde_derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ proc-macro = true

[features]
regex = ["dep:regex"]
js-sys = []

[dependencies]
syn = { version = "2", features = ["full", "derive"] }
Expand Down
11 changes: 8 additions & 3 deletions garde_derive/src/emit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,18 +304,16 @@ impl ToTokens for Rules<'_> {
}
Pattern(pat) => match pat {
model::ValidatePattern::Expr(expr) => quote_spanned!(expr.span() => (&#expr,)),
#[cfg(feature = "regex")]
#[cfg(all(feature = "regex", feature = "js-sys"))]
model::ValidatePattern::Lit(s) => quote!({
#[cfg(not(all(
feature = "js-sys",
target_arch = "wasm32",
target_os = "unknown"
)))]
static PATTERN: #rules_mod::pattern::regex::StaticPattern =
#rules_mod::pattern::regex::init_pattern!(#s);

#[cfg(all(
feature = "js-sys",
target_arch = "wasm32",
target_os = "unknown"
))]
Expand All @@ -324,6 +322,13 @@ impl ToTokens for Rules<'_> {

(&PATTERN,)
}),
#[cfg(all(feature = "regex", not(feature = "js-sys")))]
model::ValidatePattern::Lit(s) => quote!({
static PATTERN: #rules_mod::pattern::regex::StaticPattern =
#rules_mod::pattern::regex::init_pattern!(#s);

(&PATTERN,)
}),
},
};

Expand Down

0 comments on commit 7f351cb

Please sign in to comment.