Skip to content

Commit 352b678

Browse files
Fix theme lookup when variable names contain escaped dots (#1466)
Fixes #1465
1 parent a8efcb7 commit 352b678

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

packages/tailwindcss-language-service/src/util/rewriting/index.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ test('Inlining calc expressions using the design system', () => {
191191
let map = new Map<string, string>([
192192
['--spacing', '0.25rem'],
193193
['--color-red-500', 'oklch(0.637 0.237 25.331)'],
194+
['--font-size.md', '1rem'],
194195
])
195196

196197
let state: State = {
@@ -240,4 +241,9 @@ test('Inlining calc expressions using the design system', () => {
240241
expect(addThemeValues('var(--color-red-500)', state, settings)).toBe(
241242
'var(--color-red-500) /* oklch(0.637 0.237 25.331) = #fb2c36 */',
242243
)
244+
245+
// Variables containing dots
246+
expect(addThemeValues('var(--font-size\\.md)', state, settings)).toBe(
247+
'var(--font-size\\.md) /* 1rem = 10px */',
248+
)
243249
})

packages/tailwindcss-language-service/src/util/rewriting/lookup.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,9 @@ export function resolveVariableValue(design: DesignSystem, name: string): string
88
name = `--${name.slice(prefix.length + 3)}`
99
}
1010

11+
// Variables have to escape the `.` but the theme system in v4 does not store
12+
// the values with escapes so name lookups will fail.
13+
name = name.replaceAll('\\.', '.')
14+
1115
return design.resolveThemeValue?.(name, true) ?? null
1216
}

packages/vscode-tailwindcss/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Show color swatches for OKLCH colors with units in all positions ([#1442](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1442))
88
- Fix incorrect diagnostic for `--theme(--some-var inline)` ([#1443](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1443))
99
- Bump precision of evaluated calc expressions ([#1449](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1449))
10+
- Fix theme lookup when variable names contain escaped dots ([#1466](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1466))
1011

1112
## 0.14.26
1213

0 commit comments

Comments
 (0)