Repository navigation
[compiler] Support logical assignment operators in BuildHIR - #38190
Open
magic-akari wants to merge 5 commits into
Open
magic-akari wants to merge 5 commits into
magic-akari wants to merge 5 commits into
Conversation
Lower ??=, &&=, and ||= to short-circuiting logical expressions in the TypeScript compiler and Rust port. Evaluate member targets once, and only evaluate the right-hand side and store when the assignment is taken. Closes react#33315 Co-authored-by: Raashish Aggarwal <94279692+raashish1601@users.noreply.github.com> Co-authored-by: lauren <lauren@anysphere.co>
Value blocks cannot contain local declarations. Hoist only capture declarations and keep their assignments in the logical test so callee, argument, and operand evaluation stays in source order.
Fix the member base before evaluating the computed key, and snapshot identifier operands before reading the property. Getters and key expressions can rebind those variables, but the conditional store must retain the original target reference.
magic-akari
force-pushed
the
fix/compiler/logical-assignment-operators
branch
from
November 10, 2026 17:50
3e51e1b to
712d62f
Compare
A logical assignment may short-circuit without writing to its target. Treating it as an ordinary reassignment reports a false syntax error, while rewriting the binding to let would lose the runtime const check. Keep const targets out of reassignment capture analysis and record a Todo during lowering so both compilers preserve the original function.
Treat a nullish check followed by a store to the same ref.current as the existing null-guarded initialization pattern. Index direct current loads and stores at logical joins so initializers may contain value blocks. Keep render-time ref reads and additional writes subject to the existing validation in both compilers.
magic-akari
force-pushed
the
fix/compiler/logical-assignment-operators
branch
from
November 10, 2026 18:10
712d62f to
221e18d
Compare
magic-akari
marked this pull request as ready for review
November 10, 2026 18:21
willbyers1
approved these changes
Nov 10, 2026
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.
React Compiler currently skips functions that use
??=,&&=, or||=.Add support in both the TypeScript and Rust compilers, preserving short-circuit behavior, evaluation order, and member references. Capture target objects and computed keys once, while keeping temporary declarations outside expression-only blocks.