Skip to content

Commit adb6f15

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

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
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
- Improve types for `resolveConfig` ([#12272](https://github.com/tailwindlabs/tailwindcss/pull/12272))
1515
- Ensure configured `font-feature-settings` for `mono` are included in Preflight ([#12342](https://github.com/tailwindlabs/tailwindcss/pull/12342))
1616
- Don't crash when given applying a variant to a negated version of a simple utility ([#12514](https://github.com/tailwindlabs/tailwindcss/pull/12514))
17+
- Fix support for slashes in arbitrary modifiers ([#12515](https://github.com/tailwindlabs/tailwindcss/pull/12515))
1718

1819
## [3.3.5] - 2023-10-25
1920

src/util/pluginUtils.js

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

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

tests/arbitrary-values.test.js

+15
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,21 @@ crosscheck(({ stable, oxide }) => {
654654
})
655655
})
656656

657+
it('should support slashes in arbitrary modifiers', () => {
658+
let config = {
659+
content: [{ raw: html`<div class="text-lg/[calc(50px/1rem)]"></div>` }],
660+
}
661+
662+
return run('@tailwind utilities', config).then((result) => {
663+
return expect(result.css).toMatchFormattedCss(css`
664+
.text-lg\/\[calc\(50px\/1rem\)\] {
665+
font-size: 1.125rem;
666+
line-height: calc(50px / 1rem);
667+
}
668+
`)
669+
})
670+
})
671+
657672
it('should not insert spaces around operators inside `env()`', () => {
658673
let config = {
659674
content: [{ raw: html`<div class="grid-cols-[calc(env(safe-area-inset-bottom)+1px)]"></div>` }],

0 commit comments

Comments
 (0)