TypeScript/JavaScript parser for CodeGraph - extracts code entities and relationships from TS/JS source files.
codegraph-typescript v0.3.0 adds AST-based cyclomatic complexity calculation for all functions using tree-sitter.
use codegraph_parser_api::CodeParser;
use codegraph_typescript::TypeScriptParser;
let parser = TypeScriptParser::new();
let ir = parser.parse_source(source, Path::new("example.ts"))?;
for func in &ir.functions {
if let Some(complexity) = &func.complexity {
println!("{}: CC={} Grade={}",
func.name,
complexity.cyclomatic_complexity,
complexity.grade()
);
}
}- if/else statements and ternary operators
- switch/case statements
- for, while, do-while loops
- try/catch exception handling
- Logical operators (&&, ||)
- Nesting depth tracking
- ✅ Parse TypeScript and JavaScript files (.ts, .tsx, .js, .jsx)
- ✅ Extract functions (including arrow functions, async functions)
- ✅ Extract classes and interfaces
- ✅ Track imports and exports
- ✅ Cyclomatic complexity analysis (v0.3.0)
- ✅ Full integration with
codegraph-parser-api
use codegraph::CodeGraph;
use codegraph_parser_api::CodeParser;
use codegraph_typescript::TypeScriptParser;
use std::path::Path;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut graph = CodeGraph::in_memory()?;
let parser = TypeScriptParser::new();
let file_info = parser.parse_file(
Path::new("src/index.ts"),
&mut graph
)?;
println!("Parsed {} functions", file_info.functions.len());
println!("Parsed {} classes", file_info.classes.len());
Ok(())
}- Functions (regular, arrow, async, generator)
- Classes (including methods, properties, constructors)
- Interfaces
- Import/export statements
- TypeScript type annotations
- JSX/TSX syntax
Apache-2.0