postcss / postcss-nested

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

Improve `@at-root` behavior #147

Closed maranomynet closed 2 years ago

maranomynet commented 2 years 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 2 years ago

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

maranomynet commented 2 years 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 2 years ago

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

maranomynet commented 2 years ago

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

maranomynet commented 2 years ago

Hi @ai I'm done now.

maranomynet commented 2 years 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 2 years 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 2 years 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 2 years 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 2 years ago

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

ai commented 2 years ago

Thanks. Released in 6.0.