@kubb/ast 5.0.0-beta.7 → 5.0.0-beta.71
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/LICENSE +17 -10
- package/README.md +53 -27
- package/dist/defineMacro-5Dvct8k_.cjs +114 -0
- package/dist/defineMacro-5Dvct8k_.cjs.map +1 -0
- package/dist/defineMacro-BXpTwp0y.d.ts +466 -0
- package/dist/defineMacro-VfsvblGi.js +98 -0
- package/dist/defineMacro-VfsvblGi.js.map +1 -0
- package/dist/index-DJEyS5y6.d.ts +2428 -0
- package/dist/index.cjs +198 -2239
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +98 -3400
- package/dist/index.js +149 -2160
- package/dist/index.js.map +1 -1
- package/dist/macros.cjs +130 -0
- package/dist/macros.cjs.map +1 -0
- package/dist/macros.d.ts +61 -0
- package/dist/macros.js +128 -0
- package/dist/macros.js.map +1 -0
- package/dist/operationParams-BaY12i2I.d.ts +148 -0
- package/dist/refs-D18OeCgb.js +117 -0
- package/dist/refs-D18OeCgb.js.map +1 -0
- package/dist/refs-DuP3_Leg.cjs +157 -0
- package/dist/refs-DuP3_Leg.cjs.map +1 -0
- package/dist/rolldown-runtime-CNktS9qV.js +17 -0
- package/dist/types-BsP1SK9j.d.ts +244 -0
- package/dist/types.cjs +0 -0
- package/dist/types.d.ts +5 -0
- package/dist/types.js +1 -0
- package/dist/utils.cjs +803 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.ts +354 -0
- package/dist/utils.js +777 -0
- package/dist/utils.js.map +1 -0
- package/dist/visitor-CQdSiClY.cjs +1749 -0
- package/dist/visitor-CQdSiClY.cjs.map +1 -0
- package/dist/visitor-dcVC5TOW.js +1313 -0
- package/dist/visitor-dcVC5TOW.js.map +1 -0
- package/package.json +17 -5
- package/dist/chunk--u3MIqq1.js +0 -8
- package/src/constants.ts +0 -228
- package/src/factory.ts +0 -742
- package/src/guards.ts +0 -110
- package/src/index.ts +0 -46
- package/src/infer.ts +0 -130
- package/src/mocks.ts +0 -176
- package/src/nodes/base.ts +0 -56
- package/src/nodes/code.ts +0 -304
- package/src/nodes/file.ts +0 -230
- package/src/nodes/function.ts +0 -223
- package/src/nodes/http.ts +0 -119
- package/src/nodes/index.ts +0 -86
- package/src/nodes/operation.ts +0 -111
- package/src/nodes/output.ts +0 -26
- package/src/nodes/parameter.ts +0 -41
- package/src/nodes/property.ts +0 -34
- package/src/nodes/response.ts +0 -43
- package/src/nodes/root.ts +0 -64
- package/src/nodes/schema.ts +0 -656
- package/src/printer.ts +0 -250
- package/src/refs.ts +0 -67
- package/src/resolvers.ts +0 -45
- package/src/transformers.ts +0 -159
- package/src/types.ts +0 -70
- package/src/utils.ts +0 -915
- package/src/visitor.ts +0 -592
package/LICENSE
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
This repository contains software under two licenses:
|
|
1
|
+
MIT License
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
MIT License — see licenses/LICENSE-MIT for the full license text.
|
|
3
|
+
Copyright (c) 2026 Stijn Van Hulle
|
|
7
4
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
-
<h1>@kubb/ast</h1>
|
|
3
2
|
<a href="https://kubb.dev" target="_blank" rel="noopener noreferrer">
|
|
4
|
-
<img
|
|
3
|
+
<img src="https://kubb.dev/og.png" alt="Kubb banner">
|
|
5
4
|
</a>
|
|
6
5
|
|
|
7
6
|
[![npm version][npm-version-src]][npm-version-href]
|
|
8
7
|
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
9
|
-
[![
|
|
8
|
+
[![Stars][stars-src]][stars-href]
|
|
10
9
|
[![License][license-src]][license-href]
|
|
11
|
-
[![
|
|
10
|
+
[![Node][node-src]][node-href]
|
|
12
11
|
|
|
13
12
|
<h4>
|
|
14
|
-
<a href="https://kubb.dev
|
|
13
|
+
<a href="https://kubb.dev" target="_blank">Documentation</a>
|
|
15
14
|
<span> · </span>
|
|
16
15
|
<a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Report Bug</a>
|
|
17
16
|
<span> · </span>
|
|
@@ -19,14 +18,23 @@
|
|
|
19
18
|
</h4>
|
|
20
19
|
</div>
|
|
21
20
|
|
|
22
|
-
|
|
21
|
+
<br />
|
|
22
|
+
|
|
23
|
+
# @kubb/ast
|
|
24
|
+
|
|
25
|
+
### Spec-agnostic AST layer for Kubb
|
|
26
|
+
|
|
27
|
+
Defines the node tree, visitor pattern, factory functions, and type guards used across every Kubb code generation plugin.
|
|
23
28
|
|
|
24
29
|
## Imports
|
|
25
30
|
|
|
26
|
-
| Path
|
|
27
|
-
|
|
|
28
|
-
| `@kubb/ast`
|
|
29
|
-
| `@kubb/ast
|
|
31
|
+
| Path | Contents |
|
|
32
|
+
| ------------------------------- | ---------------------------------------------------------------------------------------- |
|
|
33
|
+
| `@kubb/ast` | Runtime: node definitions, guards, visitor, macro engine, constants |
|
|
34
|
+
| `ast.factory` (via `@kubb/ast`) | Node constructors (`createSchema`, `createFile`, and friends), the `ts.factory` analogue |
|
|
35
|
+
| `@kubb/ast/macros` | Built-in macro presets: `macroDiscriminatorEnum`, `macroSimplifyUnion`, `macroEnumName` |
|
|
36
|
+
| `@kubb/ast/types` | Types only: all node interfaces, type aliases, visitor types |
|
|
37
|
+
| `@kubb/ast/utils` | Spec-agnostic string and identifier helpers, ref helpers |
|
|
30
38
|
|
|
31
39
|
## Node tree
|
|
32
40
|
|
|
@@ -51,10 +59,14 @@ SchemaNode (discriminated union)
|
|
|
51
59
|
|
|
52
60
|
### Factory
|
|
53
61
|
|
|
62
|
+
Constructors are available as `ast.factory` from `@kubb/ast`, mirroring `ts.factory.createX`.
|
|
63
|
+
|
|
54
64
|
```ts
|
|
55
|
-
import {
|
|
65
|
+
import { ast } from '@kubb/ast'
|
|
66
|
+
|
|
67
|
+
const { createInput, createSchema, createProperty } = ast.factory
|
|
56
68
|
|
|
57
|
-
const root =
|
|
69
|
+
const root = createInput({
|
|
58
70
|
schemas: [
|
|
59
71
|
createSchema({
|
|
60
72
|
name: 'Pet',
|
|
@@ -106,11 +118,11 @@ const types = collect<string>(root, {
|
|
|
106
118
|
### Guards
|
|
107
119
|
|
|
108
120
|
```ts
|
|
109
|
-
import {
|
|
121
|
+
import { narrowSchema, schemaDef } from '@kubb/ast'
|
|
110
122
|
import type { Node } from '@kubb/ast/types'
|
|
111
123
|
|
|
112
124
|
function process(node: Node) {
|
|
113
|
-
if (
|
|
125
|
+
if (schemaDef.is(node)) {
|
|
114
126
|
const obj = narrowSchema(node, 'object')
|
|
115
127
|
obj?.properties?.forEach((p) => console.log(p.name))
|
|
116
128
|
}
|
|
@@ -120,17 +132,27 @@ function process(node: Node) {
|
|
|
120
132
|
### Refs
|
|
121
133
|
|
|
122
134
|
```ts
|
|
123
|
-
import {
|
|
135
|
+
import { extractRefName } from '@kubb/ast/utils'
|
|
124
136
|
|
|
125
|
-
|
|
126
|
-
const pet = resolveRef(refMap, 'Pet')
|
|
137
|
+
extractRefName('#/components/schemas/Pet') // 'Pet'
|
|
127
138
|
```
|
|
128
139
|
|
|
140
|
+
## Adding a node
|
|
141
|
+
|
|
142
|
+
Adding a node touches three files. The barrels and visitor tables derive the rest.
|
|
143
|
+
|
|
144
|
+
1. Define the node in its own `src/nodes/*.ts` file. Call `defineNode` and export the resulting `fooDef`, the `createFoo` constructor, and the node's type.
|
|
145
|
+
2. Add `fooDef` to the `nodeDefs` array in `src/registry.ts`.
|
|
146
|
+
3. Re-export `createFoo` from `src/factory.ts`.
|
|
147
|
+
|
|
148
|
+
Everything else follows from there. `@kubb/ast/types` picks up the node type through `export type *`, the `@kubb/ast` barrel picks up `fooDef` through `export * from './registry.ts'`, and the visitor tables (`VISITOR_KEYS`, `VISITOR_KEY_BY_KIND`, `nodeRebuilders`) come from the def's `children`, `visitorKey`, and `rebuild` fields. `registry.test.ts` fails when a def has no matching `factory.create*`, so missing wiring is caught in CI.
|
|
149
|
+
|
|
129
150
|
## Supporting Kubb
|
|
130
151
|
|
|
131
|
-
Kubb is an
|
|
152
|
+
Kubb is an open source project, and its development is funded entirely by sponsors. If you would like to become a sponsor, please consider:
|
|
132
153
|
|
|
133
154
|
- [Become a Sponsor on GitHub](https://github.com/sponsors/stijnvanhulle)
|
|
155
|
+
- [See sponsorship tiers and our sponsors](https://kubb.dev/sponsors)
|
|
134
156
|
|
|
135
157
|
<p align="center">
|
|
136
158
|
<a href="https://github.com/sponsors/stijnvanhulle">
|
|
@@ -138,15 +160,19 @@ Kubb is an MIT-licensed open source project with its ongoing development made po
|
|
|
138
160
|
</a>
|
|
139
161
|
</p>
|
|
140
162
|
|
|
163
|
+
## License
|
|
164
|
+
|
|
165
|
+
[MIT](https://github.com/kubb-labs/kubb/blob/main/licenses/LICENSE-MIT)
|
|
166
|
+
|
|
141
167
|
<!-- Badges -->
|
|
142
168
|
|
|
143
|
-
[npm-version-src]: https://
|
|
144
|
-
[npm-version-href]: https://
|
|
145
|
-
[npm-downloads-src]: https://
|
|
146
|
-
[npm-downloads-href]: https://
|
|
147
|
-
[
|
|
169
|
+
[npm-version-src]: https://shieldcn.dev/npm/v/@kubb/ast.svg?variant=secondary&size=xs&theme=zinc&mode=dark
|
|
170
|
+
[npm-version-href]: https://npmx.dev/package/@kubb/ast
|
|
171
|
+
[npm-downloads-src]: https://shieldcn.dev/npm/dm/@kubb/ast.svg?variant=secondary&size=xs&theme=zinc&mode=dark
|
|
172
|
+
[npm-downloads-href]: https://npmx.dev/package/@kubb/ast
|
|
173
|
+
[stars-src]: https://shieldcn.dev/github/stars/kubb-labs/kubb.svg?variant=secondary&size=xs&theme=zinc&mode=dark
|
|
174
|
+
[stars-href]: https://github.com/kubb-labs/kubb
|
|
175
|
+
[license-src]: https://shieldcn.dev/npm/license/@kubb/ast.svg?variant=secondary&size=xs&theme=zinc
|
|
148
176
|
[license-href]: https://github.com/kubb-labs/kubb/blob/main/LICENSE
|
|
149
|
-
[
|
|
150
|
-
[
|
|
151
|
-
[sponsors-src]: https://img.shields.io/github/sponsors/stijnvanhulle?style=flat&colorA=18181B&colorB=f58517
|
|
152
|
-
[sponsors-href]: https://github.com/sponsors/stijnvanhulle/
|
|
177
|
+
[node-src]: https://shieldcn.dev/npm/node/@kubb/ast.svg?variant=secondary&size=xs&theme=zinc&mode=dark
|
|
178
|
+
[node-href]: https://npmx.dev/package/@kubb/ast
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
const require_visitor = require("./visitor-CQdSiClY.cjs");
|
|
2
|
+
//#region src/defineMacro.ts
|
|
3
|
+
/**
|
|
4
|
+
* Sort weight for an `enforce` hint. `pre` sorts before unmarked items and `post` after, so a plain
|
|
5
|
+
* list keeps its authored order.
|
|
6
|
+
*/
|
|
7
|
+
function enforceWeight(enforce) {
|
|
8
|
+
if (enforce === "pre") return 0;
|
|
9
|
+
if (enforce === "post") return 2;
|
|
10
|
+
return 1;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Types a macro for inference and a single construction site, mirroring `definePlugin`.
|
|
14
|
+
* Adds no runtime behavior.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const macroUntagged = defineMacro({
|
|
19
|
+
* name: 'untagged',
|
|
20
|
+
* operation(node) {
|
|
21
|
+
* return node.tags?.length ? undefined : { ...node, tags: ['untagged'] }
|
|
22
|
+
* },
|
|
23
|
+
* })
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
function defineMacro(macro) {
|
|
27
|
+
return macro;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Runs every macro's callback for one node kind in order, chaining the result so each macro sees
|
|
31
|
+
* the previous macro's output. Returns `undefined` when nothing changed, so `transform` keeps the
|
|
32
|
+
* original reference (structural sharing).
|
|
33
|
+
*/
|
|
34
|
+
function chain({ macros, key, node, context }) {
|
|
35
|
+
let current = node;
|
|
36
|
+
for (const macro of macros) {
|
|
37
|
+
const callback = macro[key];
|
|
38
|
+
if (!callback) continue;
|
|
39
|
+
if (macro.when && !macro.when(current)) continue;
|
|
40
|
+
const next = callback(current, context);
|
|
41
|
+
if (next != null) current = next;
|
|
42
|
+
}
|
|
43
|
+
return current === node ? void 0 : current;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Folds an ordered list of macros into a single {@link Visitor} that `transform` (and the per-plugin
|
|
47
|
+
* transform layer in `@kubb/core`) can run. Macros are stable-sorted by `enforce`, then applied
|
|
48
|
+
* sequentially per node so later macros see earlier output. This differs from a plain visitor, which
|
|
49
|
+
* has no names, ordering, or composition.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* const visitor = composeMacros([macroSimplifyUnion, macroDiscriminatorEnum])
|
|
54
|
+
* const next = transform(root, visitor)
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
function composeMacros(macros) {
|
|
58
|
+
const ordered = [...macros].sort((a, b) => enforceWeight(a.enforce) - enforceWeight(b.enforce));
|
|
59
|
+
const visitor = {};
|
|
60
|
+
for (const key of require_visitor.visitorKeys) {
|
|
61
|
+
if (!ordered.some((macro) => typeof macro[key] === "function")) continue;
|
|
62
|
+
const callback = (node, context) => chain({
|
|
63
|
+
macros: ordered,
|
|
64
|
+
key,
|
|
65
|
+
node,
|
|
66
|
+
context
|
|
67
|
+
});
|
|
68
|
+
visitor[key] = callback;
|
|
69
|
+
}
|
|
70
|
+
return visitor;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Runs a list of macros over a node tree and returns the rewritten tree. Keeps `transform`'s
|
|
74
|
+
* structural sharing, so an empty or no-op macro list returns the same reference. Pass
|
|
75
|
+
* `depth: 'shallow'` to rewrite the root node only.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* const next = applyMacros(root, [macroIntegerToString])
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* @example Apply to the root node only
|
|
83
|
+
* ```ts
|
|
84
|
+
* const named = applyMacros(node, [macroEnumName({ parentName, propName, enumSuffix })], { depth: 'shallow' })
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
function applyMacros(root, macros, options) {
|
|
88
|
+
if (macros.length === 0) return root;
|
|
89
|
+
return require_visitor.transform(root, {
|
|
90
|
+
...composeMacros(macros),
|
|
91
|
+
...options
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
//#endregion
|
|
95
|
+
Object.defineProperty(exports, "applyMacros", {
|
|
96
|
+
enumerable: true,
|
|
97
|
+
get: function() {
|
|
98
|
+
return applyMacros;
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
Object.defineProperty(exports, "composeMacros", {
|
|
102
|
+
enumerable: true,
|
|
103
|
+
get: function() {
|
|
104
|
+
return composeMacros;
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
Object.defineProperty(exports, "defineMacro", {
|
|
108
|
+
enumerable: true,
|
|
109
|
+
get: function() {
|
|
110
|
+
return defineMacro;
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
//# sourceMappingURL=defineMacro-5Dvct8k_.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defineMacro-5Dvct8k_.cjs","names":["visitorKeys","transform"],"sources":["../src/defineMacro.ts"],"sourcesContent":["import type { VisitorDepth } from './constants.ts'\nimport type { VisitorKey } from './defineNode.ts'\nimport { visitorKeys } from './defineNode.ts'\nimport type { Node } from './nodes/index.ts'\nimport type { Visitor, VisitorContext } from './visitor.ts'\nimport { transform } from './visitor.ts'\n\n/**\n * Ordering hint shared by macros and plugins. `pre` runs before unmarked items, `post` after,\n * and `undefined` keeps declaration order.\n */\nexport type Enforce = 'pre' | 'post'\n\n/**\n * Sort weight for an `enforce` hint. `pre` sorts before unmarked items and `post` after, so a plain\n * list keeps its authored order.\n */\nfunction enforceWeight(enforce?: Enforce): number {\n if (enforce === 'pre') return 0\n if (enforce === 'post') return 2\n return 1\n}\n\n/**\n * A named, composable transform over the Kubb AST. It carries the same per-kind callbacks as a\n * {@link Visitor} (`schema`, `operation`, …), plus a `name`, an optional `enforce` order, and an\n * optional `when` gate. Macros run on the shared AST, so the same macro works across every adapter\n * and output target. Exports follow the `macro<Name>` convention, mirroring plugins (`pluginTs`).\n */\nexport type Macro = Visitor & {\n /**\n * Macro identifier used to tell macros apart, for example `'simplify-union'`.\n */\n name: string\n /**\n * Ordering hint. `pre` macros run before unmarked macros, `post` macros run after.\n * Ordering within a bucket follows list order.\n */\n enforce?: Enforce\n /**\n * Gate checked against the current node before any callback runs. When it returns `false`\n * the macro is skipped for that node.\n */\n when?: (node: Node) => boolean\n}\n\n/**\n * Types a macro for inference and a single construction site, mirroring `definePlugin`.\n * Adds no runtime behavior.\n *\n * @example\n * ```ts\n * const macroUntagged = defineMacro({\n * name: 'untagged',\n * operation(node) {\n * return node.tags?.length ? undefined : { ...node, tags: ['untagged'] }\n * },\n * })\n * ```\n */\nexport function defineMacro(macro: Macro): Macro {\n return macro\n}\n\ntype MacroCallback = (node: Node, context: VisitorContext) => Node | null | undefined\n\ntype ChainProps = {\n macros: ReadonlyArray<Macro>\n key: VisitorKey\n node: Node\n context: VisitorContext\n}\n\n/**\n * Runs every macro's callback for one node kind in order, chaining the result so each macro sees\n * the previous macro's output. Returns `undefined` when nothing changed, so `transform` keeps the\n * original reference (structural sharing).\n */\nfunction chain({ macros, key, node, context }: ChainProps): Node | undefined {\n let current = node\n\n for (const macro of macros) {\n const callback = macro[key] as MacroCallback | undefined\n if (!callback) continue\n if (macro.when && !macro.when(current)) continue\n\n const next = callback(current, context)\n if (next != null) current = next\n }\n\n return current === node ? undefined : current\n}\n\n/**\n * Folds an ordered list of macros into a single {@link Visitor} that `transform` (and the per-plugin\n * transform layer in `@kubb/core`) can run. Macros are stable-sorted by `enforce`, then applied\n * sequentially per node so later macros see earlier output. This differs from a plain visitor, which\n * has no names, ordering, or composition.\n *\n * @example\n * ```ts\n * const visitor = composeMacros([macroSimplifyUnion, macroDiscriminatorEnum])\n * const next = transform(root, visitor)\n * ```\n */\nexport function composeMacros(macros: ReadonlyArray<Macro>): Visitor {\n const ordered = [...macros].sort((a, b) => enforceWeight(a.enforce) - enforceWeight(b.enforce))\n\n const visitor: Visitor = {}\n for (const key of visitorKeys) {\n if (!ordered.some((macro) => typeof macro[key] === 'function')) continue\n\n const callback = (node: Node, context: VisitorContext) => chain({ macros: ordered, key, node, context })\n ;(visitor as Record<VisitorKey, MacroCallback>)[key] = callback\n }\n\n return visitor\n}\n\n/**\n * Runs a list of macros over a node tree and returns the rewritten tree. Keeps `transform`'s\n * structural sharing, so an empty or no-op macro list returns the same reference. Pass\n * `depth: 'shallow'` to rewrite the root node only.\n *\n * @example\n * ```ts\n * const next = applyMacros(root, [macroIntegerToString])\n * ```\n *\n * @example Apply to the root node only\n * ```ts\n * const named = applyMacros(node, [macroEnumName({ parentName, propName, enumSuffix })], { depth: 'shallow' })\n * ```\n */\nexport function applyMacros<TNode extends Node>(root: TNode, macros: ReadonlyArray<Macro>, options?: { depth?: VisitorDepth }): TNode {\n if (macros.length === 0) return root\n\n return transform(root, { ...composeMacros(macros), ...options }) as TNode\n}\n"],"mappings":";;;;;;AAiBA,SAAS,cAAc,SAA2B;CAChD,IAAI,YAAY,OAAO,OAAO;CAC9B,IAAI,YAAY,QAAQ,OAAO;CAC/B,OAAO;AACT;;;;;;;;;;;;;;;AAuCA,SAAgB,YAAY,OAAqB;CAC/C,OAAO;AACT;;;;;;AAgBA,SAAS,MAAM,EAAE,QAAQ,KAAK,MAAM,WAAyC;CAC3E,IAAI,UAAU;CAEd,KAAK,MAAM,SAAS,QAAQ;EAC1B,MAAM,WAAW,MAAM;EACvB,IAAI,CAAC,UAAU;EACf,IAAI,MAAM,QAAQ,CAAC,MAAM,KAAK,OAAO,GAAG;EAExC,MAAM,OAAO,SAAS,SAAS,OAAO;EACtC,IAAI,QAAQ,MAAM,UAAU;CAC9B;CAEA,OAAO,YAAY,OAAO,KAAA,IAAY;AACxC;;;;;;;;;;;;;AAcA,SAAgB,cAAc,QAAuC;CACnE,MAAM,UAAU,CAAC,GAAG,MAAM,CAAC,CAAC,MAAM,GAAG,MAAM,cAAc,EAAE,OAAO,IAAI,cAAc,EAAE,OAAO,CAAC;CAE9F,MAAM,UAAmB,CAAC;CAC1B,KAAK,MAAM,OAAOA,gBAAAA,aAAa;EAC7B,IAAI,CAAC,QAAQ,MAAM,UAAU,OAAO,MAAM,SAAS,UAAU,GAAG;EAEhE,MAAM,YAAY,MAAY,YAA4B,MAAM;GAAE,QAAQ;GAAS;GAAK;GAAM;EAAQ,CAAC;EACtG,QAA+C,OAAO;CACzD;CAEA,OAAO;AACT;;;;;;;;;;;;;;;;AAiBA,SAAgB,YAAgC,MAAa,QAA8B,SAA2C;CACpI,IAAI,OAAO,WAAW,GAAG,OAAO;CAEhC,OAAOC,gBAAAA,UAAU,MAAM;EAAE,GAAG,cAAc,MAAM;EAAG,GAAG;CAAQ,CAAC;AACjE"}
|