| 3122 | } |
| 3123 | |
| 3124 | static const char *extract_handler_arg(CBMExtractCtx *ctx, TSNode args) { |
| 3125 | /* The LAST eligible argument wins, and every argument is examined. |
| 3126 | * Express, Fastify, gin and Laravel all put middleware between the route |
| 3127 | * path and the handler, so the first function-shaped argument is usually a |
| 3128 | * middleware. Taking the first one pointed the HANDLES edge at the |
| 3129 | * middleware; stopping the scan early missed the handler outright when the |
| 3130 | * middleware was written inline, because an arrow function matches none of |
| 3131 | * the kinds below. Nothing that follows a handler matches them either — an |
| 3132 | * options argument is an object node — so the last match is the handler. */ |
| 3133 | const char *handler = NULL; |
| 3134 | uint32_t nc = ts_node_named_child_count(args); |
| 3135 | for (uint32_t ai = HANDLER_START_IDX; ai < nc; ai++) { |
| 3136 | TSNode arg2 = ts_node_named_child(args, ai); |
| 3137 | /* PHP wraps each argument in an `argument` node — unwrap to the value. */ |
| 3138 | if (strcmp(ts_node_type(arg2), "argument") == 0 && ts_node_named_child_count(arg2) > 0) { |
| 3139 | arg2 = ts_node_named_child(arg2, 0); |
| 3140 | } |
| 3141 | if (ctx->language == CBM_LANG_PHP) { |
| 3142 | const char *class_handler = php_class_route_handler(ctx, arg2); |
| 3143 | if (class_handler) { |
| 3144 | handler = class_handler; |
| 3145 | continue; |
| 3146 | } |
| 3147 | } |
| 3148 | const char *ak2 = ts_node_type(arg2); |
| 3149 | /* `name` = PHP bare identifier handler; string = Laravel string handler |
| 3150 | * ('showUsers' or 'Controller@method'). */ |
| 3151 | if (strcmp(ak2, "identifier") == 0 || strcmp(ak2, "member_expression") == 0 || |
| 3152 | strcmp(ak2, "selector_expression") == 0 || strcmp(ak2, "attribute") == 0 || |
| 3153 | strcmp(ak2, "field_expression") == 0 || strcmp(ak2, "name") == 0) { |
| 3154 | handler = cbm_node_text(ctx->arena, arg2, ctx->source); |
| 3155 | continue; |
| 3156 | } |
| 3157 | if (is_string_like(ak2)) { |
| 3158 | const char *h = |
| 3159 | normalize_string_handler(ctx->arena, cbm_node_text(ctx->arena, arg2, ctx->source)); |
| 3160 | if (h && h[0]) { |
| 3161 | handler = h; |
| 3162 | } |
| 3163 | } |
| 3164 | } |
| 3165 | return handler; |
| 3166 | } |
| 3167 | |
| 3168 | // Extract JSX component refs (uppercase tags) as CALLS edges. |
| 3169 | static void extract_jsx_component_ref(CBMExtractCtx *ctx, TSNode node, const char *kind, |
no test coverage detected