Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve @at-root behavior #147

Merged
merged 25 commits into from Oct 6, 2022
Merged

Improve @at-root behavior #147

merged 25 commits into from Oct 6, 2022

Conversation

maranomynet
Copy link
Contributor

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
Copy link
Contributor Author

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

@maranomynet
Copy link
Contributor Author

maranomynet commented Sep 30, 2022

Note to self:
In 52a602c I add some basic type definitions (via JSDoc). This immediately surfaces some obvious problems.

@ai
Copy link
Member

ai commented Sep 30, 2022

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

@maranomynet
Copy link
Contributor Author

maranomynet commented Sep 30, 2022

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

@maranomynet
Copy link
Contributor Author

Hi @ai I'm done now.

index.d.ts Show resolved Hide resolved
index.d.ts Outdated Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
@maranomynet maranomynet force-pushed the patch-1 branch 3 times, most recently from 5a8dd55 to cf2bbf0 Compare October 5, 2022 09:25
@maranomynet
Copy link
Contributor Author

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
Copy link
Contributor Author

maranomynet commented Oct 5, 2022

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.

maranomynet added a commit to rvk-utd/hanna that referenced this pull request Oct 5, 2022
maranomynet added a commit to rvk-utd/hanna that referenced this pull request Oct 5, 2022
maranomynet added a commit to rvk-utd/hanna that referenced this pull request Oct 5, 2022
index.js Outdated

RootExit(root) {
if (root[hasRootRule]) {
root.walk(node => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

walkAtRules() will be readable and could be even a little faster

index.js Outdated
Rule (rule, { Rule }) {

Once(root) {
root.walk(node => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use walkAtRules() here as well

@ai
Copy link
Member

ai commented Oct 5, 2022

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
Copy link
Contributor Author

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
Copy link
Member

ai commented Oct 5, 2022

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

Not sure how/why this didn't show up yesterday or the day before.
VSCode's ESLint plugin must have silently crashed or something.
@ai ai merged commit 62a5b85 into postcss:main Oct 6, 2022
@ai
Copy link
Member

ai commented Oct 6, 2022

Thanks. Released in 6.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants