SWC Next is a fast JavaScript and TypeScript toolchain written in Rust. It is a rewrite of SWC from the ground up, built around a flat, ESTree-based AST for performance and extensibility.
- Performance: Up to 3× faster than SWC in native parser benchmarks and up to 15× faster in JavaScript API benchmarks.
- JavaScript Extensibility: Fast AST round trips between Rust and JavaScript enable writing plugins in JavaScript.
- Correctness: Tested against Test262, TypeScript, and Babel, supplemented by additional unit tests.
The Rust API is still in a very early stage; please continue to use SWC's Rust API for production.
The JavaScript API is available from @swc-next/core. Install it with npm install @swc-next/core:
npm install @swc-next/coreThen parse and print a program:
import { parseSync, generateSync } from "@swc-next/core";
const { program, diagnostics } = parseSync("const answer = 42;");
console.log(diagnostics);
console.log(generateSync(program).code);As a ground-up rewrite, SWC Next is being developed in a separate repository and published as separate packages. We are gradually bringing its capabilities in line with SWC, with the long-term goal of becoming SWC's next major version and merging back into the SWC repository.
See the project roadmap for planned milestones and progress.
See the Flattening AST design and other documents.
Node IDs and typed handles are not tied to their owning Ast. Handles include NodeId, typed node handles such as Expr, SubRange<T> list ranges, and AstUtf8 / AstWtf8 string handles. Using them with the wrong AST or after invalidation can cause undefined behavior.
Use AstCtx through its safe APIs where possible. Custom node access requires unsafe { ctx.ast() } for reading or unsafe { ctx.ast_mut() } for mutation. You must use handles with their owning AST, keep them valid and correctly typed, and preserve these guarantees when editing. Never reuse handles invalidated by mutation.
See the Ast and AstCtx Rust docs for the full safety requirements.
SWC Next plans to support selected SWC .swcrc options. Its Rust and JavaScript APIs will not be compatible with SWC's.
Configuration compatibility has not been implemented yet.
|
|
|
Thanks to:
- Yuku, whose AST definitions, parser, and semantic analysis were ported to Rust and adapted for SWC Next.
- The Zig compiler and rowan, which inspire the flattening AST design.
- Oxc, whose arena hash collections and portions of isolated-declarations logic and conformance test infrastructure were copied or adapted for SWC Next. Its AST tooling also informs our design.
- esbuild, whose printer implementation and portions of its test suite were ported from Go to Rust and adapted for SWC Next.
SWC Next's own code is licensed under the Apache License, Version 2.0, as is SWC. Included third-party code and data retain their upstream license terms; see THIRD_PARTY_NOTICES.
See the LICENSE file for more details.