Skip to content

Commit d346004

Browse files
committed
Fix support for slashes in arbitrary modifiers
1 parent 817c466 commit d346004

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/util/pluginUtils.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,18 @@ 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+
// Backtrack to the previous `/` if the one we found was inside an arbitrary
97+
if (arbitraryStartIdx !== -1 && arbitraryEndIdx !== -1) {
98+
if (arbitraryStartIdx < slashIdx && slashIdx < arbitraryEndIdx) {
99+
slashIdx = modifier.lastIndexOf('/', arbitraryStartIdx)
100+
}
101+
}
102+
91103
if (slashIdx === -1 || slashIdx === modifier.length - 1) {
92104
return [modifier, undefined]
93105
}

tests/arbitrary-values.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,21 @@ crosscheck(({ stable, oxide }) => {
652652
`)
653653
})
654654
})
655+
656+
it('should support slashes in arbitrary modifiers', () => {
657+
let config = {
658+
content: [{ raw: html`<div class="text-lg/[calc(50px/2)]"></div>` }],
659+
}
660+
661+
return run('@tailwind utilities', config).then((result) => {
662+
return expect(result.css).toMatchFormattedCss(css`
663+
.text-lg\/\[calc\(50px\/2\)\] {
664+
font-size: 1.125rem;
665+
line-height: calc(50px / 2);
666+
}
667+
`)
668+
})
669+
})
655670
})
656671

657672
it('should not insert spaces around operators inside `env()`', () => {

0 commit comments

Comments
 (0)