amaro

repository·main·Indexed 20 days ago

https://github.com/nodejs/amaro

A WebAssembly-based TypeScript parser wrapper built on @swc/wasm-typescript that provides type stripping capabilities. Used internally by Node.js and available as a standalone package, it allows users to manage their own TypeScript transpiler versions. It supports TypeScript 5.5.4 and provides a transformSync function for programmatic type stripping.

Tokens
100.9K
Snippets
400
Records
519
Agent score
73%

What's inside amaro

  1. Overview of swc_bundler

    main

    The swc_bundler is a bundler designed for the SWC project. It provides high-performance bundling capabilities with a focus on generating clean code that is easy for subsequent optimization steps. Key features include:

    • Clean merging: Generates code that is easy to optimize.
    • Parallel file loading: Improves performance by loading files in parallel.
    • Tree shaking: Removes unused code to reduce bundle size.
    • CommonJS support: Supports require syntax.
    • Circular imports: Handles circular dependencies between modules.
  2. 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 ECMAScript 2024 features and includes support for Stage 4 proposals, specifically:

    • Duplicate named capturing groups: proposal-duplicate-named-capturing-groups
    • RegExp modifiers: proposal-regexp-modifiers
  3. Use @swc/wasm-typescript for TypeScript transforms

    main

    The @swc/wasm-typescript package provides a WebAssembly (Wasm) binding specifically for performing TypeScript transforms. It allows you to leverage SWC's TypeScript transformation capabilities within environments that support Wasm.

    Supported TypeScript Version: Currently supports TypeScript 5.5.4.

    Note on Decorators: The stage 3 decorator proposal is currently not supported.

  4. Use better_scoped_tls for scoped thread local variables

    main
    The better_scoped_tls crate provides an opinionated version of the scoped-tls crate. It maintains the exact same syntax as the original scoped-tls but improves error handling. If a scoped thread local variable is accessed outside of the closure provided by the .set method, the crate will panic with a descriptive error message indicating that the operation must be performed within the .set closure.
  5. Understand the SWC bindings build process

    main

    The SWC bindings (including @swc/core, swc_cli, and @swc/wasm) are built using the publicly published swc_core SDK. This ensures that the host binaries are deterministic for specific changes.

    Note that these bindings are intentionally excluded from the main Cargo workspace build process to prevent dependency version conflicts that occur when a workspace contains unpublished packages.

  6. Understand the swc_css_parser test suite structure

    main

    The test suite for swc_css_parser is organized into several functional categories to ensure parsing accuracy and error handling:

    • /tests/fuxture: Validates the full transformation pipeline: CSS $\rightarrow$ Parsed AST $\rightarrow$ JSON.
    • /tests/error: Focuses on error reporting and how the parser handles invalid CSS.
    • /tests/identity: Ensures consistency by verifying that input.css and input.explicit.css are parsed identically. These tests are adapted from esbuild.

    Note: Test names follow the format base64_url(md5(name)).

  7. Register Amaro programmatically with `module.register()`

    main

    To avoid passing --import flags every time, you can register Amaro in a bootstrap file using node:module's register function. This makes TypeScript work automatically for the rest of your application's lifecycle.

    ```mjs
    // bootstrap.mjs
    import { register } from "node:module";
    
    register("amaro/strip", import.meta.url);
    await import("./src/index.ts");

    Then run your application via the bootstrap file:

    node --watch ./bootstrap.mjs

    Note: For transform mode, use amaro/transform instead of amaro/strip and run Node with --enable-source-maps.