Skip to content

Commit

Permalink
Don’t clip slashes inside brackets when using the theme function (#8563)
Browse files Browse the repository at this point in the history
  • Loading branch information
thecrypticace committed Jun 9, 2022
1 parent 9a5db88 commit 7aa2d4d
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib/evaluateTailwindFunctions.js
Expand Up @@ -162,7 +162,7 @@ let nodeTypePropertyMap = {
export default function ({ tailwindConfig: config }) {
let functions = {
theme: (node, path, ...defaultValue) => {
let matches = path.match(/^([^\/\s]+)(?:\s*\/\s*([^\/\s]+))$/)
let matches = path.match(/^([^\s]+)(?![^\[]*\])(?:\s*\/\s*([^\/\s]+))$/)
let alpha = undefined

if (matches) {
Expand Down
31 changes: 31 additions & 0 deletions tests/evaluateTailwindFunctions.test.js
Expand Up @@ -1024,3 +1024,34 @@ test('Theme function can extract alpha values for colors (8)', () => {
expect(result.warnings().length).toBe(0)
})
})

test('Theme functions can reference values with slashes in brackets', () => {
let input = css`
.foo1 {
color: theme(colors[a/b]);
}
.foo2 {
color: theme(colors[a/b]/50%);
}
`

let output = css`
.foo1 {
color: #000000;
}
.foo2 {
color: rgb(0 0 0 / 50%);
}
`

return runFull(input, {
theme: {
colors: {
'a/b': '#000000',
},
},
}).then((result) => {
expect(result.css).toMatchCss(output)
expect(result.warnings().length).toBe(0)
})
})
33 changes: 33 additions & 0 deletions tests/opacity.test.js
Expand Up @@ -728,3 +728,36 @@ it('should be possible to use <alpha-value> inside arbitrary values', () => {
`)
})
})

it('Theme functions can reference values with slashes in brackets', () => {
let config = {
content: [
{
raw: html` <div class="bg-foo1 bg-foo2"></div> `,
},
],
theme: {
colors: {
'a/b': '#000000',
},
extend: {
backgroundColor: ({ theme }) => ({
foo1: theme('colors[a/b]'),
foo2: theme('colors[a/b]/50%'),
}),
},
},
}

return run('@tailwind utilities', config).then((result) => {
expect(result.css).toMatchCss(css`
.bg-foo1 {
--tw-bg-opacity: 1;
background-color: rgb(0 0 0 / var(--tw-bg-opacity));
}
.bg-foo2 {
background-color: rgb(0 0 0 / 50%);
}
`)
})
})

0 comments on commit 7aa2d4d

Please sign in to comment.