Sign in

    ts

    TypeScript/JavaScript interpreter and compiler to WebAssembly

    typescript
    javascript
    interpreter
    wasm
    Download zip
    Author
    Version
    0.1.3
    License
    Apache-2.0
    Last updated
    6 months ago
    Downloads
    1K

    #typescript.mbt

    Status: Experimental

    A TypeScript/JavaScript subset parser, interpreter, and Wasm codegen written in MoonBit. The goal is to run as much of ECMAScript (via test262) as possible, with a fallback to the interpreter when codegen is too limited.

    #Parser Scope

    The parser accepts a JS/TS subset and produces a lowered AST.

    • Declarations: function, class (lowered), let/const/var (with types)
    • Statements: block, if, while, do/while (lowered), for, for-of, for-in (parsed as for-of), break/continue, return, throw, try/catch/finally, switch
    • Expressions: literals, variables, unary/binary/ternary, new, calls, property/index access, assignments, arrow functions, function expressions, arrays/objects, yield, await
    • Types: number, int, boolean, string, void, any, array, named types, function types, interface field lists
    • Class: lowered into constructor/prototype assignments

    Not supported (parse errors or explicit skips):
    • ES modules (import/export) - parsed but not fully executed
    • with statement (deprecated)
    • Private fields (#field)

    #Interpreter Scope

    The interpreter executes the AST directly and is the main path for test262.

    • Control flow: if, while, for, for-of (arrays/strings/iterables), break/continue, return, throw, try/catch/finally, switch
    • Functions: declarations, expressions, arrows, closures, generators, async functions, async generators
    • Objects/Arrays: property access, assignment, deletion, spread
    • Special: eval (direct), new, super (limited), __proto__

    #Built-in Objects

    ObjectSupport Level
    ObjectGood - keys, values, entries, assign, defineProperty, etc.
    ArrayGood - most methods including iteration
    StringGood - most methods
    NumberGood
    MathGood
    FunctionPartial - no dynamic Function()
    DateMinimal - basic operations
    RegExpMinimal - literal parsing incomplete
    PromisePartial - async/await works
    ProxyPartial - basic traps
    ReflectPartial
    JSONGood - parse, stringify
    consoleGood - log

    test262 harness: assert.*, $262.*, $DONE, $ERROR, $DONOTEVALUATE

    #test262 Compatibility

    See TODO.md for detailed status.

    #Pass Rate by Category (2026-02-01)

    Pass Rate = Passed / (Passed + Failed), excluding skipped tests. Tests related to eval, Function constructor, and with statement are excluded.

    CategoryPassedFailedSkippedTotalPass Rate
    Math29135132789.3%
    language/statements6,5321,2307638,52584.1%
    language/expressions5,9831,7012,65310,33777.8%
    Boolean381305174.5%
    Number24984233574.8%
    Promise459180063971.8%
    String7964127121565.9%
    Function2851547050964.9%
    Object1671171228341149.4%
    Date2693101559446.5%

    #Not Tested / Not Supported

    • Intl402 - Internationalization API
    • Temporal - Temporal API
    • with statement - Deprecated feature
    • Dynamic eval - Advanced eval features
    • ES Modules - Parser accepts but not executed

    #Partial Support

    • TypedArray - Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array, BigInt64Array, BigUint64Array
    • BigInt - Basic operations

    #Experimental Wasm Codegen Scope

    The experimental Wasm codegen intentionally supports a strict subset and errors on dynamic JS features. It currently uses wasm-gc for arrays and structs.

    • Statements: let/const, assignments, if, while, do-while, for, for-of (arrays), switch, break/continue, return, block/expr statements
    • Expressions: literals, variables, arithmetic/comparison/bitwise, string +, array access/length, struct field access, new Array(size), new <interface> struct allocation, ternary, nullish coalescing (??)
    • experimental wasm-gc: GC arrays, GC structs, generator state machines

    Explicitly unsupported in codegen:
    • throw, try/catch/finally
    • typeof, void, delete
    • Object literals, closures (arrow/function expressions)
    • Dynamic call expressions

    #Development

    # Check for errors moon check --deny-warn # Run tests moon test --target native # Format code moon fmt # Run test262 (requires test262 repo in ./test262) moon run src -- test262 test262.allowlist.txt # Experimental AOT compilation (wasm-gc) just experimental-aot-check # Check AOT compilability just experimental-aot-compile # Compile fixtures to wasm just experimental-aot-test # Run with wasmtime

    #License

    Apache-2.0

    ProjectBenchmarkCorpus

    type ProjectBenchmarkCorpus derive(
    Debug
    )

    ProjectBenchmarkCorpusRun

    type ProjectBenchmarkCorpusRun derive(
    Debug
    )

    ProjectBenchmarkFailure

    type ProjectBenchmarkFailure derive(
    Debug
    )

    ProjectBenchmarkResult

    type ProjectBenchmarkResult derive(
    Debug
    )

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io