@kubb/parser-ts 2.18.0

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.
@@ -0,0 +1,453 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ // src/factory.ts
8
+ var factory_exports = {};
9
+ __export(factory_exports, {
10
+ appendJSDocToNode: () => appendJSDocToNode,
11
+ createArrayDeclaration: () => createArrayDeclaration,
12
+ createArrayTypeNode: () => createArrayTypeNode,
13
+ createEnumDeclaration: () => createEnumDeclaration,
14
+ createExportDeclaration: () => createExportDeclaration,
15
+ createIdentifier: () => createIdentifier,
16
+ createImportDeclaration: () => createImportDeclaration,
17
+ createIndexSignature: () => createIndexSignature,
18
+ createIntersectionDeclaration: () => createIntersectionDeclaration,
19
+ createJSDoc: () => createJSDoc,
20
+ createLiteralTypeNode: () => createLiteralTypeNode,
21
+ createNamespaceDeclaration: () => createNamespaceDeclaration,
22
+ createNull: () => createNull,
23
+ createNumericLiteral: () => createNumericLiteral,
24
+ createOmitDeclaration: () => createOmitDeclaration,
25
+ createParameterSignature: () => createParameterSignature,
26
+ createPropertySignature: () => createPropertySignature,
27
+ createQuestionToken: () => createQuestionToken,
28
+ createStringLiteral: () => createStringLiteral,
29
+ createTupleDeclaration: () => createTupleDeclaration,
30
+ createTupleTypeNode: () => createTupleTypeNode,
31
+ createTypeAliasDeclaration: () => createTypeAliasDeclaration,
32
+ createTypeLiteralNode: () => createTypeLiteralNode,
33
+ createTypeReferenceNode: () => createTypeReferenceNode,
34
+ createUnionDeclaration: () => createUnionDeclaration,
35
+ keywordTypeNodes: () => keywordTypeNodes,
36
+ modifiers: () => modifiers
37
+ });
38
+ var _remeda = require('remeda');
39
+ var _typescript = require('typescript'); var _typescript2 = _interopRequireDefault(_typescript);
40
+ var { factory } = _typescript2.default;
41
+ var modifiers = {
42
+ async: factory.createModifier(_typescript2.default.SyntaxKind.AsyncKeyword),
43
+ export: factory.createModifier(_typescript2.default.SyntaxKind.ExportKeyword),
44
+ const: factory.createModifier(_typescript2.default.SyntaxKind.ConstKeyword),
45
+ static: factory.createModifier(_typescript2.default.SyntaxKind.StaticKeyword)
46
+ };
47
+ function isValidIdentifier(str) {
48
+ if (!str.length || str.trim() !== str) {
49
+ return false;
50
+ }
51
+ const node = _typescript2.default.parseIsolatedEntityName(str, _typescript2.default.ScriptTarget.Latest);
52
+ return !!node && node.kind === _typescript2.default.SyntaxKind.Identifier && _typescript2.default.identifierToKeywordKind(node.kind) === void 0;
53
+ }
54
+ function propertyName(name) {
55
+ if (typeof name === "string") {
56
+ return isValidIdentifier(name) ? factory.createIdentifier(name) : factory.createStringLiteral(name);
57
+ }
58
+ return name;
59
+ }
60
+ var questionToken = factory.createToken(_typescript2.default.SyntaxKind.QuestionToken);
61
+ function createQuestionToken(token) {
62
+ if (!token) {
63
+ return void 0;
64
+ }
65
+ if (token === true) {
66
+ return questionToken;
67
+ }
68
+ return token;
69
+ }
70
+ function createIntersectionDeclaration({
71
+ nodes,
72
+ withParentheses
73
+ }) {
74
+ if (!nodes.length) {
75
+ return null;
76
+ }
77
+ if (nodes.length === 1) {
78
+ return nodes[0] || null;
79
+ }
80
+ const node = factory.createIntersectionTypeNode(nodes);
81
+ if (withParentheses) {
82
+ return factory.createParenthesizedType(node);
83
+ }
84
+ return node;
85
+ }
86
+ function createTupleDeclaration({
87
+ nodes,
88
+ withParentheses
89
+ }) {
90
+ if (!nodes.length) {
91
+ return null;
92
+ }
93
+ if (nodes.length === 1) {
94
+ return nodes[0] || null;
95
+ }
96
+ const node = factory.createTupleTypeNode(nodes);
97
+ if (withParentheses) {
98
+ return factory.createParenthesizedType(node);
99
+ }
100
+ return node;
101
+ }
102
+ function createArrayDeclaration({
103
+ nodes
104
+ }) {
105
+ if (!nodes.length) {
106
+ return factory.createTupleTypeNode([]);
107
+ }
108
+ if (nodes.length === 1) {
109
+ return factory.createArrayTypeNode(nodes.at(0));
110
+ }
111
+ return factory.createExpressionWithTypeArguments(factory.createIdentifier("Array"), [factory.createUnionTypeNode(nodes)]);
112
+ }
113
+ function createUnionDeclaration({
114
+ nodes,
115
+ withParentheses
116
+ }) {
117
+ if (!nodes.length) {
118
+ return null;
119
+ }
120
+ if (nodes.length === 1) {
121
+ return nodes[0] || null;
122
+ }
123
+ const node = factory.createUnionTypeNode(nodes);
124
+ if (withParentheses) {
125
+ return factory.createParenthesizedType(node);
126
+ }
127
+ return node;
128
+ }
129
+ function createPropertySignature({
130
+ readOnly,
131
+ modifiers: modifiers2 = [],
132
+ name,
133
+ questionToken: questionToken2,
134
+ type
135
+ }) {
136
+ return factory.createPropertySignature(
137
+ [...modifiers2, readOnly ? factory.createToken(_typescript2.default.SyntaxKind.ReadonlyKeyword) : void 0].filter(Boolean),
138
+ propertyName(name),
139
+ createQuestionToken(questionToken2),
140
+ type
141
+ );
142
+ }
143
+ function createParameterSignature(name, {
144
+ modifiers: modifiers2,
145
+ dotDotDotToken,
146
+ questionToken: questionToken2,
147
+ type,
148
+ initializer
149
+ }) {
150
+ return factory.createParameterDeclaration(modifiers2, dotDotDotToken, name, createQuestionToken(questionToken2), type, initializer);
151
+ }
152
+ function createJSDoc({ comments }) {
153
+ if (!comments.length) {
154
+ return null;
155
+ }
156
+ return factory.createJSDocComment(
157
+ factory.createNodeArray(
158
+ comments.map((comment, i) => {
159
+ if (i === comments.length - 1) {
160
+ return factory.createJSDocText(comment);
161
+ }
162
+ return factory.createJSDocText(`${comment}
163
+ `);
164
+ })
165
+ )
166
+ );
167
+ }
168
+ function appendJSDocToNode({
169
+ node,
170
+ comments
171
+ }) {
172
+ const filteredComments = comments.filter(Boolean);
173
+ if (!filteredComments.length) {
174
+ return node;
175
+ }
176
+ const text = filteredComments.reduce((acc = "", comment = "") => {
177
+ return `${acc}
178
+ * ${comment}`;
179
+ }, "*");
180
+ return _typescript2.default.addSyntheticLeadingComment({ ...node }, _typescript2.default.SyntaxKind.MultiLineCommentTrivia, `${text || "*"}
181
+ `, true);
182
+ }
183
+ function createIndexSignature(type, {
184
+ modifiers: modifiers2,
185
+ indexName = "key",
186
+ indexType = factory.createKeywordTypeNode(_typescript2.default.SyntaxKind.StringKeyword)
187
+ } = {}) {
188
+ return factory.createIndexSignature(modifiers2, [createParameterSignature(indexName, { type: indexType })], type);
189
+ }
190
+ function createTypeAliasDeclaration({
191
+ modifiers: modifiers2,
192
+ name,
193
+ typeParameters,
194
+ type
195
+ }) {
196
+ return factory.createTypeAliasDeclaration(modifiers2, name, typeParameters, type);
197
+ }
198
+ function createNamespaceDeclaration({
199
+ statements,
200
+ name
201
+ }) {
202
+ return factory.createModuleDeclaration(
203
+ [factory.createToken(_typescript2.default.SyntaxKind.ExportKeyword)],
204
+ factory.createIdentifier(name),
205
+ factory.createModuleBlock(statements),
206
+ _typescript2.default.NodeFlags.Namespace
207
+ );
208
+ }
209
+ function createImportDeclaration({
210
+ name,
211
+ path,
212
+ isTypeOnly = false,
213
+ isNameSpace = false
214
+ }) {
215
+ if (!Array.isArray(name)) {
216
+ let importPropertyName = factory.createIdentifier(name);
217
+ let importName = void 0;
218
+ if (isNameSpace) {
219
+ importPropertyName = void 0;
220
+ importName = factory.createNamespaceImport(factory.createIdentifier(name));
221
+ }
222
+ return factory.createImportDeclaration(
223
+ void 0,
224
+ factory.createImportClause(isTypeOnly, importPropertyName, importName),
225
+ factory.createStringLiteral(path),
226
+ void 0
227
+ );
228
+ }
229
+ return factory.createImportDeclaration(
230
+ void 0,
231
+ factory.createImportClause(
232
+ isTypeOnly,
233
+ void 0,
234
+ factory.createNamedImports(
235
+ name.map((item) => {
236
+ if (typeof item === "object") {
237
+ const obj = item;
238
+ if (obj.name) {
239
+ return factory.createImportSpecifier(false, factory.createIdentifier(obj.propertyName), factory.createIdentifier(obj.name));
240
+ }
241
+ return factory.createImportSpecifier(false, void 0, factory.createIdentifier(obj.propertyName));
242
+ }
243
+ return factory.createImportSpecifier(false, void 0, factory.createIdentifier(item));
244
+ })
245
+ )
246
+ ),
247
+ factory.createStringLiteral(path),
248
+ void 0
249
+ );
250
+ }
251
+ function createExportDeclaration({
252
+ path,
253
+ asAlias,
254
+ isTypeOnly = false,
255
+ name
256
+ }) {
257
+ if (name && !Array.isArray(name) && !asAlias) {
258
+ throw new Error("When using `name` as string, `asAlias` should be true");
259
+ }
260
+ if (!Array.isArray(name)) {
261
+ const parsedName = _optionalChain([name, 'optionalAccess', _ => _.match, 'call', _2 => _2(/^\d/)]) ? `_${_optionalChain([name, 'optionalAccess', _3 => _3.slice, 'call', _4 => _4(1)])}` : name;
262
+ return factory.createExportDeclaration(
263
+ void 0,
264
+ isTypeOnly,
265
+ asAlias && parsedName ? factory.createNamespaceExport(factory.createIdentifier(parsedName)) : void 0,
266
+ factory.createStringLiteral(path),
267
+ void 0
268
+ );
269
+ }
270
+ return factory.createExportDeclaration(
271
+ void 0,
272
+ isTypeOnly,
273
+ factory.createNamedExports(
274
+ name.map((propertyName2) => {
275
+ return factory.createExportSpecifier(false, void 0, typeof propertyName2 === "string" ? factory.createIdentifier(propertyName2) : propertyName2);
276
+ })
277
+ ),
278
+ factory.createStringLiteral(path),
279
+ void 0
280
+ );
281
+ }
282
+ function createEnumDeclaration({
283
+ type = "enum",
284
+ name,
285
+ typeName,
286
+ enums
287
+ }) {
288
+ if (type === "literal") {
289
+ return [
290
+ factory.createTypeAliasDeclaration(
291
+ [factory.createToken(_typescript2.default.SyntaxKind.ExportKeyword)],
292
+ factory.createIdentifier(typeName),
293
+ void 0,
294
+ factory.createUnionTypeNode(
295
+ enums.map(([_key, value]) => {
296
+ if (_remeda.isNumber.call(void 0, value)) {
297
+ return factory.createLiteralTypeNode(factory.createNumericLiteral(_optionalChain([value, 'optionalAccess', _5 => _5.toString, 'call', _6 => _6()])));
298
+ }
299
+ if (typeof value === "boolean") {
300
+ return factory.createLiteralTypeNode(value ? factory.createTrue() : factory.createFalse());
301
+ }
302
+ if (value) {
303
+ return factory.createLiteralTypeNode(factory.createStringLiteral(value.toString()));
304
+ }
305
+ return void 0;
306
+ }).filter(Boolean)
307
+ )
308
+ )
309
+ ];
310
+ }
311
+ if (type === "enum" || type === "constEnum") {
312
+ return [
313
+ factory.createEnumDeclaration(
314
+ [factory.createToken(_typescript2.default.SyntaxKind.ExportKeyword), type === "constEnum" ? factory.createToken(_typescript2.default.SyntaxKind.ConstKeyword) : void 0].filter(Boolean),
315
+ factory.createIdentifier(typeName),
316
+ enums.map(([key, value]) => {
317
+ let initializer = factory.createStringLiteral(_optionalChain([value, 'optionalAccess', _7 => _7.toString, 'call', _8 => _8()]));
318
+ if (_remeda.isNumber.call(void 0, Number.parseInt(value.toString()))) {
319
+ initializer = factory.createNumericLiteral(value);
320
+ }
321
+ if (typeof value === "boolean") {
322
+ initializer = value ? factory.createTrue() : factory.createFalse();
323
+ }
324
+ if (_remeda.isNumber.call(void 0, Number.parseInt(key.toString()))) {
325
+ return factory.createEnumMember(factory.createStringLiteral(`${typeName}_${key}`), initializer);
326
+ }
327
+ if (key) {
328
+ return factory.createEnumMember(factory.createStringLiteral(`${key}`), initializer);
329
+ }
330
+ return void 0;
331
+ }).filter(Boolean)
332
+ )
333
+ ];
334
+ }
335
+ const identifierName = type === "asPascalConst" ? typeName : name;
336
+ return [
337
+ factory.createVariableStatement(
338
+ [factory.createToken(_typescript2.default.SyntaxKind.ExportKeyword)],
339
+ factory.createVariableDeclarationList(
340
+ [
341
+ factory.createVariableDeclaration(
342
+ factory.createIdentifier(identifierName),
343
+ void 0,
344
+ void 0,
345
+ factory.createAsExpression(
346
+ factory.createObjectLiteralExpression(
347
+ enums.map(([key, value]) => {
348
+ let initializer = factory.createStringLiteral(`${_optionalChain([value, 'optionalAccess', _9 => _9.toString, 'call', _10 => _10()])}`);
349
+ if (_remeda.isNumber.call(void 0, value)) {
350
+ if (value < 0) {
351
+ initializer = factory.createPrefixUnaryExpression(_typescript2.default.SyntaxKind.MinusToken, factory.createNumericLiteral(Math.abs(value)));
352
+ } else {
353
+ initializer = factory.createNumericLiteral(value);
354
+ }
355
+ }
356
+ if (typeof value === "boolean") {
357
+ initializer = value ? factory.createTrue() : factory.createFalse();
358
+ }
359
+ if (key) {
360
+ return factory.createPropertyAssignment(factory.createStringLiteral(`${key}`), initializer);
361
+ }
362
+ return void 0;
363
+ }).filter(Boolean),
364
+ true
365
+ ),
366
+ factory.createTypeReferenceNode(factory.createIdentifier("const"), void 0)
367
+ )
368
+ )
369
+ ],
370
+ _typescript2.default.NodeFlags.Const
371
+ )
372
+ ),
373
+ factory.createTypeAliasDeclaration(
374
+ [factory.createToken(_typescript2.default.SyntaxKind.ExportKeyword)],
375
+ factory.createIdentifier(typeName),
376
+ void 0,
377
+ factory.createIndexedAccessTypeNode(
378
+ factory.createParenthesizedType(factory.createTypeQueryNode(factory.createIdentifier(identifierName), void 0)),
379
+ factory.createTypeOperatorNode(_typescript2.default.SyntaxKind.KeyOfKeyword, factory.createTypeQueryNode(factory.createIdentifier(identifierName), void 0))
380
+ )
381
+ )
382
+ ];
383
+ }
384
+ function createOmitDeclaration({
385
+ keys,
386
+ type,
387
+ nonNullable
388
+ }) {
389
+ const node = nonNullable ? factory.createTypeReferenceNode(factory.createIdentifier("NonNullable"), [type]) : type;
390
+ if (Array.isArray(keys)) {
391
+ return factory.createTypeReferenceNode(factory.createIdentifier("Omit"), [
392
+ node,
393
+ factory.createUnionTypeNode(
394
+ keys.map((key) => {
395
+ return factory.createLiteralTypeNode(factory.createStringLiteral(key));
396
+ })
397
+ )
398
+ ]);
399
+ }
400
+ return factory.createTypeReferenceNode(factory.createIdentifier("Omit"), [node, factory.createLiteralTypeNode(factory.createStringLiteral(keys))]);
401
+ }
402
+ var keywordTypeNodes = {
403
+ any: factory.createKeywordTypeNode(_typescript2.default.SyntaxKind.AnyKeyword),
404
+ unknown: factory.createKeywordTypeNode(_typescript2.default.SyntaxKind.UnknownKeyword),
405
+ number: factory.createKeywordTypeNode(_typescript2.default.SyntaxKind.NumberKeyword),
406
+ integer: factory.createKeywordTypeNode(_typescript2.default.SyntaxKind.NumberKeyword),
407
+ object: factory.createKeywordTypeNode(_typescript2.default.SyntaxKind.ObjectKeyword),
408
+ string: factory.createKeywordTypeNode(_typescript2.default.SyntaxKind.StringKeyword),
409
+ boolean: factory.createKeywordTypeNode(_typescript2.default.SyntaxKind.BooleanKeyword),
410
+ undefined: factory.createKeywordTypeNode(_typescript2.default.SyntaxKind.UndefinedKeyword),
411
+ null: factory.createLiteralTypeNode(factory.createToken(_typescript2.default.SyntaxKind.NullKeyword))
412
+ };
413
+ var createTypeLiteralNode = factory.createTypeLiteralNode;
414
+ var createTypeReferenceNode = factory.createTypeReferenceNode;
415
+ var createNumericLiteral = factory.createNumericLiteral;
416
+ var createStringLiteral = factory.createStringLiteral;
417
+ var createArrayTypeNode = factory.createArrayTypeNode;
418
+ var createLiteralTypeNode = factory.createLiteralTypeNode;
419
+ var createNull = factory.createNull;
420
+ var createIdentifier = factory.createIdentifier;
421
+ var createTupleTypeNode = factory.createTupleTypeNode;
422
+
423
+
424
+
425
+
426
+
427
+
428
+
429
+
430
+
431
+
432
+
433
+
434
+
435
+
436
+
437
+
438
+
439
+
440
+
441
+
442
+
443
+
444
+
445
+
446
+
447
+
448
+
449
+
450
+
451
+
452
+ exports.modifiers = modifiers; exports.createQuestionToken = createQuestionToken; exports.createIntersectionDeclaration = createIntersectionDeclaration; exports.createTupleDeclaration = createTupleDeclaration; exports.createArrayDeclaration = createArrayDeclaration; exports.createUnionDeclaration = createUnionDeclaration; exports.createPropertySignature = createPropertySignature; exports.createParameterSignature = createParameterSignature; exports.createJSDoc = createJSDoc; exports.appendJSDocToNode = appendJSDocToNode; exports.createIndexSignature = createIndexSignature; exports.createTypeAliasDeclaration = createTypeAliasDeclaration; exports.createNamespaceDeclaration = createNamespaceDeclaration; exports.createImportDeclaration = createImportDeclaration; exports.createExportDeclaration = createExportDeclaration; exports.createEnumDeclaration = createEnumDeclaration; exports.createOmitDeclaration = createOmitDeclaration; exports.keywordTypeNodes = keywordTypeNodes; exports.createTypeLiteralNode = createTypeLiteralNode; exports.createTypeReferenceNode = createTypeReferenceNode; exports.createNumericLiteral = createNumericLiteral; exports.createStringLiteral = createStringLiteral; exports.createArrayTypeNode = createArrayTypeNode; exports.createLiteralTypeNode = createLiteralTypeNode; exports.createNull = createNull; exports.createIdentifier = createIdentifier; exports.createTupleTypeNode = createTupleTypeNode; exports.factory_exports = factory_exports;
453
+ //# sourceMappingURL=chunk-SCIDO3JK.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/factory.ts"],"names":["modifiers","questionToken","propertyName"],"mappings":";;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,SAAS,gBAAgB;AACzB,OAAO,QAAQ;AAEf,IAAM,EAAE,QAAQ,IAAI;AAIb,IAAM,YAAY;AAAA,EACvB,OAAO,QAAQ,eAAe,GAAG,WAAW,YAAY;AAAA,EACxD,QAAQ,QAAQ,eAAe,GAAG,WAAW,aAAa;AAAA,EAC1D,OAAO,QAAQ,eAAe,GAAG,WAAW,YAAY;AAAA,EACxD,QAAQ,QAAQ,eAAe,GAAG,WAAW,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","sourcesContent":["import { isNumber } from 'remeda'\nimport ts from 'typescript'\n\nconst { factory } = ts\n\n// https://ts-ast-viewer.com/\n\nexport const modifiers = {\n async: factory.createModifier(ts.SyntaxKind.AsyncKeyword),\n export: factory.createModifier(ts.SyntaxKind.ExportKeyword),\n const: factory.createModifier(ts.SyntaxKind.ConstKeyword),\n static: factory.createModifier(ts.SyntaxKind.StaticKeyword),\n} as const\n\nfunction isValidIdentifier(str: string): boolean {\n if (!str.length || str.trim() !== str) {\n return false\n }\n const node = ts.parseIsolatedEntityName(str, ts.ScriptTarget.Latest)\n\n return !!node && node.kind === ts.SyntaxKind.Identifier && ts.identifierToKeywordKind(node.kind as unknown as ts.Identifier) === undefined\n}\n\nfunction propertyName(name: string | ts.PropertyName): ts.PropertyName {\n if (typeof name === 'string') {\n return isValidIdentifier(name) ? factory.createIdentifier(name) : factory.createStringLiteral(name)\n }\n return name\n}\n\nconst questionToken = factory.createToken(ts.SyntaxKind.QuestionToken)\n\nexport function createQuestionToken(token?: boolean | ts.QuestionToken) {\n if (!token) {\n return undefined\n }\n if (token === true) {\n return questionToken\n }\n return token\n}\n\nexport function createIntersectionDeclaration({\n nodes,\n withParentheses,\n}: {\n nodes: Array<ts.TypeNode>\n withParentheses?: boolean\n}): ts.TypeNode | null {\n if (!nodes.length) {\n return null\n }\n\n if (nodes.length === 1) {\n return nodes[0] || null\n }\n\n const node = factory.createIntersectionTypeNode(nodes)\n\n if (withParentheses) {\n return factory.createParenthesizedType(node)\n }\n\n return node\n}\n\n/**\n * Minimum nodes length of 2\n * @example `string & number`\n */\nexport function createTupleDeclaration({\n nodes,\n withParentheses,\n}: {\n nodes: Array<ts.TypeNode>\n withParentheses?: boolean\n}): ts.TypeNode | null {\n if (!nodes.length) {\n return null\n }\n\n if (nodes.length === 1) {\n return nodes[0] || null\n }\n\n const node = factory.createTupleTypeNode(nodes)\n\n if (withParentheses) {\n return factory.createParenthesizedType(node)\n }\n\n return node\n}\n\nexport function createArrayDeclaration({\n nodes,\n}: {\n nodes: Array<ts.TypeNode>\n}): ts.TypeNode | null {\n if (!nodes.length) {\n return factory.createTupleTypeNode([])\n }\n\n if (nodes.length === 1) {\n return factory.createArrayTypeNode(nodes.at(0)!)\n }\n\n return factory.createExpressionWithTypeArguments(factory.createIdentifier('Array'), [factory.createUnionTypeNode(nodes)])\n}\n\n/**\n * Minimum nodes length of 2\n * @example `string | number`\n */\nexport function createUnionDeclaration({\n nodes,\n withParentheses,\n}: {\n nodes: Array<ts.TypeNode>\n withParentheses?: boolean\n}): ts.TypeNode | null {\n if (!nodes.length) {\n return null\n }\n\n if (nodes.length === 1) {\n return nodes[0] || null\n }\n\n const node = factory.createUnionTypeNode(nodes)\n\n if (withParentheses) {\n return factory.createParenthesizedType(node)\n }\n\n return node\n}\n\nexport function createPropertySignature({\n readOnly,\n modifiers = [],\n name,\n questionToken,\n type,\n}: {\n readOnly?: boolean\n modifiers?: Array<ts.Modifier>\n name: ts.PropertyName | string\n questionToken?: ts.QuestionToken | boolean\n type?: ts.TypeNode\n}) {\n return factory.createPropertySignature(\n [...modifiers, readOnly ? factory.createToken(ts.SyntaxKind.ReadonlyKeyword) : undefined].filter(Boolean),\n propertyName(name),\n createQuestionToken(questionToken),\n type,\n )\n}\n\nexport function createParameterSignature(\n name: string | ts.BindingName,\n {\n modifiers,\n dotDotDotToken,\n questionToken,\n type,\n initializer,\n }: {\n decorators?: Array<ts.Decorator>\n modifiers?: Array<ts.Modifier>\n dotDotDotToken?: ts.DotDotDotToken\n questionToken?: ts.QuestionToken | boolean\n type?: ts.TypeNode\n initializer?: ts.Expression\n },\n): ts.ParameterDeclaration {\n return factory.createParameterDeclaration(modifiers, dotDotDotToken, name, createQuestionToken(questionToken), type, initializer)\n}\n\nexport function createJSDoc({ comments }: { comments: string[] }) {\n if (!comments.length) {\n return null\n }\n return factory.createJSDocComment(\n factory.createNodeArray(\n comments.map((comment, i) => {\n if (i === comments.length - 1) {\n return factory.createJSDocText(comment)\n }\n\n return factory.createJSDocText(`${comment}\\n`)\n }),\n ),\n )\n}\n\n/**\n * @link https://github.com/microsoft/TypeScript/issues/44151\n */\nexport function appendJSDocToNode<TNode extends ts.Node>({\n node,\n comments,\n}: {\n node: TNode\n comments: Array<string | undefined>\n}) {\n const filteredComments = comments.filter(Boolean)\n\n if (!filteredComments.length) {\n return node\n }\n\n const text = filteredComments.reduce((acc = '', comment = '') => {\n return `${acc}\\n * ${comment}`\n }, '*')\n\n // node: {...node}, with that ts.addSyntheticLeadingComment is appending\n return ts.addSyntheticLeadingComment({ ...node }, ts.SyntaxKind.MultiLineCommentTrivia, `${text || '*'}\\n`, true)\n}\n\nexport function createIndexSignature(\n type: ts.TypeNode,\n {\n modifiers,\n indexName = 'key',\n indexType = factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword),\n }: {\n indexName?: string\n indexType?: ts.TypeNode\n decorators?: Array<ts.Decorator>\n modifiers?: Array<ts.Modifier>\n } = {},\n) {\n return factory.createIndexSignature(modifiers, [createParameterSignature(indexName, { type: indexType })], type)\n}\n\nexport function createTypeAliasDeclaration({\n modifiers,\n name,\n typeParameters,\n type,\n}: {\n modifiers?: Array<ts.Modifier>\n name: string | ts.Identifier\n typeParameters?: Array<ts.TypeParameterDeclaration>\n type: ts.TypeNode\n}) {\n return factory.createTypeAliasDeclaration(modifiers, name, typeParameters, type)\n}\n\nexport function createNamespaceDeclaration({\n statements,\n name,\n}: {\n name: string\n statements: ts.Statement[]\n}) {\n return factory.createModuleDeclaration(\n [factory.createToken(ts.SyntaxKind.ExportKeyword)],\n factory.createIdentifier(name),\n factory.createModuleBlock(statements),\n ts.NodeFlags.Namespace,\n )\n}\n\n/**\n * In { propertyName: string; name?: string } is `name` being used to make the type more unique when multiple same names are used.\n * @example `import { Pet as Cat } from './Pet'`\n */\nexport function createImportDeclaration({\n name,\n path,\n isTypeOnly = false,\n isNameSpace = false,\n}: {\n name: string | Array<string | { propertyName: string; name?: string }>\n path: string\n isTypeOnly?: boolean\n isNameSpace?: boolean\n}) {\n if (!Array.isArray(name)) {\n let importPropertyName: ts.Identifier | undefined = factory.createIdentifier(name)\n let importName: ts.NamedImportBindings | undefined = undefined\n\n if (isNameSpace) {\n importPropertyName = undefined\n importName = factory.createNamespaceImport(factory.createIdentifier(name))\n }\n\n return factory.createImportDeclaration(\n undefined,\n factory.createImportClause(isTypeOnly, importPropertyName, importName),\n factory.createStringLiteral(path),\n undefined,\n )\n }\n\n return factory.createImportDeclaration(\n undefined,\n factory.createImportClause(\n isTypeOnly,\n undefined,\n factory.createNamedImports(\n name.map((item) => {\n if (typeof item === 'object') {\n const obj = item as { propertyName: string; name?: string }\n if (obj.name) {\n return factory.createImportSpecifier(false, factory.createIdentifier(obj.propertyName), factory.createIdentifier(obj.name))\n }\n\n return factory.createImportSpecifier(false, undefined, factory.createIdentifier(obj.propertyName))\n }\n\n return factory.createImportSpecifier(false, undefined, factory.createIdentifier(item))\n }),\n ),\n ),\n factory.createStringLiteral(path),\n undefined,\n )\n}\n\nexport function createExportDeclaration({\n path,\n asAlias,\n isTypeOnly = false,\n name,\n}: {\n path: string\n asAlias?: boolean\n isTypeOnly?: boolean\n name?: string | Array<ts.Identifier | string>\n}) {\n if (name && !Array.isArray(name) && !asAlias) {\n throw new Error('When using `name` as string, `asAlias` should be true')\n }\n\n if (!Array.isArray(name)) {\n const parsedName = name?.match(/^\\d/) ? `_${name?.slice(1)}` : name\n\n return factory.createExportDeclaration(\n undefined,\n isTypeOnly,\n asAlias && parsedName ? factory.createNamespaceExport(factory.createIdentifier(parsedName)) : undefined,\n factory.createStringLiteral(path),\n undefined,\n )\n }\n\n return factory.createExportDeclaration(\n undefined,\n isTypeOnly,\n factory.createNamedExports(\n name.map((propertyName) => {\n return factory.createExportSpecifier(false, undefined, typeof propertyName === 'string' ? factory.createIdentifier(propertyName) : propertyName)\n }),\n ),\n factory.createStringLiteral(path),\n undefined,\n )\n}\n\nexport function createEnumDeclaration({\n type = 'enum',\n name,\n typeName,\n enums,\n}: {\n /**\n * @default `'enum'`\n */\n type?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal'\n /**\n * Enum name in camelCase.\n */\n name: string\n /**\n * Enum name in PascalCase.\n */\n typeName: string\n enums: [key: string | number, value: string | number | boolean][]\n}) {\n if (type === 'literal') {\n return [\n factory.createTypeAliasDeclaration(\n [factory.createToken(ts.SyntaxKind.ExportKeyword)],\n factory.createIdentifier(typeName),\n undefined,\n factory.createUnionTypeNode(\n enums\n .map(([_key, value]) => {\n if (isNumber(value)) {\n return factory.createLiteralTypeNode(factory.createNumericLiteral(value?.toString()))\n }\n\n if (typeof value === 'boolean') {\n return factory.createLiteralTypeNode(value ? factory.createTrue() : factory.createFalse())\n }\n if (value) {\n return factory.createLiteralTypeNode(factory.createStringLiteral(value.toString()))\n }\n\n return undefined\n })\n .filter(Boolean),\n ),\n ),\n ]\n }\n\n if (type === 'enum' || type === 'constEnum') {\n return [\n factory.createEnumDeclaration(\n [factory.createToken(ts.SyntaxKind.ExportKeyword), type === 'constEnum' ? factory.createToken(ts.SyntaxKind.ConstKeyword) : undefined].filter(Boolean),\n factory.createIdentifier(typeName),\n enums\n .map(([key, value]) => {\n let initializer: ts.Expression = factory.createStringLiteral(value?.toString())\n\n if (isNumber(Number.parseInt(value.toString()))) {\n initializer = factory.createNumericLiteral(value as number)\n }\n if (typeof value === 'boolean') {\n initializer = value ? factory.createTrue() : factory.createFalse()\n }\n\n if (isNumber(Number.parseInt(key.toString()))) {\n return factory.createEnumMember(factory.createStringLiteral(`${typeName}_${key}`), initializer)\n }\n\n if (key) {\n return factory.createEnumMember(factory.createStringLiteral(`${key}`), initializer)\n }\n\n return undefined\n })\n .filter(Boolean),\n ),\n ]\n }\n\n // used when using `as const` instead of an TypeScript enum.\n const identifierName = type === 'asPascalConst' ? typeName : name\n\n return [\n factory.createVariableStatement(\n [factory.createToken(ts.SyntaxKind.ExportKeyword)],\n factory.createVariableDeclarationList(\n [\n factory.createVariableDeclaration(\n factory.createIdentifier(identifierName),\n undefined,\n undefined,\n factory.createAsExpression(\n factory.createObjectLiteralExpression(\n enums\n .map(([key, value]) => {\n let initializer: ts.Expression = factory.createStringLiteral(`${value?.toString()}`)\n\n if (isNumber(value)) {\n // Error: Negative numbers should be created in combination with createPrefixUnaryExpression factory.\n // The method createNumericLiteral only accepts positive numbers\n // or those combined with createPrefixUnaryExpression.\n // Therefore, we need to ensure that the number is not negative.\n if (value < 0) {\n initializer = factory.createPrefixUnaryExpression(ts.SyntaxKind.MinusToken, factory.createNumericLiteral(Math.abs(value)))\n } else {\n initializer = factory.createNumericLiteral(value)\n }\n }\n\n if (typeof value === 'boolean') {\n initializer = value ? factory.createTrue() : factory.createFalse()\n }\n\n if (key) {\n return factory.createPropertyAssignment(factory.createStringLiteral(`${key}`), initializer)\n }\n\n return undefined\n })\n .filter(Boolean),\n true,\n ),\n factory.createTypeReferenceNode(factory.createIdentifier('const'), undefined),\n ),\n ),\n ],\n ts.NodeFlags.Const,\n ),\n ),\n factory.createTypeAliasDeclaration(\n [factory.createToken(ts.SyntaxKind.ExportKeyword)],\n factory.createIdentifier(typeName),\n undefined,\n factory.createIndexedAccessTypeNode(\n factory.createParenthesizedType(factory.createTypeQueryNode(factory.createIdentifier(identifierName), undefined)),\n factory.createTypeOperatorNode(ts.SyntaxKind.KeyOfKeyword, factory.createTypeQueryNode(factory.createIdentifier(identifierName), undefined)),\n ),\n ),\n ]\n}\n\nexport function createOmitDeclaration({\n keys,\n type,\n nonNullable,\n}: {\n keys: Array<string> | string\n type: ts.TypeNode\n nonNullable?: boolean\n}) {\n const node = nonNullable ? factory.createTypeReferenceNode(factory.createIdentifier('NonNullable'), [type]) : type\n\n if (Array.isArray(keys)) {\n return factory.createTypeReferenceNode(factory.createIdentifier('Omit'), [\n node,\n factory.createUnionTypeNode(\n keys.map((key) => {\n return factory.createLiteralTypeNode(factory.createStringLiteral(key))\n }),\n ),\n ])\n }\n\n return factory.createTypeReferenceNode(factory.createIdentifier('Omit'), [node, factory.createLiteralTypeNode(factory.createStringLiteral(keys))])\n}\n\nexport const keywordTypeNodes = {\n any: factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword),\n unknown: factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword),\n number: factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword),\n integer: factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword),\n object: factory.createKeywordTypeNode(ts.SyntaxKind.ObjectKeyword),\n string: factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword),\n boolean: factory.createKeywordTypeNode(ts.SyntaxKind.BooleanKeyword),\n undefined: factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword),\n null: factory.createLiteralTypeNode(factory.createToken(ts.SyntaxKind.NullKeyword)),\n} as const\n\nexport const createTypeLiteralNode = factory.createTypeLiteralNode\n\nexport const createTypeReferenceNode = factory.createTypeReferenceNode\nexport const createNumericLiteral = factory.createNumericLiteral\nexport const createStringLiteral = factory.createStringLiteral\n\nexport const createArrayTypeNode = factory.createArrayTypeNode\n\nexport const createLiteralTypeNode = factory.createLiteralTypeNode\nexport const createNull = factory.createNull\nexport const createIdentifier = factory.createIdentifier\n\nexport const createTupleTypeNode = factory.createTupleTypeNode\n"]}
@@ -0,0 +1,165 @@
1
+ import ts from 'typescript';
2
+
3
+ declare const modifiers: {
4
+ readonly async: ts.ModifierToken<ts.SyntaxKind.AsyncKeyword>;
5
+ readonly export: ts.ModifierToken<ts.SyntaxKind.ExportKeyword>;
6
+ readonly const: ts.ModifierToken<ts.SyntaxKind.ConstKeyword>;
7
+ readonly static: ts.ModifierToken<ts.SyntaxKind.StaticKeyword>;
8
+ };
9
+ declare function createQuestionToken(token?: boolean | ts.QuestionToken): ts.PunctuationToken<ts.SyntaxKind.QuestionToken> | undefined;
10
+ declare function createIntersectionDeclaration({ nodes, withParentheses, }: {
11
+ nodes: Array<ts.TypeNode>;
12
+ withParentheses?: boolean;
13
+ }): ts.TypeNode | null;
14
+ /**
15
+ * Minimum nodes length of 2
16
+ * @example `string & number`
17
+ */
18
+ declare function createTupleDeclaration({ nodes, withParentheses, }: {
19
+ nodes: Array<ts.TypeNode>;
20
+ withParentheses?: boolean;
21
+ }): ts.TypeNode | null;
22
+ declare function createArrayDeclaration({ nodes, }: {
23
+ nodes: Array<ts.TypeNode>;
24
+ }): ts.TypeNode | null;
25
+ /**
26
+ * Minimum nodes length of 2
27
+ * @example `string | number`
28
+ */
29
+ declare function createUnionDeclaration({ nodes, withParentheses, }: {
30
+ nodes: Array<ts.TypeNode>;
31
+ withParentheses?: boolean;
32
+ }): ts.TypeNode | null;
33
+ declare function createPropertySignature({ readOnly, modifiers, name, questionToken, type, }: {
34
+ readOnly?: boolean;
35
+ modifiers?: Array<ts.Modifier>;
36
+ name: ts.PropertyName | string;
37
+ questionToken?: ts.QuestionToken | boolean;
38
+ type?: ts.TypeNode;
39
+ }): ts.PropertySignature;
40
+ declare function createParameterSignature(name: string | ts.BindingName, { modifiers, dotDotDotToken, questionToken, type, initializer, }: {
41
+ decorators?: Array<ts.Decorator>;
42
+ modifiers?: Array<ts.Modifier>;
43
+ dotDotDotToken?: ts.DotDotDotToken;
44
+ questionToken?: ts.QuestionToken | boolean;
45
+ type?: ts.TypeNode;
46
+ initializer?: ts.Expression;
47
+ }): ts.ParameterDeclaration;
48
+ declare function createJSDoc({ comments }: {
49
+ comments: string[];
50
+ }): ts.JSDoc | null;
51
+ /**
52
+ * @link https://github.com/microsoft/TypeScript/issues/44151
53
+ */
54
+ declare function appendJSDocToNode<TNode extends ts.Node>({ node, comments, }: {
55
+ node: TNode;
56
+ comments: Array<string | undefined>;
57
+ }): TNode;
58
+ declare function createIndexSignature(type: ts.TypeNode, { modifiers, indexName, indexType, }?: {
59
+ indexName?: string;
60
+ indexType?: ts.TypeNode;
61
+ decorators?: Array<ts.Decorator>;
62
+ modifiers?: Array<ts.Modifier>;
63
+ }): ts.IndexSignatureDeclaration;
64
+ declare function createTypeAliasDeclaration({ modifiers, name, typeParameters, type, }: {
65
+ modifiers?: Array<ts.Modifier>;
66
+ name: string | ts.Identifier;
67
+ typeParameters?: Array<ts.TypeParameterDeclaration>;
68
+ type: ts.TypeNode;
69
+ }): ts.TypeAliasDeclaration;
70
+ declare function createNamespaceDeclaration({ statements, name, }: {
71
+ name: string;
72
+ statements: ts.Statement[];
73
+ }): ts.ModuleDeclaration;
74
+ /**
75
+ * In { propertyName: string; name?: string } is `name` being used to make the type more unique when multiple same names are used.
76
+ * @example `import { Pet as Cat } from './Pet'`
77
+ */
78
+ declare function createImportDeclaration({ name, path, isTypeOnly, isNameSpace, }: {
79
+ name: string | Array<string | {
80
+ propertyName: string;
81
+ name?: string;
82
+ }>;
83
+ path: string;
84
+ isTypeOnly?: boolean;
85
+ isNameSpace?: boolean;
86
+ }): ts.ImportDeclaration;
87
+ declare function createExportDeclaration({ path, asAlias, isTypeOnly, name, }: {
88
+ path: string;
89
+ asAlias?: boolean;
90
+ isTypeOnly?: boolean;
91
+ name?: string | Array<ts.Identifier | string>;
92
+ }): ts.ExportDeclaration;
93
+ declare function createEnumDeclaration({ type, name, typeName, enums, }: {
94
+ /**
95
+ * @default `'enum'`
96
+ */
97
+ type?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal';
98
+ /**
99
+ * Enum name in camelCase.
100
+ */
101
+ name: string;
102
+ /**
103
+ * Enum name in PascalCase.
104
+ */
105
+ typeName: string;
106
+ enums: [key: string | number, value: string | number | boolean][];
107
+ }): ts.EnumDeclaration[] | (ts.TypeAliasDeclaration | ts.VariableStatement)[];
108
+ declare function createOmitDeclaration({ keys, type, nonNullable, }: {
109
+ keys: Array<string> | string;
110
+ type: ts.TypeNode;
111
+ nonNullable?: boolean;
112
+ }): ts.TypeReferenceNode;
113
+ declare const keywordTypeNodes: {
114
+ readonly any: ts.KeywordTypeNode<ts.SyntaxKind.AnyKeyword>;
115
+ readonly unknown: ts.KeywordTypeNode<ts.SyntaxKind.UnknownKeyword>;
116
+ readonly number: ts.KeywordTypeNode<ts.SyntaxKind.NumberKeyword>;
117
+ readonly integer: ts.KeywordTypeNode<ts.SyntaxKind.NumberKeyword>;
118
+ readonly object: ts.KeywordTypeNode<ts.SyntaxKind.ObjectKeyword>;
119
+ readonly string: ts.KeywordTypeNode<ts.SyntaxKind.StringKeyword>;
120
+ readonly boolean: ts.KeywordTypeNode<ts.SyntaxKind.BooleanKeyword>;
121
+ readonly undefined: ts.KeywordTypeNode<ts.SyntaxKind.UndefinedKeyword>;
122
+ readonly null: ts.LiteralTypeNode;
123
+ };
124
+ declare const createTypeLiteralNode: (members: readonly ts.TypeElement[] | undefined) => ts.TypeLiteralNode;
125
+ declare const createTypeReferenceNode: (typeName: string | ts.EntityName, typeArguments?: readonly ts.TypeNode[] | undefined) => ts.TypeReferenceNode;
126
+ declare const createNumericLiteral: (value: string | number, numericLiteralFlags?: ts.TokenFlags | undefined) => ts.NumericLiteral;
127
+ declare const createStringLiteral: (text: string, isSingleQuote?: boolean | undefined) => ts.StringLiteral;
128
+ declare const createArrayTypeNode: (elementType: ts.TypeNode) => ts.ArrayTypeNode;
129
+ declare const createLiteralTypeNode: (literal: ts.LiteralExpression | ts.NullLiteral | ts.BooleanLiteral | ts.PrefixUnaryExpression) => ts.LiteralTypeNode;
130
+ declare const createNull: () => ts.NullLiteral;
131
+ declare const createIdentifier: (text: string) => ts.Identifier;
132
+ declare const createTupleTypeNode: (elements: readonly (ts.TypeNode | ts.NamedTupleMember)[]) => ts.TupleTypeNode;
133
+
134
+ declare const factory_appendJSDocToNode: typeof appendJSDocToNode;
135
+ declare const factory_createArrayDeclaration: typeof createArrayDeclaration;
136
+ declare const factory_createArrayTypeNode: typeof createArrayTypeNode;
137
+ declare const factory_createEnumDeclaration: typeof createEnumDeclaration;
138
+ declare const factory_createExportDeclaration: typeof createExportDeclaration;
139
+ declare const factory_createIdentifier: typeof createIdentifier;
140
+ declare const factory_createImportDeclaration: typeof createImportDeclaration;
141
+ declare const factory_createIndexSignature: typeof createIndexSignature;
142
+ declare const factory_createIntersectionDeclaration: typeof createIntersectionDeclaration;
143
+ declare const factory_createJSDoc: typeof createJSDoc;
144
+ declare const factory_createLiteralTypeNode: typeof createLiteralTypeNode;
145
+ declare const factory_createNamespaceDeclaration: typeof createNamespaceDeclaration;
146
+ declare const factory_createNull: typeof createNull;
147
+ declare const factory_createNumericLiteral: typeof createNumericLiteral;
148
+ declare const factory_createOmitDeclaration: typeof createOmitDeclaration;
149
+ declare const factory_createParameterSignature: typeof createParameterSignature;
150
+ declare const factory_createPropertySignature: typeof createPropertySignature;
151
+ declare const factory_createQuestionToken: typeof createQuestionToken;
152
+ declare const factory_createStringLiteral: typeof createStringLiteral;
153
+ declare const factory_createTupleDeclaration: typeof createTupleDeclaration;
154
+ declare const factory_createTupleTypeNode: typeof createTupleTypeNode;
155
+ declare const factory_createTypeAliasDeclaration: typeof createTypeAliasDeclaration;
156
+ declare const factory_createTypeLiteralNode: typeof createTypeLiteralNode;
157
+ declare const factory_createTypeReferenceNode: typeof createTypeReferenceNode;
158
+ declare const factory_createUnionDeclaration: typeof createUnionDeclaration;
159
+ declare const factory_keywordTypeNodes: typeof keywordTypeNodes;
160
+ declare const factory_modifiers: typeof modifiers;
161
+ declare namespace factory {
162
+ export { factory_appendJSDocToNode as appendJSDocToNode, factory_createArrayDeclaration as createArrayDeclaration, factory_createArrayTypeNode as createArrayTypeNode, factory_createEnumDeclaration as createEnumDeclaration, factory_createExportDeclaration as createExportDeclaration, factory_createIdentifier as createIdentifier, factory_createImportDeclaration as createImportDeclaration, factory_createIndexSignature as createIndexSignature, factory_createIntersectionDeclaration as createIntersectionDeclaration, factory_createJSDoc as createJSDoc, factory_createLiteralTypeNode as createLiteralTypeNode, factory_createNamespaceDeclaration as createNamespaceDeclaration, factory_createNull as createNull, factory_createNumericLiteral as createNumericLiteral, factory_createOmitDeclaration as createOmitDeclaration, factory_createParameterSignature as createParameterSignature, factory_createPropertySignature as createPropertySignature, factory_createQuestionToken as createQuestionToken, factory_createStringLiteral as createStringLiteral, factory_createTupleDeclaration as createTupleDeclaration, factory_createTupleTypeNode as createTupleTypeNode, factory_createTypeAliasDeclaration as createTypeAliasDeclaration, factory_createTypeLiteralNode as createTypeLiteralNode, factory_createTypeReferenceNode as createTypeReferenceNode, factory_createUnionDeclaration as createUnionDeclaration, factory_keywordTypeNodes as keywordTypeNodes, factory_modifiers as modifiers };
163
+ }
164
+
165
+ export { createIdentifier as A, createTupleTypeNode as B, createIntersectionDeclaration as a, createTupleDeclaration as b, createQuestionToken as c, createArrayDeclaration as d, createUnionDeclaration as e, factory as f, createPropertySignature as g, createParameterSignature as h, createJSDoc as i, appendJSDocToNode as j, createIndexSignature as k, createTypeAliasDeclaration as l, modifiers as m, createNamespaceDeclaration as n, createImportDeclaration as o, createExportDeclaration as p, createEnumDeclaration as q, createOmitDeclaration as r, keywordTypeNodes as s, createTypeLiteralNode as t, createTypeReferenceNode as u, createNumericLiteral as v, createStringLiteral as w, createArrayTypeNode as x, createLiteralTypeNode as y, createNull as z };