Skip to content

Commit 3169d15

Browse files
Fix generation of utilities that use slashes in arbitrary modifiers (#12515)
* Fix support for slashes in arbitrary modifiers * Update changelog
1 parent b2b37e0 commit 3169d15

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
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
- Ensure configured `font-feature-settings` for `mono` are included in Preflight ([#12342](https://github.com/tailwindlabs/tailwindcss/pull/12342))
1616
- Improve candidate detection in minified JS arrays (without spaces) ([#12396](https://github.com/tailwindlabs/tailwindcss/pull/12396))
1717
- Don't crash when given applying a variant to a negated version of a simple utility ([#12514](https://github.com/tailwindlabs/tailwindcss/pull/12514))
18+
- Fix support for slashes in arbitrary modifiers ([#12515](https://github.com/tailwindlabs/tailwindcss/pull/12515))
1819
- [Oxide] Remove `autoprefixer` dependency ([#11315](https://github.com/tailwindlabs/tailwindcss/pull/11315))
1920
- [Oxide] Fix source maps issue resulting in a crash ([#11319](https://github.com/tailwindlabs/tailwindcss/pull/11319))
2021
- [Oxide] Fallback to RegEx based parser when using custom transformers or extractors ([#11335](https://github.com/tailwindlabs/tailwindcss/pull/11335))

src/util/pluginUtils.js

+16
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,22 @@ function isArbitraryValue(input) {
8787
function splitUtilityModifier(modifier) {
8888
let slashIdx = modifier.lastIndexOf('/')
8989

90+
// If the `/` is inside an arbitrary, we want to find the previous one if any
91+
// This logic probably isn't perfect but it should work for most cases
92+
let arbitraryStartIdx = modifier.lastIndexOf('[', slashIdx)
93+
let arbitraryEndIdx = modifier.indexOf(']', slashIdx)
94+
95+
let isNextToArbitrary = modifier[slashIdx - 1] === ']' || modifier[slashIdx + 1] === '['
96+
97+
// Backtrack to the previous `/` if the one we found was inside an arbitrary
98+
if (!isNextToArbitrary) {
99+
if (arbitraryStartIdx !== -1 && arbitraryEndIdx !== -1) {
100+
if (arbitraryStartIdx < slashIdx && slashIdx < arbitraryEndIdx) {
101+
slashIdx = modifier.lastIndexOf('/', arbitraryStartIdx)
102+
}
103+
}
104+
}
105+
90106
if (slashIdx === -1 || slashIdx === modifier.length - 1) {
91107
return [modifier, undefined]
92108
}

tests/arbitrary-values.test.js

+15
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,21 @@ it('should support underscores in arbitrary modifiers', () => {
639639
})
640640
})
641641

642+
it('should support slashes in arbitrary modifiers', () => {
643+
let config = {
644+
content: [{ raw: html`<div class="text-lg/[calc(50px/1rem)]"></div>` }],
645+
}
646+
647+
return run('@tailwind utilities', config).then((result) => {
648+
return expect(result.css).toMatchFormattedCss(css`
649+
.text-lg\/\[calc\(50px\/1rem\)\] {
650+
font-size: 1.125rem;
651+
line-height: calc(50px / 1rem);
652+
}
653+
`)
654+
})
655+
})
656+
642657
it('should not insert spaces around operators inside `env()`', () => {
643658
let config = {
644659
content: [{ raw: html`<div class="grid-cols-[calc(env(safe-area-inset-bottom)+1px)]"></div>` }],

0 commit comments

Comments
 (0)