Skip to content

Commit a6e79f9

Browse files
authored
Improve extractor for arbitrary values with quotes (#4817)
Fixes #4801.
1 parent 59c7e32 commit a6e79f9

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

src/jit/lib/expandTailwindAtRules.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ import cloneNodes from '../../util/cloneNodes'
66
let env = sharedState.env
77
let contentMatchCache = sharedState.contentMatchCache
88

9-
const BROAD_MATCH_GLOBAL_REGEXP = /([^<>"'`\s]*\[[^<>\s]+\])|([^<>"'`\s]*[^<>"'`\s:])/g
9+
const PATTERNS = [
10+
"([^<>\"'`\\s]*\\['[^<>\"'`\\s]*'\\])", // `content-['hello']` but not `content-['hello']']`
11+
'([^<>"\'`\\s]*\\["[^<>"\'`\\s]*"\\])', // `content-["hello"]` but not `content-["hello"]"]`
12+
'([^<>"\'`\\s]*\\[[^<>"\'`\\s]+\\])', // `fill-[#bada55]`
13+
'([^<>"\'`\\s]*[^<>"\'`\\s:])', // `px-1.5`, `uppercase` but not `uppercase:`
14+
].join('|')
15+
const BROAD_MATCH_GLOBAL_REGEXP = new RegExp(PATTERNS, 'g')
1016
const INNER_MATCH_GLOBAL_REGEXP = /[^<>"'`\s.(){}[\]#=%]*[^<>"'`\s.(){}[\]#=%:]/g
1117

1218
const builtInExtractors = {
+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import postcss from 'postcss'
2+
import path from 'path'
3+
import tailwind from '../../src/jit/index.js'
4+
5+
function run(input, config = {}) {
6+
const { currentTestName } = expect.getState()
7+
8+
return postcss(tailwind(config)).process(input, {
9+
from: `${path.resolve(__filename)}?test=${currentTestName}`,
10+
})
11+
}
12+
13+
test('PHP arrays', async () => {
14+
let config = {
15+
mode: 'jit',
16+
purge: [
17+
{
18+
raw: `<h1 class="<?php echo wrap(['class' => "max-w-[16rem]"]); ?>">Hello world</h1>`,
19+
},
20+
],
21+
theme: {},
22+
plugins: [],
23+
}
24+
25+
let css = `@tailwind utilities`
26+
27+
return run(css, config).then((result) => {
28+
expect(result.css).toMatchFormattedCss(`
29+
.max-w-\\[16rem\\] {
30+
max-width: 16rem;
31+
}
32+
`)
33+
})
34+
})
35+
36+
test('arbitrary values with quotes', async () => {
37+
let config = {
38+
mode: 'jit',
39+
purge: [
40+
{
41+
raw: `<div class="content-['hello]']"></div>`,
42+
},
43+
],
44+
theme: {},
45+
plugins: [],
46+
}
47+
48+
let css = `@tailwind utilities`
49+
50+
return run(css, config).then((result) => {
51+
expect(result.css).toMatchFormattedCss(`
52+
.content-\\[\\'hello\\]\\'\\] {
53+
content: 'hello]';
54+
}
55+
`)
56+
})
57+
})

0 commit comments

Comments
 (0)