Process a single ES import_statement node. Returns true if fully handled. */
| 915 | |
| 916 | /* Process a single ES import_statement node. Returns true if fully handled. */ |
| 917 | static bool process_es_import_statement(CBMExtractCtx *ctx, TSNode node) { |
| 918 | CBMArena *a = ctx->arena; |
| 919 | TSNode source_node = find_es_source_node(node); |
| 920 | if (ts_node_is_null(source_node)) { |
| 921 | return false; |
| 922 | } |
| 923 | char *path = strip_quotes(a, cbm_node_text(a, source_node, ctx->source)); |
| 924 | if (!path || !path[0]) { |
| 925 | return false; |
| 926 | } |
| 927 | uint32_t nc = ts_node_child_count(node); |
| 928 | bool found = false; |
| 929 | for (uint32_t j = 0; j < nc; j++) { |
| 930 | TSNode child = ts_node_child(node, j); |
| 931 | const char *ck = ts_node_type(child); |
| 932 | if (strcmp(ck, "identifier") == 0) { |
| 933 | char *name = cbm_node_text(a, child, ctx->source); |
| 934 | CBMImport imp = {.local_name = name, .module_path = path}; |
| 935 | cbm_imports_push(&ctx->result->imports, a, imp); |
| 936 | found = true; |
| 937 | } else if (strcmp(ck, "import_clause") == 0) { |
| 938 | if (process_import_clause(ctx, child, path)) { |
| 939 | found = true; |
| 940 | } |
| 941 | } |
| 942 | } |
| 943 | if (!found) { |
| 944 | CBMImport imp = {.local_name = path_last(a, path), .module_path = path}; |
| 945 | cbm_imports_push(&ctx->result->imports, a, imp); |
| 946 | } |
| 947 | return true; |
| 948 | } |
| 949 | |
| 950 | /* Handle CommonJS `require("path")` call_expression nodes. The local name |
| 951 | * is derived from the enclosing variable_declarator / assignment when |
no test coverage detected