Skip to content

Commit 3149738

Browse files
authored
Properly detect theme() value usage in arbitrary properties (#6854)
* properly detect theme value in arbitrary properties * update changelog
1 parent c912434 commit 3149738

4 files changed

+59
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- Improve `DEBUG` flag ([#6797](https://github.com/tailwindlabs/tailwindcss/pull/6797), [#6804](https://github.com/tailwindlabs/tailwindcss/pull/6804))
1313
- Ensure we can use `<` and `>` characters in modifiers ([#6851](https://github.com/tailwindlabs/tailwindcss/pull/6851))
1414
- Validate `theme()` works in arbitrary values ([#6852](https://github.com/tailwindlabs/tailwindcss/pull/6852))
15+
- Properly detect `theme()` value usage in arbitrary properties ([#6854](https://github.com/tailwindlabs/tailwindcss/pull/6854))
1516

1617
## [3.0.8] - 2021-12-28
1718

src/lib/defaultExtractor.js

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const PATTERNS = [
1010
/([^<>"'`\s]*\[\w*\("[^'`\s]*"\)\])/.source, // bg-[url("..."),url("...")]
1111
/([^<>"'`\s]*\['[^"'`\s]*'\])/.source, // `content-['hello']` but not `content-['hello']']`
1212
/([^<>"'`\s]*\["[^"'`\s]*"\])/.source, // `content-["hello"]` but not `content-["hello"]"]`
13+
/([^<>"'`\s]*\[[^<>"'`\s]*:[^\]\s]*\])/.source, // `[attr:value]`
1314
/([^<>"'`\s]*\[[^<>"'`\s]*:'[^"'`\s]*'\])/.source, // `[content:'hello']` but not `[content:"hello"]`
1415
/([^<>"'`\s]*\[[^<>"'`\s]*:"[^"'`\s]*"\])/.source, // `[content:"hello"]` but not `[content:'hello']`
1516
/([^<>"'`\s]*\[[^"'`\s]+\][^<>"'`\s]*)/.source, // `fill-[#bada55]`, `fill-[#bada55]/50`

tests/arbitrary-properties.test.js

+48
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,51 @@ test('invalid arbitrary property 2', () => {
273273
expect(result.css).toMatchFormattedCss(css``)
274274
})
275275
})
276+
277+
it('should be possible to read theme values in arbitrary properties (without quotes)', () => {
278+
let config = {
279+
content: [{ raw: html`<div class="[--a:theme(colors.blue.500)] [color:var(--a)]"></div>` }],
280+
corePlugins: { preflight: false },
281+
}
282+
283+
let input = css`
284+
@tailwind base;
285+
@tailwind components;
286+
@tailwind utilities;
287+
`
288+
289+
return run(input, config).then((result) => {
290+
return expect(result.css).toMatchFormattedCss(css`
291+
.\[--a\:theme\(colors\.blue\.500\)\] {
292+
--a: #3b82f6;
293+
}
294+
.\[color\:var\(--a\)\] {
295+
color: var(--a);
296+
}
297+
`)
298+
})
299+
})
300+
301+
it('should be possible to read theme values in arbitrary properties (with quotes)', () => {
302+
let config = {
303+
content: [{ raw: html`<div class="[--a:theme('colors.blue.500')] [color:var(--a)]"></div>` }],
304+
corePlugins: { preflight: false },
305+
}
306+
307+
let input = css`
308+
@tailwind base;
309+
@tailwind components;
310+
@tailwind utilities;
311+
`
312+
313+
return run(input, config).then((result) => {
314+
return expect(result.css).toMatchFormattedCss(css`
315+
.\[--a\:theme\(\'colors\.blue\.500\'\)\] {
316+
--a: #3b82f6;
317+
}
318+
.\[color\:var\(--a\)\] {
319+
color: var(--a);
320+
}
321+
`)
322+
})
323+
})

tests/default-extractor.test.js

+9
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,15 @@ test('arbitrary values with angle brackets in double quotes', async () => {
324324
expect(extractions).toContain(`hover:focus:content-[">"]`)
325325
})
326326

327+
test('arbitrary values with theme lookup using quotes', () => {
328+
const extractions = defaultExtractor(`
329+
<p class="[--y:theme('colors.blue.500')] [color:var(--y)]"></p>
330+
`)
331+
332+
expect(extractions).toContain(`[--y:theme('colors.blue.500')]`)
333+
expect(extractions).toContain(`[color:var(--y)]`)
334+
})
335+
327336
test('special characters', async () => {
328337
const extractions = defaultExtractor(`
329338
<div class="<sm:underline md>:font-bold"></div>

0 commit comments

Comments
 (0)