Skip to content

Commit

Permalink
Ensure classes containing number followed by dash or underscore are e…
Browse files Browse the repository at this point in the history
…xtracted 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]>
  • Loading branch information
woohm402 and philipp-spiess authored Mar 6, 2025
1 parent 9c59b07 commit 4a02364
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions crates/oxide/src/extractor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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#"<div class="text-Title1_Strong"></div>"#,
vec!["text-Title1_Strong"],
);
}

#[test]
fn test_extract_css_variables() {
for (input, expected) in [
Expand Down
8 changes: 7 additions & 1 deletion crates/oxide/src/extractor/named_utility_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
// ^^
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4a02364

Please sign in to comment.