From 4a0236471ee2168fb2c046ba239e97b1ad1ab2e7 Mon Sep 17 00:00:00 2001 From: "Hyunmin Woo (Hanul)" Date: Thu, 6 Mar 2025 19:44:43 +0900 Subject: [PATCH] Ensure classes containing number followed by dash or underscore are extracted correctly (#16980) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #16978, and also added support for dash. Classes like `text-theme1-primary` or `text-theme1_primary` should be treated as valid. If this approach is not aligned with the project’s direction or there are any concerns, please feel free to close or edit this PR 😃
### As is Classes conatining number followed by dash or underscore (e.g. `bg-theme1-primary`, `text-title1_strong`) are ignored, and utility classes are not generated. ### To be Classes conatining number followed by dash or underscore (e.g. `bg-theme1-primary`, `text-title1_strong`) are treated as valid tailwindcss classes --------- Co-authored-by: Philipp Spiess --- CHANGELOG.md | 1 + crates/oxide/src/extractor/mod.rs | 9 +++++++++ crates/oxide/src/extractor/named_utility_machine.rs | 8 +++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31c8de14d..9eee072c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Ensure classes containing `--` are extracted correctly ([#16972](https://github.com/tailwindlabs/tailwindcss/pull/16972)) +- Ensure classes containing numbers followed by dash or underscore are extracted correctly ([#16980](https://github.com/tailwindlabs/tailwindcss/pull/16980)) ## [4.0.10] - 2025-03-05 diff --git a/crates/oxide/src/extractor/mod.rs b/crates/oxide/src/extractor/mod.rs index 0a5b972dc..ba89bbf90 100644 --- a/crates/oxide/src/extractor/mod.rs +++ b/crates/oxide/src/extractor/mod.rs @@ -833,6 +833,15 @@ mod tests { ); } + // https://github.com/tailwindlabs/tailwindcss/issues/16978 + #[test] + fn test_classes_containing_number_followed_by_dash_or_underscore() { + assert_extract_sorted_candidates( + r#"
"#, + vec!["text-Title1_Strong"], + ); + } + #[test] fn test_extract_css_variables() { for (input, expected) in [ diff --git a/crates/oxide/src/extractor/named_utility_machine.rs b/crates/oxide/src/extractor/named_utility_machine.rs index a7fab0407..3483abe29 100644 --- a/crates/oxide/src/extractor/named_utility_machine.rs +++ b/crates/oxide/src/extractor/named_utility_machine.rs @@ -243,7 +243,8 @@ impl Machine for NamedUtilityMachine { } // A number must be preceded by a `-`, `.` or another alphanumeric - // character, and can be followed by a `.` or an alphanumeric character. + // character, and can be followed by a `.` or an alphanumeric character or + // dash or underscore. // // E.g.: `text-2xs` // ^^ @@ -272,6 +273,8 @@ impl Machine for NamedUtilityMachine { | Class::AlphaLower | Class::AlphaUpper | Class::Percent + | Class::Underscore + | Class::Dash ) { return self.done(self.start_pos, cursor); } @@ -395,6 +398,9 @@ mod tests { // With numbers ("px-5", vec!["px-5"]), ("px-2.5", vec!["px-2.5"]), + // With number followed by dash or underscore + ("text-title1-strong", vec!["text-title1-strong"]), + ("text-title1_strong", vec!["text-title1_strong"]), // With trailing % sign ("from-15%", vec!["from-15%"]), // Arbitrary value with bracket notation