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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
//! Interface-related IR types for TypeScript interface declarations.
//!
//! This module provides the intermediate representation for TypeScript interfaces,
//! which define the shape of objects without implementation.
//!
//! ## Example
//!
//! Given this TypeScript interface:
//!
//! ```typescript
//! /** @derive(Serialize) */
//! interface User extends Entity {
//! readonly id: string;
//! name: string;
//! email?: string;
//! greet(message: string): void;
//! }
//! ```
//!
//! The resulting [`InterfaceIR`] would contain:
//! - `name`: `"User"`
//! - `heritage`: `["Entity"]`
//! - `fields`: Three [`InterfaceFieldIR`] entries
//! - `methods`: One [`InterfaceMethodIR`] entry for `greet`
use ;
use crate;
/// Intermediate representation of a TypeScript interface declaration.
///
/// Similar to [`ClassIR`](crate::ClassIR) but for interface declarations.
/// Interfaces define the shape of objects and can extend other interfaces.
///
/// # Key Differences from ClassIR
///
/// - No visibility modifiers (all members are implicitly public)
/// - No abstract modifier
/// - No implementation bodies for methods
/// - Can only extend (not implement) other interfaces
///
/// # Example
///
/// ```rust
/// use macroforge_ts_syn::InterfaceIR;
///
/// fn generate_type_guard(iface: &InterfaceIR) -> String {
/// let mut checks = Vec::new();
///
/// for field in &iface.fields {
/// if !field.optional {
/// // Generate property existence checks
/// checks.push(format!(
/// "'{}' in obj",
/// field.name
/// ));
/// }
/// }
///
/// format!(
/// "function is{}(obj: unknown): obj is {} {{ return {}; }}",
/// iface.name, iface.name, checks.join(" && ")
/// )
/// }
/// ```
/// Intermediate representation of an interface property.
///
/// Represents a property signature within a TypeScript interface.
/// Unlike class fields, interface fields cannot have visibility modifiers
/// (they're always public).
///
/// # Example
///
/// For the TypeScript property:
///
/// ```typescript
/// /** @serde(rename = "user_email") */
/// readonly email?: string;
/// ```
///
/// The `InterfaceFieldIR` would have:
/// - `name`: `"email"`
/// - `ts_type`: `"string"`
/// - `optional`: `true`
/// - `readonly`: `true`
/// - `decorators`: Contains the `@serde(rename = "user_email")` decorator
/// Intermediate representation of an interface method signature.
///
/// Captures the signature of an interface method without implementation.
/// Interface methods are always abstract by nature.
///
/// # Example
///
/// For the TypeScript method signature:
///
/// ```typescript
/// process<T>(input: T): Promise<Result<T>>;
/// ```
///
/// The `InterfaceMethodIR` would have:
/// - `name`: `"process"`
/// - `type_params_src`: `"<T>"`
/// - `params_src`: `"input: T"`
/// - `return_type_src`: `"Promise<Result<T>>"`
/// - `optional`: `false`