Skip to content
ktox logo js language logo

ktox-js: Kotlin → JavaScript transpiler.

ktox-js allows you to write Kotlin code and transpile it to JavaScript, enabling the use of Kotlin's powerful language features (like classes, null safety, and scope functions) in JavaScript environments, including web browsers and the Dota 2 Panorama UI (V8).

Key Features

  • Modern JavaScript Output: Generates clean, readable ES6+ JavaScript.
  • Classes and Inheritance: Full support for Kotlin classes, constructors, init blocks, and inheritance (transpiles to ES6 class).
  • Null Safety: Maps Kotlin's null-safety operators (?., ?:) to modern JS equivalents (?., ??).
  • Control Flow: Supports if/else, when (as if/else chains or IIFEs), while, and for loops (over ranges or collections).
  • Named Arguments: Automatically reorders named arguments at call sites to match the target function's parameter order.
  • Dota 2 Panorama Support: A specialized V8 mode that suppresses import/require for inline script environments and provides seamless integration with engine globals.
  • Native Interop: Powerful @NativeName and @ReplaceReferencesWithLiteral annotations to bridge Kotlin code with existing JS libraries and engine globals.

Status & Support

ktox-js is currently in development. Below is the current support status for various Kotlin features:

Feature Status Notes
Functions & Variables Full val/var, top-level and local functions.
Basic Control Flow Full if, while, for (ranges & iterables), break, continue.
when expression Full Transpiles to if/else chains; uses IIFE when used as an expression.
Classes & Inheritance Full Primary constructors, init blocks, ES6 class inheritance.
Interfaces Partial Not emitted at runtime; used only for compile-time checks.
Enums & Objects Full Transpiled to frozen JavaScript objects.
Data Classes Partial Transpiles as regular classes; copy() and componentN() not yet auto-generated.
Null Safety Full ?., !!, ?: (maps to ??).
String Templates Full Maps to ES6 template literals (backticks).
Standard Library Partial Basic collections and scope functions (let, also, etc.) are supported.
Coroutines None suspend functions are not currently supported.
Reflection None No runtime reflection support.