Disable padding in @source inline(…) brace expansion (#17491)

The padding code we had was incorrect as it would always pad on the
largest string representation. So for an input like this:


```
@source inline("z-{10..100..10}");
```

It would create the following candidates: 

- `z-010`
- `z-020`
- `z-030`
- `z-040`
- `z-050`
- `z-060`
- `z-070`
- `z-060`
- `z-070`
- `z-100`

Instead of fixing the padding logic we realized that Tailwind utilities
don't need padding at all so this PR removes this feature

## Test plan

- Added the following to the Vite playground: `@source
inline("z-{10..100..10}");`
- Ensure it works: 

![image](https://github.com/user-attachments/assets/f4714729-4ef7-4678-a531-70b471e75e6e)
This commit is contained in:
Philipp Spiess 2025-04-01 22:55:03 +02:00 • committed by GitHub
parent 8f631d0d8a
commit b069d7a5a1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 10 additions and 15 deletions

View file

@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
- Nothing yet!
### Fixed
- Disable padding in `@source inline(…)` brace expansion ([#17491](https://github.com/tailwindlabs/tailwindcss/pull/17491))
## [4.1.0] - 2025-04-01

View file

@ -14,14 +14,16 @@ describe('expand(…)', () => {
['a/{0..5}/b', ['a/0/b', 'a/1/b', 'a/2/b', 'a/3/b', 'a/4/b', 'a/5/b']],
['a/{-5..0}/b', ['a/-5/b', 'a/-4/b', 'a/-3/b', 'a/-2/b', 'a/-1/b', 'a/0/b']],
['a/{0..-5}/b', ['a/0/b', 'a/-1/b', 'a/-2/b', 'a/-3/b', 'a/-4/b', 'a/-5/b']],
// Numeric range with padding
['a/{00..05}/b', ['a/00/b', 'a/01/b', 'a/02/b', 'a/03/b', 'a/04/b', 'a/05/b']],
[
'a{001..9}b',
['a001b', 'a002b', 'a003b', 'a004b', 'a005b', 'a006b', 'a007b', 'a008b', 'a009b'],
'a/{0..10..5}/b',
['a/0/b', 'a/5/b', 'a/10/b'],
['a/{10..0..5}/b', ['a/10/b', 'a/5/b', 'a/0/b']],
],
// Numeric range with padding (we do not support padding)
['a/{00..05}/b', ['a/0/b', 'a/1/b', 'a/2/b', 'a/3/b', 'a/4/b', 'a/5/b']],
['a{001..9}b', ['a1b', 'a2b', 'a3b', 'a4b', 'a5b', 'a6b', 'a7b', 'a8b', 'a9b']],
// Numeric range with step
['a/{0..5..2}/b', ['a/0/b', 'a/2/b', 'a/4/b']],
[

View file

@ -72,9 +72,6 @@ function expandSequence(seq: string): string[] {
let startNum = parseInt(start, 10)
let endNum = parseInt(end, 10)
// Determine padding length (if any) but don't count the sign as length
let padLength = Math.max(start.replace(/^-/, '').length, end.replace(/^-/, '').length)
if (step === undefined) {
step = startNum <= endNum ? 1 : -1
}
@ -84,17 +81,11 @@ function expandSequence(seq: string): string[] {
if (step > 0) {
for (let i = startNum; i <= endNum; i += step) {
let numStr = i.toString()
if (numStr.length < padLength) {
numStr = numStr.padStart(padLength, '0')
}
result.push(numStr)
}
} else {
for (let i = startNum; i >= endNum; i += step) {
let numStr = i.toString()
if (numStr.length < padLength) {
numStr = numStr.padStart(padLength, '0')
}
result.push(numStr)
}
}