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

feat(core)!: make select pseudo elements not to be moved around #2190

Merged
merged 5 commits into from Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 17 additions & 1 deletion packages/core/src/generator/index.ts
Expand Up @@ -647,11 +647,27 @@ function applyScope(css: string, scope?: string) {
return scope ? `${scope} ${css}` : css
}

const excludedPseudo = [
'::-webkit-resizer',
'::-webkit-scrollbar',
'::-webkit-scrollbar-button',
'::-webkit-scrollbar-corner',
'::-webkit-scrollbar-thumb',
'::-webkit-scrollbar-track',
'::-webkit-scrollbar-track-piece',
'::file-selector-button',
]
export function movePseudoElementsEnd(selector: string) {
const pseudoElements = selector.match(/::[\w-]+(\([\w-]+\))?/g)
if (pseudoElements) {
for (const e of pseudoElements)
for (let i = pseudoElements.length - 1; i >= 0; --i) {
const e = pseudoElements[i]
if (excludedPseudo.includes(e)) {
pseudoElements.splice(i, 1)
continue
}
selector = selector.replace(e, '')
}
selector += pseudoElements.join('')
}
return selector
Expand Down
2 changes: 1 addition & 1 deletion test/__snapshots__/order.test.ts.snap
Expand Up @@ -10,7 +10,7 @@ exports[`order > fully controlled rules merged and sorted by body 1`] = `
.css{--var:css;}"
`;

exports[`order > movePseudoElementsEnd 1`] = `".part-\\\\[hello-2\\\\]\\\\:marker\\\\:file\\\\:hover\\\\:selection\\\\:mb-4:hover::part(hello-2)::marker::file-selector-button::selection"`;
exports[`order > movePseudoElementsEnd 1`] = `".part-\\\\[hello-2\\\\]\\\\:marker\\\\:file\\\\:hover\\\\:selection\\\\:mb-4::file-selector-button:hover::part(hello-2)::marker::selection"`;

exports[`order > multiple variant sorting 1`] = `
"/* layer: default */
Expand Down