Skip to content

Commit a72d97c

Browse files
authored
Skip calc() normalisation in nested theme() calls (#11705)
* add `calc` normalisation test cases using `theme()` * ignore formatting in some known functions, such as `theme` * update changelog
1 parent ae4d213 commit a72d97c

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2424
- Make PostCSS plugin async to improve performance ([#11548](https://github.com/tailwindlabs/tailwindcss/pull/11548))
2525
- Allow variant to be an at-rule without a prelude ([#11589](https://github.com/tailwindlabs/tailwindcss/pull/11589))
2626
- Improve normalisation of `calc()`-like functions ([#11686](https://github.com/tailwindlabs/tailwindcss/pull/11686))
27+
- Skip `calc()` normalisation in nested `theme()` calls ([#11705](https://github.com/tailwindlabs/tailwindcss/pull/11705))
2728

2829
### Added
2930

src/util/dataTypes.js

+7
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ export function normalize(value, isRoot = true) {
5959
* @returns {string}
6060
*/
6161
function normalizeMathOperatorSpacing(value) {
62+
let preventFormattingInFunctions = ['theme']
63+
6264
return value.replace(/(calc|min|max|clamp)\(.+\)/g, (match) => {
6365
let result = ''
6466

@@ -100,6 +102,11 @@ function normalizeMathOperatorSpacing(value) {
100102
result += consumeUntil([')', ','])
101103
}
102104

105+
// Skip formatting inside known functions
106+
else if (preventFormattingInFunctions.some((fn) => peek(fn))) {
107+
result += consumeUntil([')'])
108+
}
109+
103110
// Handle operators
104111
else if (
105112
['+', '-', '*', '/'].includes(char) &&

tests/normalize-data-types.test.js

+6
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ let table = [
6060
'calc(var(--10-10px,calc(-20px-(-30px--40px)-50px)',
6161
'calc(var(--10-10px,calc(-20px - (-30px - -40px) - 50px)',
6262
],
63+
['calc(theme(spacing.1-bar))', 'calc(theme(spacing.1-bar))'],
64+
['theme(spacing.1-bar)', 'theme(spacing.1-bar)'],
65+
['calc(theme(spacing.1-bar))', 'calc(theme(spacing.1-bar))'],
66+
['calc(1rem-theme(spacing.1-bar))', 'calc(1rem - theme(spacing.1-bar))'],
67+
['calc(theme(spacing.foo-2))', 'calc(theme(spacing.foo-2))'],
68+
['calc(theme(spacing.foo-bar))', 'calc(theme(spacing.foo-bar))'],
6369

6470
// Misc
6571
['color(0_0_0/1.0)', 'color(0 0 0/1.0)'],

0 commit comments

Comments
 (0)