Compilation Phases
Detailed walkthrough of each phase. For overview, see Architecture Overview.
Phase 1: Discover ✅
Section titled “Phase 1: Discover ✅”Validate tsconfig.json and glob for input files matching the config pattern.
Phase 2: Load ✅
Section titled “Phase 2: Load ✅”Read files from disk, create TypeScript SourceFile AST objects.
Phase 3: Build IR ✅
Section titled “Phase 3: Build IR ✅”Parse decorators and metadata into immutable IR: components, props, events, methods.
Phase 4: Sync AST ⚠️
Section titled “Phase 4: Sync AST ⚠️”Update AST nodes to reflect IR state. Resolve cross-file dependencies.
Phase 5: Generate ⚠️
Section titled “Phase 5: Generate ⚠️”Run generators (always fully rebuild). Examples: ir.json, components.d.ts.
Phase 6: Derive ⚠️
Section titled “Phase 6: Derive ⚠️”Run derivatives (per-source framework adapters). Examples: component.react.tsx, component.angular.ts.
Phase 7: Write ✅
Section titled “Phase 7: Write ✅”Final write phase with multiple sub-stages:
- Preprocess – Collect referenced symbols, inject missing imports (see Symbol Resolution)
- Print – Convert AST to source code
- Postprocess – Format, validate, post-emit steps
- Flush – Write to disk
File Organization
Section titled “File Organization”During compilation:
sourceFiles.loadSource() // Read project *.pen.ts filessourceFiles.clearGenerated() // Clear stale outputssourceFiles.newFile(name) // Create a generated filesourceFiles.getAll() // Get both source + generatedProject source files persist across passes. Generated files are cleared at startup to prevent stale outputs.