| 293 | } |
| 294 | |
| 295 | static void parse_python_imports(CBMExtractCtx *ctx) { |
| 296 | TSTreeCursor cursor = ts_tree_cursor_new(ctx->root); |
| 297 | if (!ts_tree_cursor_goto_first_child(&cursor)) { |
| 298 | ts_tree_cursor_delete(&cursor); |
| 299 | return; |
| 300 | } |
| 301 | do { |
| 302 | TSNode node = ts_tree_cursor_current_node(&cursor); |
| 303 | const char *kind = ts_node_type(node); |
| 304 | |
| 305 | if (strcmp(kind, "import_statement") == 0) { |
| 306 | process_py_import_stmt(ctx, node); |
| 307 | } else if (strcmp(kind, "import_from_statement") == 0 || |
| 308 | strcmp(kind, "future_import_statement") == 0) { |
| 309 | // `from __future__ import annotations` is a distinct node type in |
| 310 | // tree-sitter-python but has the same shape (module + name list). |
| 311 | process_py_import_from(ctx, node); |
| 312 | } |
| 313 | } while (ts_tree_cursor_goto_next_sibling(&cursor)); |
| 314 | ts_tree_cursor_delete(&cursor); |
| 315 | } |
| 316 | |
| 317 | // --- ES module imports (JS/TS/TSX) --- |
| 318 | // import X from "Y"; import {A, B} from "Y"; import * as X from "Y" |
no test coverage detected