Skip to content

Commit e4b398b

Browse files
authored
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 5e24f8e commit e4b398b

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
@@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
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))
2727
- Skip `calc()` normalisation in nested `theme()` calls ([#11705](https://github.com/tailwindlabs/tailwindcss/pull/11705))
28+
- Fix incorrectly generated CSS when using square brackets inside arbitrary properties ([#11709](https://github.com/tailwindlabs/tailwindcss/pull/11709))
2829

2930
### Added
3031

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
@@ -1389,3 +1389,30 @@ describe('context dependent', () => {
13891389
})
13901390
})
13911391
})
1392+
1393+
test('it should handle square brackets inside `theme`, inside arbitrary properties', () => {
1394+
let config = {
1395+
content: [
1396+
{
1397+
raw: html` <div class="bg-[--color] sm:[--color:_theme(colors.green[400])]"></div> `,
1398+
},
1399+
],
1400+
}
1401+
1402+
let input = css`
1403+
@tailwind utilities;
1404+
`
1405+
1406+
return runFull(input, config).then((result) => {
1407+
expect(result.css).toMatchFormattedCss(css`
1408+
.bg-\[--color\] {
1409+
background-color: var(--color);
1410+
}
1411+
@media (min-width: 640px) {
1412+
.sm\:\[--color\:_theme\(colors\.green\[400\]\)\] {
1413+
--color: #4ade80;
1414+
}
1415+
}
1416+
`)
1417+
})
1418+
})

0 commit comments

Comments
 (0)