Skip to content

Commit 4a02364

Browse files
Ensure classes containing number followed by dash or underscore are extracted correctly (#16980)
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 😃 <br/> ### 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 <[email protected]>
1 parent 9c59b07 commit 4a02364

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2020
### Fixed
2121

2222
- Ensure classes containing `--` are extracted correctly ([#16972](https://github.com/tailwindlabs/tailwindcss/pull/16972))
23+
- Ensure classes containing numbers followed by dash or underscore are extracted correctly ([#16980](https://github.com/tailwindlabs/tailwindcss/pull/16980))
2324

2425
## [4.0.10] - 2025-03-05
2526

crates/oxide/src/extractor/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,15 @@ mod tests {
833833
);
834834
}
835835

836+
// https://github.com/tailwindlabs/tailwindcss/issues/16978
837+
#[test]
838+
fn test_classes_containing_number_followed_by_dash_or_underscore() {
839+
assert_extract_sorted_candidates(
840+
r#"<div class="text-Title1_Strong"></div>"#,
841+
vec!["text-Title1_Strong"],
842+
);
843+
}
844+
836845
#[test]
837846
fn test_extract_css_variables() {
838847
for (input, expected) in [

crates/oxide/src/extractor/named_utility_machine.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ impl Machine for NamedUtilityMachine {
243243
}
244244

245245
// A number must be preceded by a `-`, `.` or another alphanumeric
246-
// character, and can be followed by a `.` or an alphanumeric character.
246+
// character, and can be followed by a `.` or an alphanumeric character or
247+
// dash or underscore.
247248
//
248249
// E.g.: `text-2xs`
249250
// ^^
@@ -272,6 +273,8 @@ impl Machine for NamedUtilityMachine {
272273
| Class::AlphaLower
273274
| Class::AlphaUpper
274275
| Class::Percent
276+
| Class::Underscore
277+
| Class::Dash
275278
) {
276279
return self.done(self.start_pos, cursor);
277280
}
@@ -395,6 +398,9 @@ mod tests {
395398
// With numbers
396399
("px-5", vec!["px-5"]),
397400
("px-2.5", vec!["px-2.5"]),
401+
// With number followed by dash or underscore
402+
("text-title1-strong", vec!["text-title1-strong"]),
403+
("text-title1_strong", vec!["text-title1_strong"]),
398404
// With trailing % sign
399405
("from-15%", vec!["from-15%"]),
400406
// Arbitrary value with bracket notation

0 commit comments

Comments
 (0)