Repository navigation
Preserve short-circuiting in downlevel private logical assignments - #65335
Open
Ryan Cavanaugh (RyanCavanaugh) with Copilot wants to merge 3 commits into
Open
Ryan Cavanaugh (RyanCavanaugh) with Copilot wants to merge 3 commits into
Ryan Cavanaugh (RyanCavanaugh) with Copilot wants to merge 3 commits into
Conversation
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix downlevel logical assignment on private accessors
Preserve short-circuiting in downlevel private logical assignments
Nov 5, 2026
Ryan Cavanaugh (RyanCavanaugh)
approved these changes
Nov 5, 2026
Ryan Cavanaugh (RyanCavanaugh)
marked this pull request as ready for review
November 5, 2026 17:02
Ryan Cavanaugh (RyanCavanaugh)
requested review from
Wesley Wigham (weswigham)
and
a balanced review from Copilot
November 5, 2026 17:02
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block approval of the private logical-assignment lowering change.
No open issues 🎉
What changed in this PR
Fixes #65333 by preserving short-circuit behavior when the native TypeScript compiler lowers private logical assignments below ES2022, preventing setter calls when no assignment should occur.
Changes:
- Emits conditional private writes for
&&=,||=, and??=, preserving single receiver evaluation and expression results. - Adds emit coverage for instance/static accessors, wrapped targets, complex receivers, and non-writable members.
- Updates baselines for downlevel output while retaining native ES2022 syntax.
| File | Description |
|---|---|
tsc/testdata/tests/cases/compiler/privateAccessorLogicalAssignment.ts |
Adds regression cases across four targets. |
tsc/testdata/baselines/reference/conformance/nullishCoalescingAssignmentVsPrivateFieldsJsEmit1.js |
Updates expected conditional private-field writes. |
tsc/testdata/baselines/reference/compiler/privateAccessorLogicalAssignment(target=es2022).js |
Records preserved native logical assignments. |
tsc/testdata/baselines/reference/compiler/privateAccessorLogicalAssignment(target=es2021).js |
Records short-circuiting private helper calls. |
tsc/testdata/baselines/reference/compiler/privateAccessorLogicalAssignment(target=es2020).js |
Records lowered assignments with native nullish coalescing. |
tsc/testdata/baselines/reference/compiler/privateAccessorLogicalAssignment(target=es2015).js |
Records fully lowered assignments and nullish checks. |
tsc/internal/transformers/estransforms/classfields.go |
Separates logical-assignment lowering from arithmetic compound assignments. |
Review effort: Balanced
This branch has not been deployed
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.
Fixes #65333
Analysis
Below ES2022, private logical assignments use arithmetic compound-assignment lowering:
set(get() && value). This invokes the setter even when the assignment should short-circuit.Fix
get() && set(value)—likewise for||and??—while preserving single receiver evaluation and expression results.Copilot Checklist
I successfully ran the applicable command at the end of my session, and it completed without error:
this.#x &&= v/||=/??=on a private accessor always calls the setter #65333