Skip to content

Commit

Permalink
chore: simplify JSX handler matching
Browse files Browse the repository at this point in the history
  • Loading branch information
jwong101 committed Jul 2, 2024
1 parent a215fb3 commit 5166d2e
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions crates/forge_analyzer/src/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1341,29 +1341,24 @@ impl<'cx> FunctionAnalyzer<'cx> {
if let JSXExpr::Expr(expr) = &n.expr {
// FIXME: Add entry point for the functions that are called as part of the handlers
self.lower_expr(expr, None);
if let Some(second_char) = ident_value.sym.chars().nth(2) {
if ident_value.sym.starts_with("on") && second_char.is_uppercase() {
match &**expr {
Expr::Arrow(arrow_expr) => {
if let BlockStmtOrExpr::Expr(expr) = &*arrow_expr.body {
self.lower_expr(expr, None);
}
}
Expr::Ident(ident) => {
let defid = self.res.sym_to_id(ident.to_id(), self.module);
let varid = self.body.get_or_insert_global(defid.unwrap());
self.body.push_tmp(
self.block,
Rvalue::Call(
Operand::Var(Variable::from(varid)),
SmallVec::default(),
),
None,
);
}
_ => {}
match &**expr {
// JSX handler names should start with "on[A-Z]"
_ if !matches!(ident_value.sym.as_bytes(), [b'o', b'n', b'A'..=b'Z', ..]) => {}
Expr::Arrow(arrow_expr) => {
if let BlockStmtOrExpr::Expr(expr) = &*arrow_expr.body {
self.lower_expr(expr, None);
}
}
Expr::Ident(ident) => {
let defid = self.res.sym_to_id(ident.to_id(), self.module);
let varid = self.body.get_or_insert_global(defid.unwrap());
self.body.push_tmp(
self.block,
Rvalue::Call(Operand::Var(Variable::from(varid)), SmallVec::default()),
None,
);
}
_ => {}
}
}
}
Expand Down

0 comments on commit 5166d2e

Please sign in to comment.