diff --git a/CHANGELOG.md b/CHANGELOG.md index d76c07b34352..1b24c91399c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/packages/tailwindcss/src/utils/brace-expansion.test.ts b/packages/tailwindcss/src/utils/brace-expansion.test.ts index 8b1932bf1110..bab93ac434a8 100644 --- a/packages/tailwindcss/src/utils/brace-expansion.test.ts +++ b/packages/tailwindcss/src/utils/brace-expansion.test.ts @@ -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()) }) diff --git a/packages/tailwindcss/src/utils/brace-expansion.ts b/packages/tailwindcss/src/utils/brace-expansion.ts index 052e8848a059..ee382cd82a29 100644 --- a/packages/tailwindcss/src/utils/brace-expansion.ts +++ b/packages/tailwindcss/src/utils/brace-expansion.ts @@ -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