Skip to content

feat(compiler): pure Roslyn H5.Compiler.Next initial implementation#280

Open
theolivenbaum wants to merge 4 commits intomasterfrom
feature/next-gen-h5-compiler-boilerplate-5767421521241371841
Open

feat(compiler): pure Roslyn H5.Compiler.Next initial implementation#280
theolivenbaum wants to merge 4 commits intomasterfrom
feature/next-gen-h5-compiler-boilerplate-5767421521241371841

Conversation

@theolivenbaum
Copy link
Copy Markdown
Collaborator

This submission implements the foundational setup for the future H5 Compiler version (H5.Compiler.Next) as requested by the user.

Changes Made:

  • Project Structure: Setup Next/H5.Compiler.Next (CLI wrapper), Next/H5.Compiler.Service.Next (compiler library containing Roslyn-based parser and JS emitter), and Next/H5.Compiler.Next.Tests (XUnit tests).
  • Core Compilation: Dropped legacy rewriting tools and utilized pure Microsoft.CodeAnalysis.CSharp. Implemented an H5Compiler that initializes a CSharpCompilation pipeline and a JavascriptEmitter (leveraging CSharpSyntaxWalker) that directly traverses the AST and generates matching H5 JavaScript formats.
  • Functionality: Successfully handles simple namespaces, class declarations (H5.define), and standard method invocations like Console.WriteLine translated to console.log().
  • Testing: Added HelloWorldTest mapping Console.WriteLine("Hello, World!") input strings to H5.define JavaScript assertions. Wired up CLI (H5.Compiler.Next/Program.cs) to execute against source .cs files natively, writing to .js.
  • Documentation: Instantiated required .md files detailing the pure Roslyn goal.

PR created automatically by Jules for task 5767421521241371841 started by @theolivenbaum

- Established `Next/` directory containing the `H5.Compiler.Next` (executable) and `H5.Compiler.Service.Next` (library).
- Integrated `Microsoft.CodeAnalysis.CSharp` dependencies for pure Roslyn parsing and emitting.
- Implemented initial `H5Compiler` utilizing `CSharpCompilation.Create` and `JavascriptEmitter` (extending `CSharpSyntaxWalker`).
- Added capability to parse a basic "Hello World" source file and output the corresponding `H5.define(...)` JavaScript structure containing `console.log`.
- Created an initial `xUnit` test confirming successful compilation and matching JS structure.
- Addressed all prompt instructions and required configuration files (`AGENTS.md`, `TODO.md`, `WIP.md`).

Co-authored-by: theolivenbaum <8791811+theolivenbaum@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

google-labs-jules Bot and others added 3 commits March 1, 2026 17:46
…erics

- Extended `JavascriptEmitter` to process `StructDeclarationSyntax` and `ClassDeclarationSyntax`.
- Segregated properties, fields, and methods into standard H5 `statics`, `fields`, `props`, and `methods` blocks within `H5.define`.
- Added recognition and emission of the `$kind: "struct"` property for structures.
- Implemented functional wrapping (e.g., `function (T) { return { ... }; }`) to properly support generic parameters in class and struct definitions.
- Enhanced `IdentifierNameSyntax` visitation to prepend `this.` on instance fields and properties.
- Introduced `ComplexTypeTest` to assert against a generic struct, properties, and an implementation of an interface in `Next/H5.Compiler.Next.Tests`.

Co-authored-by: theolivenbaum <8791811+theolivenbaum@users.noreply.github.com>
- Added `Jint` NuGet dependency to `H5.Compiler.Next.Tests`.
- Developed `IntegrationTestRunner` to simulate H5 execution. Uses an `H5.define` JavaScript mock to reconstruct the compiled C# classes, structs, and generic types in memory.
- Overhauled `JavascriptEmitter` to avoid incorrectly outputting namespaces, return accurate `ReturnStatementSyntax`, and parse basic `BinaryExpressionSyntax`.
- Implemented incremental `IntegrationTests` suite containing:
  - `Test1_SimpleReturnValue`: Tests basic static returns.
  - `Test2_FieldAccess`: Tests instance state and variable assignment.
  - `Test3_PropertyAccess`: Tests getter/setter property simulation.
  - `Test4_GenericClass`: Tests generic instantiation closure evaluation.

Co-authored-by: theolivenbaum <8791811+theolivenbaum@users.noreply.github.com>
…uctures

- Updated `JavascriptEmitter` to process `BlockSyntax`, supporting nested scopes.
- Implemented `VisitLocalDeclarationStatement` to output JS `var` variable initialization.
- Added implementation for `VisitIfStatement`, `VisitForStatement`, and `VisitWhileStatement` to properly map C# loops and conditionals natively to JS equivalents.
- Refactored `VisitIdentifierName` to ensure `this.` is exclusively prepended to instance properties/fields and explicitly ignored if acting as the target of a `MemberAccessExpression` (resolves `other.this.Field` bugs).
- Overrode `VisitMemberAccessExpression` to format direct access via `.`.
- Added a series of `IntegrationTests` evaluating arithmetic local variables, if statement evaluation logic, and loops (For/While) resolving correctly within the Jint runtime sandbox.
- Updated the roadmap tracker (`TODO.md`) acknowledging successful milestone progression.

Co-authored-by: theolivenbaum <8791811+theolivenbaum@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant