Skip to content

Commit 6bcb445

Browse files
committed
\ are valid arbitrary variant tokens
We use `\` for escaping `.` or `_` so they should be part of the arbitrary variant regex.
1 parent 3f2e570 commit 6bcb445

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

src/lib/defaultExtractor.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function* buildRegExps(context) {
6969
'((?=((',
7070
regex.any(
7171
[
72-
regex.pattern([/([^\s"'`\[\\]+-)?\[[^\s"'`\\]+\]/, separator]),
72+
regex.pattern([/([^\s"'`\[\\]+-)?\[[^\s"'`]+\]/, separator]),
7373
regex.pattern([/[^\s"'`\[\\]+/, separator]),
7474
],
7575
true

tests/arbitrary-variants.test.js

+54
Original file line numberDiff line numberDiff line change
@@ -405,3 +405,57 @@ test('with @apply', () => {
405405
`)
406406
})
407407
})
408+
409+
test('keeps escaped underscores', () => {
410+
let config = {
411+
content: [
412+
{
413+
raw: '<div class="[&_.foo\\_\\_bar]:underline"></div>',
414+
},
415+
],
416+
corePlugins: { preflight: false },
417+
}
418+
419+
let input = `
420+
@tailwind base;
421+
@tailwind components;
422+
@tailwind utilities;
423+
`
424+
425+
return run(input, config).then((result) => {
426+
expect(result.css).toMatchFormattedCss(css`
427+
${defaults}
428+
429+
.\[\&_\.foo\\_\\_bar\]\:underline .foo__bar {
430+
text-decoration-line: underline;
431+
}
432+
`)
433+
})
434+
})
435+
436+
test('keeps escaped underscores with multiple arbitrary variants', () => {
437+
let config = {
438+
content: [
439+
{
440+
raw: '<div class="[&_.foo\\_\\_bar]:[&_.bar\\_\\_baz]:underline"></div>',
441+
},
442+
],
443+
corePlugins: { preflight: false },
444+
}
445+
446+
let input = `
447+
@tailwind base;
448+
@tailwind components;
449+
@tailwind utilities;
450+
`
451+
452+
return run(input, config).then((result) => {
453+
expect(result.css).toMatchFormattedCss(css`
454+
${defaults}
455+
456+
.\[\&_\.foo\\_\\_bar\]\:\[\&_\.bar\\_\\_baz\]\:underline .bar__baz .foo__bar {
457+
text-decoration-line: underline;
458+
}
459+
`)
460+
})
461+
})

0 commit comments

Comments
 (0)