Skip to content

Commit cedd54f

Browse files
authored
Fix variants with <digit>.</digit> are extracted correctly (#17153)
This PR fixes an issue where if you use a number with a decimal in a variant then it wasn't picked up correctly. E.g.: ``` <div class="2xl:flex 1.5xl:flex"></div> ^^^^^^^^ Picked up ^^^^^^^^^^ Not picket up ``` This PR fixes that behavior by applying the same rules for utilities where a `.` is valid if it is surrounded by numbers. # Test plan 1. Added test to ensure this is picked up 2. Existing tests pass 3. Ran the extractor on a real example with the following results: | Before | After | | --- | --- | | <img width="821" alt="image" src="https://github.com/user-attachments/assets/a77ed5e4-6848-4fe3-8cbf-cf61ff8db41d" /> | <img width="821" alt="image" src="https://github.com/user-attachments/assets/61aca66a-e38d-4b61-bf86-e6286a89a3d9" /> | They are crossed out just because it's not a default value we know in the system, but you can see that the `1.` part is also extracted now. Fixes: #17148
1 parent 215f4f3 commit cedd54f

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

CHANGELOG.md

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

2323
- Do not extract candidates with JS string interpolation `${` ([#17142](https://github.com/tailwindlabs/tailwindcss/pull/17142))
24+
- Fix extraction of variants containing `.` character ([#17153](https://github.com/tailwindlabs/tailwindcss/pull/17153))
2425

2526
## [4.0.13] - 2025-03-11
2627

crates/oxide/src/extractor/named_variant_machine.rs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,22 @@ impl Machine for NamedVariantMachine<ParsingState> {
235235
// ^
236236
Class::Colon => return self.done(self.start_pos, cursor),
237237

238+
// A dot must be surrounded by numbers
239+
//
240+
// E.g.: `2.5xl:flex`
241+
// ^^^
242+
Class::Dot => {
243+
if !matches!(cursor.prev.into(), Class::Number) {
244+
return self.restart();
245+
}
246+
247+
if !matches!(cursor.next.into(), Class::Number) {
248+
return self.restart();
249+
}
250+
251+
cursor.advance();
252+
}
253+
238254
// Everything else is invalid
239255
_ => return self.restart(),
240256
};
@@ -325,24 +341,15 @@ enum Class {
325341
#[bytes(b'.')]
326342
Dot,
327343

328-
#[bytes(b'\0')]
329-
End,
330-
331344
#[bytes_range(b'0'..=b'9')]
332345
Number,
333346

334347
#[bytes(b'[')]
335348
OpenBracket,
336349

337-
#[bytes(b']')]
338-
CloseBracket,
339-
340350
#[bytes(b'(')]
341351
OpenParen,
342352

343-
#[bytes(b'\'', b'"', b'`')]
344-
Quote,
345-
346353
#[bytes(b'*')]
347354
Star,
348355

@@ -352,9 +359,6 @@ enum Class {
352359
#[bytes(b'_')]
353360
Underscore,
354361

355-
#[bytes(b' ', b'\t', b'\n', b'\r', b'\x0C')]
356-
Whitespace,
357-
358362
#[fallback]
359363
Other,
360364
}
@@ -391,6 +395,8 @@ mod tests {
391395
vec!["group-[data-state=pending]/name:"],
392396
),
393397
("supports-(--foo)/name:flex", vec!["supports-(--foo)/name:"]),
398+
// Odd media queries
399+
("1.5xl:flex", vec!["1.5xl:"]),
394400
// Container queries
395401
("@md:flex", vec!["@md:"]),
396402
("@max-md:flex", vec!["@max-md:"]),

0 commit comments

Comments
 (0)