Extract candidates with variants in Clojure/ClojureScript keywords (#18338)

## Summary

Taking a shot at fixing my own complaint from #18336. 

Added failing test and fix for extracting classes containing a
pseudo-class from Clojure keywords. Eg., `:hover:text` ->
`"hover:text"`. This would previously produce `["hover", "text"]`.

## Test plan

- Add a failing test. 
- Verify that it fails with `cargo test`. 
- Add fix. 
- Verify that `cargo test` has no further complaints. 

ATT: @RobinMalfait

---------

Co-authored-by: Jordan Pittman <jordan@cryptica.me>
This commit is contained in:
Henrik Eneroth 2025-06-18 18:38:27 +02:00 • committed by GitHub
parent 63b5d7bdab
commit f4a7eea6cc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -42,7 +42,7 @@ impl PreProcessor for Clojure {
}
}
// A `.` surrounded by digits is a decimal number, so we don't want to replace it.
// A `.` surrounded by digits is a decimal number, so we don't want to replace it.
//
// E.g.:
// ```
@ -54,6 +54,18 @@ impl PreProcessor for Clojure {
// Keep the `.` as-is
}
// A `:` surrounded by letters denotes a variant. Keep as is.
//
// E.g.:
// ```
// lg:pr-6"
// ^
// ``
b':' if cursor.prev.is_ascii_alphanumeric() && cursor.next.is_ascii_alphanumeric() => {
// Keep the `:` as-is
}
b':' | b'.' => {
result[cursor.pos] = b' ';
}
@ -178,4 +190,16 @@ mod tests {
Clojure::test_extract_contains(input, vec!["flex", "gap-1.5", "p-1"]);
}
// https://github.com/tailwindlabs/tailwindcss/issues/18336
#[test]
fn test_extraction_of_pseudoclasses_from_keywords() {
let input = r#"
($ :div {:class [:flex :first:lg:pr-6 :first:2xl:pl-6 :group-hover/2:2xs:pt-6]} …)
:.hover:bg-white
"#;
Clojure::test_extract_contains(input, vec!["flex", "first:lg:pr-6", "first:2xl:pl-6", "group-hover/2:2xs:pt-6", "hover:bg-white"]);
}
}