Compile a focused subset of JavaScript and TypeScript into readable C for embedded targets.
native.js is built for microcontrollers that need predictable native code, low overhead, and output you can actually inspect. There is no JS runtime on-device: the compiler turns supported TS/JS into C, then target presets adapt that C to a platform such as Arduino AVR or RP2040.
- Write firmware in TypeScript syntax instead of hand-authoring every detail in C
- Keep generated output readable enough to debug, audit, and integrate into existing toolchains
- Reuse a compiler core across multiple hardware targets through presets
- Add hardware features incrementally instead of shipping a full interpreter or VM
nativejs-preset-standard- base C runtime helpers and standard pluginsnativejs-preset-arduino- Arduino-oriented headers, plugins, and examplesnativejs-preset-rp2040- RP2040 / Pico SDK support with GPIO, timing, PWM, ADC, I2C, SPI, and build helpers
Install dependencies:
yarn installBuild the compiler and presets:
yarn prepareRun lint and tests:
yarn lint
yarn testTypeScript input:
declare var GPIO: any;
declare var sleep_ms: any;
const LED_PIN = 25;
GPIO.init(LED_PIN, "output");
while (true) {
GPIO.write(LED_PIN, true);
sleep_ms(500);
GPIO.write(LED_PIN, false);
sleep_ms(500);
}This can be compiled with the RP2040 preset into C that plugs into the Pico SDK build flow. See packages/nativejs-preset-rp2040/examples/src/blink.ts.
packages/nativejs-compiler- AST traversal, type inference, template-based C generation, CLIpackages/nativejs-preset-standard- base headers, helpers, and standard library-style pluginspackages/nativejs-preset-arduino- Arduino target support and examplespackages/nativejs-preset-rp2040- RP2040 target support, Pico SDK integration, and examples
The new RP2040 preset includes:
console.logvia Pico stdioGPIO.init,GPIO.write,GPIO.readsleep_ms,millis,micros,setIntervalADC.readPWM.init,PWM.writeI2Cbyte, buffer, and register helpersSPIbyte, buffer, and register helpers
Useful entry points:
packages/nativejs-preset-rp2040/README.mdpackages/nativejs-preset-rp2040/examples/srcpackages/nativejs-preset-rp2040/scripts/pico-sdk.js
The project is structured as:
- TypeScript/JavaScript source
- TypeScript compiler API traversal and type analysis
- Native type mapping and template-driven C emission
- Target preset injection for headers, plugins, setup code, and platform helpers
- Platform-native build system such as AVR tooling or the Pico SDK
native.js is still experimental, but the repository now has:
- modernized tooling and CI
- a working compiler test suite
- multiple target presets
- compile-time validation for RP2040 examples
The language surface is intentionally a focused subset rather than full JavaScript compatibility.
Good next contributions include:
- new target presets
- broader language feature coverage
- more peripheral support for RP2040 and Arduino
- compiler output and type-system fixes
If you are evaluating the repo, start with packages/nativejs-compiler/README.md and packages/nativejs-preset-rp2040/README.md.