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