Skip to content

Commit 7aa2d4d

Browse files
Don’t clip slashes inside brackets when using the theme function (#8563)
1 parent 9a5db88 commit 7aa2d4d

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed

src/lib/evaluateTailwindFunctions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ let nodeTypePropertyMap = {
162162
export default function ({ tailwindConfig: config }) {
163163
let functions = {
164164
theme: (node, path, ...defaultValue) => {
165-
let matches = path.match(/^([^\/\s]+)(?:\s*\/\s*([^\/\s]+))$/)
165+
let matches = path.match(/^([^\s]+)(?![^\[]*\])(?:\s*\/\s*([^\/\s]+))$/)
166166
let alpha = undefined
167167

168168
if (matches) {

tests/evaluateTailwindFunctions.test.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,3 +1024,34 @@ test('Theme function can extract alpha values for colors (8)', () => {
10241024
expect(result.warnings().length).toBe(0)
10251025
})
10261026
})
1027+
1028+
test('Theme functions can reference values with slashes in brackets', () => {
1029+
let input = css`
1030+
.foo1 {
1031+
color: theme(colors[a/b]);
1032+
}
1033+
.foo2 {
1034+
color: theme(colors[a/b]/50%);
1035+
}
1036+
`
1037+
1038+
let output = css`
1039+
.foo1 {
1040+
color: #000000;
1041+
}
1042+
.foo2 {
1043+
color: rgb(0 0 0 / 50%);
1044+
}
1045+
`
1046+
1047+
return runFull(input, {
1048+
theme: {
1049+
colors: {
1050+
'a/b': '#000000',
1051+
},
1052+
},
1053+
}).then((result) => {
1054+
expect(result.css).toMatchCss(output)
1055+
expect(result.warnings().length).toBe(0)
1056+
})
1057+
})

tests/opacity.test.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,3 +728,36 @@ it('should be possible to use <alpha-value> inside arbitrary values', () => {
728728
`)
729729
})
730730
})
731+
732+
it('Theme functions can reference values with slashes in brackets', () => {
733+
let config = {
734+
content: [
735+
{
736+
raw: html` <div class="bg-foo1 bg-foo2"></div> `,
737+
},
738+
],
739+
theme: {
740+
colors: {
741+
'a/b': '#000000',
742+
},
743+
extend: {
744+
backgroundColor: ({ theme }) => ({
745+
foo1: theme('colors[a/b]'),
746+
foo2: theme('colors[a/b]/50%'),
747+
}),
748+
},
749+
},
750+
}
751+
752+
return run('@tailwind utilities', config).then((result) => {
753+
expect(result.css).toMatchCss(css`
754+
.bg-foo1 {
755+
--tw-bg-opacity: 1;
756+
background-color: rgb(0 0 0 / var(--tw-bg-opacity));
757+
}
758+
.bg-foo2 {
759+
background-color: rgb(0 0 0 / 50%);
760+
}
761+
`)
762+
})
763+
})

0 commit comments

Comments
 (0)