Process an import_clause node: default, namespace, and named imports.
| 882 | |
| 883 | // Process an import_clause node: default, namespace, and named imports. |
| 884 | static bool process_import_clause(CBMExtractCtx *ctx, TSNode clause, const char *path) { |
| 885 | CBMArena *a = ctx->arena; |
| 886 | bool found = false; |
| 887 | uint32_t cc = ts_node_child_count(clause); |
| 888 | for (uint32_t k = 0; k < cc; k++) { |
| 889 | TSNode sub = ts_node_child(clause, k); |
| 890 | const char *sk = ts_node_type(sub); |
| 891 | if (strcmp(sk, "identifier") == 0) { |
| 892 | char *name = cbm_node_text(a, sub, ctx->source); |
| 893 | CBMImport imp = {.local_name = name, .module_path = path, .is_default = true}; |
| 894 | cbm_imports_push(&ctx->result->imports, a, imp); |
| 895 | found = true; |
| 896 | } else if (strcmp(sk, "namespace_import") == 0) { |
| 897 | TSNode as_name = ts_node_child_by_field_name(sub, TS_FIELD("name")); |
| 898 | if (ts_node_is_null(as_name) && ts_node_child_count(sub) > 0) { |
| 899 | as_name = ts_node_child(sub, ts_node_child_count(sub) - SKIP_ONE); |
| 900 | } |
| 901 | if (!ts_node_is_null(as_name)) { |
| 902 | char *name = cbm_node_text(a, as_name, ctx->source); |
| 903 | CBMImport imp = {.local_name = name, .module_path = path}; |
| 904 | cbm_imports_push(&ctx->result->imports, a, imp); |
| 905 | found = true; |
| 906 | } |
| 907 | } else if (strcmp(sk, "named_imports") == 0) { |
| 908 | if (process_named_imports(ctx, sub, path)) { |
| 909 | found = true; |
| 910 | } |
| 911 | } |
| 912 | } |
| 913 | return found; |
| 914 | } |
| 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) { |
no test coverage detected