Skip to content

Commit 6ca8cc6

Browse files
Disallow negative bare values (#14453)
Right now, it is possible to type `grid-cols--8` which maps to: ```css /* Specificity: (0, 1, 0) */ .grid-cols--8 { grid-template-columns: repeat(-8, minmax(0, 1fr)); } ``` This doesn't make sense so we used this opportunity to audit all variants and utilities and properly disallow negative bare values. Utilities where negative values are supported still work by using the negative utility syntax, e.g.: `-inset-4`.
1 parent ee7e02b commit 6ca8cc6

File tree

7 files changed

+252
-73
lines changed

7 files changed

+252
-73
lines changed

CHANGELOG.md

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

2525
- Don't override explicit `leading-*`, `tracking-*`, or `font-{weight}` utilities with font-size utility defaults ([#14403](https://github.com/tailwindlabs/tailwindcss/pull/14403))
26+
- Disallow negative bare values in core utilities and variants ([#14453](https://github.com/tailwindlabs/tailwindcss/pull/14453))
2627

2728
## [4.0.0-alpha.24] - 2024-09-11
2829

packages/tailwindcss/src/compat/default-theme.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { NamedUtilityValue } from '../candidate'
2+
import { isPositiveInteger } from '../utils/infer-data-type'
23
import { segment } from '../utils/segment'
34
import colors from './colors'
45
import type { UserConfig } from './config/types'
@@ -13,44 +14,44 @@ function bareValues(fn: (value: NamedUtilityValue) => string | undefined) {
1314
}
1415

1516
let bareIntegers = bareValues((value) => {
16-
if (!Number.isNaN(Number(value.value))) {
17+
if (isPositiveInteger(value.value)) {
1718
return value.value
1819
}
1920
})
2021

2122
let barePercentages = bareValues((value: NamedUtilityValue) => {
22-
if (!Number.isNaN(Number(value.value))) {
23+
if (isPositiveInteger(value.value)) {
2324
return `${value.value}%`
2425
}
2526
})
2627

2728
let barePixels = bareValues((value: NamedUtilityValue) => {
28-
if (!Number.isNaN(Number(value.value))) {
29+
if (isPositiveInteger(value.value)) {
2930
return `${value.value}px`
3031
}
3132
})
3233

3334
let bareMilliseconds = bareValues((value: NamedUtilityValue) => {
34-
if (!Number.isNaN(Number(value.value))) {
35+
if (isPositiveInteger(value.value)) {
3536
return `${value.value}ms`
3637
}
3738
})
3839

3940
let bareDegrees = bareValues((value: NamedUtilityValue) => {
40-
if (!Number.isNaN(Number(value.value))) {
41+
if (isPositiveInteger(value.value)) {
4142
return `${value.value}deg`
4243
}
4344
})
4445

4546
let bareAspectRatio = bareValues((value) => {
4647
if (value.fraction === null) return
4748
let [lhs, rhs] = segment(value.fraction, '/')
48-
if (!Number.isInteger(Number(lhs)) || !Number.isInteger(Number(rhs))) return
49+
if (!isPositiveInteger(lhs) || !isPositiveInteger(rhs)) return
4950
return value.fraction
5051
})
5152

5253
let bareRepeatValues = bareValues((value) => {
53-
if (!Number.isNaN(Number(value.value))) {
54+
if (isPositiveInteger(Number(value.value))) {
5455
return `repeat(${value.value}, minmax(0, 1fr))`
5556
}
5657
})

0 commit comments

Comments
 (0)