Thank you for your interest in contributing to SharpTS! This project is a TypeScript interpreter and compiler written in C#, and we welcome contributions of all kinds.
- Getting Started
- How to Contribute
- Development Workflow
- Code Style Guidelines
- Adding New Language Features
- Areas Needing Help
- Code of Conduct
- .NET 10.0 SDK or later
-
Fork and clone the repository:
git clone https://github.com/nickna/SharpTS.git cd SharpTS -
Build the project:
dotnet build
-
Run the REPL to verify everything works:
dotnet run
Before diving in, we recommend reading ARCHITECTURE.md which explains:
- The compiler/interpreter pipeline
- How the type system works
- Key design patterns used throughout
- Check if the bug has already been reported in Issues
- Create a new issue with:
- A clear, descriptive title
- Steps to reproduce the bug
- Expected vs actual behavior
- A minimal TypeScript code example that triggers the bug
- Whether it affects interpretation, compilation, or both
- Open an issue to discuss the feature before implementing
- Describe the TypeScript feature or improvement you'd like to add
- Include examples of the syntax and expected behavior
-
Create a feature branch from
main:git checkout -b feature/your-feature-name
-
Make your changes following the code style guidelines
-
Add tests for new functionality in the
SharpTS.Tests/directory -
Ensure all tests pass in both interpreter and compiler modes
-
Commit with clear, descriptive messages:
Add support for [feature] - Updated Lexer.cs to handle new tokens - Added AST nodes in AST.cs - Implemented type checking in TypeChecker.cs - etc. -
Push and open a pull request against
main
dotnet buildTests are xUnit tests in the SharpTS.Tests/ directory:
dotnet testImportant: When adding or modifying features, verify they work in BOTH modes:
- Interpretation (
dotnet run -- file.ts) - Compilation (
dotnet run -- --compile file.tsthendotnet file.dll)
Add new test classes to SharpTS.Tests/ following the existing patterns (e.g., InterpreterTests/, CompilerTests/).
- C# Version: 12/13 with .NET 10 features
- Nullable Reference Types: Always enabled
- Records: Use for immutable data (AST nodes, type representations)
- Primary Constructors: Preferred for simple classes
All AST nodes should be immutable records:
// In AST.cs
public record MyNewExpr(Token Operator, Expr Operand) : Expr;
public record MyNewStmt(Expr Value, Token Keyword) : Stmt;Use switch expressions for AST traversal:
return expr switch
{
Expr.MyNewExpr e => HandleMyNewExpr(e),
// ... other cases
_ => throw new Exception($"Unknown expression type: {expr.GetType()}")
};Use consistent prefixes:
- Type errors:
throw new Exception("Type Error: message"); - Runtime errors:
throw new Exception("Runtime Error: message");
When adding a new TypeScript feature, you typically need to modify these files in order:
Add new token types if needed:
public enum TokenType
{
// ...
MY_NEW_TOKEN,
}Handle tokenization of new syntax in ScanToken().
Add new expression/statement record types.
Parse the new syntax and build AST nodes.
Add type checking logic in CheckExpr() or CheckStmt().
Implement runtime behavior in Evaluate() or Execute().
Generate IL instructions in EmitExpression() or EmitStatement().
Add a test class demonstrating the feature.
- Add token:
TokenType.MY_OP - Lexer: Recognize the operator characters
- AST: Reuse
Expr.Binaryor create new node - Parser: Add to appropriate precedence level
- TypeChecker: Validate operand types
- Interpreter: Implement the operation
- ILEmitter: Emit equivalent IL
- Test: Add tests to
SharpTS.Tests/
We especially welcome contributions in these areas:
- Generics (
<T>) - Enums
- Modules and imports
- Decorators
- Union and intersection types
- Type guards
- Async/await
- Ensure all interpreter features work when compiled
- Fix any behavioral differences between modes
- Improve generated IL efficiency
- Lexer/parser optimization
- Compiled code performance
- Interpreter evaluation speed
- Add tests for edge cases
- Add tests for error conditions
- Improve existing test comprehensiveness
Thank you for contributing to SharpTS!