Skip to content

Commit 7720e16

Browse files
RobinMalfaitthecrypticace
authored andcommitted
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 bfd0420 commit 7720e16

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

CHANGELOG.md

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

1616
- Improve normalisation of `calc()`-like functions ([#11686](https://github.com/tailwindlabs/tailwindcss/pull/11686))
17+
- Skip `calc()` normalisation in nested `theme()` calls ([#11705](https://github.com/tailwindlabs/tailwindcss/pull/11705))
1718

1819
## [3.3.3] - 2023-07-13
1920

src/util/dataTypes.js

Lines changed: 7 additions & 0 deletions
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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ let table = [
6161
'calc(var(--10-10px,calc(-20px-(-30px--40px)-50px)',
6262
'calc(var(--10-10px,calc(-20px - (-30px - -40px) - 50px)',
6363
],
64+
['calc(theme(spacing.1-bar))', 'calc(theme(spacing.1-bar))'],
65+
['theme(spacing.1-bar)', 'theme(spacing.1-bar)'],
66+
['calc(theme(spacing.1-bar))', 'calc(theme(spacing.1-bar))'],
67+
['calc(1rem-theme(spacing.1-bar))', 'calc(1rem - theme(spacing.1-bar))'],
68+
['calc(theme(spacing.foo-2))', 'calc(theme(spacing.foo-2))'],
69+
['calc(theme(spacing.foo-bar))', 'calc(theme(spacing.foo-bar))'],
6470

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

0 commit comments

Comments
 (0)