[rust-compiler] Handle TS cast wrappers as assignment targets#36492
Open
poteto wants to merge 2 commits into
Open
[rust-compiler] Handle TS cast wrappers as assignment targets#36492poteto wants to merge 2 commits into
poteto wants to merge 2 commits into
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`.
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).