Guide/Install

Install

Choose the package for your runtime. The following guides show how to parse source, walk the AST, and generate code.

Node.js

Install the combined package:

npm install @swc-next/core

It provides parseSync, printSync, and walk:

import { parseSync, printSync } from "@swc-next/core";

const { program } = parseSync("const answer = 42;");
console.log(printSync(program).code); // const answer = 42;

Use ESM imports, for example in an .mjs file. See the Core API for its exports.

Browser WebAssembly

Install the browser package:

npm install @swc-next/core-browser

Call init() once before parsing or printing. It loads the WebAssembly binary bundled with the package.

import init, { parseSync, printSync } from "@swc-next/core-browser";

await init();

const { program } = parseSync("const answer = 42;");
console.log(printSync(program).code); // const answer = 42;

Use a bundler that serves the package's .wasm asset. For AST traversal, add the standalone @swc-next/walker package. See the Browser API for initialization and runtime details.

Focused packages

Install these separately when you only need part of the pipeline:

PackagePurposeReference
@swc-next/parserParse source in Node.jsParser API
@swc-next/codegenGenerate source in Node.jsCodegen API
@swc-next/walkerTraverse and edit ASTs in either runtimeWalk API
@swc-next/typesShared TypeScript AST declarationsAST types

Continue with Parser, Walk, and Codegen. Examples use @swc-next/core; in the browser, import parsing and printing from @swc-next/core-browser after initialization, and walking from @swc-next/walker.