postcss / postcss-import

PostCSS plugin to inline at-import rules content
MIT License
1.38k stars 115 forks source link

add parsing support for `supports` conditions #530

Closed romainmenke closed 1 year ago

romainmenke commented 1 year ago

see : https://github.com/postcss/postcss-import/issues/529


Fully implementing supports conditions will require a fairly large refactor and the codebase is already very complex.

I would like to first do a few refactors. This is one of them.

I've added c8 to ensure that test coverage remains high throughout this process.

File % Stmts % Branch % Funcs % Lines Uncovered Line #s
All files 100 99.65 100 100
postcss-import 100 100 100 100
index.js 100 100 100 100
postcss-import/lib 100 99.34 100 100
assign-layer-names.js 100 100 100 100
data-url.js 100 100 100 100
join-layer.js 100 100 100 100
join-media.js 100 100 100 100
load-content.js 100 100 100 100
parse-statements.js 100 100 100 100
process-content.js 100 93.75 100 100 26
resolve-id.js 100 100 100 100

Initially the parsing algorithm was a simple split:

With layer and supports something more flexible is needed. I've changed the parsing algorithm to a loop that keeps track of what has been encountered and errors on any unexpected sequences.


Any supports conditions will give errors:

Supports conditions are not implemented at this time.

This is a behavior change. Before this PR supports conditions would be treated as if they were media conditions, which is also incorrect.

Both behaviors are "broken" but after this change CSS authors will receive more meaningful feedback.

RyanZim commented 1 year ago

@romainmenke are you thinking we should release with this warning for @supports, or is this just a temporary measure until we add support after refactoring?

romainmenke commented 1 year ago

are you thinking we should release with this warning for @supports, or is this just a temporary measure until we add support after refactoring?

I am hoping it is temporary. But I want to keep the code base healthy after each change and I would like to keep each change small-ish.

The state in this pull request is something that can be released if needed.

I plan to continue work towards full support for supports conditions, but this could take a while. It really complicates things that four different types of rules interact (import, media, layer, supports). With layer I was able to patch a few existing bits and make it work, but a larger refactor is needed for supports.

romainmenke commented 1 year ago

Thank you for the review 🙇