dbtedman / postcss-prefixwrap

A PostCSS plugin that is used to wrap css styles with a css selector to constrain their affect on parent elements in a page.
MIT License
67 stars 12 forks source link

Items within a `:where` statement are incorrectly prefixed #515

Closed talldan closed 1 month ago

talldan commented 1 month ago

If you take a selector like .class-a :where(.class-b, .class-c) and try prefixing it with .prefix-class, it results in a selector .prefix-class .class-a :where(.class-b, .prefix-class .class-c), which is incorrect. I think the expected result should be .prefix-class .class-a :where(.class-b, .class-c)

It appears to be because the code splits a selector string using the string .split( ',' ) method: https://github.com/dbtedman/postcss-prefixwrap/blob/c2636cdaa8381741df1b2b553d15a82d1e674802/src/internal/domain/CSSRuleWrapper.ts#L20-L21

I think the AST does provide an already split cssRule.selectors property, so splitting the string might not be needed, it may be ok to lean on what the AST provides.

dbtedman commented 1 month ago

Thanks for reporting this, I will take a look at your suggestion soon and prepare an update to resolve the issue.

dbtedman commented 1 month ago

Fix will be included in 1.51.0 release.