JavaScript API
compile
Compile source text from parse to generate.
function compile(code: string, options?: CompileOptions): Promise<CodeResult>;Compiles code from source to generated output, with plugins, in memory.
Parameters
| Name | Type | Description |
|---|---|---|
code | string | The source text to compile. |
options | CompileOptions | Optional compile options. |
CompileOptions
| Field | Type | Default | Description |
|---|---|---|---|
cwd | string | process.cwd() | Current working directory. |
file | string | index.ts | The file being compiled. The language is inferred from its extension. |
language | Language | inferred | The grammar of the code. Overrides the extension inference. |
sourceType | SourceType | inferred | The module system of the code. Overrides the grammar's module kind. |
output | OutputOptions | { file: file } | Output code settings. output.file derives the default source-map URL. |
sourceMap | SourceMapOptions | off | The source-map inputs and outputs requested for the run. |
plugins | PluginOption[] | [] | The plugins to run. |
An empty output.file or sourceMap.output.url is treated as unset, same as absent.
Returns
Promise<CodeResult>:
| Field | Type | Description |
|---|---|---|
code | string | The generated code. |
map | SourceMap | null | The source map for the generated code, when one was produced. |
Example
import type { CodeResult } from "telarel";
import { compile } from "telarel";
const result: CodeResult = await compile("const x: number = 1;");Last updated on
compileFromAst
Compile an existing AST through rewrite and generation.
createParser
Create a builtin parser over fixed source text and options.
Copyright © 2026, Alpheus