Skip to content

Commit 53f3597

Browse files
committed
Rewrite all occurrences of * in a CSS variable name
1 parent c8efeca commit 53f3597

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

packages/tailwindcss-language-server/src/language/rewriting.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ test('@utility', () => {
5050
'@utility foo-* {',
5151
' color: red;',
5252
'}',
53+
'@utility bar-* {',
54+
' color: --value(--font-*-line-height);',
55+
'}',
5356
]
5457

5558
let output = [
@@ -60,6 +63,9 @@ test('@utility', () => {
6063
'.placeholder {', // wrong
6164
' color: red;',
6265
'}',
66+
'.placeholder {', // wrong
67+
' color: --value(--font-_-line-height);',
68+
'}',
6369
]
6470

6571
expect(rewriteCss(input.join('\n'))).toBe(output.join('\n'))
@@ -70,11 +76,15 @@ test('@theme', () => {
7076
//
7177
'@theme {',
7278
' --color: red;',
79+
' --*: initial;',
80+
' --text*: initial;',
7381
' --font-*: initial;',
7482
' --font-weight-*: initial;',
7583
'}',
7684
'@theme inline reference static default {',
7785
' --color: red;',
86+
' --*: initial;',
87+
' --text*: initial;',
7888
' --font-*: initial;',
7989
' --font-weight-*: initial;',
8090
'}',
@@ -84,11 +94,15 @@ test('@theme', () => {
8494
//
8595
'.placeholder {', // wrong
8696
' --color: red;',
97+
' --_: initial;',
98+
' --text_: initial;',
8799
' --font-_: initial;',
88100
' --font-weight-_: initial;',
89101
'}',
90102
'.placeholder {', // wrong
91103
' --color: red;',
104+
' --_: initial;',
105+
' --text_: initial;',
92106
' --font-_: initial;',
93107
' --font-weight-_: initial;',
94108
'}',

packages/tailwindcss-language-server/src/language/rewriting.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,13 @@ export function rewriteCss(css: string) {
7373
return match.replace(/[*]/g, '_')
7474
})
7575

76+
// Replace `--*` with `--_`
77+
// Replace `--some-var*` with `--some-var_`
7678
// Replace `--some-var-*` with `--some-var-_`
77-
css = css.replace(/--([a-zA-Z0-9-]+)-[*]/g, '--$1-_')
79+
// Replace `--text-*-line-height` with `--text-_-line-height`
80+
css = css.replace(/--([a-zA-Z0-9-*]*)/g, (match) => {
81+
return match.replace(/[*]/g, '_')
82+
})
7883

7984
return css
8085
}

0 commit comments

Comments
 (0)