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

refactor(interopDefault): simplify implementation #243

Merged
merged 1 commit into from Apr 30, 2024

Conversation

SukkaW
Copy link
Contributor

@SukkaW SukkaW commented Apr 13, 2024

πŸ”— Linked issue

N/A

❓ 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

While crafting antfu/unconfig#27, I stumbled upon the implementation of interopDefault. Upon closer examination, I found out that the implementation could be simplified and redundant code could be merged.

All tests passed on my machine locally.

πŸ“ Checklist

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

enumerable: key !== "default",
configurable: key !== "default",
get() {
return sourceModule[key];
Copy link
Member

Choose a reason for hiding this comment

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

There is a small chance of behavior regression here.

In the current implementation, we were using the (cached) value of sourceModule.default via defaultValue now we dynamically access it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unless the supplied module comes with interop code (which already defines default as a getter), I don't anticipate any changes in behavior here.

Furthermore, the appropriate behavior is either to cache all keys (getter) or not cache any at all, instead of caching default only.

Copy link

codecov bot commented Apr 30, 2024

Codecov Report

All modified and coverable lines are covered by tests βœ…

Project coverage is 87.17%. Comparing base (226a47b) to head (f7ae48d).
Report is 29 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #243      +/-   ##
==========================================
- Coverage   88.04%   87.17%   -0.87%     
==========================================
  Files           8        8              
  Lines        1062     1084      +22     
  Branches      188      196       +8     
==========================================
+ Hits          935      945      +10     
- Misses        127      139      +12     

β˜” View full report in Codecov by Sentry.
πŸ“’ Have feedback on the report? Share it here.

@pi0 pi0 merged commit 74dcba9 into unjs:main Apr 30, 2024
5 of 6 checks passed
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