Skip to content

Commit

Permalink
Skip escaped commas when splitting selector (#5239)
Browse files Browse the repository at this point in the history
  • Loading branch information
bradlc authored Aug 18, 2021
1 parent 0bb3e74 commit e1160e3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/util/pluginUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,28 @@ export function updateLastClasses(selectors, updateClass) {
return result
}

function splitByNotEscapedCommas(str) {
let chunks = []
let currentChunk = ''
for (let i = 0; i < str.length; i++) {
if (str[i] === ',' && str[i - 1] !== '\\') {
chunks.push(currentChunk)
currentChunk = ''
} else {
currentChunk += str[i]
}
}
chunks.push(currentChunk)
return chunks
}

export function transformAllSelectors(transformSelector, { wrap, withRule } = {}) {
return ({ container }) => {
container.walkRules((rule) => {
if (isKeyframeRule(rule)) {
return rule
}
let transformed = rule.selector.split(',').map(transformSelector).join(',')
let transformed = splitByNotEscapedCommas(rule.selector).map(transformSelector).join(',')
rule.selector = transformed
if (withRule) {
withRule(rule)
Expand Down
4 changes: 4 additions & 0 deletions tests/jit/prefix.test.css
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@
text-align: center;
}
}
.tw-dark .dark\:tw-bg-\[rgb\(255\2c 0\2c 0\)\] {
--tw-bg-opacity: 1;
background-color: rgba(255, 0, 0, var(--tw-bg-opacity));
}
.tw-dark .dark\:focus\:tw-text-left:focus {
text-align: left;
}
Expand Down
1 change: 1 addition & 0 deletions tests/jit/prefix.test.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<div class="md:hover:tw-text-right"></div>
<div class="motion-safe:hover:tw-text-center"></div>
<div class="dark:focus:tw-text-left"></div>
<div class="dark:tw-bg-[rgb(255,0,0)]"></div>
<div class="group-hover:focus-within:tw-text-left"></div>
<div class="rtl:active:tw-text-center"></div>
<div class="tw-animate-ping"></div>
Expand Down

0 comments on commit e1160e3

Please sign in to comment.