Skip to content

Commit

Permalink
Fix support for slashes in arbitrary modifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
thecrypticace committed Nov 30, 2023
1 parent 817c466 commit d346004
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/util/pluginUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ 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)

// Backtrack to the previous `/` if the one we found was inside an arbitrary
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 @@ -652,6 +652,21 @@ crosscheck(({ stable, oxide }) => {
`)
})
})

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

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

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

0 comments on commit d346004

Please sign in to comment.