Crate macroforge_ts_macros

Crate macroforge_ts_macros 

Source
Expand description

§Macroforge TypeScript Macros

This crate provides procedural macros for generating TypeScript macro infrastructure in the Macroforge ecosystem. It simplifies the creation of derive macros that can transform TypeScript classes at compile time.

§Overview

The primary macro provided is ts_macro_derive, which transforms a Rust function into a fully-fledged TypeScript macro that integrates with the Macroforge runtime.

§Example

use macroforge_ts_macros::ts_macro_derive;

#[ts_macro_derive(Debug, description = "Generates debug formatting")]
fn debug_macro(input: TsStream) -> Result<TsStream, MacroError> {
    // Transform the input TypeScript class
    Ok(input)
}

This generates:

  • A struct implementing the [Macroforge] trait
  • A NAPI function for JavaScript interop
  • Registration with the macro registry via inventory

§Architecture

The generated code follows this pattern:

  1. Macro Struct: A unit struct that implements the Macroforge trait
  2. NAPI Bridge: A function exposed to JavaScript that handles JSON serialization
  3. Descriptor: Static metadata about the macro for runtime discovery
  4. Registration: Automatic registration with the inventory crate

Attribute Macros§

ts_macro_derive
A procedural macro attribute that transforms a function into a TypeScript derive macro.