parse
Parse source text into an AST.
function parse(code: string, options?: ParseOptions): Promise<AstResult>;Parses code with plugins, in memory.
The builtin parser is the terminal fallback after every parse plugin hook defers, and it resolves any requested input source map.
Parameters
| Name | Type | Description |
|---|---|---|
code | string | The source text to parse. |
options | ParseOptions | Optional parse options. |
ParseOptions
| Field | Type | Default | Description |
|---|---|---|---|
cwd | string | process.cwd() | Current working directory. |
file | string | index.ts | The file being parsed. 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. |
inputSourceMap | InputSourceMap | off | The input source-map request for the step. |
plugins | PluginOption[] | [] | The plugins to run. |
Language is one of "js", "ts", "dts", "jsx", or "tsx".
SourceType is one of "script", "commonjs", "module", or "unambiguous".
InputSourceMap is a SourceMap value, a literal input mode ("inline", "external", or "auto"), or { mode, path? }; in the options form, mode accepts a SourceMap value or a literal input mode.
parse produces an AST, so it has no output source map. The shared plugin options bag presents this request as sourceMap.input; a plugin-set sourceMap.output or top-level output is ignored by parse.
Returns
Promise<AstResult>, where AstResult is { ast: Ast }. ast.language is the resolved grammar: an explicit language option, or file-extension inference otherwise.
Example
import type { AstResult } from "telarel";
import { parse } from "telarel";
const result: AstResult = await parse("const x: number = 1;");Last updated on
Ast
An AST with its source text, optional language metadata and source map, and mutable program access.
rewrite
Rewrite an AST with plugins.
Copyright © 2026, Alpheus