SWC (Speedy Web Compiler)

repository·main·Indexed 12 days ago

https://github.com/swc-project/swc

A high-performance Rust-based compiler for JavaScript and TypeScript designed to replace Babel. The project includes a suite of crates for parsing, minification, and module transformation, as well as WebAssembly bindings like @swc/wasm-typescript (supporting TypeScript 5.5.4) and @swc/nodejs-support-wasm for Node.js integrations.

Tokens
115.5K
Snippets
432
Records
653
Agent score
99%

What's inside SWC

  1. Overview of Module Transforms in swc

    main

    The swc_ecma_transforms_module crate is responsible for lowering ECMAScript module (ESM) syntax into legacy module formats.

    Supported Formats

    • CommonJS: Produces require() calls and module.exports.
    • AMD: Produces define() calls with dependency arrays and factory bodies.
    • UMD: Produces an adapter IIFE with a shared factory body.
    • SystemJS: Lowers modules into a System.register format (documented separately).

    Transformation Pipeline

    Most transforms (CommonJS, AMD, UMD) follow a shared pipeline:

    1. Top-level this rewrite: Replaces this with undefined (unless Config::allow_top_level_this is enabled).
    2. Collection: SourceModule::collect walks declarations and records linkage.
    3. Stripping: syntax_strip::lower removes module syntax (like import/export) while preserving executable code.
    4. Reduction: ModuleRecordEntryReducer converts entries into ImportMap and export getters.
    5. Emission: Format-specific emitters generate the final code (e.g., require for CJS, define for AMD).
    6. Binding Rewrite: Local import references are rewritten using the generated ImportMap.
  2. What is hstr?

    main
    hstr is a high-performance string interning library designed for Rust. It is specifically intended for use in performance-critical applications such as compilers or build tools (e.g., bundlers) written in Rust, where reducing memory overhead and speeding up string comparisons via interning is required.
  3. Overview of swc_bundler

    main

    swc_bundler is the official bundler for the SWC project. It is designed to handle module bundling with a focus on performance and output quality. Key capabilities include:

    • Clean merging: Generates code that is easy for subsequent tools to optimize.
    • Parallel file loading: Speeds up the bundling process by loading files in parallel.
    • Tree shaking: Removes unused code to reduce bundle size.
    • CommonJS support: Handles require syntax and CommonJS modules.
    • Circular imports: Correctly manages dependencies with circular references.
  4. Overview of swc_ecma_regexp

    main

    The swc_ecma_regexp crate provides an implementation of the ECMAScript® 2024 Language Specification for Regular Expressions. It supports standard regular expression literals and patterns as defined by the ECMA-262 specification, as well as Stage 4 proposals including:

    • Duplicate Named Capturing Groups: proposal-duplicate-named-capturing-groups
    • RegExp Modifiers: proposal-regexp-modifiers
  5. Overview of SWC (Speedy Web Compiler)

    main
    SWC is a high-performance TypeScript and JavaScript compiler written in Rust. It is designed to be used as both a Rust library and a JavaScript library. It is intended to make web development faster by providing highly optimized compilation and transformation capabilities.
  6. Overview of @swc/nodejs-support-wasm

    main

    @swc/nodejs-support-wasm is a standalone WebAssembly (WASM) binding designed for Node.js integrations. It is architecturally independent from @swc/wasm-typescript.

    This package provides:

    • The TypeScript transform API (inherited from @swc/wasm-typescript).
    • Helpers for module syntax transformation.
    • Utilities for assertion locations.
    • Syntax validation tools.