Skip to content

Commit

Permalink
Merge pull request #105 from m-akinc/support-has
Browse files Browse the repository at this point in the history
Avoid generating invalid selector with `:has`
  • Loading branch information
ghengeveld authored Mar 5, 2024
2 parents 3baec49 + 34693f6 commit 21102cc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/preview/rewriteStyleSheet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,12 @@ describe("rewriteStyleSheet", () => {
expect(sheet.cssRules[0].selectorText).toEqual(":not(:hover), :not(.pseudo-hover)")
})

it('supports ":has"', () => {
const sheet = new Sheet(":has(:hover) { color: red }")
rewriteStyleSheet(sheet as any)
expect(sheet.cssRules[0].cssText).toEqual(":has(:hover), :has(.pseudo-hover) { color: red }")
})

it("override correct rules with media query present", () => {
const sheet = new Sheet(
`@media (max-width: 790px) {
Expand Down
2 changes: 1 addition & 1 deletion src/preview/rewriteStyleSheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const rewriteRule = ({ cssText, selectorText }: CSSStyleRule, shadowRoot?: Shado
}

return [selector, classSelector, ancestorSelector].filter(
(selector) => selector && !selector.includes(":not()")
(selector) => selector && !selector.includes(":not()") && !selector.includes(":has()")
)
})
.join(", ")
Expand Down

0 comments on commit 21102cc

Please sign in to comment.