@kubb/parser-ts 3.0.3 → 3.0.5
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.cjs +4 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/format.ts +3 -3
- package/src/print.ts +5 -4
package/dist/index.cjs
CHANGED
|
@@ -10,8 +10,8 @@ var ts__default = /*#__PURE__*/_interopDefault(ts);
|
|
|
10
10
|
var { factory } = ts__default.default;
|
|
11
11
|
var escapeNewLines = (code) => code.replace(/\n\n/g, "\n/* :newline: */");
|
|
12
12
|
var restoreNewLines = (code) => code.replace(/\/\* :newline: \*\//g, "\n");
|
|
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,
|
|
13
|
+
function print(elements, { source = "", baseName = "print.ts", removeComments, noEmitHelpers, newLine = ts__default.default.NewLineKind.LineFeed, scriptKind = ts__default.default.ScriptKind.TS } = {}) {
|
|
14
|
+
const sourceFile = ts__default.default.createSourceFile(baseName, escapeNewLines(source), ts__default.default.ScriptTarget.ES2022, false, scriptKind);
|
|
15
15
|
const printer = ts__default.default.createPrinter({
|
|
16
16
|
omitTrailingSemicolon: true,
|
|
17
17
|
newLine,
|
|
@@ -33,8 +33,8 @@ function print(elements, { source = "", baseName = "print.ts", removeComments, n
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
// src/format.ts
|
|
36
|
-
function format(source) {
|
|
37
|
-
return print([], { source, noEmitHelpers: false });
|
|
36
|
+
function format(source, options = {}) {
|
|
37
|
+
return print([], { source, noEmitHelpers: false, ...options });
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
Object.defineProperty(exports, "factory", {
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/print.ts","../src/format.ts"],"names":["ts"],"mappings":";;;;;;;;;AAIA,IAAM,EAAE,SAAY,GAAAA,mBAAA;
|
|
1
|
+
{"version":3,"sources":["../src/print.ts","../src/format.ts"],"names":["ts"],"mappings":";;;;;;;;;AAIA,IAAM,EAAE,SAAY,GAAAA,mBAAA;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;AAK5E,SAAS,MACd,QACA,EAAA,EAAE,SAAS,EAAI,EAAA,QAAA,GAAW,YAAY,cAAgB,EAAA,aAAA,EAAe,UAAUA,mBAAG,CAAA,WAAA,CAAY,UAAU,UAAa,GAAAA,mBAAA,CAAG,WAAW,EAAG,EAAA,GAAkB,EAChJ,EAAA;AACR,EAAM,MAAA,UAAA,GAAaA,mBAAG,CAAA,gBAAA,CAAiB,QAAU,EAAA,cAAA,CAAe,MAAM,CAAA,EAAGA,mBAAG,CAAA,YAAA,CAAa,MAAQ,EAAA,KAAA,EAAO,UAAU,CAAA;AAClH,EAAM,MAAA,OAAA,GAAUA,oBAAG,aAAc,CAAA;AAAA,IAC/B,qBAAuB,EAAA,IAAA;AAAA,IACvB,OAAA;AAAA,IACA,cAAA;AAAA,IACA;AAAA,GACD,CAAA;AAED,EAAA,IAAI,QAAwB,EAAC;AAE7B,EAAA,IAAI,CAAC,QAAU,EAAA;AACb,IAAO,OAAA,EAAA;AAAA;AAGT,EAAI,IAAA,KAAA,CAAM,OAAQ,CAAA,QAAQ,CAAG,EAAA;AAC3B,IAAQ,KAAA,GAAA,QAAA,CAAS,OAAO,OAAO,CAAA;AAAA,GAC1B,MAAA;AACL,IAAA,KAAA,GAAQ,CAAC,QAAQ,CAAE,CAAA,MAAA,CAAO,OAAO,CAAA;AAAA;AAGnC,EAAM,MAAA,UAAA,GAAa,OAAQ,CAAA,SAAA,CAAUA,mBAAG,CAAA,UAAA,CAAW,WAAW,OAAQ,CAAA,eAAA,CAAgB,KAAK,CAAA,EAAG,UAAU,CAAA;AACxG,EAAM,MAAA,YAAA,GAAe,OAAQ,CAAA,SAAA,CAAU,UAAU,CAAA;AAEjD,EAAO,OAAA,CAAC,UAAY,EAAA,eAAA,CAAgB,YAAY,CAAC,EAAE,MAAO,CAAA,OAAO,CAAE,CAAA,IAAA,CAAK,IAAI,CAAA;AAC9E;;;ACpDO,SAAS,MAAO,CAAA,MAAA,EAAgB,OAAwC,GAAA,EAAI,EAAA;AAEjF,EAAO,OAAA,KAAA,CAAM,EAAI,EAAA,EAAE,QAAQ,aAAe,EAAA,KAAA,EAAO,GAAG,OAAA,EAAS,CAAA;AAC/D","file":"index.cjs","sourcesContent":["import ts, { LanguageVariant } 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 {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, scriptKind = ts.ScriptKind.TS }: PrintOptions = {},\n): string {\n const sourceFile = ts.createSourceFile(baseName, escapeNewLines(source), ts.ScriptTarget.ES2022, false, scriptKind)\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 { type PrintOptions, print } from './print.ts'\n\n/**\n * Format the generated code based on the TypeScript printer.\n */\nexport function format(source: string, options: Omit<PrintOptions, 'source'> = {}) {\n // do some basic linting with the ts compiler\n return print([], { source, noEmitHelpers: false, ...options })\n}\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import ts, { PrinterOptions } from 'typescript';
|
|
2
2
|
export { f as factory } from './factory-1NIBrzkm.cjs';
|
|
3
3
|
|
|
4
|
-
type
|
|
4
|
+
type PrintOptions = {
|
|
5
5
|
source?: string;
|
|
6
6
|
baseName?: string;
|
|
7
|
+
scriptKind?: ts.ScriptKind;
|
|
7
8
|
} & PrinterOptions;
|
|
8
9
|
/**
|
|
9
10
|
* Convert AST TypeScript nodes to a string based on the TypeScript printer.
|
|
10
11
|
*/
|
|
11
|
-
declare function print(elements: Array<ts.Node>, { source, baseName, removeComments, noEmitHelpers, newLine }?:
|
|
12
|
+
declare function print(elements: Array<ts.Node>, { source, baseName, removeComments, noEmitHelpers, newLine, scriptKind }?: PrintOptions): string;
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* Format the generated code based on the TypeScript printer.
|
|
15
16
|
*/
|
|
16
|
-
declare function format(source: string): string;
|
|
17
|
+
declare function format(source: string, options?: Omit<PrintOptions, 'source'>): string;
|
|
17
18
|
|
|
18
19
|
export { format, print };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import ts, { PrinterOptions } from 'typescript';
|
|
2
2
|
export { f as factory } from './factory-1NIBrzkm.js';
|
|
3
3
|
|
|
4
|
-
type
|
|
4
|
+
type PrintOptions = {
|
|
5
5
|
source?: string;
|
|
6
6
|
baseName?: string;
|
|
7
|
+
scriptKind?: ts.ScriptKind;
|
|
7
8
|
} & PrinterOptions;
|
|
8
9
|
/**
|
|
9
10
|
* Convert AST TypeScript nodes to a string based on the TypeScript printer.
|
|
10
11
|
*/
|
|
11
|
-
declare function print(elements: Array<ts.Node>, { source, baseName, removeComments, noEmitHelpers, newLine }?:
|
|
12
|
+
declare function print(elements: Array<ts.Node>, { source, baseName, removeComments, noEmitHelpers, newLine, scriptKind }?: PrintOptions): string;
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* Format the generated code based on the TypeScript printer.
|
|
15
16
|
*/
|
|
16
|
-
declare function format(source: string): string;
|
|
17
|
+
declare function format(source: string, options?: Omit<PrintOptions, 'source'>): string;
|
|
17
18
|
|
|
18
19
|
export { format, print };
|
package/dist/index.js
CHANGED
|
@@ -4,8 +4,8 @@ import ts from 'typescript';
|
|
|
4
4
|
var { factory } = ts;
|
|
5
5
|
var escapeNewLines = (code) => code.replace(/\n\n/g, "\n/* :newline: */");
|
|
6
6
|
var restoreNewLines = (code) => code.replace(/\/\* :newline: \*\//g, "\n");
|
|
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,
|
|
7
|
+
function print(elements, { source = "", baseName = "print.ts", removeComments, noEmitHelpers, newLine = ts.NewLineKind.LineFeed, scriptKind = ts.ScriptKind.TS } = {}) {
|
|
8
|
+
const sourceFile = ts.createSourceFile(baseName, escapeNewLines(source), ts.ScriptTarget.ES2022, false, scriptKind);
|
|
9
9
|
const printer = ts.createPrinter({
|
|
10
10
|
omitTrailingSemicolon: true,
|
|
11
11
|
newLine,
|
|
@@ -27,8 +27,8 @@ function print(elements, { source = "", baseName = "print.ts", removeComments, n
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
// src/format.ts
|
|
30
|
-
function format(source) {
|
|
31
|
-
return print([], { source, noEmitHelpers: false });
|
|
30
|
+
function format(source, options = {}) {
|
|
31
|
+
return print([], { source, noEmitHelpers: false, ...options });
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
export { format, print };
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/print.ts","../src/format.ts"],"names":[],"mappings":";;;AAIA,IAAM,EAAE,SAAY,GAAA,EAAA;
|
|
1
|
+
{"version":3,"sources":["../src/print.ts","../src/format.ts"],"names":[],"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;AAK5E,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;AAClH,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,EAAA,IAAI,QAAwB,EAAC;AAE7B,EAAA,IAAI,CAAC,QAAU,EAAA;AACb,IAAO,OAAA,EAAA;AAAA;AAGT,EAAI,IAAA,KAAA,CAAM,OAAQ,CAAA,QAAQ,CAAG,EAAA;AAC3B,IAAQ,KAAA,GAAA,QAAA,CAAS,OAAO,OAAO,CAAA;AAAA,GAC1B,MAAA;AACL,IAAA,KAAA,GAAQ,CAAC,QAAQ,CAAE,CAAA,MAAA,CAAO,OAAO,CAAA;AAAA;AAGnC,EAAM,MAAA,UAAA,GAAa,OAAQ,CAAA,SAAA,CAAU,EAAG,CAAA,UAAA,CAAW,WAAW,OAAQ,CAAA,eAAA,CAAgB,KAAK,CAAA,EAAG,UAAU,CAAA;AACxG,EAAM,MAAA,YAAA,GAAe,OAAQ,CAAA,SAAA,CAAU,UAAU,CAAA;AAEjD,EAAO,OAAA,CAAC,UAAY,EAAA,eAAA,CAAgB,YAAY,CAAC,EAAE,MAAO,CAAA,OAAO,CAAE,CAAA,IAAA,CAAK,IAAI,CAAA;AAC9E;;;ACpDO,SAAS,MAAO,CAAA,MAAA,EAAgB,OAAwC,GAAA,EAAI,EAAA;AAEjF,EAAO,OAAA,KAAA,CAAM,EAAI,EAAA,EAAE,QAAQ,aAAe,EAAA,KAAA,EAAO,GAAG,OAAA,EAAS,CAAA;AAC/D","file":"index.js","sourcesContent":["import ts, { LanguageVariant } 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 {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, scriptKind = ts.ScriptKind.TS }: PrintOptions = {},\n): string {\n const sourceFile = ts.createSourceFile(baseName, escapeNewLines(source), ts.ScriptTarget.ES2022, false, scriptKind)\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 { type PrintOptions, print } from './print.ts'\n\n/**\n * Format the generated code based on the TypeScript printer.\n */\nexport function format(source: string, options: Omit<PrintOptions, 'source'> = {}) {\n // do some basic linting with the ts compiler\n return print([], { source, noEmitHelpers: false, ...options })\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/parser-ts",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.5",
|
|
4
4
|
"description": "TypeScript parser",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -53,8 +53,8 @@
|
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"tsup": "^8.3.5",
|
|
56
|
-
"@kubb/config-ts": "3.0.
|
|
57
|
-
"@kubb/config-tsup": "3.0.
|
|
56
|
+
"@kubb/config-ts": "3.0.5",
|
|
57
|
+
"@kubb/config-tsup": "3.0.5"
|
|
58
58
|
},
|
|
59
59
|
"engines": {
|
|
60
60
|
"node": ">=20"
|
package/src/format.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { print } from './print.ts'
|
|
1
|
+
import { type PrintOptions, print } from './print.ts'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Format the generated code based on the TypeScript printer.
|
|
5
5
|
*/
|
|
6
|
-
export function format(source: string) {
|
|
6
|
+
export function format(source: string, options: Omit<PrintOptions, 'source'> = {}) {
|
|
7
7
|
// do some basic linting with the ts compiler
|
|
8
|
-
return print([], { source, noEmitHelpers: false })
|
|
8
|
+
return print([], { source, noEmitHelpers: false, ...options })
|
|
9
9
|
}
|
package/src/print.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import ts from 'typescript'
|
|
1
|
+
import ts, { LanguageVariant } from 'typescript'
|
|
2
2
|
|
|
3
3
|
import type { PrinterOptions } from 'typescript'
|
|
4
4
|
|
|
5
5
|
const { factory } = ts
|
|
6
6
|
|
|
7
|
-
type
|
|
7
|
+
export type PrintOptions = {
|
|
8
8
|
source?: string
|
|
9
9
|
baseName?: string
|
|
10
|
+
scriptKind?: ts.ScriptKind
|
|
10
11
|
} & PrinterOptions
|
|
11
12
|
|
|
12
13
|
/**
|
|
@@ -28,9 +29,9 @@ const restoreNewLines = (code: string) => code.replace(/\/\* :newline: \*\//g, '
|
|
|
28
29
|
*/
|
|
29
30
|
export function print(
|
|
30
31
|
elements: Array<ts.Node>,
|
|
31
|
-
{ source = '', baseName = 'print.ts', removeComments, noEmitHelpers, newLine = ts.NewLineKind.LineFeed }:
|
|
32
|
+
{ source = '', baseName = 'print.ts', removeComments, noEmitHelpers, newLine = ts.NewLineKind.LineFeed, scriptKind = ts.ScriptKind.TS }: PrintOptions = {},
|
|
32
33
|
): string {
|
|
33
|
-
const sourceFile = ts.createSourceFile(baseName, escapeNewLines(source), ts.ScriptTarget.ES2022, false,
|
|
34
|
+
const sourceFile = ts.createSourceFile(baseName, escapeNewLines(source), ts.ScriptTarget.ES2022, false, scriptKind)
|
|
34
35
|
const printer = ts.createPrinter({
|
|
35
36
|
omitTrailingSemicolon: true,
|
|
36
37
|
newLine,
|