8000 allow escaped `\*` for `--value(--tab-size-\*)` · tailwindlabs/tailwindcss@e6fd70b · GitHub
Skip to content

Commit e6fd70b

Browse files
committed
allow escaped \* for --value(--tab-size-\*)
This makes it prettier / biome friendly.
1 parent 4d2c36b commit e6fd70b

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

packages/tailwindcss/src/utilities.test.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17518,6 +17518,43 @@ describe('custom utilities', () => {
1751817518
expect(await compileCss(input, ['tab-3', 'tab-gitlab'])).toEqual('')
1751917519
})
1752017520

17521+
test('resolving values from `@theme`, with `--tab-size-\\*` syntax (prettier friendly)', async () => {
17522+
let input = css`
17523+
@theme reference {
17524+
--tab-size-1: 1;
17525+
--tab-size-2: 2;
17526+
--tab-size-4: 4;
17527+
--tab-size-github: 8;
17528+
}
17529+
17530+
@utility tab-* {
17531+
tab-size: --value(--tab-size-\*);
17532+
}
17533+
17534+
@tailwind utilities;
17535+
`
17536+
17537+
expect(await compileCss(input, ['tab-1', 'tab-2', 'tab-4', 'tab-github']))
17538+
.toMatchInlineSnapshot(`
17539+
".tab-1 {
17540+
tab-size: 1;
17541+
}
17542+
17543+
.tab-2 {
17544+
tab-size: 2;
17545+
}
17546+
17547+
.tab-4 {
17548+
tab-size: 4;
17549+
}
17550+
17551+
.tab-github {
17552+
tab-size: 8;
17553+
}"
17554+
`)
17555+
expect(await compileCss(input, ['tab-3', 'tab-gitlab'])).toEqual('')
17556+
})
17557+
1752117558
test('resolving bare values', async () => {
1752217559
let input = css`
1752317560
@utility tab-* {
@@ -17981,6 +18018,36 @@ describe('custom utilities', () => {
1798118018
expect(await compileCss(input, ['example-foo', 'example-xs/foo'])).toEqual('')
1798218019
})
1798318020

18021+
test('resolve theme values with sub-namespace (--text-\\* --line-height)', async () => {
18022+
let input = css`
18023+
@theme reference {
18024+
--text-xs: 0.75rem;
18025+
--text-xs--line-height: calc(1 / 0.75);
18026+
}
18027+
18028+
@utility example-* {
18029+
font-size: --value(--text);
18030+
line-height: --value(--text-\* --line-height);
18031+
line-height: --modifier(number);
18032+
}
18033+
18034+
@tailwind utilities;
18035+
`
18036+
18037+
expect(await compileCss(input, ['example-xs', 'example-xs/6'])).toMatchInlineSnapshot(`
18038+
".example-xs {
18039+
font-size: .75rem;
18040+
line-height: 1.33333;
18041+
}
18042+
18043+
.example-xs\\/6 {
18044+
font-size: .75rem;
18045+
line-height: 6;
18046+
}"
18047+
`)
18048+
expect(await compileCss(input, ['example-foo', 'example-xs/foo'])).toEqual('')
18049+
})
18050+
1798418051
test('resolve theme values with sub-namespace (--value(--text --line-height))', async () => {
1798518052
let input = css`
1798618053
@theme reference {

packages/tailwindcss/src/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4658,7 +4658,7 @@ export function createCssUtility(node: AtRule) {
46584658
if (node.kind !== 'declaration') return
46594659
if (!node.value) return
46604660

4661-
let valueAst = ValueParser.parse(node.value.replace(/\s+\*/g, '*'))
4661+
let valueAst = ValueParser.parse(node.value.replace(/(?:\s+|\\)\*/g, '*'))
46624662
let result =
46634663
ValueParser.walk(valueAst, (valueNode, { replaceWith }) => {
46644664
if (valueNode.kind !== 'function') return

0 commit comments

Comments
 (0)