Skip to content

Commit 4cb548e

Browse files
Fix syntax error when resetting multi-word theme key namespaces (#1237)
Fixes #1236 This PR fixes an issue where we'd show a syntax error for multi-word namespace resets like `--font-weight-*: initial;`: ```css @theme { --font-*: initial; /* this one is fine */ --font-weight-*: initial; /* this one shows a syntax error */ } ``` <img width="686" alt="Screenshot 2025-02-26 at 12 16 38" src="https://github.com/user-attachments/assets/60a9e9e9-931a-485b-9a23-4ea972b02396" /> Now both work as expected: <img width="763" alt="Screenshot 2025-02-26 at 12 17 09" src="https://github.com/user-attachments/assets/4a245979-2b45-4931-b47a-6a5c0de42bf5" />
1 parent eabd07e commit 4cb548e

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

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

+12-4
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,28 @@ test('@theme', () => {
6969
let input = [
7070
//
7171
'@theme {',
72-
' color: red;',
72+
' --color: red;',
73+
' --font-*: initial;',
74+
' --font-weight-*: initial;',
7375
'}',
7476
'@theme inline reference static default {',
75-
' color: red;',
77+
' --color: red;',
78+
' --font-*: initial;',
79+
' --font-weight-*: initial;',
7680
'}',
7781
]
7882

7983
let output = [
8084
//
8185
'.placeholder {', // wrong
82-
' color: red;',
86+
' --color: red;',
87+
' --font-_: initial;',
88+
' --font-weight-_: initial;',
8389
'}',
8490
'.placeholder {', // wrong
85-
' color: red;',
91+
' --color: red;',
92+
' --font-_: initial;',
93+
' --font-weight-_: initial;',
8694
'}',
8795
]
8896

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export function rewriteCss(css: string) {
7474
})
7575

7676
// Replace `--some-var-*` with `--some-var-_`
77-
css = css.replace(/--([a-zA-Z0-9]+)-[*]/g, '--$1_')
77+
css = css.replace(/--([a-zA-Z0-9-]+)-[*]/g, '--$1-_')
7878

7979
return css
8080
}

packages/tailwindcss-language-server/tests/css/css-server.test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ defineTest({
219219
@theme {
220220
--color-primary: #333;
221221
--leading-*: initial;
222+
--font-weight-*: initial;
222223
}
223224
`,
224225
})
@@ -235,7 +236,7 @@ defineTest({
235236
uri: '{workspace:default}/file-1.css',
236237
range: {
237238
start: { line: 1, character: 0 },
238-
end: { line: 4, character: 1 },
239+
end: { line: 5, character: 1 },
239240
},
240241
},
241242
},

packages/vscode-tailwindcss/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Prerelease
44

55
- Don't throw when requiring() packages that resolve to a path containing a `#` character ([#1235](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1235))
6+
- Fix syntax error when resetting multi-word theme key namespaces ([#1237](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1237))
67

78
# 0.14.7
89

0 commit comments

Comments
 (0)