diff --git a/CHANGELOG.md b/CHANGELOG.md index 31c8de14d10a..9eee072c1ddd 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 0a5b972dcb08..ba89bbf9063d 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 a7fab0407a64..3483abe29c1e 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