[rust-compiler] Handle TS cast wrappers as assignment targets#36492
Merged
poteto merged 2 commits intoMay 20, 2026
Conversation
…get failure A TS cast used as an assignment target, e.g. `(obj.x as number) = 1`, is a valid Babel LVal. The Rust port currently hard-fails at AST JSON deserialization because PatternLike has no variant for the TS cast wrappers. This fixture snapshots that broken behavior: the baseline records the unexpected `Failed to parse AST JSON: unknown variant TSAsExpression` error. The TS reference instead emits a graceful FindContextIdentifiers Todo; the next commit makes Rust match it.
Babel's LVal includes TSAsExpression, TSSatisfiesExpression, TSNonNullExpression and TSTypeAssertion (e.g. `(x as T) = ...`). PatternLike had no variants for these, so the NAPI AST JSON deserializer hard-failed before compilation. Add the four variants to PatternLike, mirroring the existing MemberExpression-as-LVal precedent. find_context_identifiers now records the same graceful FindContextIdentifiers Todo the TS reference emits for these targets; all other PatternLike matches get minimal non-recording exhaustive arms (the visitor still recurses into the inner expression). The fixture baseline flips from the unexpected serde failure to the Todo bailout, and now passes under both `yarn snap` and `yarn snap --rust`.
3 tasks
poteto
added a commit
that referenced
this pull request
May 20, 2026
…ion test (#36499) ## What `cargo test --workspace` (and `cargo test -p react_compiler_ast`) currently fails to compile on `pr-36173`: ``` error[E0004]: non-exhaustive patterns: `&mut PatternLike::TSAsExpression(_)`, `&mut PatternLike::TSSatisfiesExpression(_)`, `&mut PatternLike::TSNonNullExpression(_)` and 1 more not covered --> crates/react_compiler_ast/tests/scope_resolution.rs:711:11 ``` The `visit_pat` helper in the `scope_resolution` integration test was not updated when #36492 added four TS cast-wrapper variants to `PatternLike` (`TSAsExpression`, `TSSatisfiesExpression`, `TSNonNullExpression`, `TSTypeAssertion`) to support TS cast wrappers as assignment targets. This PR adds those four arms to the test helper, mirroring exactly how `visit_expr` in the same file already handles these same wrapper types: descend into the inner `Expression` with `visit_expr`, and visit the type annotation JSON (where present) with `visit_json`. ## Why The Rust unit-test suite is currently zero-signal — `cargo test --workspace` cannot even compile, let alone run. This change restores it. ## Test plan - [x] `cargo test --workspace` compiles cleanly - [x] `cargo test --workspace` → 56 passed, 0 failed, 0 ignored - [x] No changes to non-test code; isolated to one test helper
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.
A TS cast used as an assignment target, e.g.
(obj.x as number) = 1, is avalid Babel LVal (
TSAsExpression,TSSatisfiesExpression,TSNonNullExpression,TSTypeAssertion). The Rust port had noPatternLikevariants for these, so the NAPI AST JSON deserializer hard-failed the whole
file before compilation (
Failed to parse AST JSON: unknown variant TSAsExpression). The reference TS compiler instead emits a gracefulFindContextIdentifiersTodo and skips just that function.This adds the four variants to
PatternLike, mirroring the existingMemberExpression-as-LVal precedent, and makesfind_context_identifiersrecord the byte-identical Todo the reference emits. Every other
PatternLikematch gets a minimal non-recording exhaustive arm; the AST visitor still
recurses into the inner expression so scope/identifier analysis is preserved.
No
Unknowncatch-all (the branch deliberately removed those).The first commit snapshots the broken behavior: the fixture baseline records
the unexpected serde failure. The second commit applies the fix and flips the
baseline to the Todo bailout. After the fix the fixture passes under both
yarn snapandyarn snap --rust, and the rest ofyarn snap --rustisunchanged (no regression).