Skip to content

[rust-compiler] Handle TS cast wrappers as assignment targets#36492

Open
poteto wants to merge 2 commits into
facebook:pr-36173from
poteto:rust-compiler-ts-cast-assignment-target
Open

[rust-compiler] Handle TS cast wrappers as assignment targets#36492
poteto wants to merge 2 commits into
facebook:pr-36173from
poteto:rust-compiler-ts-cast-assignment-target

Conversation

@poteto
Copy link
Copy Markdown
Contributor

@poteto poteto commented May 19, 2026

A TS cast used as an assignment target, e.g. (obj.x as number) = 1, is a
valid Babel LVal (TSAsExpression, TSSatisfiesExpression,
TSNonNullExpression, TSTypeAssertion). The Rust port had no PatternLike
variants 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 graceful
FindContextIdentifiers Todo and skips just that function.

This adds the four variants to PatternLike, mirroring the existing
MemberExpression-as-LVal precedent, and makes find_context_identifiers
record the byte-identical Todo the reference emits. Every other PatternLike
match gets a minimal non-recording exhaustive arm; the AST visitor still
recurses into the inner expression so scope/identifier analysis is preserved.
No Unknown catch-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 snap and yarn snap --rust, and the rest of yarn snap --rust is
unchanged (no regression).

poteto added 2 commits May 19, 2026 14:10
…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`.
@meta-cla meta-cla Bot added the CLA Signed label May 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant