Skip to content

Commit

Permalink
Fix incorrectly generated CSS when using square brackets inside arbit…
Browse files Browse the repository at this point in the history
…rary properties (#11709)

* ensure nested square brackets are handled properly inside arbitrary properties

* update changelog
  • Loading branch information
RobinMalfait authored and thecrypticace committed Oct 23, 2023
1 parent 7720e16 commit 808c1f0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

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

## [3.3.3] - 2023-07-13

Expand Down
3 changes: 2 additions & 1 deletion src/util/formatVariantSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import unescape from 'postcss-selector-parser/dist/util/unesc'
import escapeClassName from '../util/escapeClassName'
import prefixSelector from '../util/prefixSelector'
import { movePseudos } from './pseudoElements'
import { splitAtTopLevelOnly } from './splitAtTopLevelOnly'

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

// Parse the selector into an AST
let selector = selectorParser().astSync(current)
Expand Down
27 changes: 27 additions & 0 deletions tests/evaluateTailwindFunctions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1416,3 +1416,30 @@ crosscheck(({ stable, oxide }) => {
})
})
})

test('it should handle square brackets inside `theme`, inside arbitrary properties', () => {
let config = {
content: [
{
raw: html` <div class="bg-[--color] sm:[--color:_theme(colors.green[400])]"></div> `,
},
],
}

let input = css`
@tailwind utilities;
`

return runFull(input, config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
.bg-\[--color\] {
background-color: var(--color);
}
@media (min-width: 640px) {
.sm\:\[--color\:_theme\(colors\.green\[400\]\)\] {
--color: #4ade80;
}
}
`)
})
})

0 comments on commit 808c1f0

Please sign in to comment.