@kubb/parser-ts 0.0.0-canary-20240507120838
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 +21 -0
- package/README.md +43 -0
- package/dist/chunk-O7GB3MTG.js +453 -0
- package/dist/chunk-O7GB3MTG.js.map +1 -0
- package/dist/chunk-SCIDO3JK.cjs +453 -0
- package/dist/chunk-SCIDO3JK.cjs.map +1 -0
- package/dist/factory-DE8g6o05.d.cts +165 -0
- package/dist/factory-DE8g6o05.d.ts +165 -0
- package/dist/factory.cjs +59 -0
- package/dist/factory.cjs.map +1 -0
- package/dist/factory.d.cts +2 -0
- package/dist/factory.d.ts +2 -0
- package/dist/factory.js +59 -0
- package/dist/factory.js.map +1 -0
- package/dist/index.cjs +77 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +26 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +77 -0
- package/dist/index.js.map +1 -0
- package/package.json +80 -0
- package/src/api.ts +49 -0
- package/src/factory.ts +553 -0
- package/src/index.ts +5 -0
- package/src/parse.ts +15 -0
- package/src/print.ts +54 -0
|
@@ -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 };
|
package/dist/factory.cjs
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
var _chunkSCIDO3JKcjs = require('./chunk-SCIDO3JK.cjs');
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
exports.appendJSDocToNode = _chunkSCIDO3JKcjs.appendJSDocToNode; exports.createArrayDeclaration = _chunkSCIDO3JKcjs.createArrayDeclaration; exports.createArrayTypeNode = _chunkSCIDO3JKcjs.createArrayTypeNode; exports.createEnumDeclaration = _chunkSCIDO3JKcjs.createEnumDeclaration; exports.createExportDeclaration = _chunkSCIDO3JKcjs.createExportDeclaration; exports.createIdentifier = _chunkSCIDO3JKcjs.createIdentifier; exports.createImportDeclaration = _chunkSCIDO3JKcjs.createImportDeclaration; exports.createIndexSignature = _chunkSCIDO3JKcjs.createIndexSignature; exports.createIntersectionDeclaration = _chunkSCIDO3JKcjs.createIntersectionDeclaration; exports.createJSDoc = _chunkSCIDO3JKcjs.createJSDoc; exports.createLiteralTypeNode = _chunkSCIDO3JKcjs.createLiteralTypeNode; exports.createNamespaceDeclaration = _chunkSCIDO3JKcjs.createNamespaceDeclaration; exports.createNull = _chunkSCIDO3JKcjs.createNull; exports.createNumericLiteral = _chunkSCIDO3JKcjs.createNumericLiteral; exports.createOmitDeclaration = _chunkSCIDO3JKcjs.createOmitDeclaration; exports.createParameterSignature = _chunkSCIDO3JKcjs.createParameterSignature; exports.createPropertySignature = _chunkSCIDO3JKcjs.createPropertySignature; exports.createQuestionToken = _chunkSCIDO3JKcjs.createQuestionToken; exports.createStringLiteral = _chunkSCIDO3JKcjs.createStringLiteral; exports.createTupleDeclaration = _chunkSCIDO3JKcjs.createTupleDeclaration; exports.createTupleTypeNode = _chunkSCIDO3JKcjs.createTupleTypeNode; exports.createTypeAliasDeclaration = _chunkSCIDO3JKcjs.createTypeAliasDeclaration; exports.createTypeLiteralNode = _chunkSCIDO3JKcjs.createTypeLiteralNode; exports.createTypeReferenceNode = _chunkSCIDO3JKcjs.createTypeReferenceNode; exports.createUnionDeclaration = _chunkSCIDO3JKcjs.createUnionDeclaration; exports.keywordTypeNodes = _chunkSCIDO3JKcjs.keywordTypeNodes; exports.modifiers = _chunkSCIDO3JKcjs.modifiers;
|
|
59
|
+
//# sourceMappingURL=factory.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import 'typescript';
|
|
2
|
+
export { j as appendJSDocToNode, d as createArrayDeclaration, x as createArrayTypeNode, q as createEnumDeclaration, p as createExportDeclaration, A as createIdentifier, o as createImportDeclaration, k as createIndexSignature, a as createIntersectionDeclaration, i as createJSDoc, y as createLiteralTypeNode, n as createNamespaceDeclaration, z as createNull, v as createNumericLiteral, r as createOmitDeclaration, h as createParameterSignature, g as createPropertySignature, c as createQuestionToken, w as createStringLiteral, b as createTupleDeclaration, B as createTupleTypeNode, l as createTypeAliasDeclaration, t as createTypeLiteralNode, u as createTypeReferenceNode, e as createUnionDeclaration, s as keywordTypeNodes, m as modifiers } from './factory-DE8g6o05.cjs';
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import 'typescript';
|
|
2
|
+
export { j as appendJSDocToNode, d as createArrayDeclaration, x as createArrayTypeNode, q as createEnumDeclaration, p as createExportDeclaration, A as createIdentifier, o as createImportDeclaration, k as createIndexSignature, a as createIntersectionDeclaration, i as createJSDoc, y as createLiteralTypeNode, n as createNamespaceDeclaration, z as createNull, v as createNumericLiteral, r as createOmitDeclaration, h as createParameterSignature, g as createPropertySignature, c as createQuestionToken, w as createStringLiteral, b as createTupleDeclaration, B as createTupleTypeNode, l as createTypeAliasDeclaration, t as createTypeLiteralNode, u as createTypeReferenceNode, e as createUnionDeclaration, s as keywordTypeNodes, m as modifiers } from './factory-DE8g6o05.js';
|
package/dist/factory.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import {
|
|
2
|
+
appendJSDocToNode,
|
|
3
|
+
createArrayDeclaration,
|
|
4
|
+
createArrayTypeNode,
|
|
5
|
+
createEnumDeclaration,
|
|
6
|
+
createExportDeclaration,
|
|
7
|
+
createIdentifier,
|
|
8
|
+
createImportDeclaration,
|
|
9
|
+
createIndexSignature,
|
|
10
|
+
createIntersectionDeclaration,
|
|
11
|
+
createJSDoc,
|
|
12
|
+
createLiteralTypeNode,
|
|
13
|
+
createNamespaceDeclaration,
|
|
14
|
+
createNull,
|
|
15
|
+
createNumericLiteral,
|
|
16
|
+
createOmitDeclaration,
|
|
17
|
+
createParameterSignature,
|
|
18
|
+
createPropertySignature,
|
|
19
|
+
createQuestionToken,
|
|
20
|
+
createStringLiteral,
|
|
21
|
+
createTupleDeclaration,
|
|
22
|
+
createTupleTypeNode,
|
|
23
|
+
createTypeAliasDeclaration,
|
|
24
|
+
createTypeLiteralNode,
|
|
25
|
+
createTypeReferenceNode,
|
|
26
|
+
createUnionDeclaration,
|
|
27
|
+
keywordTypeNodes,
|
|
28
|
+
modifiers
|
|
29
|
+
} from "./chunk-O7GB3MTG.js";
|
|
30
|
+
export {
|
|
31
|
+
appendJSDocToNode,
|
|
32
|
+
createArrayDeclaration,
|
|
33
|
+
createArrayTypeNode,
|
|
34
|
+
createEnumDeclaration,
|
|
35
|
+
createExportDeclaration,
|
|
36
|
+
createIdentifier,
|
|
37
|
+
createImportDeclaration,
|
|
38
|
+
createIndexSignature,
|
|
39
|
+
createIntersectionDeclaration,
|
|
40
|
+
createJSDoc,
|
|
41
|
+
createLiteralTypeNode,
|
|
42
|
+
createNamespaceDeclaration,
|
|
43
|
+
createNull,
|
|
44
|
+
createNumericLiteral,
|
|
45
|
+
createOmitDeclaration,
|
|
46
|
+
createParameterSignature,
|
|
47
|
+
createPropertySignature,
|
|
48
|
+
createQuestionToken,
|
|
49
|
+
createStringLiteral,
|
|
50
|
+
createTupleDeclaration,
|
|
51
|
+
createTupleTypeNode,
|
|
52
|
+
createTypeAliasDeclaration,
|
|
53
|
+
createTypeLiteralNode,
|
|
54
|
+
createTypeReferenceNode,
|
|
55
|
+
createUnionDeclaration,
|
|
56
|
+
keywordTypeNodes,
|
|
57
|
+
modifiers
|
|
58
|
+
};
|
|
59
|
+
//# sourceMappingURL=factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
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; }
|
|
2
|
+
|
|
3
|
+
var _chunkSCIDO3JKcjs = require('./chunk-SCIDO3JK.cjs');
|
|
4
|
+
|
|
5
|
+
// src/api.ts
|
|
6
|
+
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
7
|
+
var _typescript = require('typescript'); var _typescript2 = _interopRequireDefault(_typescript);
|
|
8
|
+
function getExports(filePath) {
|
|
9
|
+
const rootName = _path2.default.extname(filePath) ? filePath : `${filePath}.ts`;
|
|
10
|
+
if (!rootName) {
|
|
11
|
+
return void 0;
|
|
12
|
+
}
|
|
13
|
+
const program = _typescript2.default.createProgram({
|
|
14
|
+
rootNames: [rootName],
|
|
15
|
+
options: {}
|
|
16
|
+
});
|
|
17
|
+
const checker = program.getTypeChecker();
|
|
18
|
+
const sources = program.getSourceFiles();
|
|
19
|
+
const sourceFile = sources.find((sourceFile2) => sourceFile2.fileName === rootName);
|
|
20
|
+
if (!sourceFile) {
|
|
21
|
+
return void 0;
|
|
22
|
+
}
|
|
23
|
+
const symbol = checker.getSymbolAtLocation(sourceFile);
|
|
24
|
+
if (!_optionalChain([symbol, 'optionalAccess', _ => _.flags])) {
|
|
25
|
+
return void 0;
|
|
26
|
+
}
|
|
27
|
+
const exports = checker.getExportsOfModule(symbol);
|
|
28
|
+
return exports.map((e) => {
|
|
29
|
+
const type = checker.getTypeOfSymbol(e);
|
|
30
|
+
return {
|
|
31
|
+
name: e.escapedName.toString(),
|
|
32
|
+
isTypeOnly: _optionalChain([type, 'optionalAccess', _2 => _2.id]) === 5
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// src/print.ts
|
|
38
|
+
|
|
39
|
+
var { factory } = _typescript2.default;
|
|
40
|
+
var escapeNewLines = (code) => code.replace(/\n\n/g, "\n/* :newline: */");
|
|
41
|
+
var restoreNewLines = (code) => code.replace(/\/\* :newline: \*\//g, "\n");
|
|
42
|
+
function print(elements, { source = "", baseName = "print.ts", removeComments, noEmitHelpers, newLine = _typescript2.default.NewLineKind.LineFeed } = {}) {
|
|
43
|
+
const sourceFile = _typescript2.default.createSourceFile(baseName, escapeNewLines(source), _typescript2.default.ScriptTarget.ES2022, false, _typescript2.default.ScriptKind.TS);
|
|
44
|
+
const printer = _typescript2.default.createPrinter({
|
|
45
|
+
omitTrailingSemicolon: true,
|
|
46
|
+
newLine,
|
|
47
|
+
removeComments,
|
|
48
|
+
noEmitHelpers
|
|
49
|
+
});
|
|
50
|
+
let nodes = [];
|
|
51
|
+
if (!elements) {
|
|
52
|
+
return "";
|
|
53
|
+
}
|
|
54
|
+
if (Array.isArray(elements)) {
|
|
55
|
+
nodes = elements.filter(Boolean);
|
|
56
|
+
} else {
|
|
57
|
+
nodes = [elements].filter(Boolean);
|
|
58
|
+
}
|
|
59
|
+
const outputFile = printer.printList(_typescript2.default.ListFormat.MultiLine, factory.createNodeArray(nodes), sourceFile);
|
|
60
|
+
const outputSource = printer.printFile(sourceFile);
|
|
61
|
+
return [outputFile, restoreNewLines(outputSource)].filter(Boolean).join("\n");
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// src/parse.ts
|
|
65
|
+
function parse(ast) {
|
|
66
|
+
return {
|
|
67
|
+
ast,
|
|
68
|
+
text: print(ast)
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
exports.factory = _chunkSCIDO3JKcjs.factory_exports; exports.getExports = getExports; exports.parse = parse; exports.print = print;
|
|
77
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/api.ts","../src/print.ts","../src/parse.ts"],"names":["sourceFile","ts"],"mappings":";;;;;AAAA,OAAO,UAAU;AAEjB,OAAO,QAAQ;AAUR,SAAS,WAAW,UAAoD;AAC7E,QAAM,WAAW,KAAK,QAAQ,QAAQ,IAAI,WAAW,GAAG,QAAQ;AAEhE,MAAI,CAAC,UAAU;AACb,WAAO;AAAA,EACT;AAEA,QAAM,UAAU,GAAG,cAAc;AAAA,IAC/B,WAAW,CAAC,QAAQ;AAAA,IACpB,SAAS,CAAC;AAAA,EACZ,CAAC;AAED,QAAM,UAAU,QAAQ,eAAe;AACvC,QAAM,UAAU,QAAQ,eAAe;AACvC,QAAM,aAAa,QAAQ,KAAK,CAACA,gBAAeA,YAAW,aAAa,QAAQ;AAEhF,MAAI,CAAC,YAAY;AACf,WAAO;AAAA,EACT;AAEA,QAAM,SAAS,QAAQ,oBAAoB,UAAU;AAErD,MAAI,CAAC,QAAQ,OAAO;AAClB,WAAO;AAAA,EACT;AAEA,QAAM,UAAU,QAAQ,mBAAmB,MAAM;AACjD,SAAO,QAAQ,IAAI,CAAC,MAAM;AAExB,UAAM,OAAO,QAAQ,gBAAgB,CAAC;AAEtC,WAAO;AAAA,MACL,MAAM,EAAE,YAAY,SAAS;AAAA,MAC7B,YAAY,MAAM,OAAO;AAAA,IAC3B;AAAA,EACF,CAAC;AACH;;;AChDA,OAAOC,SAAQ;AAIf,IAAM,EAAE,QAAQ,IAAIA;AAYpB,IAAM,iBAAiB,CAAC,SAAiB,KAAK,QAAQ,SAAS,mBAAmB;AAOlF,IAAM,kBAAkB,CAAC,SAAiB,KAAK,QAAQ,wBAAwB,IAAI;AAE5E,SAAS,MACd,UACA,EAAE,SAAS,IAAI,WAAW,YAAY,gBAAgB,eAAe,UAAUA,IAAG,YAAY,SAAS,IAAa,CAAC,GAC7G;AACR,QAAM,aAAaA,IAAG,iBAAiB,UAAU,eAAe,MAAM,GAAGA,IAAG,aAAa,QAAQ,OAAOA,IAAG,WAAW,EAAE;AACxH,QAAM,UAAUA,IAAG,cAAc;AAAA,IAC/B,uBAAuB;AAAA,IACvB;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AAED,MAAI,QAAwB,CAAC;AAE7B,MAAI,CAAC,UAAU;AACb,WAAO;AAAA,EACT;AAEA,MAAI,MAAM,QAAQ,QAAQ,GAAG;AAC3B,YAAQ,SAAS,OAAO,OAAO;AAAA,EACjC,OAAO;AACL,YAAQ,CAAC,QAAQ,EAAE,OAAO,OAAO;AAAA,EACnC;AAEA,QAAM,aAAa,QAAQ,UAAUA,IAAG,WAAW,WAAW,QAAQ,gBAAgB,KAAK,GAAG,UAAU;AACxG,QAAM,eAAe,QAAQ,UAAU,UAAU;AAEjD,SAAO,CAAC,YAAY,gBAAgB,YAAY,CAAC,EAAE,OAAO,OAAO,EAAE,KAAK,IAAI;AAC9E;;;AC5CO,SAAS,MAAM,KAA2B;AAC/C,SAAO;AAAA,IACL;AAAA,IACA,MAAM,MAAM,GAAG;AAAA,EACjB;AACF","sourcesContent":["import path from 'node:path'\n\nimport ts from 'typescript'\n\ntype ExportsResult = {\n name: string\n isTypeOnly: boolean\n}\n\n/**\n * @link https://github.com/microsoft/TypeScript/issues/15840\n */\nexport function getExports(filePath: string): undefined | Array<ExportsResult> {\n const rootName = path.extname(filePath) ? filePath : `${filePath}.ts`\n\n if (!rootName) {\n return undefined\n }\n\n const program = ts.createProgram({\n rootNames: [rootName],\n options: {},\n })\n\n const checker = program.getTypeChecker()\n const sources = program.getSourceFiles()\n const sourceFile = sources.find((sourceFile) => sourceFile.fileName === rootName)\n\n if (!sourceFile) {\n return undefined\n }\n\n const symbol = checker.getSymbolAtLocation(sourceFile)\n\n if (!symbol?.flags) {\n return undefined\n }\n\n const exports = checker.getExportsOfModule(symbol)\n return exports.map((e) => {\n // 5 is type and 90 is const\n const type = checker.getTypeOfSymbol(e) as unknown as { id?: 5 | 90 }\n\n return {\n name: e.escapedName.toString(),\n isTypeOnly: type?.id === 5,\n }\n })\n}\n","import ts from 'typescript'\n\nimport type { PrinterOptions } from 'typescript'\n\nconst { factory } = ts\n\ntype Options = {\n source?: string\n baseName?: string\n} & PrinterOptions\n\n/**\n * Escaped new lines in code with block comments so they can be restored by {@link restoreNewLines}\n * @param {string} code The code to escape new lines in\n * @returns The same code but with new lines escaped using block comments\n */\nconst escapeNewLines = (code: string) => code.replace(/\\n\\n/g, '\\n/* :newline: */')\n\n/**\n * Reverses {@link escapeNewLines} and restores new lines\n * @param {string} code The code with escaped new lines\n * @returns The same code with new lines restored\n */\nconst restoreNewLines = (code: string) => code.replace(/\\/\\* :newline: \\*\\//g, '\\n')\n\nexport function print(\n elements: ts.Node | Array<ts.Node | undefined> | null,\n { source = '', baseName = 'print.ts', removeComments, noEmitHelpers, newLine = ts.NewLineKind.LineFeed }: Options = {},\n): string {\n const sourceFile = ts.createSourceFile(baseName, escapeNewLines(source), ts.ScriptTarget.ES2022, false, ts.ScriptKind.TS)\n const printer = ts.createPrinter({\n omitTrailingSemicolon: true,\n newLine,\n removeComments,\n noEmitHelpers,\n })\n\n let nodes: Array<ts.Node> = []\n\n if (!elements) {\n return ''\n }\n\n if (Array.isArray(elements)) {\n nodes = elements.filter(Boolean)\n } else {\n nodes = [elements].filter(Boolean)\n }\n\n const outputFile = printer.printList(ts.ListFormat.MultiLine, factory.createNodeArray(nodes), sourceFile)\n const outputSource = printer.printFile(sourceFile)\n\n return [outputFile, restoreNewLines(outputSource)].filter(Boolean).join('\\n')\n}\n","import { print } from './print.ts'\n\nimport type ts from 'typescript'\n\ntype ParseResult = {\n ast: ts.Node\n text: string\n}\n\nexport function parse(ast: ts.Node): ParseResult {\n return {\n ast,\n text: print(ast),\n }\n}\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import ts, { PrinterOptions } from 'typescript';
|
|
2
|
+
export { default as ts } from 'typescript';
|
|
3
|
+
export { f as factory } from './factory-DE8g6o05.cjs';
|
|
4
|
+
|
|
5
|
+
type ExportsResult = {
|
|
6
|
+
name: string;
|
|
7
|
+
isTypeOnly: boolean;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* @link https://github.com/microsoft/TypeScript/issues/15840
|
|
11
|
+
*/
|
|
12
|
+
declare function getExports(filePath: string): undefined | Array<ExportsResult>;
|
|
13
|
+
|
|
14
|
+
type ParseResult = {
|
|
15
|
+
ast: ts.Node;
|
|
16
|
+
text: string;
|
|
17
|
+
};
|
|
18
|
+
declare function parse(ast: ts.Node): ParseResult;
|
|
19
|
+
|
|
20
|
+
type Options = {
|
|
21
|
+
source?: string;
|
|
22
|
+
baseName?: string;
|
|
23
|
+
} & PrinterOptions;
|
|
24
|
+
declare function print(elements: ts.Node | Array<ts.Node | undefined> | null, { source, baseName, removeComments, noEmitHelpers, newLine }?: Options): string;
|
|
25
|
+
|
|
26
|
+
export { getExports, parse, print };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import ts, { PrinterOptions } from 'typescript';
|
|
2
|
+
export { default as ts } from 'typescript';
|
|
3
|
+
export { f as factory } from './factory-DE8g6o05.js';
|
|
4
|
+
|
|
5
|
+
type ExportsResult = {
|
|
6
|
+
name: string;
|
|
7
|
+
isTypeOnly: boolean;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* @link https://github.com/microsoft/TypeScript/issues/15840
|
|
11
|
+
*/
|
|
12
|
+
declare function getExports(filePath: string): undefined | Array<ExportsResult>;
|
|
13
|
+
|
|
14
|
+
type ParseResult = {
|
|
15
|
+
ast: ts.Node;
|
|
16
|
+
text: string;
|
|
17
|
+
};
|
|
18
|
+
declare function parse(ast: ts.Node): ParseResult;
|
|
19
|
+
|
|
20
|
+
type Options = {
|
|
21
|
+
source?: string;
|
|
22
|
+
baseName?: string;
|
|
23
|
+
} & PrinterOptions;
|
|
24
|
+
declare function print(elements: ts.Node | Array<ts.Node | undefined> | null, { source, baseName, removeComments, noEmitHelpers, newLine }?: Options): string;
|
|
25
|
+
|
|
26
|
+
export { getExports, parse, print };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import {
|
|
2
|
+
factory_exports
|
|
3
|
+
} from "./chunk-O7GB3MTG.js";
|
|
4
|
+
|
|
5
|
+
// src/api.ts
|
|
6
|
+
import path from "path";
|
|
7
|
+
import ts from "typescript";
|
|
8
|
+
function getExports(filePath) {
|
|
9
|
+
const rootName = path.extname(filePath) ? filePath : `${filePath}.ts`;
|
|
10
|
+
if (!rootName) {
|
|
11
|
+
return void 0;
|
|
12
|
+
}
|
|
13
|
+
const program = ts.createProgram({
|
|
14
|
+
rootNames: [rootName],
|
|
15
|
+
options: {}
|
|
16
|
+
});
|
|
17
|
+
const checker = program.getTypeChecker();
|
|
18
|
+
const sources = program.getSourceFiles();
|
|
19
|
+
const sourceFile = sources.find((sourceFile2) => sourceFile2.fileName === rootName);
|
|
20
|
+
if (!sourceFile) {
|
|
21
|
+
return void 0;
|
|
22
|
+
}
|
|
23
|
+
const symbol = checker.getSymbolAtLocation(sourceFile);
|
|
24
|
+
if (!symbol?.flags) {
|
|
25
|
+
return void 0;
|
|
26
|
+
}
|
|
27
|
+
const exports = checker.getExportsOfModule(symbol);
|
|
28
|
+
return exports.map((e) => {
|
|
29
|
+
const type = checker.getTypeOfSymbol(e);
|
|
30
|
+
return {
|
|
31
|
+
name: e.escapedName.toString(),
|
|
32
|
+
isTypeOnly: type?.id === 5
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// src/print.ts
|
|
38
|
+
import ts2 from "typescript";
|
|
39
|
+
var { factory } = ts2;
|
|
40
|
+
var escapeNewLines = (code) => code.replace(/\n\n/g, "\n/* :newline: */");
|
|
41
|
+
var restoreNewLines = (code) => code.replace(/\/\* :newline: \*\//g, "\n");
|
|
42
|
+
function print(elements, { source = "", baseName = "print.ts", removeComments, noEmitHelpers, newLine = ts2.NewLineKind.LineFeed } = {}) {
|
|
43
|
+
const sourceFile = ts2.createSourceFile(baseName, escapeNewLines(source), ts2.ScriptTarget.ES2022, false, ts2.ScriptKind.TS);
|
|
44
|
+
const printer = ts2.createPrinter({
|
|
45
|
+
omitTrailingSemicolon: true,
|
|
46
|
+
newLine,
|
|
47
|
+
removeComments,
|
|
48
|
+
noEmitHelpers
|
|
49
|
+
});
|
|
50
|
+
let nodes = [];
|
|
51
|
+
if (!elements) {
|
|
52
|
+
return "";
|
|
53
|
+
}
|
|
54
|
+
if (Array.isArray(elements)) {
|
|
55
|
+
nodes = elements.filter(Boolean);
|
|
56
|
+
} else {
|
|
57
|
+
nodes = [elements].filter(Boolean);
|
|
58
|
+
}
|
|
59
|
+
const outputFile = printer.printList(ts2.ListFormat.MultiLine, factory.createNodeArray(nodes), sourceFile);
|
|
60
|
+
const outputSource = printer.printFile(sourceFile);
|
|
61
|
+
return [outputFile, restoreNewLines(outputSource)].filter(Boolean).join("\n");
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// src/parse.ts
|
|
65
|
+
function parse(ast) {
|
|
66
|
+
return {
|
|
67
|
+
ast,
|
|
68
|
+
text: print(ast)
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
export {
|
|
72
|
+
factory_exports as factory,
|
|
73
|
+
getExports,
|
|
74
|
+
parse,
|
|
75
|
+
print
|
|
76
|
+
};
|
|
77
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/api.ts","../src/print.ts","../src/parse.ts"],"sourcesContent":["import path from 'node:path'\n\nimport ts from 'typescript'\n\ntype ExportsResult = {\n name: string\n isTypeOnly: boolean\n}\n\n/**\n * @link https://github.com/microsoft/TypeScript/issues/15840\n */\nexport function getExports(filePath: string): undefined | Array<ExportsResult> {\n const rootName = path.extname(filePath) ? filePath : `${filePath}.ts`\n\n if (!rootName) {\n return undefined\n }\n\n const program = ts.createProgram({\n rootNames: [rootName],\n options: {},\n })\n\n const checker = program.getTypeChecker()\n const sources = program.getSourceFiles()\n const sourceFile = sources.find((sourceFile) => sourceFile.fileName === rootName)\n\n if (!sourceFile) {\n return undefined\n }\n\n const symbol = checker.getSymbolAtLocation(sourceFile)\n\n if (!symbol?.flags) {\n return undefined\n }\n\n const exports = checker.getExportsOfModule(symbol)\n return exports.map((e) => {\n // 5 is type and 90 is const\n const type = checker.getTypeOfSymbol(e) as unknown as { id?: 5 | 90 }\n\n return {\n name: e.escapedName.toString(),\n isTypeOnly: type?.id === 5,\n }\n })\n}\n","import ts from 'typescript'\n\nimport type { PrinterOptions } from 'typescript'\n\nconst { factory } = ts\n\ntype Options = {\n source?: string\n baseName?: string\n} & PrinterOptions\n\n/**\n * Escaped new lines in code with block comments so they can be restored by {@link restoreNewLines}\n * @param {string} code The code to escape new lines in\n * @returns The same code but with new lines escaped using block comments\n */\nconst escapeNewLines = (code: string) => code.replace(/\\n\\n/g, '\\n/* :newline: */')\n\n/**\n * Reverses {@link escapeNewLines} and restores new lines\n * @param {string} code The code with escaped new lines\n * @returns The same code with new lines restored\n */\nconst restoreNewLines = (code: string) => code.replace(/\\/\\* :newline: \\*\\//g, '\\n')\n\nexport function print(\n elements: ts.Node | Array<ts.Node | undefined> | null,\n { source = '', baseName = 'print.ts', removeComments, noEmitHelpers, newLine = ts.NewLineKind.LineFeed }: Options = {},\n): string {\n const sourceFile = ts.createSourceFile(baseName, escapeNewLines(source), ts.ScriptTarget.ES2022, false, ts.ScriptKind.TS)\n const printer = ts.createPrinter({\n omitTrailingSemicolon: true,\n newLine,\n removeComments,\n noEmitHelpers,\n })\n\n let nodes: Array<ts.Node> = []\n\n if (!elements) {\n return ''\n }\n\n if (Array.isArray(elements)) {\n nodes = elements.filter(Boolean)\n } else {\n nodes = [elements].filter(Boolean)\n }\n\n const outputFile = printer.printList(ts.ListFormat.MultiLine, factory.createNodeArray(nodes), sourceFile)\n const outputSource = printer.printFile(sourceFile)\n\n return [outputFile, restoreNewLines(outputSource)].filter(Boolean).join('\\n')\n}\n","import { print } from './print.ts'\n\nimport type ts from 'typescript'\n\ntype ParseResult = {\n ast: ts.Node\n text: string\n}\n\nexport function parse(ast: ts.Node): ParseResult {\n return {\n ast,\n text: print(ast),\n }\n}\n"],"mappings":";;;;;AAAA,OAAO,UAAU;AAEjB,OAAO,QAAQ;AAUR,SAAS,WAAW,UAAoD;AAC7E,QAAM,WAAW,KAAK,QAAQ,QAAQ,IAAI,WAAW,GAAG,QAAQ;AAEhE,MAAI,CAAC,UAAU;AACb,WAAO;AAAA,EACT;AAEA,QAAM,UAAU,GAAG,cAAc;AAAA,IAC/B,WAAW,CAAC,QAAQ;AAAA,IACpB,SAAS,CAAC;AAAA,EACZ,CAAC;AAED,QAAM,UAAU,QAAQ,eAAe;AACvC,QAAM,UAAU,QAAQ,eAAe;AACvC,QAAM,aAAa,QAAQ,KAAK,CAACA,gBAAeA,YAAW,aAAa,QAAQ;AAEhF,MAAI,CAAC,YAAY;AACf,WAAO;AAAA,EACT;AAEA,QAAM,SAAS,QAAQ,oBAAoB,UAAU;AAErD,MAAI,CAAC,QAAQ,OAAO;AAClB,WAAO;AAAA,EACT;AAEA,QAAM,UAAU,QAAQ,mBAAmB,MAAM;AACjD,SAAO,QAAQ,IAAI,CAAC,MAAM;AAExB,UAAM,OAAO,QAAQ,gBAAgB,CAAC;AAEtC,WAAO;AAAA,MACL,MAAM,EAAE,YAAY,SAAS;AAAA,MAC7B,YAAY,MAAM,OAAO;AAAA,IAC3B;AAAA,EACF,CAAC;AACH;;;AChDA,OAAOC,SAAQ;AAIf,IAAM,EAAE,QAAQ,IAAIA;AAYpB,IAAM,iBAAiB,CAAC,SAAiB,KAAK,QAAQ,SAAS,mBAAmB;AAOlF,IAAM,kBAAkB,CAAC,SAAiB,KAAK,QAAQ,wBAAwB,IAAI;AAE5E,SAAS,MACd,UACA,EAAE,SAAS,IAAI,WAAW,YAAY,gBAAgB,eAAe,UAAUA,IAAG,YAAY,SAAS,IAAa,CAAC,GAC7G;AACR,QAAM,aAAaA,IAAG,iBAAiB,UAAU,eAAe,MAAM,GAAGA,IAAG,aAAa,QAAQ,OAAOA,IAAG,WAAW,EAAE;AACxH,QAAM,UAAUA,IAAG,cAAc;AAAA,IAC/B,uBAAuB;AAAA,IACvB;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AAED,MAAI,QAAwB,CAAC;AAE7B,MAAI,CAAC,UAAU;AACb,WAAO;AAAA,EACT;AAEA,MAAI,MAAM,QAAQ,QAAQ,GAAG;AAC3B,YAAQ,SAAS,OAAO,OAAO;AAAA,EACjC,OAAO;AACL,YAAQ,CAAC,QAAQ,EAAE,OAAO,OAAO;AAAA,EACnC;AAEA,QAAM,aAAa,QAAQ,UAAUA,IAAG,WAAW,WAAW,QAAQ,gBAAgB,KAAK,GAAG,UAAU;AACxG,QAAM,eAAe,QAAQ,UAAU,UAAU;AAEjD,SAAO,CAAC,YAAY,gBAAgB,YAAY,CAAC,EAAE,OAAO,OAAO,EAAE,KAAK,IAAI;AAC9E;;;AC5CO,SAAS,MAAM,KAA2B;AAC/C,SAAO;AAAA,IACL;AAAA,IACA,MAAM,MAAM,GAAG;AAAA,EACjB;AACF;","names":["sourceFile","ts"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kubb/parser-ts",
|
|
3
|
+
"version": "0.0.0-canary-20240507120838",
|
|
4
|
+
"description": "TypeScript parser",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"typescript",
|
|
7
|
+
"plugins",
|
|
8
|
+
"kubb",
|
|
9
|
+
"codegen"
|
|
10
|
+
],
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git://github.com/kubb-labs/kubb.git",
|
|
14
|
+
"directory": "packages/parser-ts"
|
|
15
|
+
},
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"author": "Stijn Van Hulle <stijn@stijnvanhulle.be",
|
|
18
|
+
"sideEffects": false,
|
|
19
|
+
"type": "module",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"import": "./dist/index.js",
|
|
23
|
+
"require": "./dist/index.cjs",
|
|
24
|
+
"default": "./dist/index.cjs"
|
|
25
|
+
},
|
|
26
|
+
"./factory": {
|
|
27
|
+
"import": "./dist/factory.js",
|
|
28
|
+
"require": "./dist/factory.cjs",
|
|
29
|
+
"default": "./dist/factory.cjs"
|
|
30
|
+
},
|
|
31
|
+
"./package.json": "./package.json",
|
|
32
|
+
"./*": "./*"
|
|
33
|
+
},
|
|
34
|
+
"main": "dist/index.cjs",
|
|
35
|
+
"module": "dist/index.js",
|
|
36
|
+
"types": "./dist/index.d.cts",
|
|
37
|
+
"typesVersions": {
|
|
38
|
+
"*": {
|
|
39
|
+
"factory": [
|
|
40
|
+
"./dist/factory.d.ts"
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"files": [
|
|
45
|
+
"src",
|
|
46
|
+
"dist",
|
|
47
|
+
"!/**/**.test.**",
|
|
48
|
+
"!/**/__tests__/**"
|
|
49
|
+
],
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"remeda": "^1.61.0",
|
|
52
|
+
"typescript": "^5.4.5"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"prettier": "^3.2.5",
|
|
56
|
+
"tsup": "^8.0.2",
|
|
57
|
+
"@kubb/config-biome": "0.0.0-canary-20240507120838",
|
|
58
|
+
"@kubb/config-ts": "0.0.0-canary-20240507120838",
|
|
59
|
+
"@kubb/config-tsup": "0.0.0-canary-20240507120838"
|
|
60
|
+
},
|
|
61
|
+
"engines": {
|
|
62
|
+
"node": ">=18",
|
|
63
|
+
"pnpm": ">=8.15.0"
|
|
64
|
+
},
|
|
65
|
+
"publishConfig": {
|
|
66
|
+
"access": "public",
|
|
67
|
+
"registry": "https://registry.npmjs.org/"
|
|
68
|
+
},
|
|
69
|
+
"scripts": {
|
|
70
|
+
"build": "tsup",
|
|
71
|
+
"clean": "npx rimraf ./dist",
|
|
72
|
+
"lint": "bun biome lint .",
|
|
73
|
+
"lint:fix": "bun biome lint --apply-unsafe .",
|
|
74
|
+
"release": "pnpm publish --no-git-check",
|
|
75
|
+
"release:canary": "bash ../../.github/canary.sh && node ../../scripts/build.js canary && pnpm publish --no-git-check",
|
|
76
|
+
"start": "tsup --watch",
|
|
77
|
+
"test": "vitest --passWithNoTests",
|
|
78
|
+
"typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false"
|
|
79
|
+
}
|
|
80
|
+
}
|
package/src/api.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
|
|
3
|
+
import ts from 'typescript'
|
|
4
|
+
|
|
5
|
+
type ExportsResult = {
|
|
6
|
+
name: string
|
|
7
|
+
isTypeOnly: boolean
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @link https://github.com/microsoft/TypeScript/issues/15840
|
|
12
|
+
*/
|
|
13
|
+
export function getExports(filePath: string): undefined | Array<ExportsResult> {
|
|
14
|
+
const rootName = path.extname(filePath) ? filePath : `${filePath}.ts`
|
|
15
|
+
|
|
16
|
+
if (!rootName) {
|
|
17
|
+
return undefined
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const program = ts.createProgram({
|
|
21
|
+
rootNames: [rootName],
|
|
22
|
+
options: {},
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
const checker = program.getTypeChecker()
|
|
26
|
+
const sources = program.getSourceFiles()
|
|
27
|
+
const sourceFile = sources.find((sourceFile) => sourceFile.fileName === rootName)
|
|
28
|
+
|
|
29
|
+
if (!sourceFile) {
|
|
30
|
+
return undefined
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const symbol = checker.getSymbolAtLocation(sourceFile)
|
|
34
|
+
|
|
35
|
+
if (!symbol?.flags) {
|
|
36
|
+
return undefined
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const exports = checker.getExportsOfModule(symbol)
|
|
40
|
+
return exports.map((e) => {
|
|
41
|
+
// 5 is type and 90 is const
|
|
42
|
+
const type = checker.getTypeOfSymbol(e) as unknown as { id?: 5 | 90 }
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
name: e.escapedName.toString(),
|
|
46
|
+
isTypeOnly: type?.id === 5,
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
}
|