Skip to content

Commit 3b03395

Browse files
authored
Ensure namespace reset with escaped * works (#15603)
This PR fixes an issue if you want to reset a namespace like: ```css @theme { --color-*: initial; } ``` That some formatters such as Biome won't allow this syntax. To solve that, this PR allows you to use an escaped `*` character. ```css @theme { --color-\*: initial; } ``` Fixes: #15602
1 parent ae8fb14 commit 3b03395

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Fixed
1111

1212
- Add missing `main` and `browser` fields for `@tailwindcss/browser` ([#15594](https://github.com/tailwindlabs/tailwindcss/pull/15594))
13+
- Ensure namespace reset with escaped `*` (e.g.: `--color-\*: initial;`) ([#15603](https://github.com/tailwindlabs/tailwindcss/pull/15603))
1314
- _Upgrade (experimental)_: Pretty print `--spacing(…)` to prevent ambiguity ([#15596](https://github.com/tailwindlabs/tailwindcss/pull/15596))
1415

1516
## [4.0.0-beta.9] - 2025-01-09

packages/tailwindcss/src/index.test.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,6 +1208,53 @@ describe('Parsing themes values from CSS', () => {
12081208
`)
12091209
})
12101210

1211+
test('`@theme` values can be unset (using the escaped syntax)', async () => {
1212+
expect(
1213+
await compileCss(
1214+
css`
1215+
@theme {
1216+
--color-red: #f00;
1217+
--color-blue: #00f;
1218+
--text-sm: 13px;
1219+
--text-md: 16px;
1220+
1221+
--animate-spin: spin 1s infinite linear;
1222+
1223+
@keyframes spin {
1224+
to {
1225+
transform: rotate(360deg);
1226+
}
1227+
}
1228+
}
1229+
@theme {
1230+
--color-\*: initial;
1231+
--text-md: initial;
1232+
--animate-\*: initial;
1233+
--keyframes-\*: initial;
1234+
}
1235+
@theme {
1236+
--color-green: #0f0;
1237+
}
1238+
@tailwind utilities;
1239+
`,
1240+
['accent-red', 'accent-blue', 'accent-green', 'text-sm', 'text-md'],
1241+
),
1242+
).toMatchInlineSnapshot(`
1243+
":root {
1244+
--text-sm: 13px;
1245+
--color-green: #0f0;
1246+
}
1247+
1248+
.text-sm {
1249+
font-size: var(--text-sm);
1250+
}
1251+
1252+
.accent-green {
1253+
accent-color: var(--color-green);
1254+
}"
1255+
`)
1256+
})
1257+
12111258
test('all `@theme` values can be unset at once', async () => {
12121259
expect(
12131260
await compileCss(

packages/tailwindcss/src/theme.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ export class Theme {
4141
) {}
4242

4343
add(key: string, value: string, options = ThemeOptions.NONE): void {
44+
if (key.endsWith('\\*')) {
45+
key = key.slice(0, -2) + '*'
46+
}
47+
4448
if (key.endsWith('-*')) {
4549
if (value !== 'initial') {
4650
throw new Error(`Invalid theme value \`${value}\` for namespace \`${key}\``)

0 commit comments

Comments
 (0)