macroforge_ts_syn
TypeScript syntax types for build-time macro code generation
Overview
TypeScript syntax types for build-time macro code generation.
This crate provides a syn-like API for parsing and manipulating TypeScript
code, enabling macro authors to work with TypeScript AST in a familiar way. It is the core
infrastructure crate for the Macroforge TypeScript macro system.
Overview
The crate is organized into several modules:
abi- Application Binary Interface types for stable macro communicationast- Source-backed expression and identifier values for templatesconfig- Serializable configuration types shared between host and macro processescontext_registry- Thread-local storage for the activeMacroContextIRdeclarative- Grammar and parser for declarative (pattern-matching) macrosderive- Derive input types that mirror Rust'ssyn::DeriveInputerrors- Error types and diagnostics for macro expansionimport_registry- Unified import registry built during IR loweringjsdoc- JSDoc directive parsing used by loweringlower- AST lowering from OXC types to IR representationsstream- Parsing stream abstraction similar tosyn::parse::ParseBuffertype_normalize- Helpers for splitting TS type-string snippets into structural pieces
Architecture
The crate follows a layered architecture:
┌─────────────────────────────────────────────────────────────┐
│ User-Facing API │
│ (DeriveInput, TsStream, parse_ts_macro_input!) │
├─────────────────────────────────────────────────────────────┤
│ Lowering Layer │
│ (lower_classes, lower_interfaces, ...) │
├─────────────────────────────────────────────────────────────┤
│ IR Types (ABI Stable) │
│ (ClassIR, InterfaceIR, EnumIR, TypeAliasIR, ...) │
├─────────────────────────────────────────────────────────────┤
│ Parser Backend │
│ (OXC) │
└─────────────────────────────────────────────────────────────┘
Usage Example
Here's how to use this crate in a derive macro:
use ;
// A typical derive macro entry point (normally annotated with
// `#[ts_macro_derive(...)]` from the `macroforge_ts_macros` crate)
Re-exports
oxc- The OXC crate, for macros that work on the parsed AST directly
Installation
Key Exports
Traits
ToTsString- Trait for converting values to TypeScript string representations.
API Reference
See the full API documentation on docs.rs.
License
MIT