[rust-compiler] Allow Flow TypeCastExpression in PatternLike#36518
Open
poteto wants to merge 1 commit into
Open
[rust-compiler] Allow Flow TypeCastExpression in PatternLike#36518poteto wants to merge 1 commit into
TypeCastExpression in PatternLike#36518poteto wants to merge 1 commit into
Conversation
`PatternLike` already had the four TS cast wrapper variants
(`TSAsExpression`, `TSSatisfiesExpression`, `TSNonNullExpression`,
`TSTypeAssertion`) so that `(x as T) = ...` style assignment
targets and parameter positions are representable. Flow's analogue
of those wrappers is `TypeCastExpression`, e.g.
function f(fallback: React.Node = <></>): void { ... }
where `fallback: React.Node = <></>` reaches the converter as an
`AssignmentPattern` whose `left` is a `TypeCastExpression` over the
binding identifier. The round-trip test rejected this with:
Deserialization error: unknown variant `TypeCastExpression`,
expected one of `Identifier`, `ObjectPattern`, ... `TSTypeAssertion`
Add `TypeCastExpression` as the sixth expression-like variant of
`PatternLike`, reusing the existing
`crate::expressions::TypeCastExpression` struct (which already
matches Babel's `{ expression, typeAnnotation }` shape and is
already handled on the expression side).
Wire the new variant through every exhaustive `PatternLike` match
the workspace requires, mirroring the existing TS wrapper
handling at each site:
- `react_compiler_ast/src/visitor.rs::walk_pattern`: recurse into
the inner expression.
- `react_compiler_lowering/src/find_context_identifiers.rs`: record
the TS-faithful `[FindContextIdentifiers] Cannot handle Object
destructuring assignment target TypeCastExpression` Todo.
- `react_compiler_lowering/src/build_hir.rs`: fall-through arms in
`pattern_like_loc`, `pattern_declares_name`,
`collect_binding_names_from_pattern`, `lower_assignment`, and the
inner-function-parameter walker.
- `react_compiler/src/entrypoint/program.rs`: fall-through arms in
`calls_hooks_or_creates_jsx_in_pattern` and
`is_valid_props_annotation`.
- `react_compiler/src/entrypoint/validate_source_locations.rs`:
fall-through arms in the original/generated pattern collectors.
- `react_compiler_swc/src/convert_ast_reverse.rs`: convert to
`Pat::Expr` (mirrors TS wrappers); use `__unknown__` placeholder
in the assign-target path.
- `react_compiler_oxc/src/convert_ast.rs` and
`react_compiler_oxc/src/convert_ast_reverse.rs`: equivalent
no-op / placeholder arms in the OXC frontend.
No new behavior is introduced. The reverse converters fall through
the same way they do for TS wrappers, and the Todo emission
matches the TS reference behavior for an unsupported assignment-
target wrapper.
Fixes 1 round-trip parity failure:
- error.todo-round2_fn_type_component_to_other.js
Test plan:
- bash compiler/scripts/test-babel-ast.sh:
Before: 1778/1780 round-trip (2 failures)
After: 1779/1780 round-trip (1 failure, 1 fixed)
Remaining failure (`lone-surrogate-string-values.js`) is unrelated;
handled in the next commit as a skip-list entry pending WTF-8
string-representation work.
- cargo build: clean across the workspace.
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.
PatternLikealready had the four TS cast wrapper variants(
TSAsExpression,TSSatisfiesExpression,TSNonNullExpression,TSTypeAssertion) so that(x as T) = ...style assignmenttargets and parameter positions are representable. Flow's analogue
of those wrappers is
TypeCastExpression, e.g.where
fallback: React.Node = <></>reaches the converter as anAssignmentPatternwhoseleftis aTypeCastExpressionover thebinding identifier. The round-trip test rejected this with:
Add
TypeCastExpressionas the sixth expression-like variant ofPatternLike, reusing the existingcrate::expressions::TypeCastExpressionstruct (which alreadymatches Babel's
{ expression, typeAnnotation }shape and isalready handled on the expression side).
Wire the new variant through every exhaustive
PatternLikematchthe workspace requires, mirroring the existing TS wrapper
handling at each site:
react_compiler_ast/src/visitor.rs::walk_pattern: recurse intothe inner expression.
react_compiler_lowering/src/find_context_identifiers.rs: recordthe TS-faithful
[FindContextIdentifiers] Cannot handle Object destructuring assignment target TypeCastExpressionTodo.react_compiler_lowering/src/build_hir.rs: fall-through arms inpattern_like_loc,pattern_declares_name,collect_binding_names_from_pattern,lower_assignment, and theinner-function-parameter walker.
react_compiler/src/entrypoint/program.rs: fall-through arms incalls_hooks_or_creates_jsx_in_patternandis_valid_props_annotation.react_compiler/src/entrypoint/validate_source_locations.rs:fall-through arms in the original/generated pattern collectors.
react_compiler_swc/src/convert_ast_reverse.rs: convert toPat::Expr(mirrors TS wrappers); use__unknown__placeholderin the assign-target path.
react_compiler_oxc/src/convert_ast.rsandreact_compiler_oxc/src/convert_ast_reverse.rs: equivalentno-op / placeholder arms in the OXC frontend.
No new behavior is introduced. The reverse converters fall through
the same way they do for TS wrappers, and the Todo emission
matches the TS reference behavior for an unsupported assignment-
target wrapper.
Fixes 1 round-trip parity failure:
Test plan:
Before: 1778/1780 round-trip (2 failures)
After: 1779/1780 round-trip (1 failure, 1 fixed)
Remaining failure (
lone-surrogate-string-values.js) is unrelated;handled in the next commit as a skip-list entry pending WTF-8
string-representation work.