1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//! # TypeScript Macro Host
//!
//! The macro host module provides the core infrastructure for TypeScript macro
//! expansion. It handles the complete lifecycle of macro processing: registration,
//! dispatch, execution, and patch application.
//!
//! ## Architecture Overview
//!
//! ```text
//! ┌─────────────────────────────────────────────────────────────────┐
//! │ MacroExpander │
//! │ (Main entry point - coordinates the expansion process) │
//! └─────────────────────────────────────────────────────────────────┘
//! │
//! ▼
//! ┌─────────────────────────────────────────────────────────────────┐
//! │ MacroDispatcher │
//! │ (Routes macro calls to implementations with ABI checking) │
//! └─────────────────────────────────────────────────────────────────┘
//! │
//! ▼
//! ┌─────────────────────────────────────────────────────────────────┐
//! │ MacroRegistry │
//! │ (Thread-safe storage of registered macros using DashMap) │
//! └─────────────────────────────────────────────────────────────────┘
//! │
//! ▼
//! ┌─────────────────────────────────────────────────────────────────┐
//! │ PatchApplicator │
//! │ (Applies generated patches with source mapping) │
//! └─────────────────────────────────────────────────────────────────┘
//! ```
//!
//! ## Module Organization
//!
//! - [`config`] - Configuration loading and management (`macroforge.config.ts`)
//! - [`derived`] - Inventory-based registration for built-in derive macros
//! - [`dispatch`] - Macro call routing and ABI version checking
//! - [`error`] - Error types (`MacroError`) and `Result` type alias
//! - [`expand`] - The main `MacroExpander` that orchestrates expansion
//! - [`macros`] - Helper macros for macro registration
//! - [`package_registry`] - Global registry for macro package registrars
//! - [`patch_applicator`] - Applies code patches with source mapping
//! - [`registry`] - Thread-safe macro storage (`MacroRegistry`)
//! - [`traits`] - Core traits (`Macroforge`, `MacroPackage`)
//!
//! ## Key Types
//!
//! - [`MacroExpander`] - Main entry point for macro expansion
//! - [`MacroDispatcher`] - Routes macros to implementations
//! - [`MacroRegistry`] - Stores registered macros
//! - [`Macroforge`] - Trait that all macros must implement
//! - [`MacroConfig`] - Configuration options
//! - [`MacroError`] - Error type for macro operations
//!
//! ## Usage Example
//!
//! ```rust,no_run
//! use macroforge_ts::host::{MacroExpander, Result};
//!
//! fn example() -> Result<()> {
//! // Create a new expander (registers all built-in macros)
//! let expander = MacroExpander::new()?;
//!
//! // Parse TypeScript source code
//! let source = r#"
//! /** @derive(Debug) */
//! class User { name: string; }
//! "#;
//!
//! // Expand macros (handles parsing internally)
//! let result = expander.expand_source(source, "file.ts")?;
//! println!("Expanded: {}", result.code);
//! Ok(())
//! }
//! ```
/// Configuration loading and management.
/// Compile-time `@buildtime` evaluation — sandboxed JS execution during
/// source transformation, Zig-comptime style.
/// Declarative (pattern-matching) macros — the `$name(...)` macro system.
/// Inventory-based registration for built-in derive macros.
/// Macro call dispatching with ABI version checking.
/// Error types for macro operations.
/// The main macro expansion engine.
/// Unified import registry for macro expansion.
/// Helper macros for macro registration.
/// Global registry for macro package registrars.
/// Patch application with source mapping.
/// Thread-safe macro storage.
/// Project-wide TypeScript scanner for type awareness.
/// Core traits for macro implementations.
/// Type resolution against the project-wide registry.
// Primary exports for convenience
pub use ;
pub use MacroDispatcher;
pub use ;
pub use ;
pub use ;
pub use ;
pub use MacroPackageRegistration;
pub use ;
pub use MacroRegistry;
pub use Macroforge;
// Re-export commonly used types from the ABI module for convenience.
// These types are needed when implementing custom macros.
pub use crate;