Section 2.3Source:
server/src/parser/babel/parseFile.tsAST Generation & Parsing
Transforming raw source code strings into Babel Abstract Syntax Trees (AST) with full support for modern ECMAScript, JSX, and TypeScript syntax.
Source:
server/src/parser/babel/parseFile.tsAST Parsing Pipeline
For every discovered source file, parseFile(filePath) reads the raw UTF-8 content from disk and invokes @babel/parser.parse().
server/src/parser/babel/parseFile.ts
123456789101112export function parseFile(filePath: string): ParsedFile { const code = fs.readFileSync(filePath, 'utf-8'); const ast = parse(code, parserOptions); return { filePath, ast, symbols: [], // Populated in Stage 4 exports: [] // Populated in Stage 4 }; }
Babel Parser Configuration
To ensure CodeGraph can parse modern production codebases (Next.js, Vite, NestJS, React), the parser is configured with sourceType: "module" and the following active plugin list:
server/src/parser/babel/parserOption.ts
1234567891011121314export const parserOptions: ParserOptions = { sourceType: "module", plugins: [ "jsx", // React JSX / TSX "typescript", // Full TypeScript type annotations "decorators", // TC39 & legacy decorators "classProperties", // Public class fields "classPrivateProperties", // Private class fields (#privateField) "classPrivateMethods", // Private class methods (#privateMethod) "dynamicImport", // import() expressions "importMeta", // import.meta.url "topLevelAwait" // Top-level await in ESM ] };
The `ParsedFile` Container
The AST output is wrapped in a ParsedFile model that will be mutated in-place by the Symbol Extractor in the next stage:
server/src/parser/models/ParsedFile.ts
123456export interface ParsedFile { filePath: string; // Absolute normalized file path ast: File; // Babel AST root node symbols: ParsedSymbol[]; // Populated during Pass 1 exports: ParsedExport[]; // Export mapping populated during Pass 1 }
AST Longevity
The raw Babel AST is retained in memory through Stage 4 and Stage 5 to allow fast AST visitor traversals. When building the final in-memory
Graph in Stage 7, the heavy AST objects are discarded, keeping only lightweight node and edge instances.