Skip to content

Commit f66d287

Browse files
authored
Fix brace expansion with range going down (#17591)
1 parent 76e18e6 commit f66d287

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

CHANGELOG.md

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

1212
- Ensure `color-mix(…)` polyfills do not cause used CSS variables to be removed ([#17555](https://github.com/tailwindlabs/tailwindcss/pull/17555))
1313
- Ensure the `color-mix(…)` polyfill creates fallbacks for theme variables that reference other theme variables ([#17562](https://github.com/tailwindlabs/tailwindcss/pull/17562))
14+
- Fix brace expansion in `@source inline('z-{10..0}')` with range going down ([#17591](https://github.com/tailwindlabs/tailwindcss/pull/17591))
1415

1516
## [4.1.3] - 2025-04-04
1617

packages/tailwindcss/src/utils/brace-expansion.test.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@ describe('expand(…)', () => {
1414
['a/{0..5}/b', ['a/0/b', 'a/1/b', 'a/2/b', 'a/3/b', 'a/4/b', 'a/5/b']],
1515
['a/{-5..0}/b', ['a/-5/b', 'a/-4/b', 'a/-3/b', 'a/-2/b', 'a/-1/b', 'a/0/b']],
1616
['a/{0..-5}/b', ['a/0/b', 'a/-1/b', 'a/-2/b', 'a/-3/b', 'a/-4/b', 'a/-5/b']],
17-
[
18-
'a/{0..10..5}/b',
19-
['a/0/b', 'a/5/b', 'a/10/b'],
20-
['a/{10..0..5}/b', ['a/10/b', 'a/5/b', 'a/0/b']],
21-
],
17+
['a/{0..10..5}/b', ['a/0/b', 'a/5/b', 'a/10/b']],
18+
['a/{0..10..-5}/b', ['a/10/b', 'a/5/b', 'a/0/b']],
19+
['a/{10..0..5}/b', ['a/10/b', 'a/5/b', 'a/0/b']],
20+
['a/{10..0..-5}/b', ['a/0/b', 'a/5/b', 'a/10/b']],
2221

2322
// Numeric range with padding (we do not support padding)
2423
['a/{00..05}/b', ['a/0/b', 'a/1/b', 'a/2/b', 'a/3/b', 'a/4/b', 'a/5/b']],
@@ -64,7 +63,7 @@ describe('expand(…)', () => {
6463

6564
// Should not try to expand ranges with decimals
6665
['{1.1..2.2}', ['1.1..2.2']],
67-
])('should expand %s', (input, expected) => {
66+
])('should expand %s (%#)', (input, expected) => {
6867
expect(expand(input).sort()).toEqual(expected.sort())
6968
})
7069

packages/tailwindcss/src/utils/brace-expansion.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,13 @@ function expandSequence(seq: string): string[] {
7878
if (step === 0) {
7979
throw new Error('Step cannot be zero in sequence expansion.')
8080
}
81-
if (step > 0) {
82-
for (let i = startNum; i <= endNum; i += step) {
83-
let numStr = i.toString()
84-
result.push(numStr)
85-
}
86-
} else {
87-
for (let i = startNum; i >= endNum; i += step) {
88-
let numStr = i.toString()
89-
result.push(numStr)
90-
}
81+
82+
let increasing = startNum < endNum
83+
if (increasing && step < 0) step = -step
84+
if (!increasing && step > 0) step = -step
85+
86+
for (let i = startNum; increasing ? i <= endNum : i >= endNum; i += step) {
87+
result.push(i.toString())
9188
}
9289
}
9390
return result

0 commit comments

Comments
 (0)