Skip to content

Commit 808c1f0

Browse files
RobinMalfaitthecrypticace
authored andcommitted
Fix incorrectly generated CSS when using square brackets inside arbitrary properties (#11709)
* ensure nested square brackets are handled properly inside arbitrary properties * update changelog
1 parent 7720e16 commit 808c1f0

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515

1616
- Improve normalisation of `calc()`-like functions ([#11686](https://github.com/tailwindlabs/tailwindcss/pull/11686))
1717
- Skip `calc()` normalisation in nested `theme()` calls ([#11705](https://github.com/tailwindlabs/tailwindcss/pull/11705))
18+
- Fix incorrectly generated CSS when using square brackets inside arbitrary properties ([#11709](https://github.com/tailwindlabs/tailwindcss/pull/11709))
1819

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

src/util/formatVariantSelector.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import unescape from 'postcss-selector-parser/dist/util/unesc'
33
import escapeClassName from '../util/escapeClassName'
44
import prefixSelector from '../util/prefixSelector'
55
import { movePseudos } from './pseudoElements'
6+
import { splitAtTopLevelOnly } from './splitAtTopLevelOnly'
67

78
/** @typedef {import('postcss-selector-parser').Root} Root */
89
/** @typedef {import('postcss-selector-parser').Selector} Selector */
@@ -160,7 +161,7 @@ export function finalizeSelector(current, formats, { context, candidate, base })
160161
// │ │ │ ╰── We will not split here
161162
// ╰──┴─────┴─────────────── We will split here
162163
//
163-
base = base ?? candidate.split(new RegExp(`\\${separator}(?![^[]*\\])`)).pop()
164+
base = base ?? splitAtTopLevelOnly(candidate, separator).pop()
164165

165166
// Parse the selector into an AST
166167
let selector = selectorParser().astSync(current)

tests/evaluateTailwindFunctions.test.js

+27
Original file line numberDiff line numberDiff line change
@@ -1416,3 +1416,30 @@ crosscheck(({ stable, oxide }) => {
14161416
})
14171417
})
14181418
})
1419+
1420+
test('it should handle square brackets inside `theme`, inside arbitrary properties', () => {
1421+
let config = {
1422+
content: [
1423+
{
1424+
raw: html` <div class="bg-[--color] sm:[--color:_theme(colors.green[400])]"></div> `,
1425+
},
1426+
],
1427+
}
1428+
1429+
let input = css`
1430+
@tailwind utilities;
1431+
`
1432+
1433+
return runFull(input, config).then((result) => {
1434+
expect(result.css).toMatchFormattedCss(css`
1435+
.bg-\[--color\] {
1436+
background-color: var(--color);
1437+
}
1438+
@media (min-width: 640px) {
1439+
.sm\:\[--color\:_theme\(colors\.green\[400\]\)\] {
1440+
--color: #4ade80;
1441+
}
1442+
}
1443+
`)
1444+
})
1445+
})

0 commit comments

Comments
 (0)