Skip to content

Commit 25f2360

Browse files
committed
Handle escaped CSS variable names
1 parent 3b13a8d commit 25f2360

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ test('replacing CSS variables with their fallbacks (when they have them)', () =>
1818
['--circular-1', 'var(--circular-3)'],
1919
['--circular-2', 'var(--circular-1)'],
2020
['--circular-3', 'var(--circular-2)'],
21+
22+
['--escaped\\,name', 'green'],
2123
])
2224

2325
let state: State = {
@@ -58,6 +60,9 @@ test('replacing CSS variables with their fallbacks (when they have them)', () =>
5860
// Known theme keys are replaced with their values
5961
expect(replaceCssVarsWithFallbacks(state, 'var(--known)')).toBe('blue')
6062

63+
// Escaped commas are not treated as separators
64+
expect(replaceCssVarsWithFallbacks(state, 'var(--escaped\\,name)')).toBe('green')
65+
6166
// Values from the theme take precedence over fallbacks
6267
expect(replaceCssVarsWithFallbacks(state, 'var(--known, red)')).toBe('blue')
6368

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ export function replaceCssVars(
5252
depth++
5353
} else if (str[j] === ')' && depth > 0) {
5454
depth--
55+
} else if (str[j] === '\\') {
56+
j++
5557
} else if (str[j] === ',' && depth === 0 && fallbackStart === null) {
5658
fallbackStart = j + 1
5759
} else if (str[j] === ')' && depth === 0) {

0 commit comments

Comments
 (0)