typescript 0.0.2

TypeScript compiler and runtime
Documentation
# ๐ŸŽฏ typescript

> Rusty TypeScript Core Compiler & Runtime ๐Ÿฆ€โšก๏ธ

[![Crate](https://img.shields.io/badge/Crate-typescript-orange?logo=rust)](https://crates.io)
[![Rust Edition](https://img.shields.io/badge/Rust-2024%20Edition-blue)](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

| Module | Description | Status |
|--------|-------------|--------|
| ๐Ÿ”ค **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>