Skip to content

Commit fa9be73

Browse files
authored
Ensure variants with arbitrary values and a modifier are correctly matched in the RegEx based parser (#12179)
* add failing test * ensure variants can have modifiers in regex * update changelog
1 parent 51ac627 commit fa9be73

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2525
- Eliminate irrelevant rules when applying variants ([#12113](https://github.com/tailwindlabs/tailwindcss/pull/12113))
2626
- Improve RegEx parser, reduce possibilities as the key for arbitrary properties ([#12121](https://github.com/tailwindlabs/tailwindcss/pull/12121))
2727
- Fix sorting of utilities that share multiple candidates ([#12173](https://github.com/tailwindlabs/tailwindcss/pull/12173))
28+
- Ensure variants with arbitrary values and a modifier are correctly matched in the RegEx based parser ([#12179](https://github.com/tailwindlabs/tailwindcss/pull/12179))
2829

2930
### Added
3031

src/lib/defaultExtractor.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,18 @@ function* buildRegExps(context) {
8080
// This is here to provide special support for the `@` variant
8181
regex.pattern([/@\[[^\s"'`]+\](\/[^\s"'`]+)?/, separator]),
8282

83+
// With variant modifier (e.g.: group-[..]/modifier)
84+
regex.pattern([/([^\s"'`\[\\]+-)?\[[^\s"'`]+\]\/\w+/, separator]),
85+
8386
regex.pattern([/([^\s"'`\[\\]+-)?\[[^\s"'`]+\]/, separator]),
8487
regex.pattern([/[^\s"'`\[\\]+/, separator]),
8588
]),
8689

8790
// With quotes allowed
8891
regex.any([
92+
// With variant modifier (e.g.: group-[..]/modifier)
93+
regex.pattern([/([^\s"'`\[\\]+-)?\[[^\s`]+\]\/\w+/, separator]),
94+
8995
regex.pattern([/([^\s"'`\[\\]+-)?\[[^\s`]+\]/, separator]),
9096
regex.pattern([/[^\s`\[\\]+/, separator]),
9197
]),

tests/parse-candidate-strings.test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,5 +458,29 @@ describe.each([
458458
expect(extractions).toContain('p-2')
459459
expect(extractions).toContain('p-2.5')
460460
})
461+
462+
it.each([
463+
// With group name modifier
464+
[
465+
'<div class="bg-blue-300 group-[[data-can-play]:not([data-playing])]/parent:bg-red-300 p-4 w-60" ></div>',
466+
[
467+
'bg-blue-300',
468+
'group-[[data-can-play]:not([data-playing])]/parent:bg-red-300',
469+
'p-4',
470+
'w-60',
471+
],
472+
],
473+
// Without group name modifier
474+
[
475+
'<div class="bg-blue-300 group-[[data-can-play]:not([data-playing])]:bg-red-300 p-4 w-60">',
476+
['bg-blue-300', 'group-[[data-can-play]:not([data-playing])]:bg-red-300', 'p-4', 'w-60'],
477+
],
478+
])('should work for issue #12169 (%#)', async (content, expectations) => {
479+
let extractions = parse(content)
480+
481+
for (let value of expectations) {
482+
expect(extractions).toContain(value)
483+
}
484+
})
461485
})
462486
})

0 commit comments

Comments
 (0)