Skip to content

Fix ?? (nullish coalescing) earlyOut to not short-circuit on falsy values#345

Merged
brianmhunt merged 4 commits intomainfrom
fix/nullish-coalescing-earlyout
Apr 22, 2026
Merged

Fix ?? (nullish coalescing) earlyOut to not short-circuit on falsy values#345
brianmhunt merged 4 commits intomainfrom
fix/nullish-coalescing-earlyout

Conversation

@phillipc
Copy link
Copy Markdown
Member

@phillipc phillipc commented Apr 20, 2026

Summary

The ?? operator's earlyOut was a => a, identical to ||. This caused ?? to short-circuit on falsy values like 0, '', and false, which is incorrect — ?? should only short-circuit when the value is not null and not undefined.

Detected in #297

Fix

-operators['??'].earlyOut = a => a
+operators['??'].earlyOut = a => a !== null && a !== undefined

Verification

All 404 parser tests pass. Full suite (5371 tests) passes.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed nullish coalescing operator behavior to correctly handle null and undefined values separately from other falsy values.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 20, 2026

Warning

Rate limit exceeded

@brianmhunt has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 26 minutes and 34 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 26 minutes and 34 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 29b93105-6f18-4528-875f-2d1bf61bb9cd

📥 Commits

Reviewing files that changed from the base of the PR and between b47ab8c and c547a64.

📒 Files selected for processing (1)
  • packages/utils.parser/spec/nodeBehaviors.ts
📝 Walkthrough

Walkthrough

Modified the ?? operator's earlyOut behavior in the parser operators module. The operator now correctly returns input only when it is neither null nor undefined, aligning early-exit semantics with nullish coalescing logic.

Changes

Cohort / File(s) Summary
Nullish Coalescing Operator Logic
packages/utils.parser/src/operators.ts
Updated earlyOut condition for ?? operator from unconditional return to conditional return based on nullish check (a !== null && a !== undefined).

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Suggested reviewers

  • brianmhunt

Poem

🐰 A whisker-twitch of logic refined,
The ?? now sees what's null, undefined,
No falsy foes will pass its gate,
Only true nothingness meets its fate! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: fixing the ?? operator's earlyOut behavior to properly handle nullish coalescing instead of short-circuiting on all falsy values.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/nullish-coalescing-earlyout

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 and usage tips.

Regression test for the earlyOut fix. Uses a counter-backed rhs function
so the test fails when earlyOut is `a => a` (rhs invoked on 0/''/false)
and passes with `a => a !== null && a !== undefined`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Comment thread packages/utils.parser/spec/nodeBehaviors.ts Fixed
Copy link
Copy Markdown
Member

@brianmhunt brianmhunt left a comment

Choose a reason for hiding this comment

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

👍 test added

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Comment thread packages/utils.parser/spec/nodeBehaviors.ts Fixed
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
@brianmhunt brianmhunt merged commit 4780dfe into main Apr 22, 2026
9 checks passed
@brianmhunt brianmhunt deleted the fix/nullish-coalescing-earlyout branch April 22, 2026 16:26
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