Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions compiler/crates/react_compiler/src/entrypoint/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,8 @@ fn calls_hooks_or_creates_jsx_in_pattern(pattern: &PatternLike) -> bool {
| PatternLike::TSAsExpression(_)
| PatternLike::TSSatisfiesExpression(_)
| PatternLike::TSNonNullExpression(_)
| PatternLike::TSTypeAssertion(_) => false,
| PatternLike::TSTypeAssertion(_)
| PatternLike::TypeCastExpression(_) => false,
}
}

Expand All @@ -923,7 +924,8 @@ fn is_valid_props_annotation(param: &PatternLike) -> bool {
| PatternLike::TSAsExpression(_)
| PatternLike::TSSatisfiesExpression(_)
| PatternLike::TSNonNullExpression(_)
| PatternLike::TSTypeAssertion(_) => None,
| PatternLike::TSTypeAssertion(_)
| PatternLike::TypeCastExpression(_) => None,
};
let annot = match type_annotation {
Some(val) => val,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,8 @@ fn collect_original_pattern(
PatternLike::TSAsExpression(_)
| PatternLike::TSSatisfiesExpression(_)
| PatternLike::TSNonNullExpression(_)
| PatternLike::TSTypeAssertion(_) => {}
| PatternLike::TSTypeAssertion(_)
| PatternLike::TypeCastExpression(_) => {}
}
}

Expand Down Expand Up @@ -1243,7 +1244,8 @@ fn collect_generated_pattern(
PatternLike::TSAsExpression(_)
| PatternLike::TSSatisfiesExpression(_)
| PatternLike::TSNonNullExpression(_)
| PatternLike::TSTypeAssertion(_) => {}
| PatternLike::TSTypeAssertion(_)
| PatternLike::TypeCastExpression(_) => {}
}
}

Expand Down
2 changes: 2 additions & 0 deletions compiler/crates/react_compiler_ast/src/patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ pub enum PatternLike {
TSSatisfiesExpression(crate::expressions::TSSatisfiesExpression),
TSNonNullExpression(crate::expressions::TSNonNullExpression),
TSTypeAssertion(crate::expressions::TSTypeAssertion),
// Flow's analogue of the TS cast wrappers: `(expr: SomeType)`.
TypeCastExpression(crate::expressions::TypeCastExpression),
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down
3 changes: 3 additions & 0 deletions compiler/crates/react_compiler_ast/src/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,9 @@ impl<'a> AstWalker<'a> {
self.walk_expression(v, &node.expression)
}
PatternLike::TSTypeAssertion(node) => self.walk_expression(v, &node.expression),
PatternLike::TypeCastExpression(node) => {
self.walk_expression(v, &node.expression)
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions compiler/crates/react_compiler_ast/tests/scope_resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,10 @@ fn visit_pat(pat: &mut PatternLike, si: &ScopeInfo) {
visit_expr(&mut e.expression, si);
visit_json(&mut e.type_annotation, si);
}
PatternLike::TypeCastExpression(e) => {
visit_expr(&mut e.expression, si);
visit_json(&mut e.type_annotation, si);
}
}
}

Expand Down
20 changes: 13 additions & 7 deletions compiler/crates/react_compiler_lowering/src/build_hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ fn pattern_like_loc(
PatternLike::TSSatisfiesExpression(p) => p.base.loc.clone(),
PatternLike::TSNonNullExpression(p) => p.base.loc.clone(),
PatternLike::TSTypeAssertion(p) => p.base.loc.clone(),
PatternLike::TypeCastExpression(p) => p.base.loc.clone(),
}
}

Expand Down Expand Up @@ -2327,7 +2328,8 @@ fn pattern_declares_name(pattern: &react_compiler_ast::patterns::PatternLike, na
PatternLike::TSAsExpression(_)
| PatternLike::TSSatisfiesExpression(_)
| PatternLike::TSNonNullExpression(_)
| PatternLike::TSTypeAssertion(_) => false,
| PatternLike::TSTypeAssertion(_)
| PatternLike::TypeCastExpression(_) => false,
}
}

Expand Down Expand Up @@ -2533,7 +2535,8 @@ fn collect_binding_names_from_pattern(
PatternLike::TSAsExpression(_)
| PatternLike::TSSatisfiesExpression(_)
| PatternLike::TSNonNullExpression(_)
| PatternLike::TSTypeAssertion(_) => {}
| PatternLike::TSTypeAssertion(_)
| PatternLike::TypeCastExpression(_) => {}
}
}

Expand Down Expand Up @@ -5091,13 +5094,15 @@ fn lower_assignment(
)?)
}

// TS assignment-target wrappers (e.g. `(x as T) = ...`). The TS-faithful
// Todo is recorded once in `find_context_identifiers`; lowering itself
// never reaches a successful path for these, so do not record again.
// TS assignment-target wrappers (e.g. `(x as T) = ...`) and the Flow
// analogue `TypeCastExpression`. The TS-faithful Todo is recorded once
// in `find_context_identifiers`; lowering itself never reaches a
// successful path for these, so do not record again.
PatternLike::TSAsExpression(_)
| PatternLike::TSSatisfiesExpression(_)
| PatternLike::TSNonNullExpression(_)
| PatternLike::TSTypeAssertion(_) => Ok(None),
| PatternLike::TSTypeAssertion(_)
| PatternLike::TypeCastExpression(_) => Ok(None),
}
}

Expand Down Expand Up @@ -6037,7 +6042,8 @@ fn lower_inner(
react_compiler_ast::patterns::PatternLike::TSAsExpression(_)
| react_compiler_ast::patterns::PatternLike::TSSatisfiesExpression(_)
| react_compiler_ast::patterns::PatternLike::TSNonNullExpression(_)
| react_compiler_ast::patterns::PatternLike::TSTypeAssertion(_) => {}
| react_compiler_ast::patterns::PatternLike::TSTypeAssertion(_)
| react_compiler_ast::patterns::PatternLike::TypeCastExpression(_) => {}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,13 @@ fn walk_lval_for_reassignment(
convert_opt_loc(&node.base.loc),
)?;
}
PatternLike::TypeCastExpression(node) => {
record_unsupported_lval(
visitor.env,
"TypeCastExpression",
convert_opt_loc(&node.base.loc),
)?;
}
}
Ok(())
}
Expand Down
3 changes: 2 additions & 1 deletion compiler/crates/react_compiler_oxc/src/convert_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2637,7 +2637,8 @@ impl<'a> ConvertCtx<'a> {
PatternLike::TSAsExpression(_)
| PatternLike::TSSatisfiesExpression(_)
| PatternLike::TSNonNullExpression(_)
| PatternLike::TSTypeAssertion(_) => {}
| PatternLike::TSTypeAssertion(_)
| PatternLike::TypeCastExpression(_) => {}
}
}

Expand Down
6 changes: 4 additions & 2 deletions compiler/crates/react_compiler_oxc/src/convert_ast_reverse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,8 @@ impl<'a> ReverseCtx<'a> {
| PatternLike::TSAsExpression(_)
| PatternLike::TSSatisfiesExpression(_)
| PatternLike::TSNonNullExpression(_)
| PatternLike::TSTypeAssertion(_) => self
| PatternLike::TSTypeAssertion(_)
| PatternLike::TypeCastExpression(_) => self
.builder
.binding_pattern_binding_identifier(SPAN, self.atom("__member_pattern__")),
}
Expand Down Expand Up @@ -1285,7 +1286,8 @@ impl<'a> ReverseCtx<'a> {
PatternLike::TSAsExpression(_)
| PatternLike::TSSatisfiesExpression(_)
| PatternLike::TSNonNullExpression(_)
| PatternLike::TSTypeAssertion(_) => self
| PatternLike::TSTypeAssertion(_)
| PatternLike::TypeCastExpression(_) => self
.builder
.simple_assignment_target_assignment_target_identifier(
SPAN,
Expand Down
10 changes: 7 additions & 3 deletions compiler/crates/react_compiler_swc/src/convert_ast_reverse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1577,6 +1577,9 @@ impl ReverseCtx {
PatternLike::TSTypeAssertion(e) => {
Pat::Expr(Box::new(self.convert_expression(&e.expression)))
}
PatternLike::TypeCastExpression(e) => {
Pat::Expr(Box::new(self.convert_expression(&e.expression)))
}
}
}

Expand Down Expand Up @@ -1624,9 +1627,10 @@ impl ReverseCtx {
PatternLike::TSAsExpression(_)
| PatternLike::TSSatisfiesExpression(_)
| PatternLike::TSNonNullExpression(_)
| PatternLike::TSTypeAssertion(_) => AssignTarget::Simple(SimpleAssignTarget::Ident(
self.binding_ident("__unknown__", DUMMY_SP),
)),
| PatternLike::TSTypeAssertion(_)
| PatternLike::TypeCastExpression(_) => AssignTarget::Simple(
SimpleAssignTarget::Ident(self.binding_ident("__unknown__", DUMMY_SP)),
),
}
}

Expand Down
Loading