-
Notifications
You must be signed in to change notification settings - Fork 1
Compiler
Edgar Mesquita edited this page Jan 29, 2026
·
10 revisions
The compiler is the core component that enables the magic of eQuantic.UI. It transforms C# semantics into efficient and readable TypeScript code.
The TypeScriptEmitter is the entry point for generating .ts files. It organizes imports, defines classes, and uses the CSharpToJsConverter to convert method bodies.
A implementation based on the Strategy pattern that traverses the Roslyn syntax tree (AST).
- Each type of C# expression or statement has a dedicated strategy (e.g.,
BinaryExpressionStrategy,IfStatementStrategy).
Generates standard V3 Source Maps with Base64 VLQ encoding, mapping generated JavaScript/TypeScript back to the original .cs or .eqx source lines.
The converter applies intelligent heuristics to decide how to map variable names:
- C# properties and fields are mapped to
this.propertyNamein JS. - Local variables and parameters retain their original names.
- System methods like
Console.WriteLineare automatically mapped toconsole.log.
Currently, the compiler supports a wide range of C# constructs:
- Expressions: Arithmetic, Logical, Ternary, String Interpolation.
-
Control Flow:
if,switch,for,foreach,while. - Modern Patterns: Full support for Recursive, Property, Positional, Relational, and Logical patterns (C# 9.0 - 12.0).
-
Resource Management: Support for
usingstatements andusing vardeclarations. -
Exceptions: Full support for
try-catch-finally. -
LINQ: Direct conversion of LINQ methods to JS equivalents (
Select→map,Where→filter). -
Async/Await: Mapping of
TasktoPromiseand nativeawaitsupport.
C# Source:
private void Increment() {
Count++;
if (Count > 10) Console.WriteLine("Max reached");
}TypeScript Output:
increment() {
this.count++;
if (this.count > 10) console.log("Max reached");
}