18 · Módulos
JavaScript / TypeScript · Node
Usa JavaScript y TypeScript mediante Node integrado, incluidos módulos nativos y Promises. El shim, runtime y ABI de addons deben coincidir. int de Zolo usa bigint en firmas inline.
En esta página
Ejecuta localmente con el plugin y runtime correspondientes. Estos ejemplos no se ejecutan en el playground del navegador.
JavaScript / TypeScript / Node.
// JavaScript and TypeScript use the same embedded Node runtime.
use plugin node::{javascript as js, typescript as ts}
extern js fn add(a: int, b: int) -> int {
return a + b;
}
extern ts {
fn normalize(text: str) -> str {
return text.trim().toLowerCase();
}
fn root(value: float) -> float {
return Math.sqrt(value);
}
}
let original = " Zolo "
let greeting: str = extern js {
return `Hi ${`${original.trim()}`}`;
}
let lexical: bool = extern js {
// Braces and slashes in native literals remain inside this body.
return /[{}\/]/.test("}") && `literal } ${original.trim()}`.endsWith("Zolo");
}
extern ts fn native_import() -> str {
import { createHash } from "node:crypto";
return createHash("sha256").update("Zolo").digest("hex").slice(0, 8);
}
print(add(20, 22))
print(normalize(original))
print(root(81.0))
print(greeting)
print(lexical)
print(native_import().len())
// expected:
// 42
// zolo
// 9
// Hi Zolo
// true
// 8
Requiere la CLI o el host de Zolo; ábrelo en el playground o ejecútalo localmente.
Preparación y distribución
El empaquetado sin fuentes puede conservar artefactos externos preparados, pero no elimina dependencias de runtime o plataforma. Se cubre alojamiento en VM, native y LLVM; los bindings externos rechazan destinos WebAssembly no admitidos. La aceptación reciente cubre Windows x64. Python se verifica específicamente con CPython 3.12; otras plataformas requieren validación propia.
Consulta también