@kubb/parser-ts 3.0.0-alpha.4 → 3.0.0-alpha.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 CHANGED
@@ -5,7 +5,7 @@ var _chunkUQLRYRTMcjs = require('./chunk-UQLRYRTM.cjs');
5
5
  // src/api.ts
6
6
  var _path = require('path'); var _path2 = _interopRequireDefault(_path);
7
7
  var _typescript = require('typescript'); var _typescript2 = _interopRequireDefault(_typescript);
8
- function getExports(filePath) {
8
+ function getExports(filePath, source) {
9
9
  const rootName = _path2.default.extname(filePath) ? filePath : `${filePath}.ts`;
10
10
  if (!rootName) {
11
11
  return void 0;
@@ -16,7 +16,7 @@ function getExports(filePath) {
16
16
  });
17
17
  const checker = program.getTypeChecker();
18
18
  const sources = program.getSourceFiles();
19
- const sourceFile = sources.find((sourceFile2) => sourceFile2.fileName === rootName);
19
+ const sourceFile = source ? _typescript2.default.createSourceFile(rootName, source, _typescript2.default.ScriptTarget.ES2022, false, _typescript2.default.ScriptKind.TS) : sources.find((sourceFile2) => sourceFile2.fileName === rootName);
20
20
  if (!sourceFile) {
21
21
  return void 0;
22
22
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/kubb/kubb/packages/parser-ts/dist/index.cjs","../src/api.ts","../src/print.ts","../src/parse.ts"],"names":["sourceFile","ts"],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACA;ACJA,wEAAiB;AAEjB,gGAAe;AAUR,SAAS,UAAA,CAAW,QAAA,EAAoD;AAC7E,EAAA,MAAM,SAAA,EAAW,cAAA,CAAK,OAAA,CAAQ,QAAQ,EAAA,EAAI,SAAA,EAAW,CAAA,EAAA;AAEtC,EAAA;AACN,IAAA;AACT,EAAA;AAEiC,EAAA;AACX,IAAA;AACV,IAAA;AACX,EAAA;AAEsC,EAAA;AACA,EAAA;AACSA,EAAAA;AAE/B,EAAA;AACR,IAAA;AACT,EAAA;AAEqD,EAAA;AAEjC,EAAA;AACX,IAAA;AACT,EAAA;AAEiD,EAAA;AACvB,EAAA;AAEc,IAAA;AAE/B,IAAA;AACwB,MAAA;AACJ,MAAA;AAC3B,IAAA;AACD,EAAA;AACH;ADbwD;AACA;AEpCzC;AAIKC;AAY2C;AAOR;AAI3B;AAEuB,EAAA;AAChB,EAAA;AACR,IAAA;AACvB,IAAA;AACA,IAAA;AACA,IAAA;AACD,EAAA;AAE4B,EAAA;AAEd,EAAA;AACN,IAAA;AACT,EAAA;AAE6B,EAAA;AACI,IAAA;AAC1B,EAAA;AAC4B,IAAA;AACnC,EAAA;AAEmD,EAAA;AACF,EAAA;AAEE,EAAA;AACrD;AFSwD;AACA;AGtDP;AACxC,EAAA;AACL,IAAA;AACe,IAAA;AACjB,EAAA;AACF;AHwDwD;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/kubb/kubb/packages/parser-ts/dist/index.cjs","sourcesContent":[null,"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"]}
1
+ {"version":3,"sources":["/home/runner/work/kubb/kubb/packages/parser-ts/dist/index.cjs","../src/api.ts","../src/print.ts","../src/parse.ts"],"names":["ts"],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACA;ACJA,wEAAiB;AAEjB,gGAAe;AAUR,SAAS,UAAA,CAAW,QAAA,EAAkB,MAAA,EAAmD;AAC9F,EAAA,MAAM,SAAA,EAAW,cAAA,CAAK,OAAA,CAAQ,QAAQ,EAAA,EAAI,SAAA,EAAW,CAAA,EAAA;AAEtC,EAAA;AACN,IAAA;AACT,EAAA;AAEiC,EAAA;AACX,IAAA;AACV,IAAA;AACX,EAAA;AAEsC,EAAA;AACA,EAAA;AAEf,EAAA;AAGP,EAAA;AACR,IAAA;AACT,EAAA;AAEqD,EAAA;AAEjC,EAAA;AACX,IAAA;AACT,EAAA;AAEiD,EAAA;AACvB,EAAA;AAEc,IAAA;AAE/B,IAAA;AACwB,MAAA;AACJ,MAAA;AAC3B,IAAA;AACD,EAAA;AACH;ADfwD;AACA;AEpCzC;AAIKA;AAY2C;AAOR;AAI3B;AAEuB,EAAA;AAChB,EAAA;AACR,IAAA;AACvB,IAAA;AACA,IAAA;AACA,IAAA;AACD,EAAA;AAE4B,EAAA;AAEd,EAAA;AACN,IAAA;AACT,EAAA;AAE6B,EAAA;AACI,IAAA;AAC1B,EAAA;AAC4B,IAAA;AACnC,EAAA;AAEmD,EAAA;AACF,EAAA;AAEE,EAAA;AACrD;AFSwD;AACA;AGtDP;AACxC,EAAA;AACL,IAAA;AACe,IAAA;AACjB,EAAA;AACF;AHwDwD;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/kubb/kubb/packages/parser-ts/dist/index.cjs","sourcesContent":[null,"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, source?: 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 = source\n ? ts.createSourceFile(rootName, source, ts.ScriptTarget.ES2022, false, ts.ScriptKind.TS)\n : 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 CHANGED
@@ -9,7 +9,7 @@ type ExportsResult = {
9
9
  /**
10
10
  * @link https://github.com/microsoft/TypeScript/issues/15840
11
11
  */
12
- declare function getExports(filePath: string): undefined | Array<ExportsResult>;
12
+ declare function getExports(filePath: string, source?: string): undefined | Array<ExportsResult>;
13
13
 
14
14
  type ParseResult = {
15
15
  ast: ts.Node;
package/dist/index.d.ts CHANGED
@@ -9,7 +9,7 @@ type ExportsResult = {
9
9
  /**
10
10
  * @link https://github.com/microsoft/TypeScript/issues/15840
11
11
  */
12
- declare function getExports(filePath: string): undefined | Array<ExportsResult>;
12
+ declare function getExports(filePath: string, source?: string): undefined | Array<ExportsResult>;
13
13
 
14
14
  type ParseResult = {
15
15
  ast: ts.Node;
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  // src/api.ts
6
6
  import path from "path";
7
7
  import ts from "typescript";
8
- function getExports(filePath) {
8
+ function getExports(filePath, source) {
9
9
  const rootName = path.extname(filePath) ? filePath : `${filePath}.ts`;
10
10
  if (!rootName) {
11
11
  return void 0;
@@ -16,7 +16,7 @@ function getExports(filePath) {
16
16
  });
17
17
  const checker = program.getTypeChecker();
18
18
  const sources = program.getSourceFiles();
19
- const sourceFile = sources.find((sourceFile2) => sourceFile2.fileName === rootName);
19
+ const sourceFile = source ? ts.createSourceFile(rootName, source, ts.ScriptTarget.ES2022, false, ts.ScriptKind.TS) : sources.find((sourceFile2) => sourceFile2.fileName === rootName);
20
20
  if (!sourceFile) {
21
21
  return void 0;
22
22
  }
package/dist/index.js.map CHANGED
@@ -1 +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"]}
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, source?: 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 = source\n ? ts.createSourceFile(rootName, source, ts.ScriptTarget.ES2022, false, ts.ScriptKind.TS)\n : 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,UAAkB,QAAmD;AAC9F,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,SACf,GAAG,iBAAiB,UAAU,QAAQ,GAAG,aAAa,QAAQ,OAAO,GAAG,WAAW,EAAE,IACrF,QAAQ,KAAK,CAACA,gBAAeA,YAAW,aAAa,QAAQ;AAEjE,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;;;AClDA,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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/parser-ts",
3
- "version": "3.0.0-alpha.4",
3
+ "version": "3.0.0-alpha.5",
4
4
  "description": "TypeScript parser",
5
5
  "keywords": [
6
6
  "typescript",
@@ -55,9 +55,9 @@
55
55
  "devDependencies": {
56
56
  "prettier": "^3.3.3",
57
57
  "tsup": "^8.2.4",
58
- "@kubb/config-biome": "3.0.0-alpha.4",
59
- "@kubb/config-ts": "3.0.0-alpha.4",
60
- "@kubb/config-tsup": "3.0.0-alpha.4"
58
+ "@kubb/config-biome": "3.0.0-alpha.5",
59
+ "@kubb/config-ts": "3.0.0-alpha.5",
60
+ "@kubb/config-tsup": "3.0.0-alpha.5"
61
61
  },
62
62
  "engines": {
63
63
  "node": ">=20"
package/src/api.ts CHANGED
@@ -10,7 +10,7 @@ type ExportsResult = {
10
10
  /**
11
11
  * @link https://github.com/microsoft/TypeScript/issues/15840
12
12
  */
13
- export function getExports(filePath: string): undefined | Array<ExportsResult> {
13
+ export function getExports(filePath: string, source?: string): undefined | Array<ExportsResult> {
14
14
  const rootName = path.extname(filePath) ? filePath : `${filePath}.ts`
15
15
 
16
16
  if (!rootName) {
@@ -24,7 +24,9 @@ export function getExports(filePath: string): undefined | Array<ExportsResult> {
24
24
 
25
25
  const checker = program.getTypeChecker()
26
26
  const sources = program.getSourceFiles()
27
- const sourceFile = sources.find((sourceFile) => sourceFile.fileName === rootName)
27
+ const sourceFile = source
28
+ ? ts.createSourceFile(rootName, source, ts.ScriptTarget.ES2022, false, ts.ScriptKind.TS)
29
+ : sources.find((sourceFile) => sourceFile.fileName === rootName)
28
30
 
29
31
  if (!sourceFile) {
30
32
  return undefined