@macroforge/mcp-server 0.1.30 → 0.1.31
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.
- package/docs/custom-macros/ts-quote/comments-and.md +7 -28
- package/docs/custom-macros/ts-quote/complete-example-json-derive-macro.md +20 -16
- package/docs/custom-macros/ts-quote/interpolation-expr.md +349 -0
- package/docs/custom-macros/ts-quote/local-constants-let.md +34 -0
- package/docs/custom-macros/ts-quote/overview.md +8 -6
- package/docs/custom-macros/ts-quote/quick-reference.md +128 -80
- package/docs/custom-macros/ts-quote/side-effects-do.md +67 -3
- package/docs/custom-macros/ts-quote/tsstream-injection-typescript.md +1 -1
- package/docs/custom-macros/ts-quote/while-loops-while.md +0 -33
- package/docs/custom-macros/ts-quote.md +199 -102
- package/docs/sections.json +14 -74
- package/package.json +4 -2
|
@@ -1,83 +1,131 @@
|
|
|
1
1
|
## Quick Reference
|
|
2
2
|
|
|
3
3
|
| `@{expr}`
|
|
4
|
-
| Interpolate a Rust expression (adds space after)
|
|
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
|
-
|
|
4
|
+
| Interpolate a Rust expression (adds space after)
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
| `{| content |}`
|
|
9
|
+
| Ident block: concatenates without spaces (e.g., <code
|
|
10
|
+
>{|get@{name}|}</code
|
|
11
|
+
>
|
|
12
|
+
→ `getUser`)</td
|
|
13
|
+
>
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
<td>`{> "comment" <}`
|
|
18
|
+
| Block comment: outputs `/* comment */` (string preserves
|
|
19
|
+
whitespace)</td
|
|
20
|
+
>
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
<td>`{>> "doc" <<}`
|
|
25
|
+
| Doc comment: outputs `/** doc */` (string preserves whitespace)</td
|
|
26
|
+
>
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
<td>`@@{`
|
|
31
|
+
| Escape for literal `@{` (e.g.,
|
|
32
|
+
`"@@{foo}"`
|
|
33
|
+
→ `@{foo}`)</td
|
|
34
|
+
>
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
<td>`"text @{expr}"`
|
|
39
|
+
| String interpolation (auto-detected)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
| `"'^template ${js}^'"`
|
|
44
|
+
| JS backtick template literal (outputs <code
|
|
45
|
+
>`template ${js}`</code
|
|
46
|
+
>)</td
|
|
47
|
+
>
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
<td>`{#if cond}...{/if}`
|
|
52
|
+
| Conditional block
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
| <code
|
|
57
|
+
>{#if cond}...{:else}...{/if}</code
|
|
58
|
+
></td
|
|
59
|
+
>
|
|
60
|
+
<td>Conditional with else
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
| <code
|
|
65
|
+
>{#if a}...{:else if
|
|
66
|
+
b}...{:else}...{/if}</code
|
|
67
|
+
></td
|
|
68
|
+
>
|
|
69
|
+
<td>Full if/else-if/else chain
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
| <code
|
|
74
|
+
>{#if let pattern = expr}...{/if}</code
|
|
75
|
+
></td
|
|
76
|
+
>
|
|
77
|
+
<td>Pattern matching if-let
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
| <code
|
|
82
|
+
>{#match expr}{:case
|
|
83
|
+
pattern}...{/match}</code
|
|
84
|
+
></td
|
|
85
|
+
>
|
|
86
|
+
<td>Match expression with case arms
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
| <code>{#for item in list}...{/for}</code
|
|
91
|
+
></td
|
|
92
|
+
>
|
|
93
|
+
<td>Iterate over a collection
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
| `{#while cond}...{/while}`
|
|
98
|
+
| While loop
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
| <code
|
|
103
|
+
>{#while let pattern = expr}...{/while}</code
|
|
104
|
+
></td
|
|
105
|
+
>
|
|
106
|
+
<td>While-let pattern matching loop
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
| `{$let name = expr}`
|
|
111
|
+
| Define a local constant
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
| `{$let mut name = expr}`
|
|
116
|
+
| Define a mutable local variable
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
| `{$do expr}`
|
|
121
|
+
| Execute a side-effectful expression
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
| `{$typescript stream}`
|
|
126
|
+
<td
|
|
127
|
+
>Inject a TsStream, preserving its source and runtime_patches
|
|
128
|
+
(imports)</td
|
|
129
|
+
>
|
|
130
|
+
|
|
131
|
+
**Note:** A single `@` not followed by `{` passes through unchanged (e.g., `email@domain.com` works as expected).
|
|
@@ -16,8 +16,72 @@ Common uses for `{$do}`:
|
|
|
16
16
|
|
|
17
17
|
- Incrementing counters: `{$do i += 1}`
|
|
18
18
|
|
|
19
|
-
- Building collections: `{$do vec.push(item)}`
|
|
19
|
+
- Building collections: `{$do vec.push(item)}`
|
|
20
20
|
|
|
21
|
-
- Setting flags: `{$do found = true}`
|
|
21
|
+
- Setting flags: `{$do found = true}`
|
|
22
22
|
|
|
23
|
-
- Any mutating operation
|
|
23
|
+
- Any mutating operation
|
|
24
|
+
|
|
25
|
+
<h2 id="typescript-injection">
|
|
26
|
+
TsStream Injection: `{$typescript}`
|
|
27
|
+
</h2>
|
|
28
|
+
|
|
29
|
+
Inject another TsStream into your template, preserving both its source code and runtime patches (like imports added via `add_import()`):
|
|
30
|
+
|
|
31
|
+
```rust
|
|
32
|
+
// Create a helper method with its own import
|
|
33
|
+
let mut helper = body! {
|
|
34
|
+
validateEmail(email: string): boolean {
|
|
35
|
+
return Result.ok(true);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
helper.add_import("Result", "macroforge/utils");
|
|
39
|
+
|
|
40
|
+
// Inject the helper into the main template
|
|
41
|
+
let result = body! {
|
|
42
|
+
{$typescript helper}
|
|
43
|
+
|
|
44
|
+
process(data: Record<string, unknown>): void {
|
|
45
|
+
// ...
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
// result now includes helper's source AND its Result import
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
This is essential for composing multiple macro outputs while preserving imports and patches:
|
|
52
|
+
|
|
53
|
+
```rust
|
|
54
|
+
let extra_methods = if include_validation {
|
|
55
|
+
Some(body! {
|
|
56
|
+
validate(): boolean { return true; }
|
|
57
|
+
})
|
|
58
|
+
} else {
|
|
59
|
+
None
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
body! {
|
|
63
|
+
mainMethod(): void {}
|
|
64
|
+
|
|
65
|
+
{#if let Some(methods) = extra_methods}
|
|
66
|
+
{$typescript methods}
|
|
67
|
+
{/if}
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Escape Syntax
|
|
72
|
+
|
|
73
|
+
If you need a literal `@{` in your output (not interpolation), use `@@{`:
|
|
74
|
+
|
|
75
|
+
```rust
|
|
76
|
+
ts_template! {
|
|
77
|
+
// This outputs a literal @{foo}
|
|
78
|
+
const example = "Use @@{foo} for templates";
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
**Generates:**
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
// This outputs a literal @{foo}
|
|
86
|
+
const example = "Use @{foo} for templates";
|
|
87
|
+
```
|
|
@@ -45,37 +45,4 @@ let code = ts_template! {
|
|
|
45
45
|
result.@{next_field.name} = this.@{next_field.name};
|
|
46
46
|
{/while}
|
|
47
47
|
};
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
## Local Constants: `{$let}`
|
|
51
|
-
|
|
52
|
-
Define local variables within the template scope:
|
|
53
|
-
|
|
54
|
-
```rust
|
|
55
|
-
let items = vec![("user", "User"), ("post", "Post")];
|
|
56
|
-
|
|
57
|
-
let code = ts_template! {
|
|
58
|
-
{#for (key, class_name) in items}
|
|
59
|
-
{$let upper = class_name.to_uppercase()}
|
|
60
|
-
console.log("Processing @{upper}");
|
|
61
|
-
const @{key} = new @{class_name}();
|
|
62
|
-
{/for}
|
|
63
|
-
};
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
This is useful for computing derived values inside loops without cluttering the Rust code.
|
|
67
|
-
|
|
68
|
-
## Mutable Variables: `{$let mut}`
|
|
69
|
-
|
|
70
|
-
When you need to modify a variable within the template (e.g., in a `while` loop), use `{$let mut}`:
|
|
71
|
-
|
|
72
|
-
```rust
|
|
73
|
-
let code = ts_template! {
|
|
74
|
-
{$let mut count = 0}
|
|
75
|
-
{#for item in items}
|
|
76
|
-
console.log("Item @{count}: @{item}");
|
|
77
|
-
{$do count += 1}
|
|
78
|
-
{/for}
|
|
79
|
-
console.log("Total: @{count}");
|
|
80
|
-
};
|
|
81
48
|
```
|