postcss / postcss-nested

PostCSS plugin to unwrap nested rules like how Sass does it.
MIT License
1.15k stars 66 forks source link

Improve `@at-root` behavior #147

Closed maranomynet closed 1 year ago

maranomynet commented 1 year ago

This is a work in progress PR.

I haven't looked into index.js yet, so I don't really know my chances of fixing any of these myself.

Feel free to either clone/take over this patch branch, or push commits to it.

maranomynet commented 1 year ago

I'm looking towards https://www.sassmeister.com/ for the expected behavior in each of these test cases

maranomynet commented 1 year ago

Note to self: In https://github.com/postcss/postcss-nested/pull/147/commits/52a602cddf94786aaea730f63d14037ec699afa4 I add some basic type definitions (via JSDoc). This immediately surfaces some obvious problems.

ai commented 1 year ago

Ping me, when implementation will be ready. It looks very interesting.

maranomynet commented 1 year ago

Making small progress... 2/7 failing tests now passing.

maranomynet commented 1 year ago

Hi @ai I'm done now.

maranomynet commented 1 year ago

Right now, I can't think of any more cases to test, and everything passes.

Feel free to add more tests if you can think of any.

maranomynet commented 1 year ago

I've basically moved most of the at-root handling out of the Rule method and into two separate tree-walk passes — first on Once where I normalize and prepare the at-root nodes, and then on RootExit where I unwrap and drill upp the tree and split up blocks as needed.

What's left in the Rule method is just the conditional selector merging faff.

ai commented 1 year ago

Looks good. I will try to merge it tomorrow.

Note that I am planning to remove type comments since I do not use them.

maranomynet commented 1 year ago

Type comments lower the barrier of entry for others to make PRs. Also, in this case adding type hints at the start immediately surfaced errors that were hiding in plain sight.

ai commented 1 year ago

Unofficial nested has no future. We will not have too many PRs in the future.

ai commented 1 year ago

Thanks. Released in 6.0.