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:
- Macro Struct: A unit struct that implements the
Macroforgetrait - NAPI Bridge: A function exposed to JavaScript that handles JSON serialization
- Descriptor: Static metadata about the macro for runtime discovery
- Registration: Automatic registration with the
inventorycrate
Attribute Macros§
- ts_
macro_ derive - A procedural macro attribute that transforms a function into a TypeScript derive macro.