Skip to content

Commit 8bf06ab

Browse files
Handle legacy key behavior in theme-driven suggestions for @utility (#17733)
Fixes tailwindlabs/tailwindcss-intellisense#1328 The alpha and beta releases used `_` in theme keys to represent a `.`. This meant we used `--leading-1_5` instead of `--leading-1\.5` to add utilities like `leading-1.5`. We prefer the use of the escaped dot now but still want to make sure suggestions for the legacy key format still works as expected when surrounded by numbers. This is the same as #16433 but for `@utility` since we apparently missed this when emitting suggestions for it
1 parent 650558d commit 8bf06ab

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
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
- Don't scan `.geojson` files for classes by default ([#17700](https://github.com/tailwindlabs/tailwindcss/pull/17700))
1313
- Hide default shadow suggestions when missing theme keys ([#17743](https://github.com/tailwindlabs/tailwindcss/pull/17743))
14+
- Replace `_` with `.` in theme suggestions for `@utility` if surrounded by digits ([#17743](https://github.com/tailwindlabs/tailwindcss/pull/17743))
1415

1516
## [4.1.4] - 2025-04-14
1617

packages/tailwindcss/src/intellisense.test.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,10 @@ test('Theme keys with underscores are suggested with underscores', async () => {
579579
/* This will get suggeted with an underscore */
580580
--spacing-logo_margin: 0.875rem;
581581
}
582+
583+
@utility ex-* {
584+
width: --value(--spacing- *);
585+
}
582586
`
583587

584588
let design = await __unstable__loadDesignSystem(input, {
@@ -588,15 +592,25 @@ test('Theme keys with underscores are suggested with underscores', async () => {
588592
}),
589593
})
590594

591-
let entries = design.getClassList().filter(([name]) => name.startsWith('p-'))
595+
let entries = design
596+
.getClassList()
597+
.filter(([name]) => name.startsWith('p-') || name.startsWith('ex-'))
592598

593599
expect(entries).toContainEqual(['p-1.5', { modifiers: [] }])
594600
expect(entries).toContainEqual(['p-2.5', { modifiers: [] }])
595601
expect(entries).toContainEqual(['p-logo_margin', { modifiers: [] }])
596602

603+
expect(entries).toContainEqual(['ex-1.5', { modifiers: [] }])
604+
expect(entries).toContainEqual(['ex-2.5', { modifiers: [] }])
605+
expect(entries).toContainEqual(['ex-logo_margin', { modifiers: [] }])
606+
597607
expect(entries).not.toContainEqual(['p-1_5', { modifiers: [] }])
598608
expect(entries).not.toContainEqual(['p-2_5', { modifiers: [] }])
599609
expect(entries).not.toContainEqual(['p-logo.margin', { modifiers: [] }])
610+
611+
expect(entries).not.toContainEqual(['ex-1_5', { modifiers: [] }])
612+
expect(entries).not.toContainEqual(['ex-2_5', { modifiers: [] }])
613+
expect(entries).not.toContainEqual(['ex-logo.margin', { modifiers: [] }])
600614
})
601615

602616
test('shadow utility default suggestions', async () => {

packages/tailwindcss/src/utilities.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -266,22 +266,22 @@ function resolveThemeColor<T extends ThemeKey>(
266266
return value ? asColor(value, candidate.modifier, theme) : null
267267
}
268268

269+
/**
270+
* The alpha and beta releases used `_` in theme keys to represent a `.`. This meant we used
271+
* `--leading-1_5` instead of `--leading-1\.5` to add utilities like `leading-1.5`.
272+
*
273+
* We prefer the use of the escaped dot now but still want to make sure suggestions for the
274+
* legacy key format still works as expected when surrounded by numbers.
275+
*/
276+
const LEGACY_NUMERIC_KEY = /(\d+)_(\d+)/g
277+
269278
export function createUtilities(theme: Theme) {
270279
let utilities = new Utilities()
271280

272281
/**
273282
* Register list of suggestions for a class
274283
*/
275284
function suggest(classRoot: string, defns: () => SuggestionDefinition[]) {
276-
/**
277-
* The alpha and beta releases used `_` in theme keys to represent a `.`. This meant we used
278-
* `--leading-1_5` instead of `--leading-1\.5` to add utilities like `leading-1.5`.
279-
*
280-
* We prefer the use of the escaped dot now but still want to make sure suggestions for the
281-
* legacy key format still works as expected when surrounded by numbers.
282-
*/
283-
const LEGACY_NUMERIC_KEY = /(\d+)_(\d+)/g
284-
285285
function* resolve(themeKeys: ThemeKey[]) {
286286
for (let value of theme.keysInNamespaces(themeKeys)) {
287287
yield value.replace(LEGACY_NUMERIC_KEY, (_, a, b) => {
@@ -6060,7 +6060,11 @@ export function createCssUtility(node: AtRule) {
60606060

60616061
// Suggest theme values. E.g.: `--value(--color-*)`
60626062
for (let value of designSystem.theme.keysInNamespaces(themeKeys)) {
6063-
target.push(value)
6063+
target.push(
6064+
value.replace(LEGACY_NUMERIC_KEY, (_, a, b) => {
6065+
return `${a}.${b}`
6066+
}),
6067+
)
60646068
}
60656069
}
60666070

0 commit comments

Comments
 (0)