Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip escaped commas when splitting selector #5239

Merged
merged 1 commit into from
Aug 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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