Skip to content

fix: require own defaults before invoking function values - #197

Closed
xiehuanyi wants to merge 2 commits into
unjs:mainfrom
xiehuanyi:fix/own-function-defaults
Closed

xiehuanyi wants to merge 2 commits into
unjs:mainfrom
xiehuanyi:fix/own-function-defaults

Conversation

@xiehuanyi

@xiehuanyi xiehuanyi commented Oct 6, 2026 •

Copy link
Copy Markdown

Description

defuFn({ toString: fn }, {}) unexpectedly invokes fn with Object.prototype.toString even though no default was supplied. Require an own, defined default before applying a function transform. Explicit own defaults remain supported.

Resolves #196.

Checks

The inherited-property regression fails on unchanged main; an explicit-default control passes. All 25 tests, lint, formatting, type checks, build, and git diff --check pass. Verification completed in under 2 minutes on Node 24.19.0.

AI-assisted; the diff and results reviewed.

Summary by CodeRabbit

  • Bug Fixes
    • Function-based default merging now applies only to explicitly defined, non-undefined properties on the target object. Inherited properties such as toString and valueOf no longer trigger the merger.
    • Explicitly provided defaults continue to be passed to the transform and produce the expected result.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c3a722a9-5268-402b-8449-05b7382abac4
📥 Commits

Reviewing files that changed from the base of the PR and between 82632b6 and 034b6bc.

📒 Files selected for processing (2)
  • src/defu.ts
  • test/defu.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

defuFn now applies its function merger only when the target has an own, defined property for the key. Tests cover inherited toString and valueOf defaults and an explicitly provided toString default.

Changes

defuFn Default Handling

Layer / File(s) Summary
Own-property check and regression coverage
src/defu.ts, test/defu.test.ts
defuFn checks that the target property is its own property before applying the function merger. Tests verify that inherited defaults do not invoke supplied functions and that an explicit toString default invokes the transform once.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Merge Risk: ⚪ Minimal · up to 034b6

Inherited built-ins no longer trigger function transforms, while explicit defaults continue to work. No actionable merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: requiring an own default before invoking function values.
Linked Issues check ✅ Passed Issue #196 requires defuFn to preserve function values unless an own, defined default exists, while still transforming functions for explicit own defaults. The change in src/defu.ts checks for an …
Out of Scope Changes check ✅ Passed The reported changes are limited to src/defu.ts and test/defu.test.ts. The implementation and regression tests directly support issue #196. No unrelated changes are identified.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pi0 pi0 closed this Oct 7, 2026
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.

defuFn invokes function values for inherited default properties

3 participants