In TS-ESTree AST, import.source(...) is represented as an ImportExpression
with 'source' in the phase field (as in ESTree spec), where TS-ESLint represents it
as a CallExpression with MetaProperty as its callee.
Addition of a non-standard hashbang field to Program.
Non-standard ParenthesizedExpression and TSParenthesizedType nodes when
preserveParens is enabled (the default). Set preserveParens: false to omit them.
That aside, the AST should completely align with Acorn's ESTree AST or TS-ESLint's TS-ESTree.
Any deviation would be considered a bug.
Property order
ESTree and TS-ESTree do not define an order for node properties. oxc-parser emits them in this
order:
type.
Node-specific fields in Oxc's defined serialization order. Properties containing child nodes
have the same relative order as the entries in visitorKeys[node.type].
start, then end.
range, when the range option is enabled.
visitorKeys is an exported map from a node type to the properties containing that node's children,
in traversal order. For example, visitorKeys.ConditionalExpression is
['test', 'consequent', 'alternate']. This is not alphabetical order: walking alternate before
test would not match the syntax or evaluation order of a conditional expression.
Fields omitted by the selected astType do not change the relative order of the remaining fields.
A generic walker which recursively inspects Object.keys(node) therefore visits standard ESTree
children in the same relative order as Oxc's Visitor and the exported visitorKeys.
Prefer parseSync for most workloads. parse moves Rust parsing to a worker-pool thread,
but AST deserialization still runs synchronously on the calling thread and usually accounts
for most of the work. To parse multiple files in parallel, use parseSync in worker threads.
Example
import { parseSync, Visitor } from "oxc-parser";const code = "const url: String = /* 🤨 */ import.meta.url;";// File extension is used to determine which dialect to parse source as.const filename = "test.tsx";const result = parseSync(filename, code);// Or use async version: const result = await parse(filename, code);// An array of errors, if any.console.log(result.errors);// AST and comments.console.log(result.program, result.comments);// ESM information - imports, exports, `import.meta`s.console.log(result.module);// Visit the ASTconst visitations = [];const visitor =
Options
All options are optional.
lang: 'js' | 'jsx' | 'ts' | 'tsx' | 'dts'. Set language of source. If omitted, language is deduced from file extension.
sourceType: 'script' | 'module' | 'commonjs' | 'unambiguous'. Override the module kind. When both sourceType and lang are omitted, .mjs / .mts use module mode, .cjs / .cts use CommonJS mode, and .js / .jsx / .ts / .tsx use unambiguous mode. An explicit lang uses unambiguous mode, except 'dts', which uses module mode. An explicit sourceType takes precedence.
astType: 'js' | 'ts'. Set to 'ts' if you want ASTs of plain JS/JSX files to contain TypeScript-specific properties.
range: true | false. If true, AST nodes contain a range field. Defaults to false.
preserveParens: true | false. If true, parenthesized expressions are represented by (non-standard) ParenthesizedExpression and TSParenthesizedType AST nodes. Defaults to true.
showSemanticErrors: true | false. If true, check file for semantic errors which parser does not otherwise emit e.g. let x; let x;. Has a small performance cost. Defaults to false.