@macroforge/mcp-server 0.1.39 → 0.1.42

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.
@@ -1,53 +1,53 @@
1
1
  # API Reference
2
- <span class="stats svelte-1c8t0id">52 exported items *Macroforge provides a programmatic API for expanding macros in TypeScript code.*
2
+ <span class="stats svelte-1c8t0id">55 exported items *Macroforge provides a programmatic API for expanding macros in TypeScript code.*
3
3
  ## Overview
4
4
  ```
5
- import &#123;
6
- expandSync,
7
- transformSync,
8
- checkSyntax,
9
- parseImportSources,
10
- NativePlugin,
11
- PositionMapper
12
- &#125; from "macroforge";
5
+ import&nbsp;&#123;
6
+ &nbsp;&nbsp;expandSync,
7
+ &nbsp;&nbsp;transformSync,
8
+ &nbsp;&nbsp;checkSyntax,
9
+ &nbsp;&nbsp;parseImportSources,
10
+ &nbsp;&nbsp;NativePlugin,
11
+ &nbsp;&nbsp;PositionMapper
12
+ &#125;&nbsp;from&nbsp;"macroforge";
13
13
  ``` ## Core Functions
14
14
  | Function | Description |
15
15
  | --- | --- |
16
- | [`expandSync()`](../docs/api/expand-sync) | Expand macros synchronously |
17
- | [`transformSync()`](../docs/api/transform-sync) | Transform code with additional metadata |
18
- | `checkSyntax()` | Validate TypeScript syntax |
19
- | `parseImportSources()` | Extract import information |
16
+ | [expandSync()](../docs/api/expand-sync) | Expand macros synchronously |
17
+ | [transformSync()](../docs/api/transform-sync) | Transform code with additional metadata |
18
+ | checkSyntax() | Validate TypeScript syntax |
19
+ | parseImportSources() | Extract import information |
20
20
  ## Classes
21
21
  | Class | Description |
22
22
  | --- | --- |
23
- | [`NativePlugin`](../docs/api/native-plugin) | Stateful plugin with caching |
24
- | [`PositionMapper`](../docs/api/position-mapper) | Maps positions between original and expanded code |
23
+ | [NativePlugin](../docs/api/native-plugin) | Stateful plugin with caching |
24
+ | [PositionMapper](../docs/api/position-mapper) | Maps positions between original and expanded code |
25
25
  ## Quick Example
26
26
  ```
27
- import &#123; expandSync &#125; from "macroforge";
27
+ import&nbsp;&#123;&nbsp;expandSync&nbsp;&#125;&nbsp;from&nbsp;"macroforge";
28
28
 
29
- const sourceCode = \`
30
- /** @derive(Debug) */
31
- class User &#123;
32
- name: string;
33
- constructor(name: string) &#123;
34
- this.name = name;
35
- &#125;
29
+ const&nbsp;sourceCode&nbsp;=&nbsp;\`
30
+ /**&nbsp;@derive(Debug)&nbsp;*/
31
+ class&nbsp;User&nbsp;&#123;
32
+ &nbsp;&nbsp;name:&nbsp;string;
33
+ &nbsp;&nbsp;constructor(name:&nbsp;string)&nbsp;&#123;
34
+ &nbsp;&nbsp;&nbsp;&nbsp;this.name&nbsp;=&nbsp;name;
35
+ &nbsp;&nbsp;&#125;
36
36
  &#125;
37
37
  \`;
38
38
 
39
- const result = expandSync(sourceCode, "user.ts", &#123;
40
- keepDecorators: false
39
+ const&nbsp;result&nbsp;=&nbsp;expandSync(sourceCode,&nbsp;"user.ts",&nbsp;&#123;
40
+ &nbsp;&nbsp;keepDecorators:&nbsp;false
41
41
  &#125;);
42
42
 
43
43
  console.log(result.code);
44
- // Output: class with toString() method generated
44
+ //&nbsp;Output:&nbsp;class&nbsp;with&nbsp;toString()&nbsp;method&nbsp;generated
45
45
 
46
- if (result.diagnostics.length > 0) &#123;
47
- console.error("Errors:", result.diagnostics);
46
+ if&nbsp;(result.diagnostics.length&nbsp;>&nbsp;0)&nbsp;&#123;
47
+ &nbsp;&nbsp;console.error("Errors:",&nbsp;result.diagnostics);
48
48
  &#125;
49
49
  ``` ## Detailed Reference
50
- - [`expandSync()`](../docs/api/expand-sync) - Full options and return types
51
- - [`transformSync()`](../docs/api/transform-sync) - Transform with source maps
52
- - [`NativePlugin`](../docs/api/native-plugin) - Caching for language servers
53
- - [`PositionMapper`](../docs/api/position-mapper) - Position mapping utilities
50
+ - [<code class="shiki-inline"><span class="line"><span style="--shiki-dark:#B392F0;--shiki-light:#6F42C1">expandSync<span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">()</code>](../docs/api/expand-sync) - Full options and return types
51
+ - [<code class="shiki-inline"><span class="line"><span style="--shiki-dark:#B392F0;--shiki-light:#6F42C1">transformSync<span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">()</code>](../docs/api/transform-sync) - Transform with source maps
52
+ - [<code class="shiki-inline"><span class="line"><span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">NativePlugin</code>](../docs/api/native-plugin) - Caching for language servers
53
+ - [<code class="shiki-inline"><span class="line"><span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">PositionMapper</code>](../docs/api/position-mapper) - Position mapping utilities
@@ -2,50 +2,50 @@
2
2
  *Synchronously expands macros in TypeScript code. This is the standalone macro expansion function that doesn't use caching. For cached expansion, use [`NativePlugin::process_file`] instead.*
3
3
  ## Signature
4
4
  ```
5
- function expandSync(
6
- code: string,
7
- filepath: string,
8
- options?: ExpandOptions
9
- ): ExpandResult
5
+ function&nbsp;expandSync(
6
+ &nbsp;&nbsp;code:&nbsp;string,
7
+ &nbsp;&nbsp;filepath:&nbsp;string,
8
+ &nbsp;&nbsp;options?:&nbsp;ExpandOptions
9
+ ):&nbsp;ExpandResult
10
10
  ``` ## Parameters
11
11
  | Parameter | Type | Description |
12
12
  | --- | --- | --- |
13
- | `code` | `string` | TypeScript source code to transform |
14
- | `filepath` | `string` | File path (used for error reporting) |
15
- | `options` | `ExpandOptions` | Optional configuration |
13
+ | code | string | TypeScript source code to transform |
14
+ | filepath | string | File path (used for error reporting) |
15
+ | options | ExpandOptions | Optional configuration |
16
16
  ## ExpandOptions
17
17
  ```
18
- interface ExpandOptions &#123;
19
- // Keep @derive decorators in output (default: false)
20
- keepDecorators?: boolean;
18
+ interface&nbsp;ExpandOptions&nbsp;&#123;
19
+ &nbsp;&nbsp;//&nbsp;Keep&nbsp;@derive&nbsp;decorators&nbsp;in&nbsp;output&nbsp;(default:&nbsp;false)
20
+ &nbsp;&nbsp;keepDecorators?:&nbsp;boolean;
21
21
  &#125;
22
22
  ``` ## ExpandResult
23
23
  ```
24
- interface ExpandResult &#123;
25
- // Transformed TypeScript code
26
- code: string;
24
+ interface&nbsp;ExpandResult&nbsp;&#123;
25
+ &nbsp;&nbsp;//&nbsp;Transformed&nbsp;TypeScript&nbsp;code
26
+ &nbsp;&nbsp;code:&nbsp;string;
27
27
 
28
- // Generated type declarations (.d.ts content)
29
- types?: string;
28
+ &nbsp;&nbsp;//&nbsp;Generated&nbsp;type&nbsp;declarations&nbsp;(.d.ts&nbsp;content)
29
+ &nbsp;&nbsp;types?:&nbsp;string;
30
30
 
31
- // Macro expansion metadata (JSON string)
32
- metadata?: string;
31
+ &nbsp;&nbsp;//&nbsp;Macro&nbsp;expansion&nbsp;metadata&nbsp;(JSON&nbsp;string)
32
+ &nbsp;&nbsp;metadata?:&nbsp;string;
33
33
 
34
- // Warnings and errors from macro expansion
35
- diagnostics: MacroDiagnostic[];
34
+ &nbsp;&nbsp;//&nbsp;Warnings&nbsp;and&nbsp;errors&nbsp;from&nbsp;macro&nbsp;expansion
35
+ &nbsp;&nbsp;diagnostics:&nbsp;MacroDiagnostic[];
36
36
 
37
- // Position mapping data for source maps
38
- sourceMapping?: SourceMappingResult;
37
+ &nbsp;&nbsp;//&nbsp;Position&nbsp;mapping&nbsp;data&nbsp;for&nbsp;source&nbsp;maps
38
+ &nbsp;&nbsp;sourceMapping?:&nbsp;SourceMappingResult;
39
39
  &#125;
40
40
  ``` ## MacroDiagnostic
41
41
  ```
42
- interface MacroDiagnostic &#123;
43
- message: string;
44
- severity: "error" | "warning" | "info";
45
- span: &#123;
46
- start: number;
47
- end: number;
48
- &#125;;
42
+ interface&nbsp;MacroDiagnostic&nbsp;&#123;
43
+ &nbsp;&nbsp;message:&nbsp;string;
44
+ &nbsp;&nbsp;severity:&nbsp;"error"&nbsp;|&nbsp;"warning"&nbsp;|&nbsp;"info";
45
+ &nbsp;&nbsp;span:&nbsp;&#123;
46
+ &nbsp;&nbsp;&nbsp;&nbsp;start:&nbsp;number;
47
+ &nbsp;&nbsp;&nbsp;&nbsp;end:&nbsp;number;
48
+ &nbsp;&nbsp;&#125;;
49
49
  &#125;
50
50
  ``` ## Example
51
51
  ```
@@ -80,7 +80,7 @@ if (result.diagnostics.length > 0) {
80
80
  }
81
81
  }
82
82
  ``` ## Error Handling
83
- Syntax errors and macro errors are returned in the `diagnostics` array, not thrown as exceptions:
83
+ Syntax errors and macro errors are returned in the <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">diagnostics</code> array, not thrown as exceptions:
84
84
  ```
85
85
  const result = expandSync(invalidCode, "file.ts");
86
86
 
@@ -2,73 +2,73 @@
2
2
  *The main plugin class for macro expansion with caching support. `NativePlugin` is designed to be instantiated once and reused across multiple file processing operations. It maintains a cache of expansion results keyed by filepath and version, enabling efficient incremental processing.*
3
3
  ## Constructor
4
4
  ```
5
- const plugin = new NativePlugin();
5
+ const&nbsp;plugin&nbsp;=&nbsp;new&nbsp;NativePlugin();
6
6
  ``` ## Methods
7
7
  ### processFile()
8
8
  Process a file with version-based caching:
9
9
  ```
10
10
  processFile(
11
- filepath: string,
12
- code: string,
13
- options?: ProcessFileOptions
14
- ): ExpandResult
11
+ &nbsp;&nbsp;filepath:&nbsp;string,
12
+ &nbsp;&nbsp;code:&nbsp;string,
13
+ &nbsp;&nbsp;options?:&nbsp;ProcessFileOptions
14
+ ):&nbsp;ExpandResult
15
15
  ``` ```
16
- interface ProcessFileOptions &#123;
17
- // Cache key - if unchanged, returns cached result
18
- version?: string;
16
+ interface&nbsp;ProcessFileOptions&nbsp;&#123;
17
+ &nbsp;&nbsp;//&nbsp;Cache&nbsp;key&nbsp;-&nbsp;if&nbsp;unchanged,&nbsp;returns&nbsp;cached&nbsp;result
18
+ &nbsp;&nbsp;version?:&nbsp;string;
19
19
  &#125;
20
20
  ``` ### getMapper()
21
21
  Get the position mapper for a previously processed file:
22
22
  ```
23
- getMapper(filepath: string): NativeMapper | null
23
+ getMapper(filepath:&nbsp;string):&nbsp;NativeMapper&nbsp;|&nbsp;null
24
24
  ``` ### mapDiagnostics()
25
25
  Map diagnostics from expanded positions to original positions:
26
26
  ```
27
27
  mapDiagnostics(
28
- filepath: string,
29
- diagnostics: JsDiagnostic[]
30
- ): JsDiagnostic[]
28
+ &nbsp;&nbsp;filepath:&nbsp;string,
29
+ &nbsp;&nbsp;diagnostics:&nbsp;JsDiagnostic[]
30
+ ):&nbsp;JsDiagnostic[]
31
31
  ``` ### log() / setLogFile()
32
32
  Logging utilities for debugging:
33
33
  ```
34
- log(message: string): void
35
- setLogFile(path: string): void
34
+ log(message:&nbsp;string):&nbsp;void
35
+ setLogFile(path:&nbsp;string):&nbsp;void
36
36
  ``` ## Caching Behavior
37
37
  The plugin caches expansion results by file path and version:
38
38
  ```
39
- const plugin = new NativePlugin();
39
+ const&nbsp;plugin&nbsp;=&nbsp;new&nbsp;NativePlugin();
40
40
 
41
- // First call - performs expansion
42
- const result1 = plugin.processFile("user.ts", code, &#123; version: "1" &#125;);
41
+ //&nbsp;First&nbsp;call&nbsp;-&nbsp;performs&nbsp;expansion
42
+ const&nbsp;result1&nbsp;=&nbsp;plugin.processFile("user.ts",&nbsp;code,&nbsp;&#123;&nbsp;version:&nbsp;"1"&nbsp;&#125;);
43
43
 
44
- // Same version - returns cached result instantly
45
- const result2 = plugin.processFile("user.ts", code, &#123; version: "1" &#125;);
44
+ //&nbsp;Same&nbsp;version&nbsp;-&nbsp;returns&nbsp;cached&nbsp;result&nbsp;instantly
45
+ const&nbsp;result2&nbsp;=&nbsp;plugin.processFile("user.ts",&nbsp;code,&nbsp;&#123;&nbsp;version:&nbsp;"1"&nbsp;&#125;);
46
46
 
47
- // Different version - re-expands
48
- const result3 = plugin.processFile("user.ts", newCode, &#123; version: "2" &#125;);
47
+ //&nbsp;Different&nbsp;version&nbsp;-&nbsp;re-expands
48
+ const&nbsp;result3&nbsp;=&nbsp;plugin.processFile("user.ts",&nbsp;newCode,&nbsp;&#123;&nbsp;version:&nbsp;"2"&nbsp;&#125;);
49
49
  ``` ## Example: Language Server Integration
50
50
  ```
51
- import &#123; NativePlugin &#125; from "macroforge";
51
+ import&nbsp;&#123;&nbsp;NativePlugin&nbsp;&#125;&nbsp;from&nbsp;"macroforge";
52
52
 
53
- class MacroforgeLanguageService &#123;
54
- private plugin = new NativePlugin();
53
+ class&nbsp;MacroforgeLanguageService&nbsp;&#123;
54
+ &nbsp;&nbsp;private&nbsp;plugin&nbsp;=&nbsp;new&nbsp;NativePlugin();
55
55
 
56
- processDocument(uri: string, content: string, version: number) &#123;
57
- // Process with version-based caching
58
- const result = this.plugin.processFile(uri, content, &#123;
59
- version: String(version)
60
- &#125;);
56
+ &nbsp;&nbsp;processDocument(uri:&nbsp;string,&nbsp;content:&nbsp;string,&nbsp;version:&nbsp;number)&nbsp;&#123;
57
+ &nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Process&nbsp;with&nbsp;version-based&nbsp;caching
58
+ &nbsp;&nbsp;&nbsp;&nbsp;const&nbsp;result&nbsp;=&nbsp;this.plugin.processFile(uri,&nbsp;content,&nbsp;&#123;
59
+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;version:&nbsp;String(version)
60
+ &nbsp;&nbsp;&nbsp;&nbsp;&#125;);
61
61
 
62
- // Get mapper for position translation
63
- const mapper = this.plugin.getMapper(uri);
62
+ &nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Get&nbsp;mapper&nbsp;for&nbsp;position&nbsp;translation
63
+ &nbsp;&nbsp;&nbsp;&nbsp;const&nbsp;mapper&nbsp;=&nbsp;this.plugin.getMapper(uri);
64
64
 
65
- return &#123; result, mapper &#125;;
66
- &#125;
65
+ &nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;&#123;&nbsp;result,&nbsp;mapper&nbsp;&#125;;
66
+ &nbsp;&nbsp;&#125;
67
67
 
68
- getSemanticDiagnostics(uri: string, diagnostics: Diagnostic[]) &#123;
69
- // Map positions from expanded to original
70
- return this.plugin.mapDiagnostics(uri, diagnostics);
71
- &#125;
68
+ &nbsp;&nbsp;getSemanticDiagnostics(uri:&nbsp;string,&nbsp;diagnostics:&nbsp;Diagnostic[])&nbsp;&#123;
69
+ &nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Map&nbsp;positions&nbsp;from&nbsp;expanded&nbsp;to&nbsp;original
70
+ &nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;this.plugin.mapDiagnostics(uri,&nbsp;diagnostics);
71
+ &nbsp;&nbsp;&#125;
72
72
  &#125;
73
73
  ``` ## Thread Safety
74
- The `NativePlugin` class is thread-safe and can be used from multiple async contexts. Each file is processed in an isolated thread with its own stack space.
74
+ The <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">NativePlugin</code> class is thread-safe and can be used from multiple async contexts. Each file is processed in an isolated thread with its own stack space.
@@ -2,51 +2,51 @@
2
2
  *Bidirectional position mapper for translating between original and expanded source positions. This mapper enables IDE features like error reporting, go-to-definition, and hover to work correctly with macro-expanded code by translating positions between the original source (what the user wrote) and the expanded source (what the compiler sees).*
3
3
  ## Getting a Mapper
4
4
  ```
5
- import &#123; NativePlugin, PositionMapper &#125; from "macroforge";
5
+ import&nbsp;&#123;&nbsp;NativePlugin,&nbsp;PositionMapper&nbsp;&#125;&nbsp;from&nbsp;"macroforge";
6
6
 
7
- const plugin = new NativePlugin();
8
- const result = plugin.processFile("user.ts", code, &#123; version: "1" &#125;);
7
+ const&nbsp;plugin&nbsp;=&nbsp;new&nbsp;NativePlugin();
8
+ const&nbsp;result&nbsp;=&nbsp;plugin.processFile("user.ts",&nbsp;code,&nbsp;&#123;&nbsp;version:&nbsp;"1"&nbsp;&#125;);
9
9
 
10
- // Get the mapper for this file
11
- const mapper = plugin.getMapper("user.ts");
12
- if (mapper) &#123;
13
- // Use the mapper...
10
+ //&nbsp;Get&nbsp;the&nbsp;mapper&nbsp;for&nbsp;this&nbsp;file
11
+ const&nbsp;mapper&nbsp;=&nbsp;plugin.getMapper("user.ts");
12
+ if&nbsp;(mapper)&nbsp;&#123;
13
+ &nbsp;&nbsp;//&nbsp;Use&nbsp;the&nbsp;mapper...
14
14
  &#125;
15
15
  ``` ## Methods
16
16
  ### isEmpty()
17
17
  Check if the mapper has any mappings:
18
18
  ```
19
- isEmpty(): boolean
19
+ isEmpty():&nbsp;boolean
20
20
  ``` ### originalToExpanded()
21
21
  Map a position from original to expanded code:
22
22
  ```
23
- originalToExpanded(pos: number): number
23
+ originalToExpanded(pos:&nbsp;number):&nbsp;number
24
24
  ``` ### expandedToOriginal()
25
25
  Map a position from expanded to original code:
26
26
  ```
27
- expandedToOriginal(pos: number): number | null
28
- ``` Returns `null` if the position is in generated code.
27
+ expandedToOriginal(pos:&nbsp;number):&nbsp;number&nbsp;|&nbsp;null
28
+ ``` Returns <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#79B8FF;--shiki-light:#005CC5">null</code> if the position is in generated code.
29
29
  ### isInGenerated()
30
30
  Check if a position is in macro-generated code:
31
31
  ```
32
- isInGenerated(pos: number): boolean
32
+ isInGenerated(pos:&nbsp;number):&nbsp;boolean
33
33
  ``` ### generatedBy()
34
34
  Get the name of the macro that generated code at a position:
35
35
  ```
36
- generatedBy(pos: number): string | null
36
+ generatedBy(pos:&nbsp;number):&nbsp;string&nbsp;|&nbsp;null
37
37
  ``` ### mapSpanToOriginal()
38
38
  Map a span (range) from expanded to original code:
39
39
  ```
40
- mapSpanToOriginal(start: number, length: number): SpanResult | null
40
+ mapSpanToOriginal(start:&nbsp;number,&nbsp;length:&nbsp;number):&nbsp;SpanResult&nbsp;|&nbsp;null
41
41
 
42
- interface SpanResult &#123;
43
- start: number;
44
- length: number;
42
+ interface&nbsp;SpanResult&nbsp;&#123;
43
+ &nbsp;&nbsp;start:&nbsp;number;
44
+ &nbsp;&nbsp;length:&nbsp;number;
45
45
  &#125;
46
46
  ``` ### mapSpanToExpanded()
47
47
  Map a span from original to expanded code:
48
48
  ```
49
- mapSpanToExpanded(start: number, length: number): SpanResult
49
+ mapSpanToExpanded(start:&nbsp;number,&nbsp;length:&nbsp;number):&nbsp;SpanResult
50
50
  ``` ## Example: Error Position Mapping
51
51
  ```
52
52
  import { NativePlugin } from "macroforge";
@@ -2,32 +2,32 @@
2
2
  *Synchronously transforms TypeScript code through the macro expansion system. This is similar to [`expand_sync`] but returns a [`TransformResult`] which includes source map information (when available).*
3
3
  ## Signature
4
4
  ```
5
- function transformSync(
6
- code: string,
7
- filepath: string
8
- ): TransformResult
5
+ function&nbsp;transformSync(
6
+ &nbsp;&nbsp;code:&nbsp;string,
7
+ &nbsp;&nbsp;filepath:&nbsp;string
8
+ ):&nbsp;TransformResult
9
9
  ``` ## Parameters
10
10
  | Parameter | Type | Description |
11
11
  | --- | --- | --- |
12
- | `code` | `string` | TypeScript source code to transform |
13
- | `filepath` | `string` | File path (used for error reporting) |
12
+ | code | string | TypeScript source code to transform |
13
+ | filepath | string | File path (used for error reporting) |
14
14
  ## TransformResult
15
15
  ```
16
- interface TransformResult &#123;
17
- // Transformed TypeScript code
18
- code: string;
16
+ interface&nbsp;TransformResult&nbsp;&#123;
17
+ &nbsp;&nbsp;//&nbsp;Transformed&nbsp;TypeScript&nbsp;code
18
+ &nbsp;&nbsp;code:&nbsp;string;
19
19
 
20
- // Source map (JSON string, not yet implemented)
21
- map?: string;
20
+ &nbsp;&nbsp;//&nbsp;Source&nbsp;map&nbsp;(JSON&nbsp;string,&nbsp;not&nbsp;yet&nbsp;implemented)
21
+ &nbsp;&nbsp;map?:&nbsp;string;
22
22
 
23
- // Generated type declarations
24
- types?: string;
23
+ &nbsp;&nbsp;//&nbsp;Generated&nbsp;type&nbsp;declarations
24
+ &nbsp;&nbsp;types?:&nbsp;string;
25
25
 
26
- // Macro expansion metadata
27
- metadata?: string;
26
+ &nbsp;&nbsp;//&nbsp;Macro&nbsp;expansion&nbsp;metadata
27
+ &nbsp;&nbsp;metadata?:&nbsp;string;
28
28
  &#125;
29
29
  ``` ## Comparison with expandSync()
30
- | Feature | `expandSync` | `transformSync` |
30
+ | Feature | expandSync | transformSync |
31
31
  | --- | --- | --- |
32
32
  | Options | Yes | No |
33
33
  | Diagnostics | Yes | No |
@@ -35,32 +35,32 @@ interface TransformResult &#123;
35
35
  | Use Case | General purpose | Build tools |
36
36
  ## Example
37
37
  ```
38
- import &#123; transformSync &#125; from "macroforge";
38
+ import&nbsp;&#123;&nbsp;transformSync&nbsp;&#125;&nbsp;from&nbsp;"macroforge";
39
39
 
40
- const sourceCode = \`
41
- /** @derive(Debug) */
42
- class User &#123;
43
- name: string;
40
+ const&nbsp;sourceCode&nbsp;=&nbsp;\`
41
+ /**&nbsp;@derive(Debug)&nbsp;*/
42
+ class&nbsp;User&nbsp;&#123;
43
+ &nbsp;&nbsp;name:&nbsp;string;
44
44
  &#125;
45
45
  \`;
46
46
 
47
- const result = transformSync(sourceCode, "user.ts");
47
+ const&nbsp;result&nbsp;=&nbsp;transformSync(sourceCode,&nbsp;"user.ts");
48
48
 
49
49
  console.log(result.code);
50
50
 
51
- if (result.types) &#123;
52
- // Write to .d.ts file
53
- fs.writeFileSync("user.d.ts", result.types);
51
+ if&nbsp;(result.types)&nbsp;&#123;
52
+ &nbsp;&nbsp;//&nbsp;Write&nbsp;to&nbsp;.d.ts&nbsp;file
53
+ &nbsp;&nbsp;fs.writeFileSync("user.d.ts",&nbsp;result.types);
54
54
  &#125;
55
55
 
56
- if (result.metadata) &#123;
57
- // Parse and use metadata
58
- const meta = JSON.parse(result.metadata);
59
- console.log("Macros expanded:", meta);
56
+ if&nbsp;(result.metadata)&nbsp;&#123;
57
+ &nbsp;&nbsp;//&nbsp;Parse&nbsp;and&nbsp;use&nbsp;metadata
58
+ &nbsp;&nbsp;const&nbsp;meta&nbsp;=&nbsp;JSON.parse(result.metadata);
59
+ &nbsp;&nbsp;console.log("Macros&nbsp;expanded:",&nbsp;meta);
60
60
  &#125;
61
61
  ``` ## When to Use
62
- Use `transformSync` when:
62
+ Use <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">transformSync</code> when:
63
63
  - Building custom integrations
64
64
  - You need raw output without diagnostics
65
65
  - You're implementing a build tool plugin
66
- Use `expandSync` for most other use cases, as it provides better error handling.
66
+ Use <code class="shiki-inline"><span class="line"><span style="--shiki-dark:#E1E4E8;--shiki-light:#24292E">expandSync</code> for most other use cases, as it provides better error handling.
@@ -120,9 +120,9 @@ export function statusDefaultValue(): Status {
120
120
  return Status.Pending;
121
121
  }
122
122
 
123
- export const Status = {
124
- defaultValue: statusDefaultValue
125
- } as const;
123
+ namespace Status {
124
+ export const defaultValue = statusDefaultValue;
125
+ }
126
126
  ```
127
127
 
128
128
  Generated output:
@@ -139,9 +139,9 @@ export function statusDefaultValue(): Status {
139
139
  return Status.Pending;
140
140
  }
141
141
 
142
- export const Status = {
143
- defaultValue: statusDefaultValue
144
- } as const;
142
+ namespace Status {
143
+ export const defaultValue = statusDefaultValue;
144
+ }
145
145
  ```
146
146
 
147
147
  ## Error Handling