Skip to content

Commit

Permalink
Use last param as handler
Browse files Browse the repository at this point in the history
  • Loading branch information
stephlow committed Oct 29, 2024
1 parent 26fe0dc commit 3d89a49
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions fpx/src/static_analysis/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,16 @@ fn detect_route_handlers(
.utf8_text(source.as_bytes())
.unwrap();

if let Some(handler_node) = route_node.child(3) {
let mut cursor = route_node.walk();
let handler_param = route_node
.children(&mut cursor)
.filter(|node| {
node.kind() == "call_expression" || node.kind() == "arrow_function"
})
.last();

if let Some(handler_node) = handler_param {
// route_node.child(3) {
let route_handler = handler_node.utf8_text(source.as_bytes()).unwrap();

let mut cursor = handler_node.walk();
Expand Down Expand Up @@ -572,7 +581,7 @@ mod tests {
DetectedRoute {
route_path: "/slow".into(),
route_method: "get".into(),
route_handler: r#"(c) => {
route_handler: r#"async (c) => {
await sleep(1000);
return c.text("Hello, Hono (slow)!");
}"#
Expand All @@ -583,9 +592,9 @@ mod tests {
out_of_scope_sources: vec![]
},
DetectedRoute {
route_path: "/user/1".into(),
route_path: "user/1".into(),
route_method: "get".into(),
route_handler: r#"(c) => {
route_handler: r#"async (c) => {
// await getUser();
const user = await getUser();
return c.json(user);
Expand Down Expand Up @@ -649,9 +658,9 @@ mod tests {
assert_eq!(
vec![
DetectedRoute {
route_path: "/user/1".into(),
route_path: "user/1".into(),
route_method: "get".into(),
route_handler: r#"(c) => {
route_handler: r#"async (c) => {
// await getUser();
const user = await getUser();
return c.json(user);
Expand Down

0 comments on commit 3d89a49

Please sign in to comment.