GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix parenthesizer rules for manually constructed binary expressions with `??` and `||`/`&&` mix by Andarist · Pull Request #62311 · microsoft/TypeScript

Conversation

@Andarist

@Andarist Mateusz Burzyński (Andarist) commented Aug 21, 2025

Copy link
Copy Markdown
Contributor

fixes #62307

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

RyanCavanaugh reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@Andarist
Fix parenthesizer rules for manually constructed binary expressions w…
fe84a28
…ith `??` and `||`/`&&` mix
Copilot AI review requested due to automatic review settings August 21, 2025 09:42
@github-project-automation github-project-automation Bot added this to PR Backlog Aug 21, 2025
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Aug 21, 2025
@typescript-bot TypeScript Bot (typescript-bot) added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Aug 21, 2025
Copilot AI reviewed Aug 21, 2025
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a bug in TypeScript's printer parenthesizer rules for manually constructed binary expressions that mix the nullish coalescing operator (??) with logical operators (||/&&). The fix ensures proper parenthesization when these operators are combined to maintain correct evaluation order and avoid syntax errors.

Key changes:

  • Added logic to detect mixing of ?? with ||/&& operators and force parenthesization
  • Added comprehensive unit tests to verify correct printing behavior for all operator combinations
  • Updated test baselines to reflect the corrected parenthesization output

Reviewed Changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 8 comments.

File Description
src/compiler/factory/parenthesizerRules.ts Core fix adding mixingBinaryOperatorsRequiresParentheses function and early parenthesization check
src/testRunner/unittests/printer.ts Comprehensive unit tests for all binary operator combinations with ??
tests/baselines/reference/printerApi/*.js Test baseline files showing expected parenthesized output for various operator combinations

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/testRunner/unittests/printer.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/testRunner/unittests/printer.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/testRunner/unittests/printer.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/testRunner/unittests/printer.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/testRunner/unittests/printer.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/testRunner/unittests/printer.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/testRunner/unittests/printer.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/testRunner/unittests/printer.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Andarist
Mateusz Burzyński (Andarist) commented Aug 21, 2025
View reviewed changes
Comment thread src/compiler/factory/parenthesizerRules.ts
*/
function binaryOperandNeedsParentheses(binaryOperator: SyntaxKind, operand: Expression, isLeftSideOfBinary: boolean, leftOperand: Expression | undefined) {
const emittedOperand = skipPartiallyEmittedExpressions(operand);
if (isBinaryExpression(emittedOperand) && mixingBinaryOperatorsRequiresParentheses(binaryOperator, emittedOperand.operatorToken.kind)) {

@Andarist Mateusz Burzyński (Andarist) Aug 21, 2025

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

mixing them without parentheses is a special grammar-based syntax error, so one can't simply handle both of those cases using precedence and associativity alone, and for that reason I'm also specialcasing this here

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Andarist
remove duplicate tests
9059a09
RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh) approved these changes Aug 21, 2025
View reviewed changes

@RyanCavanaugh Ryan Cavanaugh (RyanCavanaugh) left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Seems right to me. Wesley Wigham (@weswigham) confirm / check Corsa behavior?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@github-project-automation github-project-automation Bot moved this from Not started to Needs merge in PR Backlog Aug 21, 2025
@typescript-bot TypeScript Bot (typescript-bot) added For Backlog Bug PRs that fix a backlog bug and removed For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Aug 21, 2025
weswigham
Wesley Wigham (weswigham) approved these changes Sep 9, 2025
View reviewed changes

@weswigham Wesley Wigham (weswigham) left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Corsa late-adds required parenthesis during printing, rather than upon construction via parenthesizer like strada, so it'll be different to ensure the same in corsa.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@jakebailey
Jake Bailey (jakebailey) merged commit 4f94cb2 into microsoft:main Sep 9, 2025
@github-project-automation github-project-automation Bot moved this from Needs merge to Done in PR Backlog Sep 9, 2025
@jakebailey

Jake Bailey (jakebailey) commented Sep 9, 2025

Copy link
Copy Markdown
Member

TypeScript Bot (@typescript-bot) cherry-pick to release-5.9

typescript-bot reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@typescript-bot

TypeScript Bot (typescript-bot) commented Sep 9, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Starting jobs; this comment will be updated as builds start and complete.

Command Status Results
cherry-pick to release-5.9 ✅ Started ✅ Results
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

TypeScript Bot (typescript-bot) pushed a commit that referenced this pull request Sep 9, 2025
@Andarist @typescript-bot
Fix parenthesizer rules for manually constructed binary expressions w…
f9e0ac8
…ith `??` and `||`/`&&` mix (#62311)
@typescript-bot TypeScript Bot (typescript-bot) mentioned this pull request Sep 9, 2025
🤖 Pick PR #62311 (Fix parenthesizer rules for manuall...) into release-5.9 #62424
Merged
@typescript-bot

TypeScript Bot (typescript-bot) commented Sep 9, 2025

Copy link
Copy Markdown
Contributor

Hey, Jake Bailey (@jakebailey)! I've created #62424 for you.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Andarist
Mateusz Burzyński (Andarist) deleted the fixup/nullish-vs-barbar-or-ampersandampersand-print branch September 9, 2025 17:11
Jake Bailey (jakebailey) pushed a commit that referenced this pull request Sep 25, 2025
@typescript-bot @Andarist
🤖 Pick PR #62311 (Fix parenthesizer rules for manuall...) into releas…
bdb641a
…e-5.9 (#62424)

Co-authored-by: Mateusz Burzyński <[email protected]>
@claude claude Bot mentioned this pull request Oct 7, 2025
chore(deps-dev): bump typescript from 5.9.2 to 5.9.3 DollhouseMCP/mcp-server#1247
Merged
Copilot AI added a commit to microsoft/typescript-go that referenced this pull request Feb 11, 2026
@jakebailey
Fix parenthesizer rules for manually constructed binary expressions w…
afba20a
…ith ?? and ||/&& mix

Port of microsoft/TypeScript#62311

When emitting binary expressions, the printer now checks if the parent
operator and child operator are a mix of ?? with ||/&&, which requires
parentheses per JavaScript spec. This prevents emitting syntactically
invalid code like `a || b ?? c` and instead correctly emits `(a || b) ?? c`.

Co-authored-by: jakebailey <[email protected]>
Copilot AI mentioned this pull request Feb 11, 2026
Port #62311: Fix parenthesizer rules for binary expressions mixing ?? with ||/&& microsoft/typescript-go#2758
Merged
7 of 8 tasks
@microsoft Microsoft (microsoft) locked as resolved and limited conversation to collaborators Mar 9, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments
@weswigham Wesley Wigham (weswigham) weswigham approved these changes
@RyanCavanaugh Ryan Cavanaugh (RyanCavanaugh) RyanCavanaugh approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

For Backlog Bug PRs that fix a backlog bug

Projects

PR Backlog
Status: Done

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Manually constructed nullish coalescing + OR AST is missing parentheses when printed

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@Andarist @jakebailey @typescript-bot @weswigham @RyanCavanaugh
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.