| 602 | pass |
| 603 | |
| 604 | def parse( |
| 605 | self, files_data: List[Dict[str, Any]], all_files_content: Dict[str, str] |
| 606 | ) -> Tuple[List[GraphNodeData], List[GraphEdgeData]]: |
| 607 | nodes_data: List[GraphNodeData] = [] |
| 608 | edges_data: List[GraphEdgeData] = [] |
| 609 | |
| 610 | for file_data in files_data: |
| 611 | path = file_data["path"] |
| 612 | # Ensure the parser only processes files it's supposed to handle, |
| 613 | # although GraphGenerator._get_parser should already filter. |
| 614 | if not (path.endswith((".js", ".jsx", ".ts", ".tsx"))): |
| 615 | continue |
| 616 | |
| 617 | content = file_data["content"] |
| 618 | # Module ID from path, similar to Python |
| 619 | module_id = path.replace("/", ".").rsplit(".", 1)[0] |
| 620 | if ( |
| 621 | Path(path).name == Path(path).stem and "." not in Path(path).stem |
| 622 | ): # for files like 'index' without extension in id |
| 623 | module_id = path.replace("/", ".") |
| 624 | |
| 625 | # Create module node |
| 626 | module_node: GraphNodeData = { |
| 627 | "id": module_id, |
| 628 | "name": Path(path).name, # Use full filename as name for module |
| 629 | "category": "module", |
| 630 | "file": path, |
| 631 | "start_line": 1, |
| 632 | "end_line": len(content.splitlines()), |
| 633 | "code": None, |
| 634 | "parent_id": str(Path(path).parent), # Set parent to directory path |
| 635 | "imports": [], |
| 636 | } |
| 637 | nodes_data.append(module_node) |
| 638 | |
| 639 | lines = content.splitlines() |
| 640 | for lineno_idx, line_content in enumerate(lines): |
| 641 | lineno = lineno_idx + 1 |
| 642 | |
| 643 | # Functions |
| 644 | for match in self.function_pattern.finditer(line_content): |
| 645 | func_name = match.group(1) or match.group(2) or match.group(3) |
| 646 | if func_name: |
| 647 | node_id = f"{module_id}.{func_name}" |
| 648 | nodes_data.append( |
| 649 | { |
| 650 | "id": node_id, |
| 651 | "name": func_name, |
| 652 | "category": "function", |
| 653 | "file": path, |
| 654 | "start_line": lineno, |
| 655 | "end_line": lineno, # Simplified |
| 656 | "code": line_content.strip(), |
| 657 | "parent_id": module_id, |
| 658 | } |
| 659 | ) |
| 660 | edges_data.append( |
| 661 | { |