pecto_typescript/
context.rs1use crate::TypeScriptAnalysisError;
2use crate::parser::parse_typescript;
3use tree_sitter::Tree;
4
5pub struct ParsedFile {
7 pub path: String,
8 pub source: String,
9 pub tree: Tree,
10}
11
12impl ParsedFile {
13 pub fn parse(source: String, path: String) -> Result<Self, TypeScriptAnalysisError> {
14 let is_tsx = path.ends_with(".tsx") || path.ends_with(".jsx");
15 let tree = parse_typescript(&source, is_tsx).ok_or_else(|| {
16 TypeScriptAnalysisError::ParseError(
17 path.clone(),
18 "Failed to parse TypeScript".to_string(),
19 )
20 })?;
21 Ok(Self { path, source, tree })
22 }
23}
24
25pub struct AnalysisContext {
27 pub files: Vec<ParsedFile>,
28}
29
30impl AnalysisContext {
31 pub fn new(files: Vec<ParsedFile>) -> Self {
32 Self { files }
33 }
34}