compile
Compiles the JSX in a module into calls to the ShadowJS runtime, with the fastest implementation this machine has: the Rust addon (about ten times faster on large apps), else the same code as WebAssembly, else the TypeScript implementation.
Compiles the JSX in a module into calls to the ShadowJS runtime, with the fastest implementation this machine has: the Rust addon (about ten times faster on large apps), else the same code as WebAssembly, else the TypeScript implementation. Every implementation produces the same output byte for byte, source map included, and throws the same CompileError. It is a pure function.
A call the Rust core cannot answer is answered by the TypeScript implementation, so the result never depends on the backend: a call
with plugins (they are JavaScript functions that edit the syntax tree in the build), an input with an unpaired surrogate, options
of an unusual type, or nesting deeper than the Rust implementation follows.
Import#
import { compile } from "@shadow-js/compiler";
Signature#
function compile(source: string, options?: CompileOptions): CompileResult
Parameters#
| Name | Description |
|---|---|
source |
Module text to compile. |
options |
What to generate and how; see CompileOptions. |
Returns#
The new code, a source map, the plugins' diagnostics and transformed.
Throws#
- CompileError For source the compiler cannot or refuses to transform.
Examples#
import { compile } from "@shadow-js/compiler";
const result = compile("export const A = () => <h1>Hello</h1>;", { filename: "a.tsx" });
console.log(result.transformed); // true
console.log(result.code.includes('from "@shadow-js/web"')); // true