svelte-preprocess
svelte-preprocess copied to clipboard
unexpected style when I use `:where` in global CSS
Describe the bug When I add a PostCSS preprocessor to svletekit, below CSS code doesn't work anymore:
<style global>
.btn:where(.btn-primary,.btn-secondary){
background-color: green;
}
</style>
To Reproduce
- Clone this: https://github.com/saadeghi/svelte-preprocess-postcss-bug
-
npm install -
npm run dev - now uncomment line 5 on svelte.config.js to disable the preprocess and
npm run devagain to see expected style
Expected behavior
Expected CSS:
.btn:where(.btn-primary,.btn-secondary){
background-color: green;
}
generated CSS:
.btn:where(.btn-primary),:global(.btn-secondary){
background-color:green
}
Information about your project: https://github.com/saadeghi/svelte-preprocess-postcss-bug
+1.
This actually causes problems more often than one might think since popular packages like the-new-css-reset use :where.
Minimal repro for such cases is:
<style lang="sass" global>
@use 'the-new-css-reset/css/reset'
</style>
The bug is located in this function: https://github.com/sveltejs/svelte-preprocess/blob/main/src/modules/globalifySelector.ts#L11
The Regex does not account for more modern :where, :not and :ìs selectors