Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrectly generated CSS when using square brackets inside arbitrary properties #11709

Merged
merged 2 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Allow variant to be an at-rule without a prelude ([#11589](https://github.com/tailwindlabs/tailwindcss/pull/11589))
- 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))

### Added

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 @@ -1389,3 +1389,30 @@ describe('context dependent', () => {
})
})
})

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;
}
}
`)
})
})
Loading