@kubb/parser-ts 3.0.0-alpha.2 → 3.0.0-alpha.21
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/README.md +13 -4
- package/dist/{chunk-QHLKNPYD.js → chunk-2BN5RQSZ.js} +10 -35
- package/dist/chunk-2BN5RQSZ.js.map +1 -0
- package/dist/{chunk-UQLRYRTM.cjs → chunk-TNIGP6OU.cjs} +80 -72
- package/dist/chunk-TNIGP6OU.cjs.map +1 -0
- package/dist/{factory-Cd7U4lxv.d.cts → factory-CFXA_d49.d.cts} +1 -1
- package/dist/{factory-Cd7U4lxv.d.ts → factory-CFXA_d49.d.ts} +1 -1
- package/dist/factory.cjs +115 -58
- package/dist/factory.cjs.map +1 -1
- package/dist/factory.d.cts +1 -1
- package/dist/factory.d.ts +1 -1
- package/dist/factory.js +2 -58
- package/dist/factory.js.map +1 -1
- package/dist/index.cjs +20 -50
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -19
- package/dist/index.d.ts +11 -19
- package/dist/index.js +13 -54
- package/dist/index.js.map +1 -1
- package/package.json +6 -9
- package/src/factory.ts +5 -3
- package/src/format.ts +9 -0
- package/src/index.ts +1 -3
- package/src/print.ts +4 -1
- package/dist/chunk-QHLKNPYD.js.map +0 -1
- package/dist/chunk-UQLRYRTM.cjs.map +0 -1
- package/src/api.ts +0 -49
- package/src/parse.ts +0 -15
package/dist/factory.cjs
CHANGED
|
@@ -1,59 +1,116 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkTNIGP6OU_cjs = require('./chunk-TNIGP6OU.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(exports, "appendJSDocToNode", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () { return chunkTNIGP6OU_cjs.appendJSDocToNode; }
|
|
10
|
+
});
|
|
11
|
+
Object.defineProperty(exports, "createArrayDeclaration", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function () { return chunkTNIGP6OU_cjs.createArrayDeclaration; }
|
|
14
|
+
});
|
|
15
|
+
Object.defineProperty(exports, "createArrayTypeNode", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function () { return chunkTNIGP6OU_cjs.createArrayTypeNode; }
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports, "createEnumDeclaration", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () { return chunkTNIGP6OU_cjs.createEnumDeclaration; }
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports, "createExportDeclaration", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get: function () { return chunkTNIGP6OU_cjs.createExportDeclaration; }
|
|
26
|
+
});
|
|
27
|
+
Object.defineProperty(exports, "createIdentifier", {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
get: function () { return chunkTNIGP6OU_cjs.createIdentifier; }
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(exports, "createImportDeclaration", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: function () { return chunkTNIGP6OU_cjs.createImportDeclaration; }
|
|
34
|
+
});
|
|
35
|
+
Object.defineProperty(exports, "createIndexSignature", {
|
|
36
|
+
enumerable: true,
|
|
37
|
+
get: function () { return chunkTNIGP6OU_cjs.createIndexSignature; }
|
|
38
|
+
});
|
|
39
|
+
Object.defineProperty(exports, "createIntersectionDeclaration", {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
get: function () { return chunkTNIGP6OU_cjs.createIntersectionDeclaration; }
|
|
42
|
+
});
|
|
43
|
+
Object.defineProperty(exports, "createJSDoc", {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function () { return chunkTNIGP6OU_cjs.createJSDoc; }
|
|
46
|
+
});
|
|
47
|
+
Object.defineProperty(exports, "createLiteralTypeNode", {
|
|
48
|
+
enumerable: true,
|
|
49
|
+
get: function () { return chunkTNIGP6OU_cjs.createLiteralTypeNode; }
|
|
50
|
+
});
|
|
51
|
+
Object.defineProperty(exports, "createNamespaceDeclaration", {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
get: function () { return chunkTNIGP6OU_cjs.createNamespaceDeclaration; }
|
|
54
|
+
});
|
|
55
|
+
Object.defineProperty(exports, "createNull", {
|
|
56
|
+
enumerable: true,
|
|
57
|
+
get: function () { return chunkTNIGP6OU_cjs.createNull; }
|
|
58
|
+
});
|
|
59
|
+
Object.defineProperty(exports, "createNumericLiteral", {
|
|
60
|
+
enumerable: true,
|
|
61
|
+
get: function () { return chunkTNIGP6OU_cjs.createNumericLiteral; }
|
|
62
|
+
});
|
|
63
|
+
Object.defineProperty(exports, "createOmitDeclaration", {
|
|
64
|
+
enumerable: true,
|
|
65
|
+
get: function () { return chunkTNIGP6OU_cjs.createOmitDeclaration; }
|
|
66
|
+
});
|
|
67
|
+
Object.defineProperty(exports, "createParameterSignature", {
|
|
68
|
+
enumerable: true,
|
|
69
|
+
get: function () { return chunkTNIGP6OU_cjs.createParameterSignature; }
|
|
70
|
+
});
|
|
71
|
+
Object.defineProperty(exports, "createPropertySignature", {
|
|
72
|
+
enumerable: true,
|
|
73
|
+
get: function () { return chunkTNIGP6OU_cjs.createPropertySignature; }
|
|
74
|
+
});
|
|
75
|
+
Object.defineProperty(exports, "createQuestionToken", {
|
|
76
|
+
enumerable: true,
|
|
77
|
+
get: function () { return chunkTNIGP6OU_cjs.createQuestionToken; }
|
|
78
|
+
});
|
|
79
|
+
Object.defineProperty(exports, "createStringLiteral", {
|
|
80
|
+
enumerable: true,
|
|
81
|
+
get: function () { return chunkTNIGP6OU_cjs.createStringLiteral; }
|
|
82
|
+
});
|
|
83
|
+
Object.defineProperty(exports, "createTupleDeclaration", {
|
|
84
|
+
enumerable: true,
|
|
85
|
+
get: function () { return chunkTNIGP6OU_cjs.createTupleDeclaration; }
|
|
86
|
+
});
|
|
87
|
+
Object.defineProperty(exports, "createTupleTypeNode", {
|
|
88
|
+
enumerable: true,
|
|
89
|
+
get: function () { return chunkTNIGP6OU_cjs.createTupleTypeNode; }
|
|
90
|
+
});
|
|
91
|
+
Object.defineProperty(exports, "createTypeAliasDeclaration", {
|
|
92
|
+
enumerable: true,
|
|
93
|
+
get: function () { return chunkTNIGP6OU_cjs.createTypeAliasDeclaration; }
|
|
94
|
+
});
|
|
95
|
+
Object.defineProperty(exports, "createTypeLiteralNode", {
|
|
96
|
+
enumerable: true,
|
|
97
|
+
get: function () { return chunkTNIGP6OU_cjs.createTypeLiteralNode; }
|
|
98
|
+
});
|
|
99
|
+
Object.defineProperty(exports, "createTypeReferenceNode", {
|
|
100
|
+
enumerable: true,
|
|
101
|
+
get: function () { return chunkTNIGP6OU_cjs.createTypeReferenceNode; }
|
|
102
|
+
});
|
|
103
|
+
Object.defineProperty(exports, "createUnionDeclaration", {
|
|
104
|
+
enumerable: true,
|
|
105
|
+
get: function () { return chunkTNIGP6OU_cjs.createUnionDeclaration; }
|
|
106
|
+
});
|
|
107
|
+
Object.defineProperty(exports, "keywordTypeNodes", {
|
|
108
|
+
enumerable: true,
|
|
109
|
+
get: function () { return chunkTNIGP6OU_cjs.keywordTypeNodes; }
|
|
110
|
+
});
|
|
111
|
+
Object.defineProperty(exports, "modifiers", {
|
|
112
|
+
enumerable: true,
|
|
113
|
+
get: function () { return chunkTNIGP6OU_cjs.modifiers; }
|
|
114
|
+
});
|
|
115
|
+
//# sourceMappingURL=factory.cjs.map
|
|
59
116
|
//# sourceMappingURL=factory.cjs.map
|
package/dist/factory.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"factory.cjs"}
|
package/dist/factory.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
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-
|
|
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-CFXA_d49.cjs';
|
package/dist/factory.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
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-
|
|
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-CFXA_d49.js';
|
package/dist/factory.js
CHANGED
|
@@ -1,59 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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-QHLKNPYD.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
|
-
};
|
|
1
|
+
export { appendJSDocToNode, createArrayDeclaration, createArrayTypeNode, createEnumDeclaration, createExportDeclaration, createIdentifier, createImportDeclaration, createIndexSignature, createIntersectionDeclaration, createJSDoc, createLiteralTypeNode, createNamespaceDeclaration, createNull, createNumericLiteral, createOmitDeclaration, createParameterSignature, createPropertySignature, createQuestionToken, createStringLiteral, createTupleDeclaration, createTupleTypeNode, createTypeAliasDeclaration, createTypeLiteralNode, createTypeReferenceNode, createUnionDeclaration, keywordTypeNodes, modifiers } from './chunk-2BN5RQSZ.js';
|
|
2
|
+
//# sourceMappingURL=factory.js.map
|
|
59
3
|
//# sourceMappingURL=factory.js.map
|
package/dist/factory.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"factory.js"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,47 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkTNIGP6OU_cjs = require('./chunk-TNIGP6OU.cjs');
|
|
4
|
+
var ts = require('typescript');
|
|
4
5
|
|
|
5
|
-
|
|
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
|
-
}
|
|
6
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
36
7
|
|
|
37
|
-
|
|
8
|
+
var ts__default = /*#__PURE__*/_interopDefault(ts);
|
|
38
9
|
|
|
39
|
-
var { factory } =
|
|
10
|
+
var { factory } = ts__default.default;
|
|
40
11
|
var escapeNewLines = (code) => code.replace(/\n\n/g, "\n/* :newline: */");
|
|
41
12
|
var restoreNewLines = (code) => code.replace(/\/\* :newline: \*\//g, "\n");
|
|
42
|
-
function print(elements, { source = "", baseName = "print.ts", removeComments, noEmitHelpers, newLine =
|
|
43
|
-
const sourceFile =
|
|
44
|
-
const printer =
|
|
13
|
+
function print(elements, { source = "", baseName = "print.ts", removeComments, noEmitHelpers, newLine = ts__default.default.NewLineKind.LineFeed } = {}) {
|
|
14
|
+
const sourceFile = ts__default.default.createSourceFile(baseName, escapeNewLines(source), ts__default.default.ScriptTarget.ES2022, false, ts__default.default.ScriptKind.TS);
|
|
15
|
+
const printer = ts__default.default.createPrinter({
|
|
45
16
|
omitTrailingSemicolon: true,
|
|
46
17
|
newLine,
|
|
47
18
|
removeComments,
|
|
@@ -56,22 +27,21 @@ function print(elements, { source = "", baseName = "print.ts", removeComments, n
|
|
|
56
27
|
} else {
|
|
57
28
|
nodes = [elements].filter(Boolean);
|
|
58
29
|
}
|
|
59
|
-
const outputFile = printer.printList(
|
|
30
|
+
const outputFile = printer.printList(ts__default.default.ListFormat.MultiLine, factory.createNodeArray(nodes), sourceFile);
|
|
60
31
|
const outputSource = printer.printFile(sourceFile);
|
|
61
32
|
return [outputFile, restoreNewLines(outputSource)].filter(Boolean).join("\n");
|
|
62
33
|
}
|
|
63
34
|
|
|
64
|
-
// src/
|
|
65
|
-
function
|
|
66
|
-
return {
|
|
67
|
-
ast,
|
|
68
|
-
text: print(ast)
|
|
69
|
-
};
|
|
35
|
+
// src/format.ts
|
|
36
|
+
function format(source) {
|
|
37
|
+
return print([], { source, noEmitHelpers: false });
|
|
70
38
|
}
|
|
71
39
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
exports.
|
|
40
|
+
Object.defineProperty(exports, "factory", {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
get: function () { return chunkTNIGP6OU_cjs.factory_exports; }
|
|
43
|
+
});
|
|
44
|
+
exports.format = format;
|
|
45
|
+
exports.print = print;
|
|
46
|
+
//# sourceMappingURL=index.cjs.map
|
|
77
47
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["
|
|
1
|
+
{"version":3,"sources":["../src/print.ts","../src/format.ts"],"names":["ts"],"mappings":";;;;;;;;;AAIA,IAAM,EAAE,SAAY,GAAAA,mBAAA,CAAA;AAYpB,IAAM,iBAAiB,CAAC,IAAA,KAAiB,IAAK,CAAA,OAAA,CAAQ,SAAS,mBAAmB,CAAA,CAAA;AAOlF,IAAM,kBAAkB,CAAC,IAAA,KAAiB,IAAK,CAAA,OAAA,CAAQ,wBAAwB,IAAI,CAAA,CAAA;AAK5E,SAAS,KACd,CAAA,QAAA,EACA,EAAE,MAAA,GAAS,IAAI,QAAW,GAAA,UAAA,EAAY,cAAgB,EAAA,aAAA,EAAe,UAAUA,mBAAG,CAAA,WAAA,CAAY,QAAS,EAAA,GAAa,EAC5G,EAAA;AACR,EAAA,MAAM,UAAa,GAAAA,mBAAA,CAAG,gBAAiB,CAAA,QAAA,EAAU,cAAe,CAAA,MAAM,CAAG,EAAAA,mBAAA,CAAG,YAAa,CAAA,MAAA,EAAQ,KAAO,EAAAA,mBAAA,CAAG,WAAW,EAAE,CAAA,CAAA;AACxH,EAAM,MAAA,OAAA,GAAUA,oBAAG,aAAc,CAAA;AAAA,IAC/B,qBAAuB,EAAA,IAAA;AAAA,IACvB,OAAA;AAAA,IACA,cAAA;AAAA,IACA,aAAA;AAAA,GACD,CAAA,CAAA;AAED,EAAA,IAAI,QAAwB,EAAC,CAAA;AAE7B,EAAA,IAAI,CAAC,QAAU,EAAA;AACb,IAAO,OAAA,EAAA,CAAA;AAAA,GACT;AAEA,EAAI,IAAA,KAAA,CAAM,OAAQ,CAAA,QAAQ,CAAG,EAAA;AAC3B,IAAQ,KAAA,GAAA,QAAA,CAAS,OAAO,OAAO,CAAA,CAAA;AAAA,GAC1B,MAAA;AACL,IAAA,KAAA,GAAQ,CAAC,QAAQ,CAAE,CAAA,MAAA,CAAO,OAAO,CAAA,CAAA;AAAA,GACnC;AAEA,EAAM,MAAA,UAAA,GAAa,OAAQ,CAAA,SAAA,CAAUA,mBAAG,CAAA,UAAA,CAAW,WAAW,OAAQ,CAAA,eAAA,CAAgB,KAAK,CAAA,EAAG,UAAU,CAAA,CAAA;AACxG,EAAM,MAAA,YAAA,GAAe,OAAQ,CAAA,SAAA,CAAU,UAAU,CAAA,CAAA;AAEjD,EAAO,OAAA,CAAC,UAAY,EAAA,eAAA,CAAgB,YAAY,CAAC,EAAE,MAAO,CAAA,OAAO,CAAE,CAAA,IAAA,CAAK,IAAI,CAAA,CAAA;AAC9E,CAAA;;;ACnDO,SAAS,OAAO,MAAgB,EAAA;AAErC,EAAA,OAAO,MAAM,EAAC,EAAG,EAAE,MAAQ,EAAA,aAAA,EAAe,OAAO,CAAA,CAAA;AACnD","file":"index.cjs","sourcesContent":["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\n/**\n * Convert AST TypeScript nodes to a string based on the TypeScript printer.\n */\nexport function print(\n elements: Array<ts.Node>,\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\n/**\n * Format the generated code based on the TypeScript printer.\n */\nexport function format(source: string) {\n // do some basic linting with the ts compiler\n return print([], { source, noEmitHelpers: false })\n}\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,26 +1,18 @@
|
|
|
1
1
|
import ts, { PrinterOptions } from 'typescript';
|
|
2
|
-
export {
|
|
3
|
-
export { f as factory } from './factory-Cd7U4lxv.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;
|
|
2
|
+
export { f as factory } from './factory-CFXA_d49.cjs';
|
|
19
3
|
|
|
20
4
|
type Options = {
|
|
21
5
|
source?: string;
|
|
22
6
|
baseName?: string;
|
|
23
7
|
} & PrinterOptions;
|
|
24
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Convert AST TypeScript nodes to a string based on the TypeScript printer.
|
|
10
|
+
*/
|
|
11
|
+
declare function print(elements: Array<ts.Node>, { source, baseName, removeComments, noEmitHelpers, newLine }?: Options): string;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Format the generated code based on the TypeScript printer.
|
|
15
|
+
*/
|
|
16
|
+
declare function format(source: string): string;
|
|
25
17
|
|
|
26
|
-
export {
|
|
18
|
+
export { format, print };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,26 +1,18 @@
|
|
|
1
1
|
import ts, { PrinterOptions } from 'typescript';
|
|
2
|
-
export {
|
|
3
|
-
export { f as factory } from './factory-Cd7U4lxv.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;
|
|
2
|
+
export { f as factory } from './factory-CFXA_d49.js';
|
|
19
3
|
|
|
20
4
|
type Options = {
|
|
21
5
|
source?: string;
|
|
22
6
|
baseName?: string;
|
|
23
7
|
} & PrinterOptions;
|
|
24
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Convert AST TypeScript nodes to a string based on the TypeScript printer.
|
|
10
|
+
*/
|
|
11
|
+
declare function print(elements: Array<ts.Node>, { source, baseName, removeComments, noEmitHelpers, newLine }?: Options): string;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Format the generated code based on the TypeScript printer.
|
|
15
|
+
*/
|
|
16
|
+
declare function format(source: string): string;
|
|
25
17
|
|
|
26
|
-
export {
|
|
18
|
+
export { format, print };
|
package/dist/index.js
CHANGED
|
@@ -1,47 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
} from "./chunk-QHLKNPYD.js";
|
|
1
|
+
export { factory_exports as factory } from './chunk-2BN5RQSZ.js';
|
|
2
|
+
import ts from 'typescript';
|
|
4
3
|
|
|
5
|
-
|
|
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;
|
|
4
|
+
var { factory } = ts;
|
|
40
5
|
var escapeNewLines = (code) => code.replace(/\n\n/g, "\n/* :newline: */");
|
|
41
6
|
var restoreNewLines = (code) => code.replace(/\/\* :newline: \*\//g, "\n");
|
|
42
|
-
function print(elements, { source = "", baseName = "print.ts", removeComments, noEmitHelpers, newLine =
|
|
43
|
-
const sourceFile =
|
|
44
|
-
const printer =
|
|
7
|
+
function print(elements, { source = "", baseName = "print.ts", removeComments, noEmitHelpers, newLine = ts.NewLineKind.LineFeed } = {}) {
|
|
8
|
+
const sourceFile = ts.createSourceFile(baseName, escapeNewLines(source), ts.ScriptTarget.ES2022, false, ts.ScriptKind.TS);
|
|
9
|
+
const printer = ts.createPrinter({
|
|
45
10
|
omitTrailingSemicolon: true,
|
|
46
11
|
newLine,
|
|
47
12
|
removeComments,
|
|
@@ -56,22 +21,16 @@ function print(elements, { source = "", baseName = "print.ts", removeComments, n
|
|
|
56
21
|
} else {
|
|
57
22
|
nodes = [elements].filter(Boolean);
|
|
58
23
|
}
|
|
59
|
-
const outputFile = printer.printList(
|
|
24
|
+
const outputFile = printer.printList(ts.ListFormat.MultiLine, factory.createNodeArray(nodes), sourceFile);
|
|
60
25
|
const outputSource = printer.printFile(sourceFile);
|
|
61
26
|
return [outputFile, restoreNewLines(outputSource)].filter(Boolean).join("\n");
|
|
62
27
|
}
|
|
63
28
|
|
|
64
|
-
// src/
|
|
65
|
-
function
|
|
66
|
-
return {
|
|
67
|
-
ast,
|
|
68
|
-
text: print(ast)
|
|
69
|
-
};
|
|
29
|
+
// src/format.ts
|
|
30
|
+
function format(source) {
|
|
31
|
+
return print([], { source, noEmitHelpers: false });
|
|
70
32
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
parse,
|
|
75
|
-
print
|
|
76
|
-
};
|
|
33
|
+
|
|
34
|
+
export { format, print };
|
|
35
|
+
//# sourceMappingURL=index.js.map
|
|
77
36
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/
|
|
1
|
+
{"version":3,"sources":["../src/print.ts","../src/format.ts"],"names":[],"mappings":";;;AAIA,IAAM,EAAE,SAAY,GAAA,EAAA,CAAA;AAYpB,IAAM,iBAAiB,CAAC,IAAA,KAAiB,IAAK,CAAA,OAAA,CAAQ,SAAS,mBAAmB,CAAA,CAAA;AAOlF,IAAM,kBAAkB,CAAC,IAAA,KAAiB,IAAK,CAAA,OAAA,CAAQ,wBAAwB,IAAI,CAAA,CAAA;AAK5E,SAAS,KACd,CAAA,QAAA,EACA,EAAE,MAAA,GAAS,IAAI,QAAW,GAAA,UAAA,EAAY,cAAgB,EAAA,aAAA,EAAe,UAAU,EAAG,CAAA,WAAA,CAAY,QAAS,EAAA,GAAa,EAC5G,EAAA;AACR,EAAA,MAAM,UAAa,GAAA,EAAA,CAAG,gBAAiB,CAAA,QAAA,EAAU,cAAe,CAAA,MAAM,CAAG,EAAA,EAAA,CAAG,YAAa,CAAA,MAAA,EAAQ,KAAO,EAAA,EAAA,CAAG,WAAW,EAAE,CAAA,CAAA;AACxH,EAAM,MAAA,OAAA,GAAU,GAAG,aAAc,CAAA;AAAA,IAC/B,qBAAuB,EAAA,IAAA;AAAA,IACvB,OAAA;AAAA,IACA,cAAA;AAAA,IACA,aAAA;AAAA,GACD,CAAA,CAAA;AAED,EAAA,IAAI,QAAwB,EAAC,CAAA;AAE7B,EAAA,IAAI,CAAC,QAAU,EAAA;AACb,IAAO,OAAA,EAAA,CAAA;AAAA,GACT;AAEA,EAAI,IAAA,KAAA,CAAM,OAAQ,CAAA,QAAQ,CAAG,EAAA;AAC3B,IAAQ,KAAA,GAAA,QAAA,CAAS,OAAO,OAAO,CAAA,CAAA;AAAA,GAC1B,MAAA;AACL,IAAA,KAAA,GAAQ,CAAC,QAAQ,CAAE,CAAA,MAAA,CAAO,OAAO,CAAA,CAAA;AAAA,GACnC;AAEA,EAAM,MAAA,UAAA,GAAa,OAAQ,CAAA,SAAA,CAAU,EAAG,CAAA,UAAA,CAAW,WAAW,OAAQ,CAAA,eAAA,CAAgB,KAAK,CAAA,EAAG,UAAU,CAAA,CAAA;AACxG,EAAM,MAAA,YAAA,GAAe,OAAQ,CAAA,SAAA,CAAU,UAAU,CAAA,CAAA;AAEjD,EAAO,OAAA,CAAC,UAAY,EAAA,eAAA,CAAgB,YAAY,CAAC,EAAE,MAAO,CAAA,OAAO,CAAE,CAAA,IAAA,CAAK,IAAI,CAAA,CAAA;AAC9E,CAAA;;;ACnDO,SAAS,OAAO,MAAgB,EAAA;AAErC,EAAA,OAAO,MAAM,EAAC,EAAG,EAAE,MAAQ,EAAA,aAAA,EAAe,OAAO,CAAA,CAAA;AACnD","file":"index.js","sourcesContent":["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\n/**\n * Convert AST TypeScript nodes to a string based on the TypeScript printer.\n */\nexport function print(\n elements: Array<ts.Node>,\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\n/**\n * Format the generated code based on the TypeScript printer.\n */\nexport function format(source: string) {\n // do some basic linting with the ts compiler\n return print([], { source, noEmitHelpers: false })\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/parser-ts",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.21",
|
|
4
4
|
"description": "TypeScript parser",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -48,16 +48,13 @@
|
|
|
48
48
|
"!/**/__tests__/**"
|
|
49
49
|
],
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"remeda": "^2.
|
|
52
|
-
"
|
|
53
|
-
"typescript": "^5.5.4"
|
|
51
|
+
"remeda": "^2.14.0",
|
|
52
|
+
"typescript": "^5.6.2"
|
|
54
53
|
},
|
|
55
54
|
"devDependencies": {
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"@kubb/config-
|
|
59
|
-
"@kubb/config-ts": "3.0.0-alpha.2",
|
|
60
|
-
"@kubb/config-tsup": "3.0.0-alpha.2"
|
|
55
|
+
"tsup": "^8.3.0",
|
|
56
|
+
"@kubb/config-ts": "3.0.0-alpha.21",
|
|
57
|
+
"@kubb/config-tsup": "3.0.0-alpha.21"
|
|
61
58
|
},
|
|
62
59
|
"engines": {
|
|
63
60
|
"node": ">=20"
|
package/src/factory.ts
CHANGED
|
@@ -332,7 +332,7 @@ export function createExportDeclaration({
|
|
|
332
332
|
name?: string | Array<ts.Identifier | string>
|
|
333
333
|
}) {
|
|
334
334
|
if (name && !Array.isArray(name) && !asAlias) {
|
|
335
|
-
|
|
335
|
+
console.warn(`When using name as string, asAlias should be true ${name}`)
|
|
336
336
|
}
|
|
337
337
|
|
|
338
338
|
if (!Array.isArray(name)) {
|
|
@@ -379,9 +379,10 @@ export function createEnumDeclaration({
|
|
|
379
379
|
*/
|
|
380
380
|
typeName: string
|
|
381
381
|
enums: [key: string | number, value: string | number | boolean][]
|
|
382
|
-
}) {
|
|
382
|
+
}): [name: ts.Node | undefined, type: ts.Node] {
|
|
383
383
|
if (type === 'literal') {
|
|
384
384
|
return [
|
|
385
|
+
undefined,
|
|
385
386
|
factory.createTypeAliasDeclaration(
|
|
386
387
|
[factory.createToken(ts.SyntaxKind.ExportKeyword)],
|
|
387
388
|
factory.createIdentifier(typeName),
|
|
@@ -410,6 +411,7 @@ export function createEnumDeclaration({
|
|
|
410
411
|
|
|
411
412
|
if (type === 'enum' || type === 'constEnum') {
|
|
412
413
|
return [
|
|
414
|
+
undefined,
|
|
413
415
|
factory.createEnumDeclaration(
|
|
414
416
|
[factory.createToken(ts.SyntaxKind.ExportKeyword), type === 'constEnum' ? factory.createToken(ts.SyntaxKind.ConstKeyword) : undefined].filter(Boolean),
|
|
415
417
|
factory.createIdentifier(typeName),
|
|
@@ -490,7 +492,7 @@ export function createEnumDeclaration({
|
|
|
490
492
|
),
|
|
491
493
|
),
|
|
492
494
|
factory.createTypeAliasDeclaration(
|
|
493
|
-
[factory.createToken(ts.SyntaxKind.ExportKeyword)],
|
|
495
|
+
type === 'asPascalConst' ? [] : [factory.createToken(ts.SyntaxKind.ExportKeyword)],
|
|
494
496
|
factory.createIdentifier(typeName),
|
|
495
497
|
undefined,
|
|
496
498
|
factory.createIndexedAccessTypeNode(
|
package/src/format.ts
ADDED
package/src/index.ts
CHANGED