-
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, Null-coalescing (
??), Conditional Access (?.,?[]). -
Control Flow:
if,switch,for,foreach,while,do-while,break,continue,throw. - 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-finallyandthrowstatements (Exception → Error). -
Indexes and Ranges: Support for index-from-end operator (
array[^1]→array[array.length - 1]). -
LINQ: Direct conversion of LINQ methods to JS equivalents:
-
Projection:
Select→map,SelectMany→flatMap -
Filtering:
Where→filter,Distinct→[...new Set()] -
Ordering:
OrderBy/OrderByDescending→sort,Reverse→[...arr].reverse() -
Partitioning:
Skip→slice(n),Take→slice(0, n) -
Element:
First/FirstOrDefault→find/[0],Last/LastOrDefault→arr[arr.length-1],Single/SingleOrDefault→find/[0] -
Quantifiers:
Any→some/length > 0,All→every,Contains→includes -
Aggregation:
Count→length/filter().length,Sum→reduce((a,b) => a+b, 0),Average→reduce()/length,Min→Math.min(...),Max→Math.max(...)
-
Projection:
-
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");
}