Fix brace expansion with range going down (#17591)

This commit is contained in:
Robin Malfait 2025-04-07 15:48:19 +02:00 committed by GitHub
parent 76e18e679c
commit f66d287436
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 13 additions and 16 deletions

View File

@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Ensure `color-mix(…)` polyfills do not cause used CSS variables to be removed ([#17555](https://github.com/tailwindlabs/tailwindcss/pull/17555))
- Ensure the `color-mix(…)` polyfill creates fallbacks for theme variables that reference other theme variables ([#17562](https://github.com/tailwindlabs/tailwindcss/pull/17562))
- Fix brace expansion in `@source inline('z-{10..0}')` with range going down ([#17591](https://github.com/tailwindlabs/tailwindcss/pull/17591))
## [4.1.3] - 2025-04-04

View File

@ -14,11 +14,10 @@ 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']],
[
'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']],
],
['a/{0..10..5}/b', ['a/0/b', 'a/5/b', 'a/10/b']],
['a/{0..10..-5}/b', ['a/10/b', 'a/5/b', 'a/0/b']],
['a/{10..0..5}/b', ['a/10/b', 'a/5/b', 'a/0/b']],
['a/{10..0..-5}/b', ['a/0/b', 'a/5/b', 'a/10/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']],
@ -64,7 +63,7 @@ describe('expand(…)', () => {
// Should not try to expand ranges with decimals
['{1.1..2.2}', ['1.1..2.2']],
])('should expand %s', (input, expected) => {
])('should expand %s (%#)', (input, expected) => {
expect(expand(input).sort()).toEqual(expected.sort())
})

View File

@ -78,16 +78,13 @@ function expandSequence(seq: string): string[] {
if (step === 0) {
throw new Error('Step cannot be zero in sequence expansion.')
}
if (step > 0) {
for (let i = startNum; i <= endNum; i += step) {
let numStr = i.toString()
result.push(numStr)
}
} else {
for (let i = startNum; i >= endNum; i += step) {
let numStr = i.toString()
result.push(numStr)
}
let increasing = startNum < endNum
if (increasing && step < 0) step = -step
if (!increasing && step > 0) step = -step
for (let i = startNum; increasing ? i <= endNum : i >= endNum; i += step) {
result.push(i.toString())
}
}
return result