Process a single ES import_statement node. Returns true if fully handled. */
| 395 | |
| 396 | /* Process a single ES import_statement node. Returns true if fully handled. */ |
| 397 | static bool process_es_import_statement(CBMExtractCtx *ctx, TSNode node) { |
| 398 | CBMArena *a = ctx->arena; |
| 399 | TSNode source_node = find_es_source_node(node); |
| 400 | if (ts_node_is_null(source_node)) { |
| 401 | return false; |
| 402 | } |
| 403 | char *path = strip_quotes(a, cbm_node_text(a, source_node, ctx->source)); |
| 404 | if (!path || !path[0]) { |
| 405 | return false; |
| 406 | } |
| 407 | uint32_t nc = ts_node_child_count(node); |
| 408 | bool found = false; |
| 409 | for (uint32_t j = 0; j < nc; j++) { |
| 410 | TSNode child = ts_node_child(node, j); |
| 411 | const char *ck = ts_node_type(child); |
| 412 | if (strcmp(ck, "identifier") == 0) { |
| 413 | char *name = cbm_node_text(a, child, ctx->source); |
| 414 | CBMImport imp = {.local_name = name, .module_path = path}; |
| 415 | cbm_imports_push(&ctx->result->imports, a, imp); |
| 416 | found = true; |
| 417 | } else if (strcmp(ck, "import_clause") == 0) { |
| 418 | if (process_import_clause(ctx, child, path)) { |
| 419 | found = true; |
| 420 | } |
| 421 | } |
| 422 | } |
| 423 | if (!found) { |
| 424 | CBMImport imp = {.local_name = path_last(a, path), .module_path = path}; |
| 425 | cbm_imports_push(&ctx->result->imports, a, imp); |
| 426 | } |
| 427 | return true; |
| 428 | } |
| 429 | |
| 430 | /* Handle CommonJS `require("path")` call_expression nodes. The local name |
| 431 | * is derived from the enclosing variable_declarator / assignment when |
no test coverage detected