Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Fix support for slashes in arbitrary modifiers
  • Loading branch information
thecrypticace committed Dec 1, 2023
commit 492c3a41782a565e0b02e5bd1846f47c9d800719
16 changes: 16 additions & 0 deletions src/util/pluginUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,22 @@ function isArbitraryValue(input) {
function splitUtilityModifier(modifier) {
let slashIdx = modifier.lastIndexOf('/')

// If the `/` is inside an arbitrary, we want to find the previous one if any
// This logic probably isn't perfect but it should work for most cases
let arbitraryStartIdx = modifier.lastIndexOf('[', slashIdx)
let arbitraryEndIdx = modifier.indexOf(']', slashIdx)

let isNextToArbitrary = modifier[slashIdx - 1] === ']' || modifier[slashIdx + 1] === '['

// Backtrack to the previous `/` if the one we found was inside an arbitrary
if (!isNextToArbitrary) {
if (arbitraryStartIdx !== -1 && arbitraryEndIdx !== -1) {
if (arbitraryStartIdx < slashIdx && slashIdx < arbitraryEndIdx) {
slashIdx = modifier.lastIndexOf('/', arbitraryStartIdx)
}
}
}

if (slashIdx === -1 || slashIdx === modifier.length - 1) {
return [modifier, undefined]
}
Expand Down
15 changes: 15 additions & 0 deletions tests/arbitrary-values.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,21 @@ it('should support underscores in arbitrary modifiers', () => {
})
})

it('should support slashes in arbitrary modifiers', () => {
let config = {
content: [{ raw: html`<div class="text-lg/[calc(50px/1rem)]"></div>` }],
}

return run('@tailwind utilities', config).then((result) => {
return expect(result.css).toMatchFormattedCss(css`
.text-lg\/\[calc\(50px\/1rem\)\] {
font-size: 1.125rem;
line-height: calc(50px / 1rem);
}
`)
})
})

it('should not insert spaces around operators inside `env()`', () => {
let config = {
content: [{ raw: html`<div class="grid-cols-[calc(env(safe-area-inset-bottom)+1px)]"></div>` }],
Expand Down