macroforge 0.1.73 → 0.1.75

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.d.ts +487 -476
  2. package/index.js +748 -560
  3. package/package.json +7 -7
package/index.d.ts CHANGED
@@ -7,46 +7,46 @@
7
7
  * different JavaScript class name. Used internally by [`NativePlugin::get_mapper`].
8
8
  */
9
9
  export declare class NativeMapper {
10
- /**
11
- * Creates a new mapper wrapping the given source mapping.
12
- *
13
- * # Arguments
14
- *
15
- * * `mapping` - The source mapping result from macro expansion
16
- */
17
- constructor(mapping: SourceMappingResult)
18
- /** Checks if this mapper has no mapping data. */
19
- isEmpty(): boolean
20
- /**
21
- * Converts a position in the original source to expanded source.
22
- * See [`NativePositionMapper::original_to_expanded`] for details.
23
- */
24
- originalToExpanded(pos: number): number
25
- /**
26
- * Converts a position in the expanded source back to original.
27
- * See [`NativePositionMapper::expanded_to_original`] for details.
28
- */
29
- expandedToOriginal(pos: number): number | null
30
- /**
31
- * Returns the name of the macro that generated code at the given position.
32
- * See [`NativePositionMapper::generated_by`] for details.
33
- */
34
- generatedBy(pos: number): string | null
35
- /**
36
- * Maps a span from expanded source to original source.
37
- * See [`NativePositionMapper::map_span_to_original`] for details.
38
- */
39
- mapSpanToOriginal(start: number, length: number): SpanResult | null
40
- /**
41
- * Maps a span from original source to expanded source.
42
- * See [`NativePositionMapper::map_span_to_expanded`] for details.
43
- */
44
- mapSpanToExpanded(start: number, length: number): SpanResult
45
- /**
46
- * Checks if a position is inside macro-generated code.
47
- * See [`NativePositionMapper::is_in_generated`] for details.
48
- */
49
- isInGenerated(pos: number): boolean
10
+ /**
11
+ * Creates a new mapper wrapping the given source mapping.
12
+ *
13
+ * # Arguments
14
+ *
15
+ * * `mapping` - The source mapping result from macro expansion
16
+ */
17
+ constructor(mapping: SourceMappingResult);
18
+ /** Checks if this mapper has no mapping data. */
19
+ isEmpty(): boolean;
20
+ /**
21
+ * Converts a position in the original source to expanded source.
22
+ * See [`NativePositionMapper::original_to_expanded`] for details.
23
+ */
24
+ originalToExpanded(pos: number): number;
25
+ /**
26
+ * Converts a position in the expanded source back to original.
27
+ * See [`NativePositionMapper::expanded_to_original`] for details.
28
+ */
29
+ expandedToOriginal(pos: number): number | null;
30
+ /**
31
+ * Returns the name of the macro that generated code at the given position.
32
+ * See [`NativePositionMapper::generated_by`] for details.
33
+ */
34
+ generatedBy(pos: number): string | null;
35
+ /**
36
+ * Maps a span from expanded source to original source.
37
+ * See [`NativePositionMapper::map_span_to_original`] for details.
38
+ */
39
+ mapSpanToOriginal(start: number, length: number): SpanResult | null;
40
+ /**
41
+ * Maps a span from original source to expanded source.
42
+ * See [`NativePositionMapper::map_span_to_expanded`] for details.
43
+ */
44
+ mapSpanToExpanded(start: number, length: number): SpanResult;
45
+ /**
46
+ * Checks if a position is inside macro-generated code.
47
+ * See [`NativePositionMapper::is_in_generated`] for details.
48
+ */
49
+ isInGenerated(pos: number): boolean;
50
50
  }
51
51
 
52
52
  /**
@@ -78,120 +78,124 @@ export declare class NativeMapper {
78
78
  * ```
79
79
  */
80
80
  export declare class NativePlugin {
81
- /**
82
- * Creates a new `NativePlugin` instance.
83
- *
84
- * Initializes the plugin with an empty cache and sets up a default log file
85
- * at `/tmp/macroforge-plugin.log` for debugging purposes.
86
- *
87
- * # Returns
88
- *
89
- * A new `NativePlugin` ready for processing files.
90
- *
91
- * # Side Effects
92
- *
93
- * Creates or clears the log file at `/tmp/macroforge-plugin.log`.
94
- */
95
- constructor()
96
- /**
97
- * Writes a message to the plugin's log file.
98
- *
99
- * Useful for debugging macro expansion issues in production environments.
100
- *
101
- * # Arguments
102
- *
103
- * * `message` - The message to log
104
- *
105
- * # Note
106
- *
107
- * Messages are appended to the log file. If the log file hasn't been
108
- * configured or cannot be written to, the message is silently dropped.
109
- */
110
- log(message: string): void
111
- /**
112
- * Sets the path for the plugin's log file.
113
- *
114
- * # Arguments
115
- *
116
- * * `path` - The file path to use for logging
117
- *
118
- * # Note
119
- *
120
- * This does not create the file; it will be created when the first
121
- * message is logged.
122
- */
123
- setLogFile(path: string): void
124
- /**
125
- * Processes a TypeScript file through the macro expansion system.
126
- *
127
- * This is the main entry point for file processing. It handles caching,
128
- * thread isolation (to prevent stack overflow), and error recovery.
129
- *
130
- * # Arguments
131
- *
132
- * * `_env` - NAPI environment (unused but required by NAPI)
133
- * * `filepath` - Path to the file (used for TSX detection and caching)
134
- * * `code` - The TypeScript source code to process
135
- * * `options` - Optional configuration for expansion and caching
136
- *
137
- * # Returns
138
- *
139
- * An [`ExpandResult`] containing the expanded code, diagnostics, and source mapping.
140
- *
141
- * # Errors
142
- *
143
- * Returns an error if:
144
- * - Thread spawning fails
145
- * - The worker thread panics (often due to stack overflow)
146
- * - Macro expansion fails internally
147
- *
148
- * # Performance
149
- *
150
- * - Uses a 32MB thread stack to prevent stack overflow during deep AST recursion
151
- * - Caches results by filepath and version for efficient incremental processing
152
- * - Early bailout for files without `@derive` decorators
153
- *
154
- * # Thread Safety
155
- *
156
- * Macro expansion runs in a separate thread because:
157
- * 1. SWC AST operations can be deeply recursive, exceeding default stack limits
158
- * 2. Node.js thread stack is typically only 2MB
159
- * 3. Panics in the worker thread are caught and reported gracefully
160
- */
161
- processFile(filepath: string, code: string, options?: ProcessFileOptions | undefined | null): ExpandResult
162
- /**
163
- * Retrieves a position mapper for a previously processed file.
164
- *
165
- * The mapper enables translation between original and expanded source positions,
166
- * which is essential for IDE features like error reporting and navigation.
167
- *
168
- * # Arguments
169
- *
170
- * * `filepath` - Path to the file (must have been previously processed)
171
- *
172
- * # Returns
173
- *
174
- * `Some(NativeMapper)` if the file has been processed and has source mapping data,
175
- * `None` if the file hasn't been processed or has no mapping (no macros expanded).
176
- */
177
- getMapper(filepath: string): NativeMapper | null
178
- /**
179
- * Maps diagnostics from expanded source positions back to original source positions.
180
- *
181
- * This is used by IDE integrations to show errors at the correct locations
182
- * in the user's original code, rather than in the macro-expanded output.
183
- *
184
- * # Arguments
185
- *
186
- * * `filepath` - Path to the file the diagnostics are for
187
- * * `diags` - Diagnostics with positions in the expanded source
188
- *
189
- * # Returns
190
- *
191
- * Diagnostics with positions mapped back to the original source.
192
- * If no mapper is available for the file, returns diagnostics unchanged.
193
- */
194
- mapDiagnostics(filepath: string, diags: Array<JsDiagnostic>): Array<JsDiagnostic>
81
+ /**
82
+ * Creates a new `NativePlugin` instance.
83
+ *
84
+ * Initializes the plugin with an empty cache and sets up a default log file
85
+ * at `/tmp/macroforge-plugin.log` for debugging purposes.
86
+ *
87
+ * # Returns
88
+ *
89
+ * A new `NativePlugin` ready for processing files.
90
+ *
91
+ * # Side Effects
92
+ *
93
+ * Creates or clears the log file at `/tmp/macroforge-plugin.log`.
94
+ */
95
+ constructor();
96
+ /**
97
+ * Writes a message to the plugin's log file.
98
+ *
99
+ * Useful for debugging macro expansion issues in production environments.
100
+ *
101
+ * # Arguments
102
+ *
103
+ * * `message` - The message to log
104
+ *
105
+ * # Note
106
+ *
107
+ * Messages are appended to the log file. If the log file hasn't been
108
+ * configured or cannot be written to, the message is silently dropped.
109
+ */
110
+ log(message: string): void;
111
+ /**
112
+ * Sets the path for the plugin's log file.
113
+ *
114
+ * # Arguments
115
+ *
116
+ * * `path` - The file path to use for logging
117
+ *
118
+ * # Note
119
+ *
120
+ * This does not create the file; it will be created when the first
121
+ * message is logged.
122
+ */
123
+ setLogFile(path: string): void;
124
+ /**
125
+ * Processes a TypeScript file through the macro expansion system.
126
+ *
127
+ * This is the main entry point for file processing. It handles caching,
128
+ * thread isolation (to prevent stack overflow), and error recovery.
129
+ *
130
+ * # Arguments
131
+ *
132
+ * * `_env` - NAPI environment (unused but required by NAPI)
133
+ * * `filepath` - Path to the file (used for TSX detection and caching)
134
+ * * `code` - The TypeScript source code to process
135
+ * * `options` - Optional configuration for expansion and caching
136
+ *
137
+ * # Returns
138
+ *
139
+ * An [`ExpandResult`] containing the expanded code, diagnostics, and source mapping.
140
+ *
141
+ * # Errors
142
+ *
143
+ * Returns an error if:
144
+ * - Thread spawning fails
145
+ * - The worker thread panics (often due to stack overflow)
146
+ * - Macro expansion fails internally
147
+ *
148
+ * # Performance
149
+ *
150
+ * - Uses a 32MB thread stack to prevent stack overflow during deep AST recursion
151
+ * - Caches results by filepath and version for efficient incremental processing
152
+ * - Early bailout for files without `@derive` decorators
153
+ *
154
+ * # Thread Safety
155
+ *
156
+ * Macro expansion runs in a separate thread because:
157
+ * 1. SWC AST operations can be deeply recursive, exceeding default stack limits
158
+ * 2. Node.js thread stack is typically only 2MB
159
+ * 3. Panics in the worker thread are caught and reported gracefully
160
+ */
161
+ processFile(
162
+ filepath: string,
163
+ code: string,
164
+ options?: ProcessFileOptions | undefined | null
165
+ ): ExpandResult;
166
+ /**
167
+ * Retrieves a position mapper for a previously processed file.
168
+ *
169
+ * The mapper enables translation between original and expanded source positions,
170
+ * which is essential for IDE features like error reporting and navigation.
171
+ *
172
+ * # Arguments
173
+ *
174
+ * * `filepath` - Path to the file (must have been previously processed)
175
+ *
176
+ * # Returns
177
+ *
178
+ * `Some(NativeMapper)` if the file has been processed and has source mapping data,
179
+ * `None` if the file hasn't been processed or has no mapping (no macros expanded).
180
+ */
181
+ getMapper(filepath: string): NativeMapper | null;
182
+ /**
183
+ * Maps diagnostics from expanded source positions back to original source positions.
184
+ *
185
+ * This is used by IDE integrations to show errors at the correct locations
186
+ * in the user's original code, rather than in the macro-expanded output.
187
+ *
188
+ * # Arguments
189
+ *
190
+ * * `filepath` - Path to the file the diagnostics are for
191
+ * * `diags` - Diagnostics with positions in the expanded source
192
+ *
193
+ * # Returns
194
+ *
195
+ * Diagnostics with positions mapped back to the original source.
196
+ * If no mapper is available for the file, returns diagnostics unchanged.
197
+ */
198
+ mapDiagnostics(filepath: string, diags: Array<JsDiagnostic>): Array<JsDiagnostic>;
195
199
  }
196
200
 
197
201
  /**
@@ -224,124 +228,124 @@ export declare class NativePlugin {
224
228
  * ```
225
229
  */
226
230
  export declare class PositionMapper {
227
- /**
228
- * Creates a new position mapper from source mapping data.
229
- *
230
- * # Arguments
231
- *
232
- * * `mapping` - The source mapping result from macro expansion
233
- *
234
- * # Returns
235
- *
236
- * A new `NativePositionMapper` ready for position translation.
237
- */
238
- constructor(mapping: SourceMappingResult)
239
- /**
240
- * Checks if this mapper has no mapping data.
241
- *
242
- * An empty mapper indicates no transformations occurred, so position
243
- * translation is an identity operation.
244
- *
245
- * # Returns
246
- *
247
- * `true` if there are no segments and no generated regions.
248
- */
249
- isEmpty(): boolean
250
- /**
251
- * Converts a position in the original source to the corresponding position in expanded source.
252
- *
253
- * Uses binary search for O(log n) lookup performance.
254
- *
255
- * # Arguments
256
- *
257
- * * `pos` - Byte offset in the original source
258
- *
259
- * # Returns
260
- *
261
- * The corresponding byte offset in the expanded source. If the position falls
262
- * in a gap between segments, returns the position unchanged. If after the last
263
- * segment, extrapolates based on the delta.
264
- *
265
- * # Algorithm
266
- *
267
- * 1. Binary search to find the segment containing or after `pos`
268
- * 2. If inside a segment, compute offset within segment and translate
269
- * 3. If after all segments, extrapolate from the last segment
270
- * 4. Otherwise, return position unchanged (gap or before first segment)
271
- */
272
- originalToExpanded(pos: number): number
273
- /**
274
- * Converts a position in the expanded source back to the original source position.
275
- *
276
- * Returns `None` if the position is inside macro-generated code that has no
277
- * corresponding location in the original source.
278
- *
279
- * # Arguments
280
- *
281
- * * `pos` - Byte offset in the expanded source
282
- *
283
- * # Returns
284
- *
285
- * `Some(original_pos)` if the position maps to original code,
286
- * `None` if the position is in macro-generated code.
287
- */
288
- expandedToOriginal(pos: number): number | null
289
- /**
290
- * Returns the name of the macro that generated code at the given position.
291
- *
292
- * # Arguments
293
- *
294
- * * `pos` - Byte offset in the expanded source
295
- *
296
- * # Returns
297
- *
298
- * `Some(macro_name)` if the position is inside generated code (e.g., "Debug"),
299
- * `None` if the position is in original (non-generated) code.
300
- */
301
- generatedBy(pos: number): string | null
302
- /**
303
- * Maps a span (start + length) from expanded source to original source.
304
- *
305
- * # Arguments
306
- *
307
- * * `start` - Start byte offset in expanded source
308
- * * `length` - Length of the span in bytes
309
- *
310
- * # Returns
311
- *
312
- * `Some(SpanResult)` with the mapped span in original source,
313
- * `None` if either endpoint is in generated code.
314
- */
315
- mapSpanToOriginal(start: number, length: number): SpanResult | null
316
- /**
317
- * Maps a span (start + length) from original source to expanded source.
318
- *
319
- * This always succeeds since every original position has an expanded equivalent.
320
- *
321
- * # Arguments
322
- *
323
- * * `start` - Start byte offset in original source
324
- * * `length` - Length of the span in bytes
325
- *
326
- * # Returns
327
- *
328
- * A `SpanResult` with the mapped span in expanded source.
329
- */
330
- mapSpanToExpanded(start: number, length: number): SpanResult
331
- /**
332
- * Checks if a position is inside macro-generated code.
333
- *
334
- * # Arguments
335
- *
336
- * * `pos` - Byte offset in the expanded source
337
- *
338
- * # Returns
339
- *
340
- * `true` if the position is inside a generated region, `false` otherwise.
341
- */
342
- isInGenerated(pos: number): boolean
231
+ /**
232
+ * Creates a new position mapper from source mapping data.
233
+ *
234
+ * # Arguments
235
+ *
236
+ * * `mapping` - The source mapping result from macro expansion
237
+ *
238
+ * # Returns
239
+ *
240
+ * A new `NativePositionMapper` ready for position translation.
241
+ */
242
+ constructor(mapping: SourceMappingResult);
243
+ /**
244
+ * Checks if this mapper has no mapping data.
245
+ *
246
+ * An empty mapper indicates no transformations occurred, so position
247
+ * translation is an identity operation.
248
+ *
249
+ * # Returns
250
+ *
251
+ * `true` if there are no segments and no generated regions.
252
+ */
253
+ isEmpty(): boolean;
254
+ /**
255
+ * Converts a position in the original source to the corresponding position in expanded source.
256
+ *
257
+ * Uses binary search for O(log n) lookup performance.
258
+ *
259
+ * # Arguments
260
+ *
261
+ * * `pos` - Byte offset in the original source
262
+ *
263
+ * # Returns
264
+ *
265
+ * The corresponding byte offset in the expanded source. If the position falls
266
+ * in a gap between segments, returns the position unchanged. If after the last
267
+ * segment, extrapolates based on the delta.
268
+ *
269
+ * # Algorithm
270
+ *
271
+ * 1. Binary search to find the segment containing or after `pos`
272
+ * 2. If inside a segment, compute offset within segment and translate
273
+ * 3. If after all segments, extrapolate from the last segment
274
+ * 4. Otherwise, return position unchanged (gap or before first segment)
275
+ */
276
+ originalToExpanded(pos: number): number;
277
+ /**
278
+ * Converts a position in the expanded source back to the original source position.
279
+ *
280
+ * Returns `None` if the position is inside macro-generated code that has no
281
+ * corresponding location in the original source.
282
+ *
283
+ * # Arguments
284
+ *
285
+ * * `pos` - Byte offset in the expanded source
286
+ *
287
+ * # Returns
288
+ *
289
+ * `Some(original_pos)` if the position maps to original code,
290
+ * `None` if the position is in macro-generated code.
291
+ */
292
+ expandedToOriginal(pos: number): number | null;
293
+ /**
294
+ * Returns the name of the macro that generated code at the given position.
295
+ *
296
+ * # Arguments
297
+ *
298
+ * * `pos` - Byte offset in the expanded source
299
+ *
300
+ * # Returns
301
+ *
302
+ * `Some(macro_name)` if the position is inside generated code (e.g., "Debug"),
303
+ * `None` if the position is in original (non-generated) code.
304
+ */
305
+ generatedBy(pos: number): string | null;
306
+ /**
307
+ * Maps a span (start + length) from expanded source to original source.
308
+ *
309
+ * # Arguments
310
+ *
311
+ * * `start` - Start byte offset in expanded source
312
+ * * `length` - Length of the span in bytes
313
+ *
314
+ * # Returns
315
+ *
316
+ * `Some(SpanResult)` with the mapped span in original source,
317
+ * `None` if either endpoint is in generated code.
318
+ */
319
+ mapSpanToOriginal(start: number, length: number): SpanResult | null;
320
+ /**
321
+ * Maps a span (start + length) from original source to expanded source.
322
+ *
323
+ * This always succeeds since every original position has an expanded equivalent.
324
+ *
325
+ * # Arguments
326
+ *
327
+ * * `start` - Start byte offset in original source
328
+ * * `length` - Length of the span in bytes
329
+ *
330
+ * # Returns
331
+ *
332
+ * A `SpanResult` with the mapped span in expanded source.
333
+ */
334
+ mapSpanToExpanded(start: number, length: number): SpanResult;
335
+ /**
336
+ * Checks if a position is inside macro-generated code.
337
+ *
338
+ * # Arguments
339
+ *
340
+ * * `pos` - Byte offset in the expanded source
341
+ *
342
+ * # Returns
343
+ *
344
+ * `true` if the position is inside a generated region, `false` otherwise.
345
+ */
346
+ isInGenerated(pos: number): boolean;
343
347
  }
344
- export type NativePositionMapper = PositionMapper
348
+ export type NativePositionMapper = PositionMapper;
345
349
 
346
350
  /**
347
351
  * Returns debug information about all registered macro descriptors (debug API).
@@ -353,7 +357,7 @@ export type NativePositionMapper = PositionMapper
353
357
  *
354
358
  * A vector of strings describing each registered macro descriptor.
355
359
  */
356
- export declare function __macroforgeDebugDescriptors(): Array<string>
360
+ export declare function __macroforgeDebugDescriptors(): Array<string>;
357
361
 
358
362
  /**
359
363
  * Returns all registered macro module names (debug API).
@@ -364,7 +368,7 @@ export declare function __macroforgeDebugDescriptors(): Array<string>
364
368
  *
365
369
  * A vector of module names.
366
370
  */
367
- export declare function __macroforgeDebugGetModules(): Array<string>
371
+ export declare function __macroforgeDebugGetModules(): Array<string>;
368
372
 
369
373
  /**
370
374
  * Looks up a macro by module and name (debug API).
@@ -380,7 +384,7 @@ export declare function __macroforgeDebugGetModules(): Array<string>
380
384
  *
381
385
  * A string describing whether the macro was found or not.
382
386
  */
383
- export declare function __macroforgeDebugLookup(module: string, name: string): string
387
+ export declare function __macroforgeDebugLookup(module: string, name: string): string;
384
388
 
385
389
  /**
386
390
  * Returns the names of all registered macros.
@@ -389,7 +393,7 @@ export declare function __macroforgeDebugLookup(module: string, name: string): s
389
393
  *
390
394
  * A vector of macro names (e.g., `["Debug", "Clone", "Serialize"]`).
391
395
  */
392
- export declare function __macroforgeGetMacroNames(): Array<string>
396
+ export declare function __macroforgeGetMacroNames(): Array<string>;
393
397
 
394
398
  /**
395
399
  * Returns the complete manifest of all registered macros and decorators.
@@ -409,7 +413,7 @@ export declare function __macroforgeGetMacroNames(): Array<string>
409
413
  * // ["Debug", "Clone", "PartialEq", "Hash", "Serialize", "Deserialize", ...]
410
414
  * ```
411
415
  */
412
- export declare function __macroforgeGetManifest(): MacroManifest
416
+ export declare function __macroforgeGetManifest(): MacroManifest;
413
417
 
414
418
  /**
415
419
  * Checks if any macros are registered in this package.
@@ -420,7 +424,7 @@ export declare function __macroforgeGetManifest(): MacroManifest
420
424
  *
421
425
  * `true` if at least one macro is registered, `false` otherwise.
422
426
  */
423
- export declare function __macroforgeIsMacroPackage(): boolean
427
+ export declare function __macroforgeIsMacroPackage(): boolean;
424
428
 
425
429
  /**
426
430
  * r" Run this macro with the given context.
@@ -448,7 +452,7 @@ export declare function __macroforgeIsMacroPackage(): boolean
448
452
  * r" - The `TsStream` cannot be created from the context
449
453
  * r" - The result cannot be serialized to JSON
450
454
  */
451
- export declare function __macroforgeRunClone(contextJson: string): string
455
+ export declare function __macroforgeRunClone(contextJson: string): string;
452
456
 
453
457
  /**
454
458
  * r" Run this macro with the given context.
@@ -476,7 +480,7 @@ export declare function __macroforgeRunClone(contextJson: string): string
476
480
  * r" - The `TsStream` cannot be created from the context
477
481
  * r" - The result cannot be serialized to JSON
478
482
  */
479
- export declare function __macroforgeRunDebug(contextJson: string): string
483
+ export declare function __macroforgeRunDebug(contextJson: string): string;
480
484
 
481
485
  /**
482
486
  * r" Run this macro with the given context.
@@ -504,7 +508,7 @@ export declare function __macroforgeRunDebug(contextJson: string): string
504
508
  * r" - The `TsStream` cannot be created from the context
505
509
  * r" - The result cannot be serialized to JSON
506
510
  */
507
- export declare function __macroforgeRunDefault(contextJson: string): string
511
+ export declare function __macroforgeRunDefault(contextJson: string): string;
508
512
 
509
513
  /**
510
514
  * r" Run this macro with the given context.
@@ -532,7 +536,7 @@ export declare function __macroforgeRunDefault(contextJson: string): string
532
536
  * r" - The `TsStream` cannot be created from the context
533
537
  * r" - The result cannot be serialized to JSON
534
538
  */
535
- export declare function __macroforgeRunDeserialize(contextJson: string): string
539
+ export declare function __macroforgeRunDeserialize(contextJson: string): string;
536
540
 
537
541
  /**
538
542
  * r" Run this macro with the given context.
@@ -560,7 +564,7 @@ export declare function __macroforgeRunDeserialize(contextJson: string): string
560
564
  * r" - The `TsStream` cannot be created from the context
561
565
  * r" - The result cannot be serialized to JSON
562
566
  */
563
- export declare function __macroforgeRunHash(contextJson: string): string
567
+ export declare function __macroforgeRunHash(contextJson: string): string;
564
568
 
565
569
  /**
566
570
  * r" Run this macro with the given context.
@@ -588,7 +592,7 @@ export declare function __macroforgeRunHash(contextJson: string): string
588
592
  * r" - The `TsStream` cannot be created from the context
589
593
  * r" - The result cannot be serialized to JSON
590
594
  */
591
- export declare function __macroforgeRunOrd(contextJson: string): string
595
+ export declare function __macroforgeRunOrd(contextJson: string): string;
592
596
 
593
597
  /**
594
598
  * r" Run this macro with the given context.
@@ -616,7 +620,7 @@ export declare function __macroforgeRunOrd(contextJson: string): string
616
620
  * r" - The `TsStream` cannot be created from the context
617
621
  * r" - The result cannot be serialized to JSON
618
622
  */
619
- export declare function __macroforgeRunPartialEq(contextJson: string): string
623
+ export declare function __macroforgeRunPartialEq(contextJson: string): string;
620
624
 
621
625
  /**
622
626
  * r" Run this macro with the given context.
@@ -644,7 +648,7 @@ export declare function __macroforgeRunPartialEq(contextJson: string): string
644
648
  * r" - The `TsStream` cannot be created from the context
645
649
  * r" - The result cannot be serialized to JSON
646
650
  */
647
- export declare function __macroforgeRunPartialOrd(contextJson: string): string
651
+ export declare function __macroforgeRunPartialOrd(contextJson: string): string;
648
652
 
649
653
  /**
650
654
  * r" Run this macro with the given context.
@@ -672,7 +676,7 @@ export declare function __macroforgeRunPartialOrd(contextJson: string): string
672
676
  * r" - The `TsStream` cannot be created from the context
673
677
  * r" - The result cannot be serialized to JSON
674
678
  */
675
- export declare function __macroforgeRunSerialize(contextJson: string): string
679
+ export declare function __macroforgeRunSerialize(contextJson: string): string;
676
680
 
677
681
  /**
678
682
  * Checks if the given TypeScript code has valid syntax.
@@ -698,7 +702,7 @@ export declare function __macroforgeRunSerialize(contextJson: string): string
698
702
  * }
699
703
  * ```
700
704
  */
701
- export declare function checkSyntax(code: string, filepath: string): SyntaxCheckResult
705
+ export declare function checkSyntax(code: string, filepath: string): SyntaxCheckResult;
702
706
 
703
707
  /**
704
708
  * Clears the configuration cache.
@@ -718,7 +722,7 @@ export declare function checkSyntax(code: string, filepath: string): SyntaxCheck
718
722
  * const result = loadConfig(configContent, configPath);
719
723
  * ```
720
724
  */
721
- export declare function clearConfigCache(): void
725
+ export declare function clearConfigCache(): void;
722
726
 
723
727
  /**
724
728
  * Entry for a registered decorator in the manifest.
@@ -727,14 +731,14 @@ export declare function clearConfigCache(): void
727
731
  * that can be used with macros.
728
732
  */
729
733
  export interface DecoratorManifestEntry {
730
- /** The module this decorator belongs to (e.g., "serde"). */
731
- module: string
732
- /** The exported name of the decorator (e.g., "skip", "rename"). */
733
- export: string
734
- /** The decorator kind: "class", "property", "method", "accessor", "parameter". */
735
- kind: string
736
- /** Documentation string for the decorator. */
737
- docs: string
734
+ /** The module this decorator belongs to (e.g., "serde"). */
735
+ module: string;
736
+ /** The exported name of the decorator (e.g., "skip", "rename"). */
737
+ export: string;
738
+ /** The decorator kind: "class", "property", "method", "accessor", "parameter". */
739
+ kind: string;
740
+ /** Documentation string for the decorator. */
741
+ docs: string;
738
742
  }
739
743
 
740
744
  /**
@@ -756,7 +760,7 @@ export interface DecoratorManifestEntry {
756
760
  * }
757
761
  * ```
758
762
  */
759
- export declare function Derive(...features: any[]): ClassDecorator
763
+ export declare function Derive(...features: any[]): ClassDecorator;
760
764
 
761
765
  /**
762
766
  * Options for macro expansion.
@@ -764,49 +768,49 @@ export declare function Derive(...features: any[]): ClassDecorator
764
768
  * Used by [`expand_sync`] to configure expansion behavior.
765
769
  */
766
770
  export interface ExpandOptions {
767
- /**
768
- * If `true`, preserves `@derive` decorators in the output.
769
- * If `false` (default), decorators are stripped after expansion.
770
- */
771
- keepDecorators?: boolean
772
- /**
773
- * Additional decorator module names from external macros.
774
- *
775
- * These are used during decorator stripping to identify Macroforge-specific
776
- * decorators that should be removed from the output. Built-in decorator modules
777
- * (like "serde", "debug") are automatically included.
778
- *
779
- * External macro packages should export their decorator module names, which
780
- * plugins can collect and pass here.
781
- *
782
- * # Example
783
- *
784
- * ```javascript
785
- * expandSync(code, filepath, {
786
- * keepDecorators: false,
787
- * externalDecoratorModules: ["myMacro", "customValidator"]
788
- * });
789
- * ```
790
- */
791
- externalDecoratorModules?: Array<string>
792
- /**
793
- * Path to a previously loaded config file.
794
- *
795
- * When provided, the expansion will use the cached configuration
796
- * (including foreign types) from this path. The config must have been
797
- * previously loaded via [`load_config`].
798
- *
799
- * # Example
800
- *
801
- * ```javascript
802
- * // First, load the config
803
- * const configResult = loadConfig(configContent, configPath);
804
- *
805
- * // Then use it during expansion
806
- * expandSync(code, filepath, { configPath });
807
- * ```
808
- */
809
- configPath?: string
771
+ /**
772
+ * If `true`, preserves `@derive` decorators in the output.
773
+ * If `false` (default), decorators are stripped after expansion.
774
+ */
775
+ keepDecorators?: boolean;
776
+ /**
777
+ * Additional decorator module names from external macros.
778
+ *
779
+ * These are used during decorator stripping to identify Macroforge-specific
780
+ * decorators that should be removed from the output. Built-in decorator modules
781
+ * (like "serde", "debug") are automatically included.
782
+ *
783
+ * External macro packages should export their decorator module names, which
784
+ * plugins can collect and pass here.
785
+ *
786
+ * # Example
787
+ *
788
+ * ```javascript
789
+ * expandSync(code, filepath, {
790
+ * keepDecorators: false,
791
+ * externalDecoratorModules: ["myMacro", "customValidator"]
792
+ * });
793
+ * ```
794
+ */
795
+ externalDecoratorModules?: Array<string>;
796
+ /**
797
+ * Path to a previously loaded config file.
798
+ *
799
+ * When provided, the expansion will use the cached configuration
800
+ * (including foreign types) from this path. The config must have been
801
+ * previously loaded via [`load_config`].
802
+ *
803
+ * # Example
804
+ *
805
+ * ```javascript
806
+ * // First, load the config
807
+ * const configResult = loadConfig(configContent, configPath);
808
+ *
809
+ * // Then use it during expansion
810
+ * expandSync(code, filepath, { configPath });
811
+ * ```
812
+ */
813
+ configPath?: string;
810
814
  }
811
815
 
812
816
  /**
@@ -836,16 +840,16 @@ export interface ExpandOptions {
836
840
  * ```
837
841
  */
838
842
  export interface ExpandResult {
839
- /** The expanded TypeScript code with all macros processed. */
840
- code: string
841
- /** Optional TypeScript type declarations for generated methods. */
842
- types?: string
843
- /** Optional JSON metadata about processed classes. */
844
- metadata?: string
845
- /** Diagnostics (errors, warnings, info) from the expansion process. */
846
- diagnostics: Array<MacroDiagnostic>
847
- /** Source mapping for position translation between original and expanded code. */
848
- sourceMapping?: SourceMappingResult
843
+ /** The expanded TypeScript code with all macros processed. */
844
+ code: string;
845
+ /** Optional TypeScript type declarations for generated methods. */
846
+ types?: string;
847
+ /** Optional JSON metadata about processed classes. */
848
+ metadata?: string;
849
+ /** Diagnostics (errors, warnings, info) from the expansion process. */
850
+ diagnostics: Array<MacroDiagnostic>;
851
+ /** Source mapping for position translation between original and expanded code. */
852
+ sourceMapping?: SourceMappingResult;
849
853
  }
850
854
 
851
855
  /**
@@ -885,7 +889,11 @@ export interface ExpandResult {
885
889
  * console.log(result.diagnostics); // Any warnings or errors
886
890
  * ```
887
891
  */
888
- export declare function expandSync(code: string, filepath: string, options?: ExpandOptions | undefined | null): ExpandResult
892
+ export declare function expandSync(
893
+ code: string,
894
+ filepath: string,
895
+ options?: ExpandOptions | undefined | null
896
+ ): ExpandResult;
889
897
 
890
898
  /**
891
899
  * A region in the expanded source that was generated by a macro.
@@ -900,12 +908,12 @@ export declare function expandSync(code: string, filepath: string, options?: Exp
900
908
  * with `source_macro = "Debug"`.
901
909
  */
902
910
  export interface GeneratedRegionResult {
903
- /** Byte offset where the generated region starts in the expanded source. */
904
- start: number
905
- /** Byte offset where the generated region ends in the expanded source. */
906
- end: number
907
- /** Name of the macro that generated this region (e.g., "Debug", "Clone"). */
908
- sourceMacro: string
911
+ /** Byte offset where the generated region starts in the expanded source. */
912
+ start: number;
913
+ /** Byte offset where the generated region ends in the expanded source. */
914
+ end: number;
915
+ /** Name of the macro that generated this region (e.g., "Debug", "Clone"). */
916
+ sourceMacro: string;
909
917
  }
910
918
 
911
919
  /**
@@ -914,10 +922,10 @@ export interface GeneratedRegionResult {
914
922
  * Used to track where decorators and macro-related imports come from.
915
923
  */
916
924
  export interface ImportSourceResult {
917
- /** Local identifier name in the import statement (e.g., `Derive` in `import { Derive }`). */
918
- local: string
919
- /** Module specifier this identifier was imported from (e.g., `"macroforge-ts"`). */
920
- module: string
925
+ /** Local identifier name in the import statement (e.g., `Derive` in `import { Derive }`). */
926
+ local: string;
927
+ /** Module specifier this identifier was imported from (e.g., `"macroforge-ts"`). */
928
+ module: string;
921
929
  }
922
930
 
923
931
  /**
@@ -927,16 +935,16 @@ export interface ImportSourceResult {
927
935
  * with language servers and IDEs.
928
936
  */
929
937
  export interface JsDiagnostic {
930
- /** Byte offset where the diagnostic starts. `None` for global diagnostics. */
931
- start?: number
932
- /** Length of the diagnostic span in bytes. */
933
- length?: number
934
- /** Human-readable diagnostic message. */
935
- message?: string
936
- /** TypeScript diagnostic code (e.g., 2304 for "Cannot find name"). */
937
- code?: number
938
- /** Diagnostic category: "error", "warning", "suggestion", "message". */
939
- category?: string
938
+ /** Byte offset where the diagnostic starts. `None` for global diagnostics. */
939
+ start?: number;
940
+ /** Length of the diagnostic span in bytes. */
941
+ length?: number;
942
+ /** Human-readable diagnostic message. */
943
+ message?: string;
944
+ /** TypeScript diagnostic code (e.g., 2304 for "Cannot find name"). */
945
+ code?: number;
946
+ /** Diagnostic category: "error", "warning", "suggestion", "message". */
947
+ category?: string;
940
948
  }
941
949
 
942
950
  /**
@@ -972,7 +980,7 @@ export interface JsDiagnostic {
972
980
  * const expanded = expandSync(code, filepath, { configPath });
973
981
  * ```
974
982
  */
975
- export declare function loadConfig(content: string, filepath: string): LoadConfigResult
983
+ export declare function loadConfig(content: string, filepath: string): LoadConfigResult;
976
984
 
977
985
  /**
978
986
  * Result of loading a macroforge configuration file.
@@ -980,14 +988,14 @@ export declare function loadConfig(content: string, filepath: string): LoadConfi
980
988
  * Returned by [`load_config`] after parsing a `macroforge.config.js/ts` file.
981
989
  */
982
990
  export interface LoadConfigResult {
983
- /** Whether to preserve `@derive` decorators in the output code. */
984
- keepDecorators: boolean
985
- /** Whether to generate a convenience const for non-class types. */
986
- generateConvenienceConst: boolean
987
- /** Whether the config has any foreign type handlers defined. */
988
- hasForeignTypes: boolean
989
- /** Number of foreign types configured. */
990
- foreignTypeCount: number
991
+ /** Whether to preserve `@derive` decorators in the output code. */
992
+ keepDecorators: boolean;
993
+ /** Whether to generate a convenience const for non-class types. */
994
+ generateConvenienceConst: boolean;
995
+ /** Whether the config has any foreign type handlers defined. */
996
+ hasForeignTypes: boolean;
997
+ /** Number of foreign types configured. */
998
+ foreignTypeCount: number;
991
999
  }
992
1000
 
993
1001
  /**
@@ -1017,23 +1025,23 @@ export interface LoadConfigResult {
1017
1025
  * ```
1018
1026
  */
1019
1027
  export interface MacroDiagnostic {
1020
- /**
1021
- * Severity level of the diagnostic.
1022
- * One of: "error", "warning", "info".
1023
- */
1024
- level: string
1025
- /** Human-readable message describing the diagnostic. */
1026
- message: string
1027
- /**
1028
- * Byte offset in the original source where the issue starts.
1029
- * `None` if the diagnostic is not associated with a specific location.
1030
- */
1031
- start?: number
1032
- /**
1033
- * Byte offset in the original source where the issue ends.
1034
- * `None` if the diagnostic is not associated with a specific location.
1035
- */
1036
- end?: number
1028
+ /**
1029
+ * Severity level of the diagnostic.
1030
+ * One of: "error", "warning", "info".
1031
+ */
1032
+ level: string;
1033
+ /** Human-readable message describing the diagnostic. */
1034
+ message: string;
1035
+ /**
1036
+ * Byte offset in the original source where the issue starts.
1037
+ * `None` if the diagnostic is not associated with a specific location.
1038
+ */
1039
+ start?: number;
1040
+ /**
1041
+ * Byte offset in the original source where the issue ends.
1042
+ * `None` if the diagnostic is not associated with a specific location.
1043
+ */
1044
+ end?: number;
1037
1045
  }
1038
1046
 
1039
1047
  /**
@@ -1045,12 +1053,12 @@ export interface MacroDiagnostic {
1045
1053
  * - Tooling integration
1046
1054
  */
1047
1055
  export interface MacroManifest {
1048
- /** ABI version for compatibility checking. */
1049
- version: number
1050
- /** All registered macros (derive, attribute, function). */
1051
- macros: Array<MacroManifestEntry>
1052
- /** All registered field/class decorators. */
1053
- decorators: Array<DecoratorManifestEntry>
1056
+ /** ABI version for compatibility checking. */
1057
+ version: number;
1058
+ /** All registered macros (derive, attribute, function). */
1059
+ macros: Array<MacroManifestEntry>;
1060
+ /** All registered field/class decorators. */
1061
+ decorators: Array<DecoratorManifestEntry>;
1054
1062
  }
1055
1063
 
1056
1064
  /**
@@ -1060,14 +1068,14 @@ export interface MacroManifest {
1060
1068
  * such as IDE extensions and documentation generators.
1061
1069
  */
1062
1070
  export interface MacroManifestEntry {
1063
- /** The macro name (e.g., "Debug", "Clone", "Serialize"). */
1064
- name: string
1065
- /** The macro kind: "derive", "attribute", or "function". */
1066
- kind: string
1067
- /** Human-readable description of what the macro does. */
1068
- description: string
1069
- /** The package that provides this macro (e.g., "macroforge-ts"). */
1070
- package: string
1071
+ /** The macro name (e.g., "Debug", "Clone", "Serialize"). */
1072
+ name: string;
1073
+ /** The macro kind: "derive", "attribute", or "function". */
1074
+ kind: string;
1075
+ /** Human-readable description of what the macro does. */
1076
+ description: string;
1077
+ /** The package that provides this macro (e.g., "macroforge-ts"). */
1078
+ package: string;
1071
1079
  }
1072
1080
 
1073
1081
  /**
@@ -1084,14 +1092,14 @@ export interface MacroManifestEntry {
1084
1092
  * - Segments are non-overlapping and sorted by position
1085
1093
  */
1086
1094
  export interface MappingSegmentResult {
1087
- /** Byte offset where this segment starts in the original source. */
1088
- originalStart: number
1089
- /** Byte offset where this segment ends in the original source. */
1090
- originalEnd: number
1091
- /** Byte offset where this segment starts in the expanded source. */
1092
- expandedStart: number
1093
- /** Byte offset where this segment ends in the expanded source. */
1094
- expandedEnd: number
1095
+ /** Byte offset where this segment starts in the original source. */
1096
+ originalStart: number;
1097
+ /** Byte offset where this segment ends in the original source. */
1098
+ originalEnd: number;
1099
+ /** Byte offset where this segment starts in the expanded source. */
1100
+ expandedStart: number;
1101
+ /** Byte offset where this segment ends in the expanded source. */
1102
+ expandedEnd: number;
1095
1103
  }
1096
1104
 
1097
1105
  /**
@@ -1125,7 +1133,10 @@ export interface MappingSegmentResult {
1125
1133
  * // ]
1126
1134
  * ```
1127
1135
  */
1128
- export declare function parseImportSources(code: string, filepath: string): Array<ImportSourceResult>
1136
+ export declare function parseImportSources(
1137
+ code: string,
1138
+ filepath: string
1139
+ ): Array<ImportSourceResult>;
1129
1140
 
1130
1141
  /**
1131
1142
  * Options for processing a file through the macro system.
@@ -1134,26 +1145,26 @@ export declare function parseImportSources(code: string, filepath: string): Arra
1134
1145
  * and caching.
1135
1146
  */
1136
1147
  export interface ProcessFileOptions {
1137
- /**
1138
- * If `true`, preserves `@derive` decorators in the output.
1139
- * If `false` (default), decorators are stripped after expansion.
1140
- */
1141
- keepDecorators?: boolean
1142
- /**
1143
- * Version string for cache invalidation.
1144
- * When provided, cached results are only reused if versions match.
1145
- */
1146
- version?: string
1147
- /**
1148
- * Additional decorator module names from external macros.
1149
- * See [`ExpandOptions::external_decorator_modules`] for details.
1150
- */
1151
- externalDecoratorModules?: Array<string>
1152
- /**
1153
- * Path to a previously loaded config file (for foreign types lookup).
1154
- * See [`ExpandOptions::config_path`] for details.
1155
- */
1156
- configPath?: string
1148
+ /**
1149
+ * If `true`, preserves `@derive` decorators in the output.
1150
+ * If `false` (default), decorators are stripped after expansion.
1151
+ */
1152
+ keepDecorators?: boolean;
1153
+ /**
1154
+ * Version string for cache invalidation.
1155
+ * When provided, cached results are only reused if versions match.
1156
+ */
1157
+ version?: string;
1158
+ /**
1159
+ * Additional decorator module names from external macros.
1160
+ * See [`ExpandOptions::external_decorator_modules`] for details.
1161
+ */
1162
+ externalDecoratorModules?: Array<string>;
1163
+ /**
1164
+ * Path to a previously loaded config file (for foreign types lookup).
1165
+ * See [`ExpandOptions::config_path`] for details.
1166
+ */
1167
+ configPath?: string;
1157
1168
  }
1158
1169
 
1159
1170
  /**
@@ -1170,16 +1181,16 @@ export interface ProcessFileOptions {
1170
1181
  * - Mapping IDE diagnostics from expanded code back to original source
1171
1182
  */
1172
1183
  export interface SourceMappingResult {
1173
- /**
1174
- * Segments mapping preserved regions between original and expanded source.
1175
- * Sorted by position for efficient binary search lookups.
1176
- */
1177
- segments: Array<MappingSegmentResult>
1178
- /**
1179
- * Regions in the expanded source that were generated by macros.
1180
- * Used to identify synthetic code with no original source location.
1181
- */
1182
- generatedRegions: Array<GeneratedRegionResult>
1184
+ /**
1185
+ * Segments mapping preserved regions between original and expanded source.
1186
+ * Sorted by position for efficient binary search lookups.
1187
+ */
1188
+ segments: Array<MappingSegmentResult>;
1189
+ /**
1190
+ * Regions in the expanded source that were generated by macros.
1191
+ * Used to identify synthetic code with no original source location.
1192
+ */
1193
+ generatedRegions: Array<GeneratedRegionResult>;
1183
1194
  }
1184
1195
 
1185
1196
  /**
@@ -1188,10 +1199,10 @@ export interface SourceMappingResult {
1188
1199
  * Used for mapping diagnostics and other positional information.
1189
1200
  */
1190
1201
  export interface SpanResult {
1191
- /** Byte offset where the span starts. */
1192
- start: number
1193
- /** Length of the span in bytes. */
1194
- length: number
1202
+ /** Byte offset where the span starts. */
1203
+ start: number;
1204
+ /** Length of the span in bytes. */
1205
+ length: number;
1195
1206
  }
1196
1207
 
1197
1208
  /**
@@ -1200,10 +1211,10 @@ export interface SpanResult {
1200
1211
  * Returned by [`check_syntax`] to indicate whether code parses successfully.
1201
1212
  */
1202
1213
  export interface SyntaxCheckResult {
1203
- /** `true` if the code parsed without errors, `false` otherwise. */
1204
- ok: boolean
1205
- /** Error message if parsing failed, `None` if successful. */
1206
- error?: string
1214
+ /** `true` if the code parsed without errors, `false` otherwise. */
1215
+ ok: boolean;
1216
+ /** Error message if parsing failed, `None` if successful. */
1217
+ error?: string;
1207
1218
  }
1208
1219
 
1209
1220
  /**
@@ -1220,23 +1231,23 @@ export interface SyntaxCheckResult {
1220
1231
  * * `metadata` - Optional JSON metadata about processed classes
1221
1232
  */
1222
1233
  export interface TransformResult {
1223
- /** The transformed TypeScript/JavaScript code with all macros expanded. */
1224
- code: string
1225
- /**
1226
- * Source map for mapping transformed positions back to original.
1227
- * Currently always `None` - source mapping is handled separately via `SourceMappingResult`.
1228
- */
1229
- map?: string
1230
- /**
1231
- * TypeScript type declarations (`.d.ts` content) for generated methods.
1232
- * Used by IDEs to provide type information for macro-generated code.
1233
- */
1234
- types?: string
1235
- /**
1236
- * JSON-serialized metadata about processed classes.
1237
- * Contains information about which classes were processed and what was generated.
1238
- */
1239
- metadata?: string
1234
+ /** The transformed TypeScript/JavaScript code with all macros expanded. */
1235
+ code: string;
1236
+ /**
1237
+ * Source map for mapping transformed positions back to original.
1238
+ * Currently always `None` - source mapping is handled separately via `SourceMappingResult`.
1239
+ */
1240
+ map?: string;
1241
+ /**
1242
+ * TypeScript type declarations (`.d.ts` content) for generated methods.
1243
+ * Used by IDEs to provide type information for macro-generated code.
1244
+ */
1245
+ types?: string;
1246
+ /**
1247
+ * JSON-serialized metadata about processed classes.
1248
+ * Contains information about which classes were processed and what was generated.
1249
+ */
1250
+ metadata?: string;
1240
1251
  }
1241
1252
 
1242
1253
  /**
@@ -1266,4 +1277,4 @@ export interface TransformResult {
1266
1277
  *
1267
1278
  * Uses a 32MB thread stack to prevent stack overflow during deep AST recursion.
1268
1279
  */
1269
- export declare function transformSync(code: string, filepath: string): TransformResult
1280
+ export declare function transformSync(code: string, filepath: string): TransformResult;