# ๐ฏ typescript
> Rusty TypeScript Core Compiler & Runtime ๐ฆโก๏ธ
[](https://crates.io)
[](https://www.rust-lang.org)
---
## ๐ Introduction
This is the core compiler package for **Rusty TypeScript**, providing full TypeScript compilation and execution capabilities. It integrates the complete compilation pipeline from lexical analysis and parsing to IR transformation and virtual machine execution.
### โจ Core Features
| ๐ค **Lexer/Parser** | Oak-based lexical and syntax analysis | โ
Ready |
| ๐ **IR** | Intermediate representation transformation | โ
Ready |
| ๐ฏ **VM** | Virtual machine execution engine | โ
Ready |
| ๐ **Type Checker** | Type checking system | ๐ง In Development |
| ๐ค **Codegen** | Code generation | ๐ง In Development |
| ๐ **FFI/NAPI** | Node.js integration | โ
Ready |
| ๐๏ธ **GC** | Garbage collector | โ
Ready |
---
## ๐ Quick Start
### Add Dependency
```toml
[dependencies]
typescript = { path = "../compilers/typescript" }
```
### Basic Usage
```rust
use typescript::TypeScript;
fn main() {
// ๐ฌ Create runtime
let mut ts = TypeScript::new();
// ๐ Execute TypeScript code
let result = ts.execute_script(r#"
// Variable declaration
let count: number = 42;
// Function definition
function greet(name: string): string {
return `Hello, ${name}! ๐`;
}
// Call function
console.log(greet("Rusty TypeScript"));
// Return result
count * 2
"#);
match result {
Ok(value) => println!("โ
Result: {}", value),
Err(e) => eprintln!("โ Error: {}", e),
}
}
```
### N-API Integration (Node.js)
```javascript
const { TypeScriptRuntime } = require('./index.node');
// Create runtime
const runtime = new TypeScriptRuntime();
// Execute code
const result = runtime.executeScript(`
const fib = (n: number): number => {
if (n <= 1) return n;
return fib(n - 1) + fib(n - 2);
};
fib(10)
`);
console.log('๐ Result:', result);
```
---
## ๐ง Advanced Usage
### Custom Global Variables
```rust
use typescript::TypeScript;
use typescript_types::{TsValue, ToTsValue};
let mut ts = TypeScript::new();
// Inject custom function
ts.register_global("myApi", |args: &[TsValue]| {
println!("๐ Called with args: {:?}", args);
TsValue::String("Hello from Rust! ๐ฆ".to_string())
});
```
### Error Handling
```rust
match ts.execute_script("invalid syntax !!!") {
Ok(value) => println!("Result: {}", value),
Err(TsError::SyntaxError(msg)) => {
eprintln!("Syntax error: {}", msg);
}
Err(TsError::TypeError(msg)) => {
eprintln!("Type error: {}", msg);
}
Err(e) => eprintln!("Other error: {}", e),
}
```
---
## ๐งช Testing
```bash
# Run all tests
cargo test --package typescript
# Run specific test
cargo test --package typescript -- test_lexer_parser
# Debug mode
cargo test --package typescript -- --nocapture
```
---
## ๐ Dependencies
- **typescript-types** - Type definitions
- **typescript-ir** - Intermediate representation
- **oak-typescript** - Parser (external)
- **oak-core** - Parsing core (external)
- **napi** - Node.js bindings
- **napi-derive** - NAPI macros
---
## ๐ค Contributing
We welcome issues and PRs! Please ensure:
1. โ
Code passes `cargo clippy` checks
2. โ
Code is formatted with `cargo fmt`
3. โ
All tests pass with `cargo test`
4. โ
Necessary documentation comments are added
---
## ๐ License
MIT License - see [LICENSE](../../license.md)
---
<div align="center">
**๐ฆ Built with Rust, optimized for performance โก๏ธ**
</div>