-
Notifications
You must be signed in to change notification settings - Fork 1
CompilerEvolution
Transform the current TypeScriptEmitter from a syntax-based transpiler into a semantic-aware, extensible compiler capable of handling complex business logic and producing optimized, type-safe TypeScript/JavaScript.
To prevent "spaghetti code" and unsupported operations in the browser, the compiler will enforce strict boundaries, inspired by Next.js (Server/Client split) and Flutter (Constraints).
-
Server Components (
.csonly): Can useSystem.IO,DbContext, and any .NET library. Renders static HTML or initial state. -
Client Components (
StatefulComponent/StatelessComponent):-
Allowed: UI Logic, State Management,
System.Linq(via compilation), Basic Types (string,int,DateTime). -
Forbidden:
System.IO,System.Net.Http(direct), blocking.Wait(). -
Bridge: Data fetching MUST use
ServerActions(RPC style).
-
Allowed: UI Logic, State Management,
The compiler will reject code that breaks these rules before emitting JS:
- ❌
File.ReadAllText()in aStatefulComponent. - ❌ Direct SQL queries in
OnMount. - ✅ Calling a method annotated with
[ServerAction].
Goal: Replace hardcoded method translations with a data-driven registry. Implementation:
- Create
TypeMappingRegistryclass. - Support key-value mapping for types (
DateTime->Date) and methods (Console.WriteLine->console.log). - Replace
switchstatements inCSharpToJsConverterwith registry lookups.
Goal: Eliminate StringBuilder fragility and ensure syntactically correct output.
Implementation:
- Create
TypeScriptCodeBuilderclass. - Methods for
Class(),Method(),If(),Block(), avoiding manual indentation management.
Goal: Resolve types to handle overloads and extension methods correctly. Implementation:
- Update
ComponentCompilerto compile C# trees (RoslynCSharpCompilation). - Pass
SemanticModeltoCSharpToJsConverter. - Use symbol information to distinguish between
List.Addand otherAddmethods.
Goal: Translate C# LINQ to JS Array methods. Implementation:
- Map
.Where->.filter - Map
.Select->.map - Map
.First->.find
Goal: Robust Task handling.
Implementation:
- Ensure all
Taskreturning methods are markedasyncin JS. - Automatically await calls to these methods if they are awaited in C#.