@kubb/parser-ts 4.1.4 → 5.0.0-alpha.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/LICENSE +10 -17
- package/dist/chunk--u3MIqq1.js +8 -0
- package/dist/index.cjs +146 -53
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +61 -18
- package/dist/index.js +120 -46
- package/dist/index.js.map +1 -1
- package/package.json +14 -27
- package/src/index.ts +2 -3
- package/src/parserTs.ts +212 -0
- package/src/parserTsx.ts +20 -0
- package/README.md +0 -54
- package/dist/chunk-CTAAG5j7.js +0 -13
- package/dist/factory-BJCGLhSr.d.ts +0 -227
- package/dist/factory-BNDICAoK.cjs +0 -496
- package/dist/factory-BNDICAoK.cjs.map +0 -1
- package/dist/factory-CroRqsMR.js +0 -249
- package/dist/factory-CroRqsMR.js.map +0 -1
- package/dist/factory-DqBZ_C7_.d.cts +0 -227
- package/dist/factory.cjs +0 -36
- package/dist/factory.d.cts +0 -2
- package/dist/factory.d.ts +0 -2
- package/dist/factory.js +0 -3
- package/dist/index.d.cts +0 -25
- package/src/factory.ts +0 -578
- package/src/format.ts +0 -25
- package/src/print.ts +0 -48
package/package.json
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/parser-ts",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "TypeScript
|
|
3
|
+
"version": "5.0.0-alpha.31",
|
|
4
|
+
"description": "TypeScript and TSX file parser for Kubb, converting generated files to strings using the TypeScript compiler.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
7
|
+
"tsx",
|
|
7
8
|
"parser",
|
|
8
|
-
"
|
|
9
|
-
"code-generation",
|
|
10
|
-
"syntax",
|
|
11
|
-
"formatting",
|
|
9
|
+
"code-generator",
|
|
12
10
|
"codegen",
|
|
13
11
|
"kubb"
|
|
14
12
|
],
|
|
15
13
|
"repository": {
|
|
16
14
|
"type": "git",
|
|
17
|
-
"url": "https://github.com/kubb-labs/kubb.git",
|
|
15
|
+
"url": "git+https://github.com/kubb-labs/kubb.git",
|
|
18
16
|
"directory": "packages/parser-ts"
|
|
19
17
|
},
|
|
20
18
|
"license": "MIT",
|
|
@@ -26,43 +24,32 @@
|
|
|
26
24
|
"import": "./dist/index.js",
|
|
27
25
|
"require": "./dist/index.cjs"
|
|
28
26
|
},
|
|
29
|
-
"./factory": {
|
|
30
|
-
"import": "./dist/factory.js",
|
|
31
|
-
"require": "./dist/factory.cjs"
|
|
32
|
-
},
|
|
33
27
|
"./package.json": "./package.json"
|
|
34
28
|
},
|
|
35
|
-
"
|
|
36
|
-
"module": "./dist/index.js",
|
|
37
|
-
"types": "./dist/index.d.cts",
|
|
38
|
-
"typesVersions": {
|
|
39
|
-
"*": {
|
|
40
|
-
"factory": [
|
|
41
|
-
"./dist/factory.d.ts"
|
|
42
|
-
]
|
|
43
|
-
}
|
|
44
|
-
},
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
45
30
|
"files": [
|
|
46
31
|
"src",
|
|
47
32
|
"dist",
|
|
48
33
|
"!/**/**.test.**",
|
|
49
|
-
"!/**/__tests__/**"
|
|
34
|
+
"!/**/__tests__/**",
|
|
35
|
+
"!/**/__snapshots__/**"
|
|
50
36
|
],
|
|
51
37
|
"dependencies": {
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"typescript": "5.9.3"
|
|
38
|
+
"typescript": "^6.0.2",
|
|
39
|
+
"@kubb/core": "5.0.0-alpha.31"
|
|
55
40
|
},
|
|
56
41
|
"devDependencies": {
|
|
57
|
-
"
|
|
42
|
+
"@internals/utils": "0.0.0"
|
|
58
43
|
},
|
|
59
44
|
"engines": {
|
|
60
|
-
"node": ">=
|
|
45
|
+
"node": ">=22"
|
|
61
46
|
},
|
|
62
47
|
"publishConfig": {
|
|
63
48
|
"access": "public",
|
|
64
49
|
"registry": "https://registry.npmjs.org/"
|
|
65
50
|
},
|
|
51
|
+
"main": "./dist/index.cjs",
|
|
52
|
+
"module": "./dist/index.js",
|
|
66
53
|
"scripts": {
|
|
67
54
|
"build": "tsdown",
|
|
68
55
|
"clean": "npx rimraf ./dist",
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export {
|
|
3
|
-
export { print } from './print.ts'
|
|
1
|
+
export { createExport, createImport, parserTs, print, safePrint, validateNodes } from './parserTs.ts'
|
|
2
|
+
export { parserTsx } from './parserTsx.ts'
|
package/src/parserTs.ts
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { normalize, relative } from 'node:path'
|
|
2
|
+
import type { KubbFile, Parser } from '@kubb/core'
|
|
3
|
+
import { defineParser } from '@kubb/core'
|
|
4
|
+
import ts from 'typescript'
|
|
5
|
+
|
|
6
|
+
const { factory } = ts
|
|
7
|
+
|
|
8
|
+
function slash(path: string): string {
|
|
9
|
+
return normalize(path).replaceAll(/\\/g, '/').replace('../', '')
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function getRelativePath(rootDir: string, filePath: string): string {
|
|
13
|
+
const rel = relative(rootDir, filePath)
|
|
14
|
+
const slashed = slash(rel)
|
|
15
|
+
return slashed.startsWith('../') ? slashed : `./${slashed}`
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function trimExtName(text: string): string {
|
|
19
|
+
return text.replace(/\.[^/.]+$/, '')
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Validates TypeScript AST nodes before printing.
|
|
24
|
+
* Throws an error if any node has SyntaxKind.Unknown which would cause the
|
|
25
|
+
* TypeScript printer to crash.
|
|
26
|
+
*/
|
|
27
|
+
export function validateNodes(...nodes: ts.Node[]): void {
|
|
28
|
+
for (const node of nodes) {
|
|
29
|
+
if (!node) {
|
|
30
|
+
throw new Error('Attempted to print undefined or null TypeScript node')
|
|
31
|
+
}
|
|
32
|
+
if (node.kind === ts.SyntaxKind.Unknown) {
|
|
33
|
+
throw new Error(
|
|
34
|
+
'Invalid TypeScript AST node detected with SyntaxKind.Unknown. ' +
|
|
35
|
+
'This typically indicates a schema pattern that could not be properly converted to TypeScript. ' +
|
|
36
|
+
`Node: ${JSON.stringify(node, null, 2)}`,
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Converts TypeScript/TSX AST nodes to a string using the TypeScript printer.
|
|
44
|
+
*/
|
|
45
|
+
export function print(...elements: Array<ts.Node>): string {
|
|
46
|
+
const sourceFile = ts.createSourceFile('print.tsx', '', ts.ScriptTarget.ES2022, true, ts.ScriptKind.TSX)
|
|
47
|
+
|
|
48
|
+
const printer = ts.createPrinter({
|
|
49
|
+
omitTrailingSemicolon: true,
|
|
50
|
+
newLine: ts.NewLineKind.LineFeed,
|
|
51
|
+
removeComments: false,
|
|
52
|
+
noEmitHelpers: true,
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
const output = printer.printList(ts.ListFormat.MultiLine, factory.createNodeArray(elements.filter(Boolean)), sourceFile)
|
|
56
|
+
|
|
57
|
+
return output.replace(/\r\n/g, '\n')
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Like `print` but validates nodes first to surface issues early.
|
|
62
|
+
*/
|
|
63
|
+
export function safePrint(...elements: Array<ts.Node>): string {
|
|
64
|
+
validateNodes(...elements)
|
|
65
|
+
return print(...elements)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function createImport({
|
|
69
|
+
name,
|
|
70
|
+
path,
|
|
71
|
+
root,
|
|
72
|
+
isTypeOnly = false,
|
|
73
|
+
isNameSpace = false,
|
|
74
|
+
}: {
|
|
75
|
+
name: string | Array<string | { propertyName: string; name?: string }>
|
|
76
|
+
path: string
|
|
77
|
+
root?: string
|
|
78
|
+
/** @default false */
|
|
79
|
+
isTypeOnly?: boolean
|
|
80
|
+
/** @default false */
|
|
81
|
+
isNameSpace?: boolean
|
|
82
|
+
}): ts.ImportDeclaration {
|
|
83
|
+
const resolvePath = root ? getRelativePath(root, path) : path
|
|
84
|
+
|
|
85
|
+
if (!Array.isArray(name)) {
|
|
86
|
+
if (isNameSpace) {
|
|
87
|
+
return factory.createImportDeclaration(
|
|
88
|
+
undefined,
|
|
89
|
+
factory.createImportClause(isTypeOnly, undefined, factory.createNamespaceImport(factory.createIdentifier(name))),
|
|
90
|
+
factory.createStringLiteral(resolvePath),
|
|
91
|
+
undefined,
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return factory.createImportDeclaration(
|
|
96
|
+
undefined,
|
|
97
|
+
factory.createImportClause(isTypeOnly, factory.createIdentifier(name), undefined),
|
|
98
|
+
factory.createStringLiteral(resolvePath),
|
|
99
|
+
undefined,
|
|
100
|
+
)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const specifiers = name.map((item) => {
|
|
104
|
+
if (typeof item === 'object') {
|
|
105
|
+
const { propertyName, name: alias } = item
|
|
106
|
+
return factory.createImportSpecifier(false, alias ? factory.createIdentifier(propertyName) : undefined, factory.createIdentifier(alias ?? propertyName))
|
|
107
|
+
}
|
|
108
|
+
return factory.createImportSpecifier(false, undefined, factory.createIdentifier(item))
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
return factory.createImportDeclaration(
|
|
112
|
+
undefined,
|
|
113
|
+
factory.createImportClause(isTypeOnly, undefined, factory.createNamedImports(specifiers)),
|
|
114
|
+
factory.createStringLiteral(resolvePath),
|
|
115
|
+
undefined,
|
|
116
|
+
)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function createExport({
|
|
120
|
+
path,
|
|
121
|
+
asAlias,
|
|
122
|
+
isTypeOnly = false,
|
|
123
|
+
name,
|
|
124
|
+
}: {
|
|
125
|
+
path: string
|
|
126
|
+
/** @default false */
|
|
127
|
+
asAlias?: boolean
|
|
128
|
+
/** @default false */
|
|
129
|
+
isTypeOnly?: boolean
|
|
130
|
+
name?: string | Array<ts.Identifier | string>
|
|
131
|
+
}): ts.ExportDeclaration {
|
|
132
|
+
if (name && !Array.isArray(name) && !asAlias) {
|
|
133
|
+
console.warn(`When using name as string, asAlias should be true: ${name}`)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (!Array.isArray(name)) {
|
|
137
|
+
const parsedName = name?.match(/^\d/) ? `_${name?.slice(1)}` : name
|
|
138
|
+
|
|
139
|
+
return factory.createExportDeclaration(
|
|
140
|
+
undefined,
|
|
141
|
+
isTypeOnly,
|
|
142
|
+
asAlias && parsedName ? factory.createNamespaceExport(factory.createIdentifier(parsedName)) : undefined,
|
|
143
|
+
factory.createStringLiteral(path),
|
|
144
|
+
undefined,
|
|
145
|
+
)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return factory.createExportDeclaration(
|
|
149
|
+
undefined,
|
|
150
|
+
isTypeOnly,
|
|
151
|
+
factory.createNamedExports(
|
|
152
|
+
name.map((propertyName) =>
|
|
153
|
+
factory.createExportSpecifier(false, undefined, typeof propertyName === 'string' ? factory.createIdentifier(propertyName) : propertyName),
|
|
154
|
+
),
|
|
155
|
+
),
|
|
156
|
+
factory.createStringLiteral(path),
|
|
157
|
+
undefined,
|
|
158
|
+
)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Parser that converts `.ts` and `.js` files to strings using the TypeScript
|
|
163
|
+
* compiler. Handles import/export statement generation from file metadata.
|
|
164
|
+
*
|
|
165
|
+
* @default Used automatically when no `parsers` option is set in `defineConfig`.
|
|
166
|
+
*/
|
|
167
|
+
export const parserTs: Parser = defineParser({
|
|
168
|
+
name: 'typescript',
|
|
169
|
+
extNames: ['.ts', '.js'],
|
|
170
|
+
async parse(file, options = { extname: '.ts' }) {
|
|
171
|
+
const sourceParts: Array<string> = []
|
|
172
|
+
for (const item of file.sources) {
|
|
173
|
+
if (item.value) {
|
|
174
|
+
sourceParts.push(item.value)
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
const source = sourceParts.join('\n\n')
|
|
178
|
+
|
|
179
|
+
const importNodes: Array<ts.ImportDeclaration> = []
|
|
180
|
+
for (const item of (file as KubbFile.ResolvedFile).imports) {
|
|
181
|
+
const importPath = item.root ? getRelativePath(item.root, item.path) : item.path
|
|
182
|
+
const hasExtname = !!/\.[^/.]+$/.exec(importPath)
|
|
183
|
+
|
|
184
|
+
importNodes.push(
|
|
185
|
+
createImport({
|
|
186
|
+
name: item.name as string | Array<string | { propertyName: string; name?: string }>,
|
|
187
|
+
path: options?.extname && hasExtname ? `${trimExtName(importPath)}${options.extname}` : item.root ? trimExtName(importPath) : importPath,
|
|
188
|
+
isTypeOnly: item.isTypeOnly,
|
|
189
|
+
isNameSpace: item.isNameSpace,
|
|
190
|
+
}),
|
|
191
|
+
)
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const exportNodes: Array<ts.ExportDeclaration> = []
|
|
195
|
+
for (const item of (file as KubbFile.ResolvedFile).exports) {
|
|
196
|
+
const exportPath = item.path
|
|
197
|
+
const hasExtname = !!/\.[^/.]+$/.exec(exportPath)
|
|
198
|
+
|
|
199
|
+
exportNodes.push(
|
|
200
|
+
createExport({
|
|
201
|
+
name: item.name as string | Array<ts.Identifier | string> | undefined,
|
|
202
|
+
path: options?.extname && hasExtname ? `${trimExtName(item.path)}${options.extname}` : trimExtName(item.path),
|
|
203
|
+
isTypeOnly: item.isTypeOnly,
|
|
204
|
+
asAlias: item.asAlias,
|
|
205
|
+
}),
|
|
206
|
+
)
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const parts = [file.banner, print(...importNodes, ...exportNodes), source, file.footer].filter((segment): segment is string => segment != null)
|
|
210
|
+
return parts.join('\n')
|
|
211
|
+
},
|
|
212
|
+
})
|
package/src/parserTsx.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Parser } from '@kubb/core'
|
|
2
|
+
import { defineParser } from '@kubb/core'
|
|
3
|
+
import { parserTs } from './parserTs.ts'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Parser that converts `.tsx` and `.jsx` files to strings.
|
|
7
|
+
* Delegates to `typescriptParser` since the TypeScript compiler natively
|
|
8
|
+
* supports JSX/TSX syntax via `ScriptKind.TSX`.
|
|
9
|
+
*
|
|
10
|
+
* Add this parser to the `parsers` option in `defineConfig` when generating `.tsx`/`.jsx` files.
|
|
11
|
+
*
|
|
12
|
+
* @default extname '.tsx'
|
|
13
|
+
*/
|
|
14
|
+
export const parserTsx: Parser = defineParser({
|
|
15
|
+
name: 'tsx',
|
|
16
|
+
extNames: ['.tsx', '.jsx'],
|
|
17
|
+
async parse(file, options = { extname: '.tsx' }) {
|
|
18
|
+
return parserTs.parse(file, options)
|
|
19
|
+
},
|
|
20
|
+
})
|
package/README.md
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
<div align="center">
|
|
2
|
-
<h1>Parser TypeScript</h1>
|
|
3
|
-
<a href="https://kubb.dev" target="_blank" rel="noopener noreferrer">
|
|
4
|
-
<img width="180" src="https://raw.githubusercontent.com/kubb-labs/kubb/main/assets/logo.png" alt="Kubb logo">
|
|
5
|
-
</a>
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
[![npm version][npm-version-src]][npm-version-href]
|
|
9
|
-
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
10
|
-
[![Coverage][coverage-src]][coverage-href]
|
|
11
|
-
[![License][license-src]][license-href]
|
|
12
|
-
[![Sponsors][sponsors-src]][sponsors-href]
|
|
13
|
-
<h4>
|
|
14
|
-
<a href="https://codesandbox.io/s/github/kubb-labs/kubb/tree/main//examples/typescript" target="_blank">View Demo</a>
|
|
15
|
-
<span> · </span>
|
|
16
|
-
<a href="https://kubb.dev/" target="_blank">Documentation</a>
|
|
17
|
-
<span> · </span>
|
|
18
|
-
<a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Report Bug</a>
|
|
19
|
-
<span> · </span>
|
|
20
|
-
<a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Request Feature</a>
|
|
21
|
-
</h4>
|
|
22
|
-
</div>
|
|
23
|
-
|
|
24
|
-
Typescript Parser
|
|
25
|
-
|
|
26
|
-
## Supporting Kubb
|
|
27
|
-
|
|
28
|
-
Kubb uses an MIT-licensed open source project with its ongoing development made possible entirely by the support of Sponsors. If you would like to become a sponsor, please consider:
|
|
29
|
-
|
|
30
|
-
- [Become a Sponsor on GitHub](https://github.com/sponsors/stijnvanhulle)
|
|
31
|
-
|
|
32
|
-
<p align="center">
|
|
33
|
-
<a href="https://github.com/sponsors/stijnvanhulle">
|
|
34
|
-
<img src="https://raw.githubusercontent.com/stijnvanhulle/sponsors/main/sponsors.svg" alt="My sponsors" />
|
|
35
|
-
</a>
|
|
36
|
-
</p>
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
<!-- Badges -->
|
|
40
|
-
|
|
41
|
-
[npm-version-src]: https://img.shields.io/npm/v/@kubb/parser-ts?flat&colorA=18181B&colorB=f58517
|
|
42
|
-
[npm-version-href]: https://npmjs.com/package/@kubb/parser-ts
|
|
43
|
-
[npm-downloads-src]: https://img.shields.io/npm/dm/@kubb/parser-ts?flat&colorA=18181B&colorB=f58517
|
|
44
|
-
[npm-downloads-href]: https://npmjs.com/package/@kubb/parser-ts
|
|
45
|
-
[license-src]: https://img.shields.io/github/license/kubb-labs/kubb.svg?flat&colorA=18181B&colorB=f58517
|
|
46
|
-
[license-href]: https://github.com/kubb-labs/kubb/blob/main/LICENSE
|
|
47
|
-
[build-src]: https://img.shields.io/github/actions/workflow/status/kubb-labs/kubb/ci.yaml?style=flat&colorA=18181B&colorB=f58517
|
|
48
|
-
[build-href]: https://www.npmjs.com/package/@kubb/parser-ts
|
|
49
|
-
[minified-src]: https://img.shields.io/bundlephobia/min/@kubb/parser-ts?style=flat&colorA=18181B&colorB=f58517
|
|
50
|
-
[minified-href]: https://www.npmjs.com/package/@kubb/parser-ts
|
|
51
|
-
[coverage-src]: https://img.shields.io/codecov/c/github/kubb-labs/kubb?style=flat&colorA=18181B&colorB=f58517
|
|
52
|
-
[coverage-href]: https://www.npmjs.com/package/@kubb/parser-ts
|
|
53
|
-
[sponsors-src]: https://img.shields.io/github/sponsors/stijnvanhulle?style=flat&colorA=18181B&colorB=f58517
|
|
54
|
-
[sponsors-href]: https://github.com/sponsors/stijnvanhulle/
|
package/dist/chunk-CTAAG5j7.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
//#region rolldown:runtime
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __export = (all) => {
|
|
4
|
-
let target = {};
|
|
5
|
-
for (var name in all) __defProp(target, name, {
|
|
6
|
-
get: all[name],
|
|
7
|
-
enumerable: true
|
|
8
|
-
});
|
|
9
|
-
return target;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
//#endregion
|
|
13
|
-
export { __export };
|
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
//#region src/factory.d.ts
|
|
4
|
-
declare const modifiers: {
|
|
5
|
-
readonly async: ts.ModifierToken<ts.SyntaxKind.AsyncKeyword>;
|
|
6
|
-
readonly export: ts.ModifierToken<ts.SyntaxKind.ExportKeyword>;
|
|
7
|
-
readonly const: ts.ModifierToken<ts.SyntaxKind.ConstKeyword>;
|
|
8
|
-
readonly static: ts.ModifierToken<ts.SyntaxKind.StaticKeyword>;
|
|
9
|
-
};
|
|
10
|
-
declare const syntaxKind: {
|
|
11
|
-
readonly union: 192;
|
|
12
|
-
};
|
|
13
|
-
declare function createQuestionToken(token?: boolean | ts.QuestionToken): ts.PunctuationToken<ts.SyntaxKind.QuestionToken> | undefined;
|
|
14
|
-
declare function createIntersectionDeclaration({
|
|
15
|
-
nodes,
|
|
16
|
-
withParentheses
|
|
17
|
-
}: {
|
|
18
|
-
nodes: Array<ts.TypeNode>;
|
|
19
|
-
withParentheses?: boolean;
|
|
20
|
-
}): ts.TypeNode | null;
|
|
21
|
-
/**
|
|
22
|
-
* Minimum nodes length of 2
|
|
23
|
-
* @example `string & number`
|
|
24
|
-
*/
|
|
25
|
-
declare function createTupleDeclaration({
|
|
26
|
-
nodes,
|
|
27
|
-
withParentheses
|
|
28
|
-
}: {
|
|
29
|
-
nodes: Array<ts.TypeNode>;
|
|
30
|
-
withParentheses?: boolean;
|
|
31
|
-
}): ts.TypeNode | null;
|
|
32
|
-
declare function createArrayDeclaration({
|
|
33
|
-
nodes
|
|
34
|
-
}: {
|
|
35
|
-
nodes: Array<ts.TypeNode>;
|
|
36
|
-
}): ts.TypeNode | null;
|
|
37
|
-
/**
|
|
38
|
-
* Minimum nodes length of 2
|
|
39
|
-
* @example `string | number`
|
|
40
|
-
*/
|
|
41
|
-
declare function createUnionDeclaration({
|
|
42
|
-
nodes,
|
|
43
|
-
withParentheses
|
|
44
|
-
}: {
|
|
45
|
-
nodes: Array<ts.TypeNode>;
|
|
46
|
-
withParentheses?: boolean;
|
|
47
|
-
}): ts.TypeNode;
|
|
48
|
-
declare function createPropertySignature({
|
|
49
|
-
readOnly,
|
|
50
|
-
modifiers,
|
|
51
|
-
name,
|
|
52
|
-
questionToken,
|
|
53
|
-
type
|
|
54
|
-
}: {
|
|
55
|
-
readOnly?: boolean;
|
|
56
|
-
modifiers?: Array<ts.Modifier>;
|
|
57
|
-
name: ts.PropertyName | string;
|
|
58
|
-
questionToken?: ts.QuestionToken | boolean;
|
|
59
|
-
type?: ts.TypeNode;
|
|
60
|
-
}): ts.PropertySignature;
|
|
61
|
-
declare function createParameterSignature(name: string | ts.BindingName, {
|
|
62
|
-
modifiers,
|
|
63
|
-
dotDotDotToken,
|
|
64
|
-
questionToken,
|
|
65
|
-
type,
|
|
66
|
-
initializer
|
|
67
|
-
}: {
|
|
68
|
-
decorators?: Array<ts.Decorator>;
|
|
69
|
-
modifiers?: Array<ts.Modifier>;
|
|
70
|
-
dotDotDotToken?: ts.DotDotDotToken;
|
|
71
|
-
questionToken?: ts.QuestionToken | boolean;
|
|
72
|
-
type?: ts.TypeNode;
|
|
73
|
-
initializer?: ts.Expression;
|
|
74
|
-
}): ts.ParameterDeclaration;
|
|
75
|
-
declare function createJSDoc({
|
|
76
|
-
comments
|
|
77
|
-
}: {
|
|
78
|
-
comments: string[];
|
|
79
|
-
}): ts.JSDoc | null;
|
|
80
|
-
/**
|
|
81
|
-
* @link https://github.com/microsoft/TypeScript/issues/44151
|
|
82
|
-
*/
|
|
83
|
-
declare function appendJSDocToNode<TNode extends ts.Node>({
|
|
84
|
-
node,
|
|
85
|
-
comments
|
|
86
|
-
}: {
|
|
87
|
-
node: TNode;
|
|
88
|
-
comments: Array<string | undefined>;
|
|
89
|
-
}): TNode;
|
|
90
|
-
declare function createIndexSignature(type: ts.TypeNode, {
|
|
91
|
-
modifiers,
|
|
92
|
-
indexName,
|
|
93
|
-
indexType
|
|
94
|
-
}?: {
|
|
95
|
-
indexName?: string;
|
|
96
|
-
indexType?: ts.TypeNode;
|
|
97
|
-
decorators?: Array<ts.Decorator>;
|
|
98
|
-
modifiers?: Array<ts.Modifier>;
|
|
99
|
-
}): ts.IndexSignatureDeclaration;
|
|
100
|
-
declare function createTypeAliasDeclaration({
|
|
101
|
-
modifiers,
|
|
102
|
-
name,
|
|
103
|
-
typeParameters,
|
|
104
|
-
type
|
|
105
|
-
}: {
|
|
106
|
-
modifiers?: Array<ts.Modifier>;
|
|
107
|
-
name: string | ts.Identifier;
|
|
108
|
-
typeParameters?: Array<ts.TypeParameterDeclaration>;
|
|
109
|
-
type: ts.TypeNode;
|
|
110
|
-
}): ts.TypeAliasDeclaration;
|
|
111
|
-
declare function createInterfaceDeclaration({
|
|
112
|
-
modifiers,
|
|
113
|
-
name,
|
|
114
|
-
typeParameters,
|
|
115
|
-
members
|
|
116
|
-
}: {
|
|
117
|
-
modifiers?: Array<ts.Modifier>;
|
|
118
|
-
name: string | ts.Identifier;
|
|
119
|
-
typeParameters?: Array<ts.TypeParameterDeclaration>;
|
|
120
|
-
members: Array<ts.TypeElement>;
|
|
121
|
-
}): ts.InterfaceDeclaration;
|
|
122
|
-
declare function createTypeDeclaration({
|
|
123
|
-
syntax,
|
|
124
|
-
isExportable,
|
|
125
|
-
comments,
|
|
126
|
-
name,
|
|
127
|
-
type
|
|
128
|
-
}: {
|
|
129
|
-
syntax: 'type' | 'interface';
|
|
130
|
-
comments: Array<string | undefined>;
|
|
131
|
-
isExportable?: boolean;
|
|
132
|
-
name: string | ts.Identifier;
|
|
133
|
-
type: ts.TypeNode;
|
|
134
|
-
}): ts.TypeAliasDeclaration | ts.InterfaceDeclaration;
|
|
135
|
-
declare function createNamespaceDeclaration({
|
|
136
|
-
statements,
|
|
137
|
-
name
|
|
138
|
-
}: {
|
|
139
|
-
name: string;
|
|
140
|
-
statements: ts.Statement[];
|
|
141
|
-
}): ts.ModuleDeclaration;
|
|
142
|
-
/**
|
|
143
|
-
* In { propertyName: string; name?: string } is `name` being used to make the type more unique when multiple same names are used.
|
|
144
|
-
* @example `import { Pet as Cat } from './Pet'`
|
|
145
|
-
*/
|
|
146
|
-
declare function createImportDeclaration({
|
|
147
|
-
name,
|
|
148
|
-
path,
|
|
149
|
-
isTypeOnly,
|
|
150
|
-
isNameSpace
|
|
151
|
-
}: {
|
|
152
|
-
name: string | Array<string | {
|
|
153
|
-
propertyName: string;
|
|
154
|
-
name?: string;
|
|
155
|
-
}>;
|
|
156
|
-
path: string;
|
|
157
|
-
isTypeOnly?: boolean;
|
|
158
|
-
isNameSpace?: boolean;
|
|
159
|
-
}): ts.ImportDeclaration;
|
|
160
|
-
declare function createExportDeclaration({
|
|
161
|
-
path,
|
|
162
|
-
asAlias,
|
|
163
|
-
isTypeOnly,
|
|
164
|
-
name
|
|
165
|
-
}: {
|
|
166
|
-
path: string;
|
|
167
|
-
asAlias?: boolean;
|
|
168
|
-
isTypeOnly?: boolean;
|
|
169
|
-
name?: string | Array<ts.Identifier | string>;
|
|
170
|
-
}): ts.ExportDeclaration;
|
|
171
|
-
declare function createEnumDeclaration({
|
|
172
|
-
type,
|
|
173
|
-
name,
|
|
174
|
-
typeName,
|
|
175
|
-
enums
|
|
176
|
-
}: {
|
|
177
|
-
/**
|
|
178
|
-
* @default `'enum'`
|
|
179
|
-
*/
|
|
180
|
-
type?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal';
|
|
181
|
-
/**
|
|
182
|
-
* Enum name in camelCase.
|
|
183
|
-
*/
|
|
184
|
-
name: string;
|
|
185
|
-
/**
|
|
186
|
-
* Enum name in PascalCase.
|
|
187
|
-
*/
|
|
188
|
-
typeName: string;
|
|
189
|
-
enums: [key: string | number, value: string | number | boolean][];
|
|
190
|
-
}): [name: ts.Node | undefined, type: ts.Node];
|
|
191
|
-
declare function createOmitDeclaration({
|
|
192
|
-
keys,
|
|
193
|
-
type,
|
|
194
|
-
nonNullable
|
|
195
|
-
}: {
|
|
196
|
-
keys: Array<string> | string;
|
|
197
|
-
type: ts.TypeNode;
|
|
198
|
-
nonNullable?: boolean;
|
|
199
|
-
}): ts.TypeReferenceNode;
|
|
200
|
-
declare const keywordTypeNodes: {
|
|
201
|
-
readonly any: ts.KeywordTypeNode<ts.SyntaxKind.AnyKeyword>;
|
|
202
|
-
readonly unknown: ts.KeywordTypeNode<ts.SyntaxKind.UnknownKeyword>;
|
|
203
|
-
readonly void: ts.KeywordTypeNode<ts.SyntaxKind.VoidKeyword>;
|
|
204
|
-
readonly number: ts.KeywordTypeNode<ts.SyntaxKind.NumberKeyword>;
|
|
205
|
-
readonly integer: ts.KeywordTypeNode<ts.SyntaxKind.NumberKeyword>;
|
|
206
|
-
readonly object: ts.KeywordTypeNode<ts.SyntaxKind.ObjectKeyword>;
|
|
207
|
-
readonly string: ts.KeywordTypeNode<ts.SyntaxKind.StringKeyword>;
|
|
208
|
-
readonly boolean: ts.KeywordTypeNode<ts.SyntaxKind.BooleanKeyword>;
|
|
209
|
-
readonly undefined: ts.KeywordTypeNode<ts.SyntaxKind.UndefinedKeyword>;
|
|
210
|
-
readonly null: ts.LiteralTypeNode;
|
|
211
|
-
};
|
|
212
|
-
declare const createTypeLiteralNode: (members: readonly ts.TypeElement[] | undefined) => ts.TypeLiteralNode;
|
|
213
|
-
declare const createTypeReferenceNode: (typeName: string | ts.EntityName, typeArguments?: readonly ts.TypeNode[]) => ts.TypeReferenceNode;
|
|
214
|
-
declare const createNumericLiteral: (value: string | number, numericLiteralFlags?: ts.TokenFlags) => ts.NumericLiteral;
|
|
215
|
-
declare const createStringLiteral: (text: string, isSingleQuote?: boolean) => ts.StringLiteral;
|
|
216
|
-
declare const createArrayTypeNode: (elementType: ts.TypeNode) => ts.ArrayTypeNode;
|
|
217
|
-
declare const createLiteralTypeNode: (literal: ts.LiteralTypeNode["literal"]) => ts.LiteralTypeNode;
|
|
218
|
-
declare const createNull: () => ts.NullLiteral;
|
|
219
|
-
declare const createIdentifier: (text: string) => ts.Identifier;
|
|
220
|
-
declare const createOptionalTypeNode: (type: ts.TypeNode) => ts.OptionalTypeNode;
|
|
221
|
-
declare const createTupleTypeNode: (elements: readonly (ts.TypeNode | ts.NamedTupleMember)[]) => ts.TupleTypeNode;
|
|
222
|
-
declare const createRestTypeNode: (type: ts.TypeNode) => ts.RestTypeNode;
|
|
223
|
-
declare const createTrue: () => ts.TrueLiteral;
|
|
224
|
-
declare const createFalse: () => ts.FalseLiteral;
|
|
225
|
-
//#endregion
|
|
226
|
-
export { appendJSDocToNode, createArrayDeclaration, createArrayTypeNode, createEnumDeclaration, createExportDeclaration, createFalse, createIdentifier, createImportDeclaration, createIndexSignature, createInterfaceDeclaration, createIntersectionDeclaration, createJSDoc, createLiteralTypeNode, createNamespaceDeclaration, createNull, createNumericLiteral, createOmitDeclaration, createOptionalTypeNode, createParameterSignature, createPropertySignature, createQuestionToken, createRestTypeNode, createStringLiteral, createTrue, createTupleDeclaration, createTupleTypeNode, createTypeAliasDeclaration, createTypeDeclaration, createTypeLiteralNode, createTypeReferenceNode, createUnionDeclaration, factory_d_exports, keywordTypeNodes, modifiers, syntaxKind };
|
|
227
|
-
//# sourceMappingURL=factory-BJCGLhSr.d.ts.map
|