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

fix: use Map size to calculate the number of children #73

Merged
merged 4 commits into from
Nov 28, 2023
Merged

fix: use Map size to calculate the number of children #73

merged 4 commits into from
Nov 28, 2023

Conversation

AndrewWalsh
Copy link
Contributor

fix: use Map size property to calculate the number of children. The current approach does not count them correctly

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/size

🔗 Linked issue

❓ Type of change

  • 📖 Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

  • The current approach to count the number of children that a node has is incorrect
  • This means that calling remove will remove nodes that have no data, but do have children
  • The intention is to remove nodes that have both no data and no children
  • This uses the Map size property to count children correctly and align with the original intended behaviour

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@pi0
Copy link
Member

pi0 commented Nov 27, 2023

Thanks for the PR! Is there a chance you can add a fixture to the tests that were previously failing? 🙏🏼

Copy link

codecov bot commented Nov 27, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (fe00560) 95.63% compared to head (4a744e0) 95.63%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #73   +/-   ##
=======================================
  Coverage   95.63%   95.63%           
=======================================
  Files           4        4           
  Lines         435      435           
  Branches       83       84    +1     
=======================================
  Hits          416      416           
  Misses         19       19           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@AndrewWalsh
Copy link
Contributor Author

Thanks for taking a look @pi0. I've written a test to cover this. Changing node.children.size === 0 to Object.keys(node.children).length === 0 will make this fail.

Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

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

Thanks 💯

@pi0 pi0 merged commit ef08c2f into unjs:main Nov 28, 2023
3 checks passed
@pi0
Copy link
Member

pi0 commented Nov 28, 2023

@AndrewWalsh Since main branch is already prepared for 2.x release, this patch will be included in 2.x once released but please let me know if it is something blocking for you i can make a hotfix branch to cherry-pick it.

@AndrewWalsh
Copy link
Contributor Author

All good, I don't need the fix from my end, thanks for the consideration.

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.

2 participants