From 5166d2e2601aa12a7f31a8cb432bdcb41bd7eb99 Mon Sep 17 00:00:00 2001 From: Joshua Wong Date: Mon, 1 Jul 2024 21:51:39 -0400 Subject: [PATCH] chore: simplify JSX handler matching --- crates/forge_analyzer/src/definitions.rs | 37 ++++++++++-------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/crates/forge_analyzer/src/definitions.rs b/crates/forge_analyzer/src/definitions.rs index 935efce..497ef9f 100644 --- a/crates/forge_analyzer/src/definitions.rs +++ b/crates/forge_analyzer/src/definitions.rs @@ -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, + ); + } + _ => {} } } }