@kubb/parser-ts 5.0.0-beta.6 → 5.0.0-beta.61
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 +111 -0
- package/dist/index.cjs +244 -130
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +60 -55
- package/dist/index.js +246 -127
- package/dist/index.js.map +1 -1
- package/package.json +6 -7
- package/src/constants.ts +16 -6
- package/src/index.ts +1 -1
- package/src/parserTs.ts +36 -468
- package/src/parserTsx.ts +25 -8
- package/src/utils.ts +488 -0
- package/extension.yaml +0 -100
- /package/dist/{chunk--u3MIqq1.js → chunk-C0LytTxp.js} +0 -0
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
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<a href="https://kubb.dev" target="_blank" rel="noopener noreferrer">
|
|
3
|
+
<img src="https://kubb.dev/og.png" alt="Kubb banner">
|
|
4
|
+
</a>
|
|
5
|
+
|
|
6
|
+
[![npm version][npm-version-src]][npm-version-href]
|
|
7
|
+
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
8
|
+
[![Stars][stars-src]][stars-href]
|
|
9
|
+
[![License][license-src]][license-href]
|
|
10
|
+
[![Node][node-src]][node-href]
|
|
11
|
+
|
|
12
|
+
<h4>
|
|
13
|
+
<a href="https://kubb.dev" target="_blank">Documentation</a>
|
|
14
|
+
<span> · </span>
|
|
15
|
+
<a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Report Bug</a>
|
|
16
|
+
<span> · </span>
|
|
17
|
+
<a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Request Feature</a>
|
|
18
|
+
</h4>
|
|
19
|
+
</div>
|
|
20
|
+
|
|
21
|
+
<br />
|
|
22
|
+
|
|
23
|
+
# @kubb/parser-ts
|
|
24
|
+
|
|
25
|
+
### TypeScript source file parser for Kubb
|
|
26
|
+
|
|
27
|
+
Converts AST nodes and raw TypeScript code into formatted source strings using the TypeScript compiler API. Handles both `.ts` and `.tsx` output.
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
bun add @kubb/parser-ts
|
|
33
|
+
# or
|
|
34
|
+
pnpm add @kubb/parser-ts
|
|
35
|
+
# or
|
|
36
|
+
npm install @kubb/parser-ts
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Usage
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
import { defineConfig } from 'kubb'
|
|
43
|
+
import { parserTs, parserTsx } from '@kubb/parser-ts'
|
|
44
|
+
|
|
45
|
+
export default defineConfig({
|
|
46
|
+
input: { path: './petstore.yaml' },
|
|
47
|
+
output: { path: './src/gen' },
|
|
48
|
+
parsers: [parserTs, parserTsx],
|
|
49
|
+
})
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
To render compiler AST nodes to source text from inside a plugin, call `print` on the parser instance:
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
import { parserTs } from '@kubb/parser-ts'
|
|
56
|
+
import ts from 'typescript'
|
|
57
|
+
|
|
58
|
+
const source = parserTs.print(
|
|
59
|
+
ts.factory.createVariableStatement(
|
|
60
|
+
[ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
|
|
61
|
+
ts.factory.createVariableDeclarationList(
|
|
62
|
+
[ts.factory.createVariableDeclaration('hello', undefined, undefined, ts.factory.createStringLiteral('world'))],
|
|
63
|
+
ts.NodeFlags.Const,
|
|
64
|
+
),
|
|
65
|
+
),
|
|
66
|
+
)
|
|
67
|
+
// → export const hello = 'world'
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## API
|
|
71
|
+
|
|
72
|
+
### `parserTs`
|
|
73
|
+
|
|
74
|
+
Parser instance for `.ts` and `.js` files. Pass to `defineConfig({ parsers: [...] })` to emit TypeScript source files.
|
|
75
|
+
|
|
76
|
+
- `parserTs.parse(file, options?)` — serialize a `FileNode` to TypeScript source.
|
|
77
|
+
- `parserTs.print(...nodes)` — convert TypeScript compiler `Node` instances to a formatted source string.
|
|
78
|
+
|
|
79
|
+
### `parserTsx`
|
|
80
|
+
|
|
81
|
+
Parser instance for `.tsx` and `.jsx` files. Same API as `parserTs` with JSX support.
|
|
82
|
+
|
|
83
|
+
## Supporting Kubb
|
|
84
|
+
|
|
85
|
+
Kubb is an open source project, and its development is funded entirely by sponsors. If you would like to become a sponsor, please consider:
|
|
86
|
+
|
|
87
|
+
- [Become a Sponsor on GitHub](https://github.com/sponsors/stijnvanhulle)
|
|
88
|
+
- [See sponsorship tiers and our sponsors](https://kubb.dev/sponsors)
|
|
89
|
+
|
|
90
|
+
<p align="center">
|
|
91
|
+
<a href="https://github.com/sponsors/stijnvanhulle">
|
|
92
|
+
<img src="https://raw.githubusercontent.com/stijnvanhulle/sponsors/main/sponsors.svg" alt="My sponsors" />
|
|
93
|
+
</a>
|
|
94
|
+
</p>
|
|
95
|
+
|
|
96
|
+
## License
|
|
97
|
+
|
|
98
|
+
[MIT](https://github.com/kubb-labs/kubb/blob/main/licenses/LICENSE-MIT)
|
|
99
|
+
|
|
100
|
+
<!-- Badges -->
|
|
101
|
+
|
|
102
|
+
[npm-version-src]: https://shieldcn.dev/npm/v/@kubb/parser-ts.svg?variant=secondary&size=xs&theme=zinc&mode=dark
|
|
103
|
+
[npm-version-href]: https://npmx.dev/package/@kubb/parser-ts
|
|
104
|
+
[npm-downloads-src]: https://shieldcn.dev/npm/dm/@kubb/parser-ts.svg?variant=secondary&size=xs&theme=zinc&mode=dark
|
|
105
|
+
[npm-downloads-href]: https://npmx.dev/package/@kubb/parser-ts
|
|
106
|
+
[stars-src]: https://shieldcn.dev/github/stars/kubb-labs/kubb.svg?variant=secondary&size=xs&theme=zinc&mode=dark
|
|
107
|
+
[stars-href]: https://github.com/kubb-labs/kubb
|
|
108
|
+
[license-src]: https://shieldcn.dev/npm/license/@kubb/parser-ts.svg?variant=secondary&size=xs&theme=zinc
|
|
109
|
+
[license-href]: https://github.com/kubb-labs/kubb/blob/main/LICENSE
|
|
110
|
+
[node-src]: https://shieldcn.dev/npm/node/@kubb/parser-ts.svg?variant=secondary&size=xs&theme=zinc&mode=dark
|
|
111
|
+
[node-href]: https://npmx.dev/package/@kubb/parser-ts
|