From 506e480131b2f45d545900d909455bd40c6f4633 Mon Sep 17 00:00:00 2001 From: "Hyunmin Woo (Hanul)" Date: Thu, 6 Mar 2025 17:26:04 +0900 Subject: [PATCH 1/4] allow number followed by dash or underscore --- crates/oxide/src/extractor/named_utility_machine.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/oxide/src/extractor/named_utility_machine.rs b/crates/oxide/src/extractor/named_utility_machine.rs index a7fab0407a64..d19f6ab5b7cf 100644 --- a/crates/oxide/src/extractor/named_utility_machine.rs +++ b/crates/oxide/src/extractor/named_utility_machine.rs @@ -243,7 +243,7 @@ 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 +272,8 @@ impl Machine for NamedUtilityMachine { | Class::AlphaLower | Class::AlphaUpper | Class::Percent + | Class::Underscore + | Class::Dash ) { return self.done(self.start_pos, cursor); } @@ -395,6 +397,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 From 0fdf697985496a47d8af454d0aac04af8202d41b Mon Sep 17 00:00:00 2001 From: woohm402 Date: Thu, 6 Mar 2025 17:41:34 +0900 Subject: [PATCH 2/4] add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31c8de14d10a..3aa9f7b88c34 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 number followed by dash or underscore are extracted correctly ([#16980](https://github.com/tailwindlabs/tailwindcss/pull/16980)) ## [4.0.10] - 2025-03-05 From c60d983a02f934a87ad3e3548605db4616a26607 Mon Sep 17 00:00:00 2001 From: woohm402 Date: Thu, 6 Mar 2025 17:54:26 +0900 Subject: [PATCH 3/4] add test for extractor & utility_machine --- crates/oxide/src/extractor/mod.rs | 3 +++ crates/oxide/src/extractor/utility_machine.rs | 3 +++ 2 files changed, 6 insertions(+) diff --git a/crates/oxide/src/extractor/mod.rs b/crates/oxide/src/extractor/mod.rs index 0a5b972dcb08..d8a5b91a3ad2 100644 --- a/crates/oxide/src/extractor/mod.rs +++ b/crates/oxide/src/extractor/mod.rs @@ -300,6 +300,9 @@ mod tests { ("items--center", vec!["items--center"]), // Simple utility with numbers ("px-2.5", vec!["px-2.5"]), + // Simple utility with number followed by dash or underscore + ("text-title1-strong", vec!["text-title1-strong"]), + ("text-title1_strong", vec!["text-title1_strong"]), // Arbitrary properties ("[color:red]", vec!["[color:red]"]), ("![color:red]", vec!["![color:red]"]), diff --git a/crates/oxide/src/extractor/utility_machine.rs b/crates/oxide/src/extractor/utility_machine.rs index ea5241a2d4d9..9d2e486dd493 100644 --- a/crates/oxide/src/extractor/utility_machine.rs +++ b/crates/oxide/src/extractor/utility_machine.rs @@ -220,6 +220,9 @@ mod tests { // With dashes ("items-center", vec!["items-center"]), ("items--center", vec!["items--center"]), + // With number followed by dash or underscore + ("text-title1-strong", vec!["text-title1-strong"]), + ("text-title1_strong", vec!["text-title1_strong"]), // Inside a string ("'flex'", vec!["flex"]), // Multiple utilities From 6daf55eedb5fcd1bfb929f15964fd4a3cd4cf632 Mon Sep 17 00:00:00 2001 From: Philipp Spiess Date: Thu, 6 Mar 2025 11:36:40 +0100 Subject: [PATCH 4/4] Smaller improvements --- CHANGELOG.md | 2 +- crates/oxide/src/extractor/mod.rs | 12 +++++++++--- crates/oxide/src/extractor/named_utility_machine.rs | 3 ++- crates/oxide/src/extractor/utility_machine.rs | 3 --- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3aa9f7b88c34..9eee072c1ddd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +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 number followed by dash or underscore are extracted correctly ([#16980](https://github.com/tailwindlabs/tailwindcss/pull/16980)) +- 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 d8a5b91a3ad2..ba89bbf9063d 100644 --- a/crates/oxide/src/extractor/mod.rs +++ b/crates/oxide/src/extractor/mod.rs @@ -300,9 +300,6 @@ mod tests { ("items--center", vec!["items--center"]), // Simple utility with numbers ("px-2.5", vec!["px-2.5"]), - // Simple utility with number followed by dash or underscore - ("text-title1-strong", vec!["text-title1-strong"]), - ("text-title1_strong", vec!["text-title1_strong"]), // Arbitrary properties ("[color:red]", vec!["[color:red]"]), ("![color:red]", vec!["![color:red]"]), @@ -836,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 d19f6ab5b7cf..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 or dash or underscore. + // character, and can be followed by a `.` or an alphanumeric character or + // dash or underscore. // // E.g.: `text-2xs` // ^^ diff --git a/crates/oxide/src/extractor/utility_machine.rs b/crates/oxide/src/extractor/utility_machine.rs index 9d2e486dd493..ea5241a2d4d9 100644 --- a/crates/oxide/src/extractor/utility_machine.rs +++ b/crates/oxide/src/extractor/utility_machine.rs @@ -220,9 +220,6 @@ mod tests { // With dashes ("items-center", vec!["items-center"]), ("items--center", vec!["items--center"]), - // With number followed by dash or underscore - ("text-title1-strong", vec!["text-title1-strong"]), - ("text-title1_strong", vec!["text-title1_strong"]), // Inside a string ("'flex'", vec!["flex"]), // Multiple utilities