Port #62311: Fix parenthesizer rules for binary expressions mixing ?? with ||/&૆
Merged
DanielRosenwasser merged 3 commits intomainfrom Feb 11, 2026
Merged
Conversation
…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 <5341706+jakebailey@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix parenthesizer rules for binary expressions with ?? and ||/&& mix
Port #62311: Fix parenthesizer rules for binary expressions mixing ?? with ||/&&
Feb 11, 2026
jakebailey
reviewed
Feb 11, 2026
testdata/baselines/reference/submodule/conformance/plainJSGrammarErrors.js.diff
Outdated
Show resolved
Hide resolved
The parenthesization for ?? and ||/&& mixing should only apply to manually constructed (synthesized) AST nodes, not parsed source code. Parsed code like `a || b ?? c` should be faithfully reproduced even though it's a syntax error, matching TypeScript's behavior. Added `ast.NodeIsSynthesized` check to guard the mixing parenthesization, and added comprehensive unit tests for all mixing combinations. Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Member
Contributor
There was a problem hiding this comment.
Pull request overview
Ports TypeScript PR #62311 to the Go printer to ensure emitted output is syntactically valid when synthesized (factory-created) binary expressions mix ?? with ||/&&, while preserving parsed source output.
Changes:
- Added
mixingBinaryOperatorsRequiresParentheseshelper to detect??mixing with||/&&. - Updated
emitBinaryExpressionto force parentheses around synthesized left/right operands when such operator mixing occurs. - Added a table-driven printer test covering synthesized AST cases for all
??+||/&&mixing combinations and operand sides.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| internal/printer/utilities.go | Adds helper for detecting ?? mixed with ` |
| internal/printer/printer.go | Applies mixing rule during binary expression emit for synthesized operands by forcing higher precedence (parenthesization). |
| internal/printer/printer_test.go | Adds table-driven test validating emitted parentheses for synthesized mixed-operator binary expressions. |
DanielRosenwasser
approved these changes
Feb 11, 2026
Copilot AI
added a commit
that referenced
this pull request
Feb 25, 2026
… with ||/&& (#2758) Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
??and||/&&mixmixingBinaryOperatorsRequiresParentheseshelper function in the printer utilitiesemitBinaryExpressionto check for operator mixing before emitting left/right operands✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.