| 2730 | } |
| 2731 | |
| 2732 | void ts_process_statement(TSLSPContext *ctx, TSNode node) { |
| 2733 | if (!ctx || ts_node_is_null(node)) |
| 2734 | return; |
| 2735 | const char *kind = ts_node_type(node); |
| 2736 | |
| 2737 | if (strcmp(kind, "lexical_declaration") == 0 || strcmp(kind, "variable_declaration") == 0) { |
| 2738 | uint32_t nc = ts_node_named_child_count(node); |
| 2739 | for (uint32_t i = 0; i < nc; i++) { |
| 2740 | TSNode c = ts_node_named_child(node, i); |
| 2741 | if (node_kind_is(c, "variable_declarator")) |
| 2742 | bind_variable_declarator(ctx, c); |
| 2743 | } |
| 2744 | } else if (strcmp(kind, "for_in_statement") == 0 || strcmp(kind, "for_of_statement") == 0) { |
| 2745 | TSNode left = ts_node_child_by_field_name(node, "left", TS_LSP_FIELD_LEN("left")); |
| 2746 | TSNode right = ts_node_child_by_field_name(node, "right", TS_LSP_FIELD_LEN("right")); |
| 2747 | if (!ts_node_is_null(left) && !ts_node_is_null(right)) { |
| 2748 | const CBMType *iter = ts_eval_expr_type(ctx, right); |
| 2749 | const CBMType *elem = cbm_type_unknown(); |
| 2750 | if (iter && iter->kind == CBM_TYPE_TEMPLATE && iter->data.template_type.template_args && |
| 2751 | iter->data.template_type.arg_count >= 1) { |
| 2752 | elem = iter->data.template_type.template_args[0]; |
| 2753 | } |
| 2754 | // left is typically `lexical_declaration` of `(let x of arr)` or bare identifier. |
| 2755 | if (node_kind_is(left, "lexical_declaration") || |
| 2756 | node_kind_is(left, "variable_declaration")) { |
| 2757 | TSNode v = ts_node_named_child(left, 0); |
| 2758 | if (node_kind_is(v, "variable_declarator")) { |
| 2759 | TSNode nm = ts_node_child_by_field_name(v, "name", TS_LSP_FIELD_LEN("name")); |
| 2760 | if (node_kind_is(nm, "identifier")) { |
| 2761 | char *s = node_text(ctx, nm); |
| 2762 | if (s) |
| 2763 | cbm_scope_bind(ctx->current_scope, s, elem); |
| 2764 | } |
| 2765 | } |
| 2766 | } else if (node_kind_is(left, "identifier")) { |
| 2767 | char *s = node_text(ctx, left); |
| 2768 | if (s) |
| 2769 | cbm_scope_bind(ctx->current_scope, s, elem); |
| 2770 | } |
| 2771 | } |
| 2772 | } |
| 2773 | } |
| 2774 | |
| 2775 | // ── Call resolution + tree walk ─────────────────────────────────────────────── |
| 2776 |
no test coverage detected