The `oxc-parser` package provides a high-performance JavaScript and TypeScript parser with a Node.js API, currently at version 0.126.0. It's part of the broader Oxc project, known for its fast Rust-based tooling. The project exhibits a rapid release cadence, with frequent updates incorporating new features, bug fixes, and occasional breaking changes as seen in recent `crates_v` releases. Oxc Parser generates an AST that is fully conformant with the ESTree standard for JavaScript/JSX and `@typescript-eslint/typescript-estree` for TypeScript, with minor deviations for Stage 3 decorators and specific import syntax proposals (`import defer`, `import source`). A key differentiator is its 'Fast Mode,' which disables semantic error reporting by default for performance-critical scenarios, leaving error checks to downstream tools. It also offers WASM support and direct ESM information extraction, making it suitable for parser plugins and code transformation tasks.
npm install oxc-parserVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates synchronous parsing of TypeScript code, enabling semantic error checks, and then traversing the generated AST using a custom visitor to count statements, also showing access to ESM information.
Review any code that directly interacts with `oxc_allocator` if you're building custom plugins that expose these Rust-level details. For most users, no direct fix is required.
If your code directly imported or relied on specific string or span types re-exported from `oxc_span` or used `FromIn` for `Ident`, you might need to adjust imports and type usage according to the latest Oxc crate API. Consult the Oxc changelog for specifics.
To enable full semantic error reporting, pass `showSemanticErrors: true` in the `options` object to `parse` or `parseSync`. Ensure your build pipeline includes another linter or checker if you rely on Oxc's parser for semantic validation without this option.
Refer to the Oxc documentation regarding AST deviations for Stage 3 features. Adapt any AST traversal or transformation logic that might be sensitive to these differences, particularly for `ImportExpression`'s `phase` field versus `CallExpression` structures.
Change `const { parseSync } = require('oxc-parser');` to `import { parseSync } from 'oxc-parser';`. Ensure your `package.json` has `"type": "module"` or use `.mjs` file extensions for ESM.Always check `result.errors` after parsing to identify any syntax or semantic issues. If semantic errors (like duplicate declarations) are expected but not found, ensure `showSemanticErrors: true` is passed to the parser options.
Always check for parsing errors (`result.errors`) before attempting to traverse or use the AST (`result.program`). Implement defensive checks (e.g., `if (node && node.type === '...')`) when traversing, especially with experimental syntax.