Skip to content

Commit e1160e3

Browse files
authored
Skip escaped commas when splitting selector (#5239)
1 parent 0bb3e74 commit e1160e3

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

src/util/pluginUtils.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,28 @@ export function updateLastClasses(selectors, updateClass) {
7070
return result
7171
}
7272

73+
function splitByNotEscapedCommas(str) {
74+
let chunks = []
75+
let currentChunk = ''
76+
for (let i = 0; i < str.length; i++) {
77+
if (str[i] === ',' && str[i - 1] !== '\\') {
78+
chunks.push(currentChunk)
79+
currentChunk = ''
80+
} else {
81+
currentChunk += str[i]
82+
}
83+
}
84+
chunks.push(currentChunk)
85+
return chunks
86+
}
87+
7388
export function transformAllSelectors(transformSelector, { wrap, withRule } = {}) {
7489
return ({ container }) => {
7590
container.walkRules((rule) => {
7691
if (isKeyframeRule(rule)) {
7792
return rule
7893
}
79-
let transformed = rule.selector.split(',').map(transformSelector).join(',')
94+
let transformed = splitByNotEscapedCommas(rule.selector).map(transformSelector).join(',')
8095
rule.selector = transformed
8196
if (withRule) {
8297
withRule(rule)

tests/jit/prefix.test.css

+4
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@
7272
text-align: center;
7373
}
7474
}
75+
.tw-dark .dark\:tw-bg-\[rgb\(255\2c 0\2c 0\)\] {
76+
--tw-bg-opacity: 1;
77+
background-color: rgba(255, 0, 0, var(--tw-bg-opacity));
78+
}
7579
.tw-dark .dark\:focus\:tw-text-left:focus {
7680
text-align: left;
7781
}

tests/jit/prefix.test.html

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<div class="md:hover:tw-text-right"></div>
1414
<div class="motion-safe:hover:tw-text-center"></div>
1515
<div class="dark:focus:tw-text-left"></div>
16+
<div class="dark:tw-bg-[rgb(255,0,0)]"></div>
1617
<div class="group-hover:focus-within:tw-text-left"></div>
1718
<div class="rtl:active:tw-text-center"></div>
1819
<div class="tw-animate-ping"></div>

0 commit comments

Comments
 (0)