@kubb/parser-ts 3.16.2 → 3.16.4

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/dist/index.js CHANGED
@@ -1,40 +1,59 @@
1
- export { factory_exports as factory } from './chunk-BEHWCDCH.js';
2
- import ts from 'typescript';
3
- import { format as format$1 } from 'prettier';
4
- import pluginTypescript from 'prettier/plugins/typescript';
1
+ import { factory_exports } from "./factory-CTKjALU5.js";
2
+ import ts from "typescript";
3
+ import { format as format$1 } from "prettier";
4
+ import pluginTypescript from "prettier/plugins/typescript";
5
5
 
6
- var { factory } = ts;
7
- var escapeNewLines = (code) => code.replace(/\n\n/g, "\n/* :newline: */");
8
- var restoreNewLines = (code) => code.replace(/\/\* :newline: \*\//g, "\n");
6
+ //#region src/print.ts
7
+ const { factory } = ts;
8
+ /**
9
+ * Escaped new lines in code with block comments so they can be restored by {@link restoreNewLines}
10
+ * @param code The code to escape new lines in
11
+ * @returns The same code but with new lines escaped using block comments
12
+ */
13
+ const escapeNewLines = (code) => code.replace(/\n\n/g, "\n/* :newline: */");
14
+ /**
15
+ * Reverses {@link escapeNewLines} and restores new lines
16
+ * @param code The code with escaped new lines
17
+ * @returns The same code with new lines restored
18
+ */
19
+ const restoreNewLines = (code) => code.replace(/\/\* :newline: \*\//g, "\n");
20
+ /**
21
+ * Convert AST TypeScript nodes to a string based on the TypeScript printer.
22
+ * Ensures consistent output across environments.
23
+ */
9
24
  function print(elements, { source = "", baseName = "print.ts", removeComments, noEmitHelpers, newLine = ts.NewLineKind.LineFeed, scriptKind = ts.ScriptKind.TS } = {}) {
10
- const sourceFile = ts.createSourceFile(baseName, escapeNewLines(source), ts.ScriptTarget.ES2022, false, scriptKind);
11
- const printer = ts.createPrinter({
12
- omitTrailingSemicolon: true,
13
- newLine,
14
- removeComments,
15
- noEmitHelpers
16
- });
17
- const nodes = (Array.isArray(elements) ? elements : [elements]).filter(Boolean).sort((a, b) => (a.pos ?? 0) - (b.pos ?? 0));
18
- const output = printer.printList(ts.ListFormat.MultiLine, factory.createNodeArray(nodes), sourceFile);
19
- return restoreNewLines(output).replace(/\r\n/g, "\n");
25
+ const sourceFile = ts.createSourceFile(baseName, escapeNewLines(source), ts.ScriptTarget.ES2022, false, scriptKind);
26
+ const printer = ts.createPrinter({
27
+ omitTrailingSemicolon: true,
28
+ newLine,
29
+ removeComments,
30
+ noEmitHelpers
31
+ });
32
+ const nodes = (Array.isArray(elements) ? elements : [elements]).filter(Boolean).sort((a, b) => (a.pos ?? 0) - (b.pos ?? 0));
33
+ const output = printer.printList(ts.ListFormat.MultiLine, factory.createNodeArray(nodes), sourceFile);
34
+ return restoreNewLines(output).replace(/\r\n/g, "\n");
20
35
  }
21
- var formatOptions = {
22
- tabWidth: 2,
23
- printWidth: 160,
24
- parser: "typescript",
25
- singleQuote: true,
26
- semi: false,
27
- bracketSameLine: false,
28
- endOfLine: "auto",
29
- plugins: [pluginTypescript]
36
+
37
+ //#endregion
38
+ //#region src/format.ts
39
+ const formatOptions = {
40
+ tabWidth: 2,
41
+ printWidth: 160,
42
+ parser: "typescript",
43
+ singleQuote: true,
44
+ semi: false,
45
+ bracketSameLine: false,
46
+ endOfLine: "auto",
47
+ plugins: [pluginTypescript]
30
48
  };
49
+ /**
50
+ * Format the generated code based on Prettier
51
+ */
31
52
  async function format(source) {
32
- if (!source) {
33
- return "";
34
- }
35
- return format$1(source, formatOptions);
53
+ if (!source) return "";
54
+ return format$1(source, formatOptions);
36
55
  }
37
56
 
38
- export { format, print };
39
- //# sourceMappingURL=index.js.map
57
+ //#endregion
58
+ export { factory_exports as factory, format, print };
40
59
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/print.ts","../src/format.ts"],"names":["prettierFormat"],"mappings":";;;;;AAIA,IAAM,EAAE,SAAY,GAAA,EAAA;AAapB,IAAM,iBAAiB,CAAC,IAAA,KAAiB,IAAK,CAAA,OAAA,CAAQ,SAAS,mBAAmB,CAAA;AAOlF,IAAM,kBAAkB,CAAC,IAAA,KAAiB,IAAK,CAAA,OAAA,CAAQ,wBAAwB,IAAI,CAAA;AAM5E,SAAS,MACd,QACA,EAAA,EAAE,SAAS,EAAI,EAAA,QAAA,GAAW,YAAY,cAAgB,EAAA,aAAA,EAAe,UAAU,EAAG,CAAA,WAAA,CAAY,UAAU,UAAa,GAAA,EAAA,CAAG,WAAW,EAAG,EAAA,GAAkB,EAChJ,EAAA;AACR,EAAM,MAAA,UAAA,GAAa,EAAG,CAAA,gBAAA,CAAiB,QAAU,EAAA,cAAA,CAAe,MAAM,CAAA,EAAG,EAAG,CAAA,YAAA,CAAa,MAAQ,EAAA,KAAA,EAAO,UAAU,CAAA;AAElH,EAAM,MAAA,OAAA,GAAU,GAAG,aAAc,CAAA;AAAA,IAC/B,qBAAuB,EAAA,IAAA;AAAA,IACvB,OAAA;AAAA,IACA,cAAA;AAAA,IACA;AAAA,GACD,CAAA;AAED,EAAM,MAAA,KAAA,GAAA,CAAS,MAAM,OAAQ,CAAA,QAAQ,IAAI,QAAW,GAAA,CAAC,QAAQ,CAAG,EAAA,MAAA,CAAO,OAAO,CAAE,CAAA,IAAA,CAAK,CAAC,CAAG,EAAA,CAAA,KAAA,CAAO,EAAE,GAAO,IAAA,CAAA,KAAM,CAAE,CAAA,GAAA,IAAO,CAAE,CAAA,CAAA;AAE1H,EAAM,MAAA,MAAA,GAAS,OAAQ,CAAA,SAAA,CAAU,EAAG,CAAA,UAAA,CAAW,WAAW,OAAQ,CAAA,eAAA,CAAgB,KAAK,CAAA,EAAG,UAAU,CAAA;AAEpG,EAAA,OAAO,eAAgB,CAAA,MAAM,CAAE,CAAA,OAAA,CAAQ,SAAS,IAAI,CAAA;AACtD;AC3CA,IAAM,aAAyB,GAAA;AAAA,EAC7B,QAAU,EAAA,CAAA;AAAA,EACV,UAAY,EAAA,GAAA;AAAA,EACZ,MAAQ,EAAA,YAAA;AAAA,EACR,WAAa,EAAA,IAAA;AAAA,EACb,IAAM,EAAA,KAAA;AAAA,EACN,eAAiB,EAAA,KAAA;AAAA,EACjB,SAAW,EAAA,MAAA;AAAA,EACX,OAAA,EAAS,CAAC,gBAAgB;AAC5B,CAAA;AAKA,eAAsB,OAAO,MAAgB,EAAA;AAE3C,EAAA,IAAI,CAAC,MAAQ,EAAA;AACX,IAAO,OAAA,EAAA;AAAA;AAGT,EAAO,OAAAA,QAAA,CAAe,QAAQ,aAAa,CAAA;AAC7C","file":"index.js","sourcesContent":["import ts from 'typescript'\n\nimport type { PrinterOptions } from 'typescript'\n\nconst { factory } = ts\n\nexport type PrintOptions = {\n source?: string\n baseName?: string\n scriptKind?: ts.ScriptKind\n} & PrinterOptions\n\n/**\n * Escaped new lines in code with block comments so they can be restored by {@link restoreNewLines}\n * @param 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 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 * Ensures consistent output across environments.\n */\nexport function print(\n elements: Array<ts.Node>,\n { source = '', baseName = 'print.ts', removeComments, noEmitHelpers, newLine = ts.NewLineKind.LineFeed, scriptKind = ts.ScriptKind.TS }: PrintOptions = {},\n): string {\n const sourceFile = ts.createSourceFile(baseName, escapeNewLines(source), ts.ScriptTarget.ES2022, false, scriptKind)\n\n const printer = ts.createPrinter({\n omitTrailingSemicolon: true,\n newLine,\n removeComments,\n noEmitHelpers,\n })\n // make sure that the nodes have the same order on every machine\n const nodes = (Array.isArray(elements) ? elements : [elements]).filter(Boolean).sort((a, b) => (a.pos ?? 0) - (b.pos ?? 0))\n\n const output = printer.printList(ts.ListFormat.MultiLine, factory.createNodeArray(nodes), sourceFile)\n\n return restoreNewLines(output).replace(/\\r\\n/g, '\\n')\n}\n","import { format as prettierFormat } from 'prettier'\nimport pluginTypescript from 'prettier/plugins/typescript'\n\nimport type { Options } from 'prettier'\n\nconst formatOptions: Options = {\n tabWidth: 2,\n printWidth: 160,\n parser: 'typescript',\n singleQuote: true,\n semi: false,\n bracketSameLine: false,\n endOfLine: 'auto',\n plugins: [pluginTypescript],\n}\n\n/**\n * Format the generated code based on Prettier\n */\nexport async function format(source: string) {\n // do some basic linting with the ts compiler\n if (!source) {\n return ''\n }\n\n return prettierFormat(source, formatOptions)\n}\n"]}
1
+ {"version":3,"file":"index.js","names":["code: string","elements: Array<ts.Node>","formatOptions: Options","source: string","prettierFormat"],"sources":["../src/print.ts","../src/format.ts"],"sourcesContent":["import ts from 'typescript'\n\nimport type { PrinterOptions } from 'typescript'\n\nconst { factory } = ts\n\nexport type PrintOptions = {\n source?: string\n baseName?: string\n scriptKind?: ts.ScriptKind\n} & PrinterOptions\n\n/**\n * Escaped new lines in code with block comments so they can be restored by {@link restoreNewLines}\n * @param 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 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 * Ensures consistent output across environments.\n */\nexport function print(\n elements: Array<ts.Node>,\n { source = '', baseName = 'print.ts', removeComments, noEmitHelpers, newLine = ts.NewLineKind.LineFeed, scriptKind = ts.ScriptKind.TS }: PrintOptions = {},\n): string {\n const sourceFile = ts.createSourceFile(baseName, escapeNewLines(source), ts.ScriptTarget.ES2022, false, scriptKind)\n\n const printer = ts.createPrinter({\n omitTrailingSemicolon: true,\n newLine,\n removeComments,\n noEmitHelpers,\n })\n // make sure that the nodes have the same order on every machine\n const nodes = (Array.isArray(elements) ? elements : [elements]).filter(Boolean).sort((a, b) => (a.pos ?? 0) - (b.pos ?? 0))\n\n const output = printer.printList(ts.ListFormat.MultiLine, factory.createNodeArray(nodes), sourceFile)\n\n return restoreNewLines(output).replace(/\\r\\n/g, '\\n')\n}\n","import { format as prettierFormat } from 'prettier'\nimport pluginTypescript from 'prettier/plugins/typescript'\n\nimport type { Options } from 'prettier'\n\nconst formatOptions: Options = {\n tabWidth: 2,\n printWidth: 160,\n parser: 'typescript',\n singleQuote: true,\n semi: false,\n bracketSameLine: false,\n endOfLine: 'auto',\n plugins: [pluginTypescript],\n}\n\n/**\n * Format the generated code based on Prettier\n */\nexport async function format(source: string) {\n // do some basic linting with the ts compiler\n if (!source) {\n return ''\n }\n\n return prettierFormat(source, formatOptions)\n}\n"],"mappings":";;;;;;AAIA,MAAM,EAAE,SAAS,GAAG;;;;;;AAapB,MAAM,iBAAiB,CAACA,SAAiB,KAAK,QAAQ,SAAS,oBAAoB;;;;;;AAOnF,MAAM,kBAAkB,CAACA,SAAiB,KAAK,QAAQ,wBAAwB,KAAK;;;;;AAMpF,SAAgB,MACdC,UACA,EAAE,SAAS,IAAI,WAAW,YAAY,gBAAgB,eAAe,UAAU,GAAG,YAAY,UAAU,aAAa,GAAG,WAAW,IAAkB,GAAG,CAAE,GAClJ;CACR,MAAM,aAAa,GAAG,iBAAiB,UAAU,eAAe,OAAO,EAAE,GAAG,aAAa,QAAQ,OAAO,WAAW;CAEnH,MAAM,UAAU,GAAG,cAAc;EAC/B,uBAAuB;EACvB;EACA;EACA;CACD,EAAC;CAEF,MAAM,SAAS,MAAM,QAAQ,SAAS,GAAG,WAAW,CAAC,QAAS,GAAE,OAAO,QAAQ,CAAC,KAAK,CAAC,GAAG,OAAO,EAAE,OAAO,MAAM,EAAE,OAAO,GAAG;CAE3H,MAAM,SAAS,QAAQ,UAAU,GAAG,WAAW,WAAW,QAAQ,gBAAgB,MAAM,EAAE,WAAW;AAErG,QAAO,gBAAgB,OAAO,CAAC,QAAQ,SAAS,KAAK;AACtD;;;;AC3CD,MAAMC,gBAAyB;CAC7B,UAAU;CACV,YAAY;CACZ,QAAQ;CACR,aAAa;CACb,MAAM;CACN,iBAAiB;CACjB,WAAW;CACX,SAAS,CAAC,gBAAiB;AAC5B;;;;AAKD,eAAsB,OAAOC,QAAgB;AAE3C,KAAI,CAAC,OACH,QAAO;AAGT,QAAOC,SAAe,QAAQ,cAAc;AAC7C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/parser-ts",
3
- "version": "3.16.2",
3
+ "version": "3.16.4",
4
4
  "description": "TypeScript parsing and manipulation utilities for Kubb, enabling code generation with proper TypeScript syntax and formatting.",
5
5
  "keywords": [
6
6
  "typescript",
@@ -24,19 +24,16 @@
24
24
  "exports": {
25
25
  ".": {
26
26
  "import": "./dist/index.js",
27
- "require": "./dist/index.cjs",
28
- "default": "./dist/index.cjs"
27
+ "require": "./dist/index.cjs"
29
28
  },
30
29
  "./factory": {
31
30
  "import": "./dist/factory.js",
32
- "require": "./dist/factory.cjs",
33
- "default": "./dist/factory.cjs"
31
+ "require": "./dist/factory.cjs"
34
32
  },
35
- "./package.json": "./package.json",
36
- "./*": "./*"
33
+ "./package.json": "./package.json"
37
34
  },
38
- "main": "dist/index.cjs",
39
- "module": "dist/index.js",
35
+ "main": "./dist/index.cjs",
36
+ "module": "./dist/index.js",
40
37
  "types": "./dist/index.d.cts",
41
38
  "typesVersions": {
42
39
  "*": {
@@ -57,9 +54,8 @@
57
54
  "typescript": "5.9.2"
58
55
  },
59
56
  "devDependencies": {
60
- "tsup": "^8.5.0",
61
- "@kubb/config-ts": "3.16.2",
62
- "@kubb/config-tsup": "3.16.2"
57
+ "tsdown": "^0.14.1",
58
+ "@kubb/config-ts": "3.16.4"
63
59
  },
64
60
  "engines": {
65
61
  "node": ">=20"
@@ -69,13 +65,13 @@
69
65
  "registry": "https://registry.npmjs.org/"
70
66
  },
71
67
  "scripts": {
72
- "build": "tsup",
68
+ "build": "tsdown",
73
69
  "clean": "npx rimraf ./dist",
74
70
  "lint": "bun biome lint .",
75
- "lint:fix": "bun biome lint--fix --unsafe .",
71
+ "lint:fix": "bun biome lint --fix --unsafe .",
76
72
  "release": "pnpm publish --no-git-check",
77
73
  "release:canary": "bash ../../.github/canary.sh && node ../../scripts/build.js canary && pnpm publish --no-git-check",
78
- "start": "tsup --watch",
74
+ "start": "tsdown --watch",
79
75
  "test": "vitest --passWithNoTests",
80
76
  "typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false"
81
77
  }
package/src/factory.ts CHANGED
@@ -442,9 +442,9 @@ export function createEnumDeclaration({
442
442
  enums
443
443
  .map(([key, value]) => {
444
444
  let initializer: ts.Expression = factory.createStringLiteral(value?.toString())
445
- const isExactNumber = Number.parseInt(value.toString()) === value
445
+ const isExactNumber = Number.parseInt(value.toString(), 10) === value
446
446
 
447
- if (isExactNumber && isNumber(Number.parseInt(value.toString()))) {
447
+ if (isExactNumber && isNumber(Number.parseInt(value.toString(), 10))) {
448
448
  initializer = factory.createNumericLiteral(value as number)
449
449
  }
450
450
 
@@ -452,7 +452,7 @@ export function createEnumDeclaration({
452
452
  initializer = value ? factory.createTrue() : factory.createFalse()
453
453
  }
454
454
 
455
- if (isNumber(Number.parseInt(key.toString()))) {
455
+ if (isNumber(Number.parseInt(key.toString(), 10))) {
456
456
  return factory.createEnumMember(factory.createStringLiteral(`${typeName}_${key}`), initializer)
457
457
  }
458
458
 
@@ -1,461 +0,0 @@
1
- import { isNumber } from 'remeda';
2
- import ts from 'typescript';
3
-
4
- var __defProp = Object.defineProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
-
10
- // src/factory.ts
11
- var factory_exports = {};
12
- __export(factory_exports, {
13
- appendJSDocToNode: () => appendJSDocToNode,
14
- createArrayDeclaration: () => createArrayDeclaration,
15
- createArrayTypeNode: () => createArrayTypeNode,
16
- createEnumDeclaration: () => createEnumDeclaration,
17
- createExportDeclaration: () => createExportDeclaration,
18
- createFalse: () => createFalse,
19
- createIdentifier: () => createIdentifier,
20
- createImportDeclaration: () => createImportDeclaration,
21
- createIndexSignature: () => createIndexSignature,
22
- createInterfaceDeclaration: () => createInterfaceDeclaration,
23
- createIntersectionDeclaration: () => createIntersectionDeclaration,
24
- createJSDoc: () => createJSDoc,
25
- createLiteralTypeNode: () => createLiteralTypeNode,
26
- createNamespaceDeclaration: () => createNamespaceDeclaration,
27
- createNull: () => createNull,
28
- createNumericLiteral: () => createNumericLiteral,
29
- createOmitDeclaration: () => createOmitDeclaration,
30
- createOptionalTypeNode: () => createOptionalTypeNode,
31
- createParameterSignature: () => createParameterSignature,
32
- createPropertySignature: () => createPropertySignature,
33
- createQuestionToken: () => createQuestionToken,
34
- createRestTypeNode: () => createRestTypeNode,
35
- createStringLiteral: () => createStringLiteral,
36
- createTrue: () => createTrue,
37
- createTupleDeclaration: () => createTupleDeclaration,
38
- createTupleTypeNode: () => createTupleTypeNode,
39
- createTypeAliasDeclaration: () => createTypeAliasDeclaration,
40
- createTypeDeclaration: () => createTypeDeclaration,
41
- createTypeLiteralNode: () => createTypeLiteralNode,
42
- createTypeReferenceNode: () => createTypeReferenceNode,
43
- createUnionDeclaration: () => createUnionDeclaration,
44
- keywordTypeNodes: () => keywordTypeNodes,
45
- modifiers: () => modifiers,
46
- syntaxKind: () => syntaxKind
47
- });
48
- var { SyntaxKind, factory } = ts;
49
- var modifiers = {
50
- async: factory.createModifier(ts.SyntaxKind.AsyncKeyword),
51
- export: factory.createModifier(ts.SyntaxKind.ExportKeyword),
52
- const: factory.createModifier(ts.SyntaxKind.ConstKeyword),
53
- static: factory.createModifier(ts.SyntaxKind.StaticKeyword)
54
- };
55
- var syntaxKind = {
56
- union: SyntaxKind.UnionType
57
- };
58
- function isValidIdentifier(str) {
59
- if (!str.length || str.trim() !== str) {
60
- return false;
61
- }
62
- const node = ts.parseIsolatedEntityName(str, ts.ScriptTarget.Latest);
63
- return !!node && node.kind === ts.SyntaxKind.Identifier && ts.identifierToKeywordKind(node.kind) === void 0;
64
- }
65
- function propertyName(name) {
66
- if (typeof name === "string") {
67
- return isValidIdentifier(name) ? factory.createIdentifier(name) : factory.createStringLiteral(name);
68
- }
69
- return name;
70
- }
71
- var questionToken = factory.createToken(ts.SyntaxKind.QuestionToken);
72
- function createQuestionToken(token) {
73
- if (!token) {
74
- return void 0;
75
- }
76
- if (token === true) {
77
- return questionToken;
78
- }
79
- return token;
80
- }
81
- function createIntersectionDeclaration({ nodes, withParentheses }) {
82
- if (!nodes.length) {
83
- return null;
84
- }
85
- if (nodes.length === 1) {
86
- return nodes[0] || null;
87
- }
88
- const node = factory.createIntersectionTypeNode(nodes);
89
- if (withParentheses) {
90
- return factory.createParenthesizedType(node);
91
- }
92
- return node;
93
- }
94
- function createTupleDeclaration({ nodes, withParentheses }) {
95
- if (!nodes.length) {
96
- return null;
97
- }
98
- if (nodes.length === 1) {
99
- return nodes[0] || null;
100
- }
101
- const node = factory.createTupleTypeNode(nodes);
102
- if (withParentheses) {
103
- return factory.createParenthesizedType(node);
104
- }
105
- return node;
106
- }
107
- function createArrayDeclaration({ nodes }) {
108
- if (!nodes.length) {
109
- return factory.createTupleTypeNode([]);
110
- }
111
- if (nodes.length === 1) {
112
- return factory.createArrayTypeNode(nodes.at(0));
113
- }
114
- return factory.createExpressionWithTypeArguments(factory.createIdentifier("Array"), [factory.createUnionTypeNode(nodes)]);
115
- }
116
- function createUnionDeclaration({ nodes, withParentheses }) {
117
- if (!nodes.length) {
118
- return keywordTypeNodes.any;
119
- }
120
- if (nodes.length === 1) {
121
- return nodes[0];
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(ts.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({ node, comments }) {
169
- const filteredComments = comments.filter(Boolean);
170
- if (!filteredComments.length) {
171
- return node;
172
- }
173
- const text = filteredComments.reduce((acc = "", comment = "") => {
174
- return `${acc}
175
- * ${comment.replaceAll("*/", "*\\/")}`;
176
- }, "*");
177
- return ts.addSyntheticLeadingComment({ ...node }, ts.SyntaxKind.MultiLineCommentTrivia, `${text || "*"}
178
- `, true);
179
- }
180
- function createIndexSignature(type, {
181
- modifiers: modifiers2,
182
- indexName = "key",
183
- indexType = factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword)
184
- } = {}) {
185
- return factory.createIndexSignature(modifiers2, [createParameterSignature(indexName, { type: indexType })], type);
186
- }
187
- function createTypeAliasDeclaration({
188
- modifiers: modifiers2,
189
- name,
190
- typeParameters,
191
- type
192
- }) {
193
- return factory.createTypeAliasDeclaration(modifiers2, name, typeParameters, type);
194
- }
195
- function createInterfaceDeclaration({
196
- modifiers: modifiers2,
197
- name,
198
- typeParameters,
199
- members
200
- }) {
201
- return factory.createInterfaceDeclaration(modifiers2, name, typeParameters, void 0, members);
202
- }
203
- function createTypeDeclaration({
204
- syntax,
205
- isExportable,
206
- comments,
207
- name,
208
- type
209
- }) {
210
- if (syntax === "interface" && "members" in type) {
211
- const node2 = createInterfaceDeclaration({
212
- members: type.members,
213
- modifiers: isExportable ? [modifiers.export] : [],
214
- name,
215
- typeParameters: void 0
216
- });
217
- return appendJSDocToNode({
218
- node: node2,
219
- comments
220
- });
221
- }
222
- const node = createTypeAliasDeclaration({
223
- type,
224
- modifiers: isExportable ? [modifiers.export] : [],
225
- name,
226
- typeParameters: void 0
227
- });
228
- return appendJSDocToNode({
229
- node,
230
- comments
231
- });
232
- }
233
- function createNamespaceDeclaration({ statements, name }) {
234
- return factory.createModuleDeclaration(
235
- [factory.createToken(ts.SyntaxKind.ExportKeyword)],
236
- factory.createIdentifier(name),
237
- factory.createModuleBlock(statements),
238
- ts.NodeFlags.Namespace
239
- );
240
- }
241
- function createImportDeclaration({
242
- name,
243
- path,
244
- isTypeOnly = false,
245
- isNameSpace = false
246
- }) {
247
- if (!Array.isArray(name)) {
248
- let importPropertyName = factory.createIdentifier(name);
249
- let importName;
250
- if (isNameSpace) {
251
- importPropertyName = void 0;
252
- importName = factory.createNamespaceImport(factory.createIdentifier(name));
253
- }
254
- return factory.createImportDeclaration(
255
- void 0,
256
- factory.createImportClause(isTypeOnly, importPropertyName, importName),
257
- factory.createStringLiteral(path),
258
- void 0
259
- );
260
- }
261
- return factory.createImportDeclaration(
262
- void 0,
263
- factory.createImportClause(
264
- isTypeOnly,
265
- void 0,
266
- factory.createNamedImports(
267
- name.map((item) => {
268
- if (typeof item === "object") {
269
- const obj = item;
270
- if (obj.name) {
271
- return factory.createImportSpecifier(false, factory.createIdentifier(obj.propertyName), factory.createIdentifier(obj.name));
272
- }
273
- return factory.createImportSpecifier(false, void 0, factory.createIdentifier(obj.propertyName));
274
- }
275
- return factory.createImportSpecifier(false, void 0, factory.createIdentifier(item));
276
- })
277
- )
278
- ),
279
- factory.createStringLiteral(path),
280
- void 0
281
- );
282
- }
283
- function createExportDeclaration({
284
- path,
285
- asAlias,
286
- isTypeOnly = false,
287
- name
288
- }) {
289
- if (name && !Array.isArray(name) && !asAlias) {
290
- console.warn(`When using name as string, asAlias should be true ${name}`);
291
- }
292
- if (!Array.isArray(name)) {
293
- const parsedName = name?.match(/^\d/) ? `_${name?.slice(1)}` : name;
294
- return factory.createExportDeclaration(
295
- void 0,
296
- isTypeOnly,
297
- asAlias && parsedName ? factory.createNamespaceExport(factory.createIdentifier(parsedName)) : void 0,
298
- factory.createStringLiteral(path),
299
- void 0
300
- );
301
- }
302
- return factory.createExportDeclaration(
303
- void 0,
304
- isTypeOnly,
305
- factory.createNamedExports(
306
- name.map((propertyName2) => {
307
- return factory.createExportSpecifier(false, void 0, typeof propertyName2 === "string" ? factory.createIdentifier(propertyName2) : propertyName2);
308
- })
309
- ),
310
- factory.createStringLiteral(path),
311
- void 0
312
- );
313
- }
314
- function createEnumDeclaration({
315
- type = "enum",
316
- name,
317
- typeName,
318
- enums
319
- }) {
320
- if (type === "literal") {
321
- return [
322
- void 0,
323
- factory.createTypeAliasDeclaration(
324
- [factory.createToken(ts.SyntaxKind.ExportKeyword)],
325
- factory.createIdentifier(typeName),
326
- void 0,
327
- factory.createUnionTypeNode(
328
- enums.map(([_key, value]) => {
329
- if (isNumber(value)) {
330
- return factory.createLiteralTypeNode(factory.createNumericLiteral(value?.toString()));
331
- }
332
- if (typeof value === "boolean") {
333
- return factory.createLiteralTypeNode(value ? factory.createTrue() : factory.createFalse());
334
- }
335
- if (value) {
336
- return factory.createLiteralTypeNode(factory.createStringLiteral(value.toString()));
337
- }
338
- return void 0;
339
- }).filter(Boolean)
340
- )
341
- )
342
- ];
343
- }
344
- if (type === "enum" || type === "constEnum") {
345
- return [
346
- void 0,
347
- factory.createEnumDeclaration(
348
- [factory.createToken(ts.SyntaxKind.ExportKeyword), type === "constEnum" ? factory.createToken(ts.SyntaxKind.ConstKeyword) : void 0].filter(Boolean),
349
- factory.createIdentifier(typeName),
350
- enums.map(([key, value]) => {
351
- let initializer = factory.createStringLiteral(value?.toString());
352
- const isExactNumber = Number.parseInt(value.toString()) === value;
353
- if (isExactNumber && isNumber(Number.parseInt(value.toString()))) {
354
- initializer = factory.createNumericLiteral(value);
355
- }
356
- if (typeof value === "boolean") {
357
- initializer = value ? factory.createTrue() : factory.createFalse();
358
- }
359
- if (isNumber(Number.parseInt(key.toString()))) {
360
- return factory.createEnumMember(factory.createStringLiteral(`${typeName}_${key}`), initializer);
361
- }
362
- if (key) {
363
- return factory.createEnumMember(factory.createStringLiteral(`${key}`), initializer);
364
- }
365
- return void 0;
366
- }).filter(Boolean)
367
- )
368
- ];
369
- }
370
- const identifierName = type === "asPascalConst" ? typeName : name;
371
- return [
372
- factory.createVariableStatement(
373
- [factory.createToken(ts.SyntaxKind.ExportKeyword)],
374
- factory.createVariableDeclarationList(
375
- [
376
- factory.createVariableDeclaration(
377
- factory.createIdentifier(identifierName),
378
- void 0,
379
- void 0,
380
- factory.createAsExpression(
381
- factory.createObjectLiteralExpression(
382
- enums.map(([key, value]) => {
383
- let initializer = factory.createStringLiteral(value?.toString());
384
- if (isNumber(value)) {
385
- if (value < 0) {
386
- initializer = factory.createPrefixUnaryExpression(ts.SyntaxKind.MinusToken, factory.createNumericLiteral(Math.abs(value)));
387
- } else {
388
- initializer = factory.createNumericLiteral(value);
389
- }
390
- }
391
- if (typeof value === "boolean") {
392
- initializer = value ? factory.createTrue() : factory.createFalse();
393
- }
394
- if (key) {
395
- return factory.createPropertyAssignment(factory.createStringLiteral(`${key}`), initializer);
396
- }
397
- return void 0;
398
- }).filter(Boolean),
399
- true
400
- ),
401
- factory.createTypeReferenceNode(factory.createIdentifier("const"), void 0)
402
- )
403
- )
404
- ],
405
- ts.NodeFlags.Const
406
- )
407
- ),
408
- factory.createTypeAliasDeclaration(
409
- type === "asPascalConst" ? [] : [factory.createToken(ts.SyntaxKind.ExportKeyword)],
410
- factory.createIdentifier(typeName),
411
- void 0,
412
- factory.createIndexedAccessTypeNode(
413
- factory.createParenthesizedType(factory.createTypeQueryNode(factory.createIdentifier(identifierName), void 0)),
414
- factory.createTypeOperatorNode(ts.SyntaxKind.KeyOfKeyword, factory.createTypeQueryNode(factory.createIdentifier(identifierName), void 0))
415
- )
416
- )
417
- ];
418
- }
419
- function createOmitDeclaration({ keys, type, nonNullable }) {
420
- const node = nonNullable ? factory.createTypeReferenceNode(factory.createIdentifier("NonNullable"), [type]) : type;
421
- if (Array.isArray(keys)) {
422
- return factory.createTypeReferenceNode(factory.createIdentifier("Omit"), [
423
- node,
424
- factory.createUnionTypeNode(
425
- keys.map((key) => {
426
- return factory.createLiteralTypeNode(factory.createStringLiteral(key));
427
- })
428
- )
429
- ]);
430
- }
431
- return factory.createTypeReferenceNode(factory.createIdentifier("Omit"), [node, factory.createLiteralTypeNode(factory.createStringLiteral(keys))]);
432
- }
433
- var keywordTypeNodes = {
434
- any: factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword),
435
- unknown: factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword),
436
- void: factory.createKeywordTypeNode(ts.SyntaxKind.VoidKeyword),
437
- number: factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword),
438
- integer: factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword),
439
- object: factory.createKeywordTypeNode(ts.SyntaxKind.ObjectKeyword),
440
- string: factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword),
441
- boolean: factory.createKeywordTypeNode(ts.SyntaxKind.BooleanKeyword),
442
- undefined: factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword),
443
- null: factory.createLiteralTypeNode(factory.createToken(ts.SyntaxKind.NullKeyword))
444
- };
445
- var createTypeLiteralNode = factory.createTypeLiteralNode;
446
- var createTypeReferenceNode = factory.createTypeReferenceNode;
447
- var createNumericLiteral = factory.createNumericLiteral;
448
- var createStringLiteral = factory.createStringLiteral;
449
- var createArrayTypeNode = factory.createArrayTypeNode;
450
- var createLiteralTypeNode = factory.createLiteralTypeNode;
451
- var createNull = factory.createNull;
452
- var createIdentifier = factory.createIdentifier;
453
- var createOptionalTypeNode = factory.createOptionalTypeNode;
454
- var createTupleTypeNode = factory.createTupleTypeNode;
455
- var createRestTypeNode = factory.createRestTypeNode;
456
- var createTrue = factory.createTrue;
457
- var createFalse = factory.createFalse;
458
-
459
- export { appendJSDocToNode, createArrayDeclaration, createArrayTypeNode, createEnumDeclaration, createExportDeclaration, createFalse, createIdentifier, createImportDeclaration, createIndexSignature, createInterfaceDeclaration, createIntersectionDeclaration, createJSDoc, createLiteralTypeNode, createNamespaceDeclaration, createNull, createNumericLiteral, createOmitDeclaration, createOptionalTypeNode, createParameterSignature, createPropertySignature, createQuestionToken, createRestTypeNode, createStringLiteral, createTrue, createTupleDeclaration, createTupleTypeNode, createTypeAliasDeclaration, createTypeDeclaration, createTypeLiteralNode, createTypeReferenceNode, createUnionDeclaration, factory_exports, keywordTypeNodes, modifiers, syntaxKind };
460
- //# sourceMappingURL=chunk-BEHWCDCH.js.map
461
- //# sourceMappingURL=chunk-BEHWCDCH.js.map