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

NameTypeDescription
codestringThe source text to compile.
optionsCompileOptionsOptional compile options.

CompileOptions

FieldTypeDefaultDescription
cwdstringprocess.cwd()Current working directory.
filestringindex.tsThe file being compiled. The language is inferred from its extension.
languageLanguageinferredThe grammar of the code. Overrides the extension inference.
sourceTypeSourceTypeinferredThe module system of the code. Overrides the grammar's module kind.
outputOutputOptions{ file: file }Output code settings. output.file derives the default source-map URL.
sourceMapSourceMapOptionsoffThe source-map inputs and outputs requested for the run.
pluginsPluginOption[][]The plugins to run.

An empty output.file or sourceMap.output.url is treated as unset, same as absent.

Returns

Promise<CodeResult>:

FieldTypeDescription
codestringThe generated code.
mapSourceMap | nullThe 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

Copyright © 2026, Alpheus

On this page