@kubb/parser-ts 5.12.7 → 5.13.0

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 CHANGED
@@ -24,7 +24,7 @@
24
24
 
25
25
  ### TypeScript source file parser for Kubb
26
26
 
27
- Prints Kubb AST nodes as TypeScript source strings, and renders TypeScript compiler nodes through the `print` helper. Handles both `.ts` and `.tsx` output.
27
+ Prints Kubb AST nodes as TypeScript source strings. Handles both `.ts` and `.tsx` output.
28
28
 
29
29
  ## Installation
30
30
 
@@ -59,23 +59,7 @@ export default defineConfig({
59
59
  })
60
60
  ```
61
61
 
62
- To render compiler AST nodes to source text from inside a plugin, call `print` on a parser instance. Install `@typescript/typescript6` first, because `typescript` 7 no longer exports the compiler API:
63
-
64
- ```typescript
65
- import { parserTs } from '@kubb/parser-ts'
66
- import ts from '@typescript/typescript6'
67
-
68
- const source = parserTs().print(
69
- ts.factory.createVariableStatement(
70
- [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
71
- ts.factory.createVariableDeclarationList(
72
- [ts.factory.createVariableDeclaration('hello', undefined, undefined, ts.factory.createStringLiteral('world'))],
73
- ts.NodeFlags.Const,
74
- ),
75
- ),
76
- )
77
- // → export const hello = 'world'
78
- ```
62
+ `print(...fragments)` joins printed code strings with a newline. It still accepts TypeScript compiler nodes, but that form is deprecated and needs `typescript` 5 or 6, or `@typescript/typescript6`, installed. It is removed in the next major.
79
63
 
80
64
  ## API
81
65
 
@@ -83,7 +67,7 @@ const source = parserTs().print(
83
67
 
84
68
  Factory returning a parser instance for `.ts` and `.js` files. Pass to `defineConfig({ parsers: [...] })` to emit TypeScript source files. The optional `extension` map rewrites the extensions written in `import`/`export` statements and defaults to `{ '.ts': '' }`.
85
69
 
86
- The returned instance exposes `parse(file)` to serialize a `FileNode` to TypeScript source and `print(...nodes)` to convert TypeScript compiler `Node` instances to a formatted source string.
70
+ The returned instance exposes `parse(file)` to serialize a `FileNode` to TypeScript source and `print(...fragments)` to join printed code strings.
87
71
 
88
72
  ### `parserTsx(options?)`
89
73
 
package/dist/index.cjs CHANGED
@@ -4,36 +4,46 @@ let _kubb_ast = require("@kubb/ast");
4
4
  let _kubb_core = require("@kubb/core");
5
5
  let node_module = require("node:module");
6
6
  let node_path = require("node:path");
7
+ let node_url = require("node:url");
8
+ let yuku_parser = require("yuku-parser");
7
9
  //#region kubb-extension.json
8
10
  var compatibility = {
9
11
  "kubb": ">=5.8.3",
10
- "node": ">=22.12"
12
+ "node": ">=22.22"
11
13
  };
12
14
  //#endregion
13
15
  //#region package.json
14
- var version = "5.12.7";
16
+ var version = "5.13.0";
15
17
  //#endregion
16
18
  //#region src/utils.ts
17
19
  let compiler;
18
20
  /**
19
- * Loads TypeScript on the first `print` or `copy`; `parse` is string templating and never needs it.
21
+ * Loads TypeScript the first time `print` gets a compiler node. Strings never need it, so bundles for edge runtimes such as Cloudflare Workers leave it out.
20
22
  *
21
23
  * Loaded with `require`, not `import`: when ESM imports a CommonJS package, Node keeps a second copy of its source
22
24
  * to detect named exports, and for TypeScript that copy is about 9 MB.
23
25
  */
24
26
  function loadCompiler() {
25
27
  if (compiler) return compiler;
26
- const typescript = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href)("@typescript/typescript6");
27
- compiler = {
28
- typescript,
29
- printer: typescript.createPrinter({
30
- omitTrailingSemicolon: true,
31
- newLine: typescript.NewLineKind.LineFeed,
32
- removeComments: false,
33
- noEmitHelpers: true
34
- }),
35
- sourceFile: typescript.createSourceFile("print.tsx", "", typescript.ScriptTarget.ES2022, true, typescript.ScriptKind.TSX)
36
- };
28
+ const require$1 = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
29
+ const paths = [process.cwd(), (0, node_path.dirname)((0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href))];
30
+ let typescript;
31
+ for (const name of ["typescript", "@typescript/typescript6"]) try {
32
+ const candidate = require$1(require$1.resolve(name, { paths }));
33
+ if (typeof candidate.createPrinter === "function") {
34
+ typescript = candidate;
35
+ break;
36
+ }
37
+ } catch {}
38
+ if (!typescript) throw new Error("`print` received a TypeScript compiler node, which needs `typescript` 5 or 6, or `@typescript/typescript6`, installed. Pass a printed string instead.");
39
+ const printer = typescript.createPrinter({
40
+ omitTrailingSemicolon: true,
41
+ newLine: typescript.NewLineKind.LineFeed,
42
+ removeComments: false,
43
+ noEmitHelpers: true
44
+ });
45
+ const sourceFile = typescript.createSourceFile("print.tsx", "", typescript.ScriptTarget.ES2022, true, typescript.ScriptKind.TSX);
46
+ compiler = { printNodes: (nodes) => printer.printList(typescript.ListFormat.MultiLine, typescript.factory.createNodeArray(nodes), sourceFile) };
37
47
  return compiler;
38
48
  }
39
49
  /**
@@ -52,79 +62,95 @@ function resolveOutputPath(path, extname, rootAware) {
52
62
  return current ? `${path.slice(0, -current.length)}${extname ?? ""}` : path;
53
63
  }
54
64
  /**
65
+ * Node types this module reads from the yuku AST.
66
+ */
67
+ const nodeTypes = {
68
+ identifier: "Identifier",
69
+ literal: "Literal",
70
+ importDeclaration: "ImportDeclaration",
71
+ importSpecifier: "ImportSpecifier",
72
+ importDefaultSpecifier: "ImportDefaultSpecifier",
73
+ importNamespaceSpecifier: "ImportNamespaceSpecifier",
74
+ exportAllDeclaration: "ExportAllDeclaration",
75
+ exportNamedDeclaration: "ExportNamedDeclaration"
76
+ };
77
+ /**
78
+ * `importKind` and `exportKind` values this module reads from the yuku AST.
79
+ */
80
+ const declarationKinds = { type: "type" };
81
+ function nameOf(node) {
82
+ return node.type === nodeTypes.literal ? node.value : node.name;
83
+ }
84
+ /**
55
85
  * Converts an import specifier into an `ImportNode` name, keeping the quotes of a string-literal name (`{ 'a-b' as ab }`).
56
86
  */
57
- function toImportName(element) {
58
- if (!element.propertyName) return element.name.text;
59
- const { typescript } = loadCompiler();
60
- const { propertyName } = element;
87
+ function toImportName({ imported, local }) {
88
+ if (imported.type === nodeTypes.identifier && imported.name === local.name) return local.name;
61
89
  return {
62
- propertyName: typescript.isStringLiteral(propertyName) ? quoteModulePath(propertyName.text) : propertyName.text,
63
- name: element.name.text
90
+ propertyName: imported.type === nodeTypes.literal ? quoteModulePath(imported.value) : imported.name,
91
+ name: local.name
64
92
  };
65
93
  }
66
94
  /**
67
- * Converts an `import` declaration into `ImportNode`s. Side-effect imports and imports with attributes stay as written.
95
+ * Converts an `import` declaration into `ImportNode`s. Side-effect imports and imports with attributes or a phase stay as written.
68
96
  */
69
97
  function toImportNodes(statement, filePath) {
70
- const { typescript } = loadCompiler();
71
- if (!typescript.isImportDeclaration(statement) || !statement.importClause || !typescript.isStringLiteral(statement.moduleSpecifier) || statement.attributes) return [];
72
- const { name, namedBindings, phaseModifier } = statement.importClause;
73
- const specifier = statement.moduleSpecifier.text;
98
+ if (statement.type !== nodeTypes.importDeclaration || !statement.specifiers.length || statement.attributes.length || statement.phase) return [];
99
+ const specifier = statement.source.value;
74
100
  const target = specifier.startsWith(".") ? {
75
101
  path: (0, node_path.resolve)((0, node_path.dirname)(filePath), specifier),
76
102
  root: filePath
77
103
  } : { path: specifier };
78
- const isTypeOnly = phaseModifier === typescript.SyntaxKind.TypeKeyword;
104
+ const isTypeOnly = statement.importKind === declarationKinds.type;
79
105
  const nodes = [];
80
- if (name) nodes.push(_kubb_ast.ast.factory.createImport({
81
- name: name.text,
82
- ...target,
83
- isTypeOnly
84
- }));
85
- if (namedBindings && typescript.isNamespaceImport(namedBindings)) nodes.push(_kubb_ast.ast.factory.createImport({
86
- name: namedBindings.name.text,
87
- ...target,
88
- isTypeOnly,
89
- isNameSpace: true
90
- }));
91
- if (namedBindings && typescript.isNamedImports(namedBindings)) {
92
- const values = namedBindings.elements.filter((element) => !element.isTypeOnly);
93
- const types = namedBindings.elements.filter((element) => element.isTypeOnly);
94
- if (values.length) nodes.push(_kubb_ast.ast.factory.createImport({
95
- name: values.map(toImportName),
106
+ const named = statement.specifiers.filter((element) => element.type === nodeTypes.importSpecifier);
107
+ for (const element of statement.specifiers) {
108
+ if (element.type === nodeTypes.importDefaultSpecifier) nodes.push(_kubb_ast.ast.factory.createImport({
109
+ name: element.local.name,
96
110
  ...target,
97
111
  isTypeOnly
98
112
  }));
99
- if (types.length) nodes.push(_kubb_ast.ast.factory.createImport({
100
- name: types.map(toImportName),
113
+ if (element.type === nodeTypes.importNamespaceSpecifier) nodes.push(_kubb_ast.ast.factory.createImport({
114
+ name: element.local.name,
101
115
  ...target,
102
- isTypeOnly: true
116
+ isTypeOnly,
117
+ isNameSpace: true
103
118
  }));
104
119
  }
120
+ const values = named.filter((element) => element.importKind !== declarationKinds.type);
121
+ const types = named.filter((element) => element.importKind === declarationKinds.type);
122
+ if (values.length) nodes.push(_kubb_ast.ast.factory.createImport({
123
+ name: values.map(toImportName),
124
+ ...target,
125
+ isTypeOnly
126
+ }));
127
+ if (types.length) nodes.push(_kubb_ast.ast.factory.createImport({
128
+ name: types.map(toImportName),
129
+ ...target,
130
+ isTypeOnly: true
131
+ }));
105
132
  return nodes;
106
133
  }
107
134
  /**
108
135
  * Converts an `export … from` declaration into `ExportNode`s. Forms `printExport` cannot print stay as written.
109
136
  */
110
137
  function toExportNodes(statement) {
111
- const { typescript } = loadCompiler();
112
- if (!typescript.isExportDeclaration(statement) || !statement.moduleSpecifier || !typescript.isStringLiteral(statement.moduleSpecifier) || statement.attributes) return [];
113
- const { exportClause, isTypeOnly } = statement;
114
- const path = statement.moduleSpecifier.text;
115
- if (!exportClause) return [_kubb_ast.ast.factory.createExport({
116
- path,
117
- isTypeOnly
118
- })];
119
- if (typescript.isNamespaceExport(exportClause)) return [_kubb_ast.ast.factory.createExport({
120
- name: exportClause.name.text,
138
+ if (statement.type !== nodeTypes.exportAllDeclaration && statement.type !== nodeTypes.exportNamedDeclaration) return [];
139
+ if (!statement.source || statement.attributes.length) return [];
140
+ const path = statement.source.value;
141
+ const isTypeOnly = statement.exportKind === declarationKinds.type;
142
+ if (statement.type === nodeTypes.exportAllDeclaration) return [statement.exported ? _kubb_ast.ast.factory.createExport({
143
+ name: nameOf(statement.exported),
121
144
  path,
122
145
  isTypeOnly,
123
146
  asAlias: true
147
+ }) : _kubb_ast.ast.factory.createExport({
148
+ path,
149
+ isTypeOnly
124
150
  })];
125
- if (exportClause.elements.some((element) => element.propertyName || element.isTypeOnly || typescript.isStringLiteral(element.name))) return [];
151
+ if (statement.specifiers.some((element) => element.exportKind === declarationKinds.type || element.exported.type === nodeTypes.literal || nameOf(element.exported) !== nameOf(element.local))) return [];
126
152
  return [_kubb_ast.ast.factory.createExport({
127
- name: exportClause.elements.map((element) => element.name.text),
153
+ name: statement.specifiers.map((element) => nameOf(element.local)),
128
154
  path,
129
155
  isTypeOnly
130
156
  })];
@@ -133,26 +159,28 @@ function toExportNodes(statement) {
133
159
  * Splits `source` into its lifted `import`/`export … from` nodes, the `header` above the first one (shebang, directives, comments) and the rest as `body`.
134
160
  */
135
161
  function splitModuleDeclarations(source, filePath) {
136
- const { typescript } = loadCompiler();
137
- const sourceFile = typescript.createSourceFile(filePath, source, typescript.ScriptTarget.Latest);
162
+ const { program } = (0, yuku_parser.parse)(source, {
163
+ lang: "ts",
164
+ sourceType: "module"
165
+ });
138
166
  const imports = [];
139
167
  const exports = [];
140
168
  let header = "";
141
169
  let body = "";
142
170
  let cursor = 0;
143
- for (const statement of sourceFile.statements) {
171
+ for (const statement of program.body) {
144
172
  const importNodes = toImportNodes(statement, filePath);
145
173
  const exportNodes = toExportNodes(statement);
146
174
  if (!importNodes.length && !exportNodes.length) {
147
- if (typescript.isImportDeclaration(statement) || typescript.isExportDeclaration(statement) && statement.moduleSpecifier) break;
175
+ if (statement.type === nodeTypes.importDeclaration || (statement.type === nodeTypes.exportNamedDeclaration || statement.type === nodeTypes.exportAllDeclaration) && statement.source) break;
148
176
  continue;
149
177
  }
150
- const text = source.slice(cursor, statement.getStart(sourceFile));
178
+ const text = source.slice(cursor, statement.start);
151
179
  if (imports.length || exports.length) body += text;
152
180
  else header = text;
153
181
  imports.push(...importNodes);
154
182
  exports.push(...exportNodes);
155
- cursor = statement.getEnd();
183
+ cursor = statement.end;
156
184
  }
157
185
  return {
158
186
  header: header.trim(),
@@ -194,14 +222,15 @@ function indentLines(text) {
194
222
  */
195
223
  function dedent(text) {
196
224
  if (!text) return "";
225
+ if (!text.includes("\n")) return text.trim() ? text.trimStart() : "";
197
226
  const lines = text.split("\n");
198
227
  const isBlank = (line) => line.trim() === "";
199
228
  const start = lines.findIndex((line) => !isBlank(line));
200
229
  if (start === -1) return "";
201
230
  const end = lines.findLastIndex((line) => !isBlank(line));
202
231
  const trimmed = lines.slice(start, end + 1);
203
- const indents = trimmed.filter((line) => !isBlank(line)).map((line) => line.match(/^\s*/)?.[0].length ?? 0);
204
- const min = indents.length ? Math.min(...indents) : 0;
232
+ let min = Infinity;
233
+ for (const line of trimmed) if (!isBlank(line)) min = Math.min(min, line.length - line.trimStart().length);
205
234
  return trimmed.map((line) => isBlank(line) ? "" : line.slice(min)).join("\n");
206
235
  }
207
236
  /**
@@ -221,13 +250,17 @@ function withJSDoc({ jsDoc, declaration }) {
221
250
  return jsDocStr ? `${jsDocStr}\n${declaration}` : declaration;
222
251
  }
223
252
  /**
224
- * Converts TypeScript/TSX AST nodes to a string using the TypeScript printer.
253
+ * Joins printed code fragments with a newline.
254
+ *
255
+ * Passing TypeScript compiler nodes still works but is deprecated and needs `typescript` 5 or 6, or `@typescript/typescript6`, installed.
256
+ * Support for compiler nodes is removed in the next major.
225
257
  */
226
258
  function print(...elements) {
227
259
  const filtered = elements.filter(Boolean);
228
260
  if (filtered.length === 0) return "";
229
- const { typescript, printer, sourceFile } = loadCompiler();
230
- return printer.printList(typescript.ListFormat.MultiLine, typescript.factory.createNodeArray(filtered), sourceFile);
261
+ if (filtered.every((element) => typeof element === "string")) return filtered.join("\n");
262
+ if (filtered.every((element) => typeof element !== "string")) return loadCompiler().printNodes(filtered);
263
+ return filtered.map((element) => typeof element === "string" ? element : loadCompiler().printNodes([element]).trimEnd()).join("\n");
231
264
  }
232
265
  /**
233
266
  * Converts a {@link ast.JSDocNode} to a `/** … *\/` block, dropping blank comments.
@@ -369,8 +402,7 @@ const DEFAULT_EXTENSION = { ".ts": "" };
369
402
  /**
370
403
  * Default Kubb parser for `.ts` and `.js` files. Takes the universal AST
371
404
  * produced by an adapter and prints it as TypeScript source. Imports and exports
372
- * are rewritten based on each file's metadata and the `extension` option. The
373
- * `print` helper renders TypeScript compiler nodes with the TypeScript printer.
405
+ * are rewritten based on each file's metadata and the `extension` option.
374
406
  *
375
407
  * Used automatically when no `parsers` option is set on `defineConfig`. Use
376
408
  * `parserTsx` instead for React projects that emit JSX.
@@ -437,9 +469,8 @@ const parserTs = (0, _kubb_core.defineExtension)({
437
469
  //#endregion
438
470
  //#region src/parserTsx.ts
439
471
  /**
440
- * Kubb parser for `.tsx` and `.jsx` files. Delegates to `parserTs` because the
441
- * TypeScript compiler handles JSX natively via `ScriptKind.TSX`, so it shares the
442
- * same `extension` option.
472
+ * Kubb parser for `.tsx` and `.jsx` files. Delegates to `parserTs`, since JSX
473
+ * prints as text the same way, so it shares the same `extension` option.
443
474
  *
444
475
  * Add to the `parsers` array on `defineConfig` when generating components for
445
476
  * React (or any framework that emits JSX).
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["createRequire","relative","dirname","getExtname","resolve","ast","defineExtension","ast","defineExtension"],"sources":["../kubb-extension.json","../package.json","../src/utils.ts","../src/parserTs.ts","../src/parserTsx.ts"],"sourcesContent":["","","import { createRequire } from 'node:module'\nimport { dirname, extname as getExtname, relative, resolve } from 'node:path'\nimport { ast } from '@kubb/ast'\nimport type * as ts from '@typescript/typescript6'\n\ntype Compiler = {\n typescript: typeof ts\n printer: ts.Printer\n sourceFile: ts.SourceFile\n}\n\nlet compiler: Compiler | undefined\n\n/**\n * Loads TypeScript on the first `print` or `copy`; `parse` is string templating and never needs it.\n *\n * Loaded with `require`, not `import`: when ESM imports a CommonJS package, Node keeps a second copy of its source\n * to detect named exports, and for TypeScript that copy is about 9 MB.\n */\nfunction loadCompiler(): Compiler {\n if (compiler) return compiler\n\n const typescript: typeof ts = createRequire(import.meta.url)('@typescript/typescript6')\n\n compiler = {\n typescript,\n // One printer serves every call; printing does not mutate the source file, which only lends its compiler options\n printer: typescript.createPrinter({\n omitTrailingSemicolon: true,\n newLine: typescript.NewLineKind.LineFeed,\n removeComments: false,\n noEmitHelpers: true,\n }),\n sourceFile: typescript.createSourceFile('print.tsx', '', typescript.ScriptTarget.ES2022, true, typescript.ScriptKind.TSX),\n }\n\n return compiler\n}\n\n/**\n * Module specifier that imports `filePath` from the file at `root`: POSIX, relative to that file's directory, `./`-prefixed unless it climbs with `../`.\n */\nexport function getRelativePath(root: string, filePath: string): string {\n const slashed = relative(dirname(root), filePath).replaceAll('\\\\', '/')\n return slashed.startsWith('../') ? slashed : `./${slashed}`\n}\n\n/**\n * Swaps the extension of a relative import/export path for `extname`. Package specifiers and extension-less paths stay as-is.\n */\nexport function resolveOutputPath(path: string, extname: string | undefined, rootAware: boolean): string {\n if (!rootAware) return path\n const current = getExtname(path)\n return current ? `${path.slice(0, -current.length)}${extname ?? ''}` : path\n}\n\n/**\n * Converts an import specifier into an `ImportNode` name, keeping the quotes of a string-literal name (`{ 'a-b' as ab }`).\n */\nfunction toImportName(element: ts.ImportSpecifier): string | { propertyName: string; name: string } {\n if (!element.propertyName) return element.name.text\n\n const { typescript } = loadCompiler()\n const { propertyName } = element\n return { propertyName: typescript.isStringLiteral(propertyName) ? quoteModulePath(propertyName.text) : propertyName.text, name: element.name.text }\n}\n\n/**\n * Converts an `import` declaration into `ImportNode`s. Side-effect imports and imports with attributes stay as written.\n */\nfunction toImportNodes(statement: ts.Statement, filePath: string): Array<ast.ImportNode> {\n const { typescript } = loadCompiler()\n if (!typescript.isImportDeclaration(statement) || !statement.importClause || !typescript.isStringLiteral(statement.moduleSpecifier) || statement.attributes)\n return []\n\n const { name, namedBindings, phaseModifier } = statement.importClause\n const specifier = statement.moduleSpecifier.text\n const target = specifier.startsWith('.') ? { path: resolve(dirname(filePath), specifier), root: filePath } : { path: specifier }\n const isTypeOnly = phaseModifier === typescript.SyntaxKind.TypeKeyword\n const nodes: Array<ast.ImportNode> = []\n\n if (name) nodes.push(ast.factory.createImport({ name: name.text, ...target, isTypeOnly }))\n if (namedBindings && typescript.isNamespaceImport(namedBindings)) {\n nodes.push(ast.factory.createImport({ name: namedBindings.name.text, ...target, isTypeOnly, isNameSpace: true }))\n }\n if (namedBindings && typescript.isNamedImports(namedBindings)) {\n const values = namedBindings.elements.filter((element) => !element.isTypeOnly)\n const types = namedBindings.elements.filter((element) => element.isTypeOnly)\n if (values.length) nodes.push(ast.factory.createImport({ name: values.map(toImportName), ...target, isTypeOnly }))\n if (types.length) nodes.push(ast.factory.createImport({ name: types.map(toImportName), ...target, isTypeOnly: true }))\n }\n\n return nodes\n}\n\n/**\n * Converts an `export … from` declaration into `ExportNode`s. Forms `printExport` cannot print stay as written.\n */\nfunction toExportNodes(statement: ts.Statement): Array<ast.ExportNode> {\n const { typescript } = loadCompiler()\n if (\n !typescript.isExportDeclaration(statement) ||\n !statement.moduleSpecifier ||\n !typescript.isStringLiteral(statement.moduleSpecifier) ||\n statement.attributes\n )\n return []\n\n const { exportClause, isTypeOnly } = statement\n const path = statement.moduleSpecifier.text\n\n if (!exportClause) return [ast.factory.createExport({ path, isTypeOnly })]\n if (typescript.isNamespaceExport(exportClause)) return [ast.factory.createExport({ name: exportClause.name.text, path, isTypeOnly, asAlias: true })]\n if (exportClause.elements.some((element) => element.propertyName || element.isTypeOnly || typescript.isStringLiteral(element.name))) return []\n\n return [ast.factory.createExport({ name: exportClause.elements.map((element) => element.name.text), path, isTypeOnly })]\n}\n\n/**\n * Splits `source` into its lifted `import`/`export … from` nodes, the `header` above the first one (shebang, directives, comments) and the rest as `body`.\n */\nexport function splitModuleDeclarations(\n source: string,\n filePath: string,\n): { header: string; imports: Array<ast.ImportNode>; exports: Array<ast.ExportNode>; body: string } {\n const { typescript } = loadCompiler()\n const sourceFile = typescript.createSourceFile(filePath, source, typescript.ScriptTarget.Latest)\n const imports: Array<ast.ImportNode> = []\n const exports: Array<ast.ExportNode> = []\n let header = ''\n let body = ''\n let cursor = 0\n\n for (const statement of sourceFile.statements) {\n const importNodes = toImportNodes(statement, filePath)\n const exportNodes = toExportNodes(statement)\n if (!importNodes.length && !exportNodes.length) {\n // Lifted declarations print above the body, so stop at the first one that stays in place to keep the evaluation order.\n if (typescript.isImportDeclaration(statement) || (typescript.isExportDeclaration(statement) && statement.moduleSpecifier)) break\n continue\n }\n\n const text = source.slice(cursor, statement.getStart(sourceFile))\n if (imports.length || exports.length) body += text\n else header = text\n imports.push(...importNodes)\n exports.push(...exportNodes)\n cursor = statement.getEnd()\n }\n\n return { header: header.trim(), imports, exports, body: `${body}${source.slice(cursor)}`.trim() }\n}\n\n/**\n * Joins the printed `nodes` with `separator`; a `Break` widens the next separator to a blank line, and leading, trailing and repeated breaks fold into one.\n *\n * Imperative on purpose: this runs once per source fragment and `map().filter().join()` showed up in deopt traces.\n */\nfunction printNodes({ nodes, separator }: { nodes: Array<ast.CodeNode> | undefined; separator: '\\n' | '\\n\\n' }): string {\n let result = ''\n let pendingBreak = false\n\n for (const node of nodes ?? []) {\n if (node.kind === 'Break') {\n pendingBreak = result !== ''\n continue\n }\n\n const text = printCodeNode(node)\n if (!text) continue\n\n if (result) result += pendingBreak ? '\\n\\n' : separator\n result += text\n pendingBreak = false\n }\n\n return result\n}\n\n/**\n * Indents every non-empty line of `text` by two spaces.\n */\nfunction indentLines(text: string): string {\n if (!text) return ''\n return text\n .split('\\n')\n .map((line) => (line.trim() ? ` ${line}` : ''))\n .join('\\n')\n}\n\n/**\n * Strips the common leading whitespace and the surrounding blank lines, counting tabs and spaces alike, so indented template literals start at column zero.\n */\nfunction dedent(text: string): string {\n if (!text) return ''\n\n const lines = text.split('\\n')\n const isBlank = (line: string) => line.trim() === ''\n\n const start = lines.findIndex((line) => !isBlank(line))\n if (start === -1) return ''\n const end = lines.findLastIndex((line) => !isBlank(line))\n\n const trimmed = lines.slice(start, end + 1)\n const indents = trimmed.filter((line) => !isBlank(line)).map((line) => line.match(/^\\s*/)?.[0].length ?? 0)\n const min = indents.length ? Math.min(...indents) : 0\n\n return trimmed.map((line) => (isBlank(line) ? '' : line.slice(min))).join('\\n')\n}\n\n/**\n * Renders `<T>(params): ReturnType`; an async function wraps its return type in `Promise<>`.\n */\nfunction signature({ async: isAsync, generics, params, returnType }: Pick<ast.FunctionNode, 'async' | 'generics' | 'params' | 'returnType'>): string {\n const genericsStr = generics ? `<${Array.isArray(generics) ? generics.join(', ') : generics}>` : ''\n const wrapped = isAsync ? `Promise<${returnType}>` : returnType\n const returnTypeStr = returnType ? `: ${wrapped}` : ''\n\n return `${genericsStr}(${params ?? ''})${returnTypeStr}`\n}\n\n/**\n * Puts the JSDoc block, when it renders to something, above `declaration`.\n */\nfunction withJSDoc({ jsDoc, declaration }: { jsDoc?: ast.JSDocNode | null; declaration: string }): string {\n const jsDocStr = jsDoc ? printJSDoc(jsDoc) : ''\n\n return jsDocStr ? `${jsDocStr}\\n${declaration}` : declaration\n}\n\n/**\n * Converts TypeScript/TSX AST nodes to a string using the TypeScript printer.\n */\nexport function print(...elements: Array<ts.Node>): string {\n const filtered = elements.filter(Boolean)\n if (filtered.length === 0) return ''\n\n const { typescript, printer, sourceFile } = loadCompiler()\n return printer.printList(typescript.ListFormat.MultiLine, typescript.factory.createNodeArray(filtered), sourceFile)\n}\n\n/**\n * Converts a {@link ast.JSDocNode} to a `/** … *\\/` block, dropping blank comments.\n */\nfunction printJSDoc(jsDoc: ast.JSDocNode): string {\n const comments = (jsDoc.comments ?? []).filter((c) => c != null)\n if (comments.length === 0) return ''\n\n const lines = comments\n .flatMap((c) => c.split(/\\r?\\n/))\n .map((l) => l.replace(/\\*\\//g, '* /').replace(/\\r/g, ''))\n .filter((l) => l.trim().length > 0)\n\n if (lines.length === 0) return ''\n\n return ['/**', ...lines.map((l) => ` * ${l}`), ' */'].join('\\n')\n}\n\n/**\n * Converts a {@link ast.ConstNode} to a `const` declaration, mirroring the `Const` component from `@kubb/renderer-jsx`.\n */\nfunction printConst(node: ast.ConstNode): string {\n const { name, export: canExport, type, JSDoc, asConst, nodes } = node\n\n const declaration = `${canExport ? 'export ' : ''}const ${name}${type ? `: ${type}` : ''} = ${printNodes({ nodes, separator: '\\n' })}${asConst ? ' as const' : ''}`\n\n return withJSDoc({ jsDoc: JSDoc, declaration })\n}\n\n/**\n * Converts a {@link ast.TypeNode} to a `type` alias, mirroring the `Type` component from `@kubb/renderer-jsx`.\n */\nfunction printType(node: ast.TypeNode): string {\n const { name, export: canExport, JSDoc, nodes } = node\n\n const declaration = `${canExport ? 'export ' : ''}type ${name} = ${printNodes({ nodes, separator: '\\n' })}`\n\n return withJSDoc({ jsDoc: JSDoc, declaration })\n}\n\n/**\n * Converts a {@link ast.FunctionNode} to a `function` declaration, mirroring the `Function` component from `@kubb/renderer-jsx`.\n */\nfunction printFunction(node: ast.FunctionNode): string {\n const { name, default: isDefault, export: canExport, async: isAsync, generics, params, returnType, JSDoc, nodes } = node\n\n const body = indentLines(printNodes({ nodes, separator: '\\n' }))\n const prefix = `${canExport ? 'export ' : ''}${isDefault ? 'default ' : ''}${isAsync ? 'async ' : ''}`\n const declaration = `${prefix}function ${name}${signature({ async: isAsync, generics, params, returnType })} {${body ? `\\n${body}\\n` : ''}}`\n\n return withJSDoc({ jsDoc: JSDoc, declaration })\n}\n\n/**\n * Converts an {@link ast.ArrowFunctionNode} to a `const` arrow function, mirroring the `Function.Arrow` component from `@kubb/renderer-jsx`.\n */\nfunction printArrowFunction(node: ast.ArrowFunctionNode): string {\n const { name, default: isDefault, export: canExport, async: isAsync, generics, params, returnType, JSDoc, nodes, singleLine } = node\n\n const body = printNodes({ nodes, separator: '\\n' })\n const arrowBody = singleLine ? ` => ${body}` : body ? ` => {\\n${indentLines(body)}\\n}` : ' => {}'\n const prefix = `${canExport ? 'export ' : ''}${isDefault ? 'default ' : ''}`\n const declaration = `${prefix}const ${name} = ${isAsync ? 'async ' : ''}${signature({ async: isAsync, generics, params, returnType })}${arrowBody}`\n\n return withJSDoc({ jsDoc: JSDoc, declaration })\n}\n\n/**\n * Dispatches a {@link ast.CodeNode} to the printer for its `kind`.\n */\nfunction printCodeNode(node: ast.CodeNode): string {\n switch (node.kind) {\n case 'Break':\n return ''\n case 'Text':\n case 'Jsx':\n return dedent(node.value)\n case 'Const':\n return printConst(node)\n case 'Type':\n return printType(node)\n case 'Function':\n return printFunction(node)\n case 'ArrowFunction':\n return printArrowFunction(node)\n }\n}\n\n/**\n * Prints a {@link ast.SourceNode} with a blank line between its top-level nodes.\n */\nexport function printSource(node: ast.SourceNode): string {\n return printNodes({ nodes: node.nodes, separator: '\\n\\n' })\n}\n\n/**\n * Wraps a module specifier in single quotes, escaping embedded backslashes and quotes.\n */\nfunction quoteModulePath(path: string): string {\n return `'${path.replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\")}'`\n}\n\n/**\n * Renders an `import` declaration (default, `* as`, or named with `{ a as b }`, each optionally `type`-only). `path` is used verbatim, so resolve it first.\n */\nexport function printImport({\n name,\n path,\n isTypeOnly = false,\n isNameSpace = false,\n}: Pick<ast.ImportNode, 'name' | 'path' | 'isTypeOnly' | 'isNameSpace'>): string {\n const typePrefix = isTypeOnly ? 'type ' : ''\n const from = quoteModulePath(path)\n\n if (!Array.isArray(name)) {\n if (isNameSpace) return `import ${typePrefix}* as ${name} from ${from}`\n return `import ${typePrefix}${name} from ${from}`\n }\n\n const specifiers = name.map((item) => {\n if (typeof item === 'object') {\n return item.name ? `${item.propertyName} as ${item.name}` : item.propertyName\n }\n return item\n })\n\n return `import ${typePrefix}{ ${specifiers.join(', ')} } from ${from}`\n}\n\n/**\n * Renders an `export … from` declaration (named, `* as name`, or wildcard, each optionally `type`-only). `path` is used verbatim, so resolve it first.\n */\nexport function printExport({ path, name, isTypeOnly = false, asAlias = false }: Pick<ast.ExportNode, 'name' | 'path' | 'isTypeOnly' | 'asAlias'>): string {\n const typePrefix = isTypeOnly ? 'type ' : ''\n const from = quoteModulePath(path)\n\n if (Array.isArray(name)) {\n return `export ${typePrefix}{ ${name.join(', ')} } from ${from}`\n }\n\n if (asAlias && name) {\n // An identifier cannot start with a digit, so swap the digit for `_`\n const parsedName = /^\\d/.test(name) ? `_${name.slice(1)}` : name\n return `export ${typePrefix}* as ${parsedName} from ${from}`\n }\n\n if (name) {\n return `export ${typePrefix}{ ${name} } from ${from}`\n }\n\n return `export ${typePrefix}* from ${from}`\n}\n","import { ast } from '@kubb/ast'\nimport { defineExtension } from '@kubb/core'\nimport type * as ts from '@typescript/typescript6'\nimport { compatibility } from '../kubb-extension.json'\nimport { version } from '../package.json'\nimport { getRelativePath, print, printExport, printImport, printSource, resolveOutputPath, splitModuleDeclarations } from './utils.ts'\n\nconst DEFAULT_EXTENSION: Record<ast.FileNode['extname'], ast.FileNode['extname'] | ''> = { '.ts': '' }\n\n/**\n * Options accepted by `parserTs` and `parserTsx`.\n */\nexport type ParserTsOptions = {\n /**\n * Rewrite extensions on relative `import`/`export` statements. Each key is the extension of a\n * generated file, and its value is the extension written on the relative specifiers in that\n * file. `''` drops it, and so does a generated file whose extension has no key. Package\n * specifiers stay unchanged. Also applies to relative paths in `copy` templates.\n *\n * Use `{ '.ts': '.js' }` for ESM output compiled to JavaScript, or `{ '.ts': '.ts' }` to run the\n * `.ts` files directly in Node.js or compile them with `rewriteRelativeImportExtensions`.\n *\n * @default { '.ts': '' }\n * @example\n * ```ts\n * parserTs({ extension: { '.ts': '.js' } }) // import './api.js' instead of './api'\n * parserTs({ extension: { '.ts': '.ts' } }) // import './api.ts' instead of './api'\n * ```\n */\n extension?: Record<ast.FileNode['extname'], ast.FileNode['extname'] | ''>\n}\n\n/**\n * Default Kubb parser for `.ts` and `.js` files. Takes the universal AST\n * produced by an adapter and prints it as TypeScript source. Imports and exports\n * are rewritten based on each file's metadata and the `extension` option. The\n * `print` helper renders TypeScript compiler nodes with the TypeScript printer.\n *\n * Used automatically when no `parsers` option is set on `defineConfig`. Use\n * `parserTsx` instead for React projects that emit JSX.\n *\n * @example\n * ```ts\n * import { defineConfig } from 'kubb'\n * import { adapterOas } from '@kubb/adapter-oas'\n * import { parserTs } from '@kubb/parser-ts'\n *\n * export default defineConfig({\n * input: './petStore.yaml',\n * output: { path: './src/gen' },\n * adapter: adapterOas(),\n * parsers: [parserTs()],\n * plugins: [],\n * })\n * ```\n */\nexport const parserTs = defineExtension<ParserTsOptions, object, ts.Node>({\n kind: 'parser',\n meta: { name: 'typescript', version, compatibility, issues: 'https://github.com/kubb-labs/kubb/issues' },\n build({ extension = DEFAULT_EXTENSION }) {\n return {\n extNames: ['.ts', '.js'],\n print,\n parse(file) {\n const extname = extension[file.extname] || undefined\n\n const source = file.sources\n .map((item) => printSource(item))\n .filter(Boolean)\n .map((text) => text.trimEnd())\n .join('\\n\\n')\n\n const importLines = file.imports.map((item) =>\n printImport({\n ...item,\n path: resolveOutputPath(item.root ? getRelativePath(item.root, item.path) : item.path, extname, Boolean(item.root)),\n }),\n )\n\n const exportLines = file.exports.map((item) => printExport({ ...item, path: resolveOutputPath(item.path, extname, item.path.startsWith('.')) }))\n\n const importExportBlock = [...importLines, ...exportLines].join('\\n')\n\n const parts = [file.banner, importExportBlock, source, file.footer].filter((segment): segment is string => Boolean(segment)).map((s) => s.trimEnd())\n\n return parts.join('\\n\\n')\n },\n copy(file, source) {\n const { header, imports, exports, body } = splitModuleDeclarations(source, file.path)\n\n return {\n ...file,\n banner: [header, file.banner].filter(Boolean).join('\\n') || undefined,\n imports: [...file.imports, ...imports],\n exports: [...file.exports, ...exports],\n sources: [ast.factory.createSource({ nodes: [ast.factory.createText(body)] })],\n }\n },\n }\n },\n})\n","import { defineExtension } from '@kubb/core'\nimport type * as ts from '@typescript/typescript6'\nimport { parserTs, type ParserTsOptions } from './parserTs.ts'\n\n/**\n * Kubb parser for `.tsx` and `.jsx` files. Delegates to `parserTs` because the\n * TypeScript compiler handles JSX natively via `ScriptKind.TSX`, so it shares the\n * same `extension` option.\n *\n * Add to the `parsers` array on `defineConfig` when generating components for\n * React (or any framework that emits JSX).\n *\n * @example\n * ```ts\n * import { defineConfig } from 'kubb'\n * import { adapterOas } from '@kubb/adapter-oas'\n * import { parserTsx } from '@kubb/parser-ts'\n *\n * export default defineConfig({\n * input: './petStore.yaml',\n * output: { path: './src/gen' },\n * adapter: adapterOas(),\n * parsers: [parserTsx()],\n * plugins: [],\n * })\n * ```\n */\nexport const parserTsx = defineExtension<ParserTsOptions, object, ts.Node>({\n kind: 'parser',\n meta: { name: 'tsx', issues: 'https://github.com/kubb-labs/kubb/issues' },\n build: (options) => ({ ...parserTs(options), extNames: ['.tsx', '.jsx'] }),\n})\n"],"mappings":";;;;;;;;;;;;;;;;AEWA,IAAI;;;;;;;AAQJ,SAAS,eAAyB;CAChC,IAAI,UAAU,OAAO;CAErB,MAAM,cAAA,GAAwBA,YAAAA,cAAAA,CAAAA,QAAAA,KAAAA,CAAAA,CAAAA,cAAAA,UAAAA,CAAAA,CAAAA,IAA6B,CAAC,CAAC,yBAAyB;CAEtF,WAAW;EACT;EAEA,SAAS,WAAW,cAAc;GAChC,uBAAuB;GACvB,SAAS,WAAW,YAAY;GAChC,gBAAgB;GAChB,eAAe;EACjB,CAAC;EACD,YAAY,WAAW,iBAAiB,aAAa,IAAI,WAAW,aAAa,QAAQ,MAAM,WAAW,WAAW,GAAG;CAC1H;CAEA,OAAO;AACT;;;;AAKA,SAAgB,gBAAgB,MAAc,UAA0B;CACtE,MAAM,WAAA,GAAUC,UAAAA,SAAAA,EAAAA,GAASC,UAAAA,QAAAA,CAAQ,IAAI,GAAG,QAAQ,CAAC,CAAC,WAAW,MAAM,GAAG;CACtE,OAAO,QAAQ,WAAW,KAAK,IAAI,UAAU,KAAK;AACpD;;;;AAKA,SAAgB,kBAAkB,MAAc,SAA6B,WAA4B;CACvG,IAAI,CAAC,WAAW,OAAO;CACvB,MAAM,WAAA,GAAUC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,GAAYC,WAAAA,gBAAAA,CAAkD;CACzE,MAAM;CACN,MAAM;EAAE,MAAM;EAAO,QAAQ;CAA2C;CACxE,QAAQ,aAAa;EAAE,GAAG,SAAS,OAAO;EAAG,UAAU,CAAC,QAAQ,MAAM;CAAE;AAC1E,CAAC"}
1
+ {"version":3,"file":"index.cjs","names":["require","createRequire","dirname","fileURLToPath","relative","getExtname","resolve","ast","parse","defineExtension","ast","defineExtension"],"sources":["../kubb-extension.json","../package.json","../src/utils.ts","../src/parserTs.ts","../src/parserTsx.ts"],"sourcesContent":["","","import { createRequire } from 'node:module'\nimport { dirname, extname as getExtname, relative, resolve } from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport { ast } from '@kubb/ast'\nimport { type ImportSpecifier, type ModuleExportName, parse, type ProgramStatement } from 'yuku-parser'\n\n/**\n * A TypeScript compiler node, typed structurally so `@kubb/parser-ts` does not depend on `@typescript/typescript6`.\n *\n * @deprecated Pass printed strings to `print` instead. Support for compiler nodes is removed in the next major.\n */\nexport type TsNode = { readonly kind: number }\n\ntype Compiler = {\n printNodes: (nodes: Array<TsNode>) => string\n}\n\nlet compiler: Compiler | undefined\n\n// The parts of the TypeScript 6 API that printing compiler nodes uses, typed here so no package depends on it\ntype TypeScript = {\n createPrinter(options: { omitTrailingSemicolon: boolean; newLine: number; removeComments: boolean; noEmitHelpers: boolean }): {\n printList(format: number, list: unknown, sourceFile: unknown): string\n }\n createSourceFile(fileName: string, text: string, target: number, setParentNodes: boolean, kind: number): unknown\n factory: { createNodeArray(nodes: Array<TsNode>): unknown }\n NewLineKind: { LineFeed: number }\n ScriptTarget: { ES2022: number }\n ScriptKind: { TSX: number }\n ListFormat: { MultiLine: number }\n}\n\n/**\n * Loads TypeScript the first time `print` gets a compiler node. Strings never need it, so bundles for edge runtimes such as Cloudflare Workers leave it out.\n *\n * Loaded with `require`, not `import`: when ESM imports a CommonJS package, Node keeps a second copy of its source\n * to detect named exports, and for TypeScript that copy is about 9 MB.\n */\nfunction loadCompiler(): Compiler {\n if (compiler) return compiler\n\n const require = createRequire(import.meta.url)\n // Look in the user's project first: a strict package manager such as pnpm does not link it next to this package\n const paths = [process.cwd(), dirname(fileURLToPath(import.meta.url))]\n let typescript: TypeScript | undefined\n // `typescript` 5 and 6 ship the compiler API; next to TypeScript 7 it comes from `@typescript/typescript6`\n for (const name of ['typescript', '@typescript/typescript6']) {\n try {\n const candidate = require(require.resolve(name, { paths }))\n if (typeof candidate.createPrinter === 'function') {\n typescript = candidate as TypeScript\n break\n }\n } catch {}\n }\n if (!typescript) {\n throw new Error(\n '`print` received a TypeScript compiler node, which needs `typescript` 5 or 6, or `@typescript/typescript6`, installed. Pass a printed string instead.',\n )\n }\n\n // One printer serves every call; printing does not mutate the source file, which only lends its compiler options\n const printer = typescript.createPrinter({\n omitTrailingSemicolon: true,\n newLine: typescript.NewLineKind.LineFeed,\n removeComments: false,\n noEmitHelpers: true,\n })\n const sourceFile = typescript.createSourceFile('print.tsx', '', typescript.ScriptTarget.ES2022, true, typescript.ScriptKind.TSX)\n\n compiler = {\n printNodes: (nodes) => printer.printList(typescript.ListFormat.MultiLine, typescript.factory.createNodeArray(nodes), sourceFile),\n }\n\n return compiler\n}\n\n/**\n * Module specifier that imports `filePath` from the file at `root`: POSIX, relative to that file's directory, `./`-prefixed unless it climbs with `../`.\n */\nexport function getRelativePath(root: string, filePath: string): string {\n const slashed = relative(dirname(root), filePath).replaceAll('\\\\', '/')\n return slashed.startsWith('../') ? slashed : `./${slashed}`\n}\n\n/**\n * Swaps the extension of a relative import/export path for `extname`. Package specifiers and extension-less paths stay as-is.\n */\nexport function resolveOutputPath(path: string, extname: string | undefined, rootAware: boolean): string {\n if (!rootAware) return path\n const current = getExtname(path)\n return current ? `${path.slice(0, -current.length)}${extname ?? ''}` : path\n}\n\n/**\n * Node types this module reads from the yuku AST.\n */\nconst nodeTypes = {\n identifier: 'Identifier',\n literal: 'Literal',\n importDeclaration: 'ImportDeclaration',\n importSpecifier: 'ImportSpecifier',\n importDefaultSpecifier: 'ImportDefaultSpecifier',\n importNamespaceSpecifier: 'ImportNamespaceSpecifier',\n exportAllDeclaration: 'ExportAllDeclaration',\n exportNamedDeclaration: 'ExportNamedDeclaration',\n} as const\n\n/**\n * `importKind` and `exportKind` values this module reads from the yuku AST.\n */\nconst declarationKinds = {\n type: 'type',\n} as const\n\nfunction nameOf(node: ModuleExportName): string {\n return node.type === nodeTypes.literal ? node.value : node.name\n}\n\n/**\n * Converts an import specifier into an `ImportNode` name, keeping the quotes of a string-literal name (`{ 'a-b' as ab }`).\n */\nfunction toImportName({ imported, local }: ImportSpecifier): string | { propertyName: string; name: string } {\n if (imported.type === nodeTypes.identifier && imported.name === local.name) return local.name\n\n return { propertyName: imported.type === nodeTypes.literal ? quoteModulePath(imported.value) : imported.name, name: local.name }\n}\n\n/**\n * Converts an `import` declaration into `ImportNode`s. Side-effect imports and imports with attributes or a phase stay as written.\n */\nfunction toImportNodes(statement: ProgramStatement, filePath: string): Array<ast.ImportNode> {\n if (statement.type !== nodeTypes.importDeclaration || !statement.specifiers.length || statement.attributes.length || statement.phase) return []\n\n const specifier = statement.source.value\n const target = specifier.startsWith('.') ? { path: resolve(dirname(filePath), specifier), root: filePath } : { path: specifier }\n const isTypeOnly = statement.importKind === declarationKinds.type\n const nodes: Array<ast.ImportNode> = []\n const named = statement.specifiers.filter((element) => element.type === nodeTypes.importSpecifier)\n\n for (const element of statement.specifiers) {\n if (element.type === nodeTypes.importDefaultSpecifier) nodes.push(ast.factory.createImport({ name: element.local.name, ...target, isTypeOnly }))\n if (element.type === nodeTypes.importNamespaceSpecifier)\n nodes.push(ast.factory.createImport({ name: element.local.name, ...target, isTypeOnly, isNameSpace: true }))\n }\n const values = named.filter((element) => element.importKind !== declarationKinds.type)\n const types = named.filter((element) => element.importKind === declarationKinds.type)\n if (values.length) nodes.push(ast.factory.createImport({ name: values.map(toImportName), ...target, isTypeOnly }))\n if (types.length) nodes.push(ast.factory.createImport({ name: types.map(toImportName), ...target, isTypeOnly: true }))\n\n return nodes\n}\n\n/**\n * Converts an `export … from` declaration into `ExportNode`s. Forms `printExport` cannot print stay as written.\n */\nfunction toExportNodes(statement: ProgramStatement): Array<ast.ExportNode> {\n if (statement.type !== nodeTypes.exportAllDeclaration && statement.type !== nodeTypes.exportNamedDeclaration) return []\n if (!statement.source || statement.attributes.length) return []\n\n const path = statement.source.value\n const isTypeOnly = statement.exportKind === declarationKinds.type\n\n if (statement.type === nodeTypes.exportAllDeclaration) {\n return [\n statement.exported\n ? ast.factory.createExport({ name: nameOf(statement.exported), path, isTypeOnly, asAlias: true })\n : ast.factory.createExport({ path, isTypeOnly }),\n ]\n }\n if (\n statement.specifiers.some(\n (element) =>\n element.exportKind === declarationKinds.type || element.exported.type === nodeTypes.literal || nameOf(element.exported) !== nameOf(element.local),\n )\n )\n return []\n\n return [ast.factory.createExport({ name: statement.specifiers.map((element) => nameOf(element.local)), path, isTypeOnly })]\n}\n\n/**\n * Splits `source` into its lifted `import`/`export … from` nodes, the `header` above the first one (shebang, directives, comments) and the rest as `body`.\n */\nexport function splitModuleDeclarations(\n source: string,\n filePath: string,\n): { header: string; imports: Array<ast.ImportNode>; exports: Array<ast.ExportNode>; body: string } {\n const { program } = parse(source, { lang: 'ts', sourceType: 'module' })\n const imports: Array<ast.ImportNode> = []\n const exports: Array<ast.ExportNode> = []\n let header = ''\n let body = ''\n let cursor = 0\n\n for (const statement of program.body) {\n const importNodes = toImportNodes(statement, filePath)\n const exportNodes = toExportNodes(statement)\n if (!importNodes.length && !exportNodes.length) {\n // Lifted declarations print above the body, so stop at the first one that stays in place to keep the evaluation order.\n if (\n statement.type === nodeTypes.importDeclaration ||\n ((statement.type === nodeTypes.exportNamedDeclaration || statement.type === nodeTypes.exportAllDeclaration) && statement.source)\n )\n break\n continue\n }\n\n const text = source.slice(cursor, statement.start)\n if (imports.length || exports.length) body += text\n else header = text\n imports.push(...importNodes)\n exports.push(...exportNodes)\n cursor = statement.end\n }\n\n return { header: header.trim(), imports, exports, body: `${body}${source.slice(cursor)}`.trim() }\n}\n\n/**\n * Joins the printed `nodes` with `separator`; a `Break` widens the next separator to a blank line, and leading, trailing and repeated breaks fold into one.\n *\n * Imperative on purpose: this runs once per source fragment and `map().filter().join()` showed up in deopt traces.\n */\nfunction printNodes({ nodes, separator }: { nodes: Array<ast.CodeNode> | undefined; separator: '\\n' | '\\n\\n' }): string {\n let result = ''\n let pendingBreak = false\n\n for (const node of nodes ?? []) {\n if (node.kind === 'Break') {\n pendingBreak = result !== ''\n continue\n }\n\n const text = printCodeNode(node)\n if (!text) continue\n\n if (result) result += pendingBreak ? '\\n\\n' : separator\n result += text\n pendingBreak = false\n }\n\n return result\n}\n\n/**\n * Indents every non-empty line of `text` by two spaces.\n */\nfunction indentLines(text: string): string {\n if (!text) return ''\n return text\n .split('\\n')\n .map((line) => (line.trim() ? ` ${line}` : ''))\n .join('\\n')\n}\n\n/**\n * Strips the common leading whitespace and the surrounding blank lines, counting tabs and spaces alike, so indented template literals start at column zero.\n */\nfunction dedent(text: string): string {\n if (!text) return ''\n // Most text nodes are one line, so the common indent is its leading whitespace.\n if (!text.includes('\\n')) return text.trim() ? text.trimStart() : ''\n\n const lines = text.split('\\n')\n const isBlank = (line: string) => line.trim() === ''\n\n const start = lines.findIndex((line) => !isBlank(line))\n if (start === -1) return ''\n const end = lines.findLastIndex((line) => !isBlank(line))\n\n const trimmed = lines.slice(start, end + 1)\n // A loop, not `Math.min(...indents)`, which overflows the stack on very long text.\n let min = Infinity\n for (const line of trimmed) {\n if (!isBlank(line)) min = Math.min(min, line.length - line.trimStart().length)\n }\n\n return trimmed.map((line) => (isBlank(line) ? '' : line.slice(min))).join('\\n')\n}\n\n/**\n * Renders `<T>(params): ReturnType`; an async function wraps its return type in `Promise<>`.\n */\nfunction signature({ async: isAsync, generics, params, returnType }: Pick<ast.FunctionNode, 'async' | 'generics' | 'params' | 'returnType'>): string {\n const genericsStr = generics ? `<${Array.isArray(generics) ? generics.join(', ') : generics}>` : ''\n const wrapped = isAsync ? `Promise<${returnType}>` : returnType\n const returnTypeStr = returnType ? `: ${wrapped}` : ''\n\n return `${genericsStr}(${params ?? ''})${returnTypeStr}`\n}\n\n/**\n * Puts the JSDoc block, when it renders to something, above `declaration`.\n */\nfunction withJSDoc({ jsDoc, declaration }: { jsDoc?: ast.JSDocNode | null; declaration: string }): string {\n const jsDocStr = jsDoc ? printJSDoc(jsDoc) : ''\n\n return jsDocStr ? `${jsDocStr}\\n${declaration}` : declaration\n}\n\n/**\n * Joins printed code fragments with a newline.\n *\n * Passing TypeScript compiler nodes still works but is deprecated and needs `typescript` 5 or 6, or `@typescript/typescript6`, installed.\n * Support for compiler nodes is removed in the next major.\n */\nexport function print(...elements: Array<string | TsNode>): string {\n const filtered = elements.filter(Boolean)\n if (filtered.length === 0) return ''\n if (filtered.every((element) => typeof element === 'string')) return filtered.join('\\n')\n // Printing compiler nodes as one list keeps the output byte-for-byte the same as before strings were accepted\n if (filtered.every((element) => typeof element !== 'string')) return loadCompiler().printNodes(filtered)\n\n return filtered.map((element) => (typeof element === 'string' ? element : loadCompiler().printNodes([element]).trimEnd())).join('\\n')\n}\n\n/**\n * Converts a {@link ast.JSDocNode} to a `/** … *\\/` block, dropping blank comments.\n */\nfunction printJSDoc(jsDoc: ast.JSDocNode): string {\n const comments = (jsDoc.comments ?? []).filter((c) => c != null)\n if (comments.length === 0) return ''\n\n const lines = comments\n .flatMap((c) => c.split(/\\r?\\n/))\n .map((l) => l.replace(/\\*\\//g, '* /').replace(/\\r/g, ''))\n .filter((l) => l.trim().length > 0)\n\n if (lines.length === 0) return ''\n\n return ['/**', ...lines.map((l) => ` * ${l}`), ' */'].join('\\n')\n}\n\n/**\n * Converts a {@link ast.ConstNode} to a `const` declaration, mirroring the `Const` component from `@kubb/renderer-jsx`.\n */\nfunction printConst(node: ast.ConstNode): string {\n const { name, export: canExport, type, JSDoc, asConst, nodes } = node\n\n const declaration = `${canExport ? 'export ' : ''}const ${name}${type ? `: ${type}` : ''} = ${printNodes({ nodes, separator: '\\n' })}${asConst ? ' as const' : ''}`\n\n return withJSDoc({ jsDoc: JSDoc, declaration })\n}\n\n/**\n * Converts a {@link ast.TypeNode} to a `type` alias, mirroring the `Type` component from `@kubb/renderer-jsx`.\n */\nfunction printType(node: ast.TypeNode): string {\n const { name, export: canExport, JSDoc, nodes } = node\n\n const declaration = `${canExport ? 'export ' : ''}type ${name} = ${printNodes({ nodes, separator: '\\n' })}`\n\n return withJSDoc({ jsDoc: JSDoc, declaration })\n}\n\n/**\n * Converts a {@link ast.FunctionNode} to a `function` declaration, mirroring the `Function` component from `@kubb/renderer-jsx`.\n */\nfunction printFunction(node: ast.FunctionNode): string {\n const { name, default: isDefault, export: canExport, async: isAsync, generics, params, returnType, JSDoc, nodes } = node\n\n const body = indentLines(printNodes({ nodes, separator: '\\n' }))\n const prefix = `${canExport ? 'export ' : ''}${isDefault ? 'default ' : ''}${isAsync ? 'async ' : ''}`\n const declaration = `${prefix}function ${name}${signature({ async: isAsync, generics, params, returnType })} {${body ? `\\n${body}\\n` : ''}}`\n\n return withJSDoc({ jsDoc: JSDoc, declaration })\n}\n\n/**\n * Converts an {@link ast.ArrowFunctionNode} to a `const` arrow function, mirroring the `Function.Arrow` component from `@kubb/renderer-jsx`.\n */\nfunction printArrowFunction(node: ast.ArrowFunctionNode): string {\n const { name, default: isDefault, export: canExport, async: isAsync, generics, params, returnType, JSDoc, nodes, singleLine } = node\n\n const body = printNodes({ nodes, separator: '\\n' })\n const arrowBody = singleLine ? ` => ${body}` : body ? ` => {\\n${indentLines(body)}\\n}` : ' => {}'\n const prefix = `${canExport ? 'export ' : ''}${isDefault ? 'default ' : ''}`\n const declaration = `${prefix}const ${name} = ${isAsync ? 'async ' : ''}${signature({ async: isAsync, generics, params, returnType })}${arrowBody}`\n\n return withJSDoc({ jsDoc: JSDoc, declaration })\n}\n\n/**\n * Dispatches a {@link ast.CodeNode} to the printer for its `kind`.\n */\nfunction printCodeNode(node: ast.CodeNode): string {\n switch (node.kind) {\n case 'Break':\n return ''\n case 'Text':\n case 'Jsx':\n return dedent(node.value)\n case 'Const':\n return printConst(node)\n case 'Type':\n return printType(node)\n case 'Function':\n return printFunction(node)\n case 'ArrowFunction':\n return printArrowFunction(node)\n }\n}\n\n/**\n * Prints a {@link ast.SourceNode} with a blank line between its top-level nodes.\n */\nexport function printSource(node: ast.SourceNode): string {\n return printNodes({ nodes: node.nodes, separator: '\\n\\n' })\n}\n\n/**\n * Wraps a module specifier in single quotes, escaping embedded backslashes and quotes.\n */\nfunction quoteModulePath(path: string): string {\n return `'${path.replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\")}'`\n}\n\n/**\n * Renders an `import` declaration (default, `* as`, or named with `{ a as b }`, each optionally `type`-only). `path` is used verbatim, so resolve it first.\n */\nexport function printImport({\n name,\n path,\n isTypeOnly = false,\n isNameSpace = false,\n}: Pick<ast.ImportNode, 'name' | 'path' | 'isTypeOnly' | 'isNameSpace'>): string {\n const typePrefix = isTypeOnly ? 'type ' : ''\n const from = quoteModulePath(path)\n\n if (!Array.isArray(name)) {\n if (isNameSpace) return `import ${typePrefix}* as ${name} from ${from}`\n return `import ${typePrefix}${name} from ${from}`\n }\n\n const specifiers = name.map((item) => {\n if (typeof item === 'object') {\n return item.name ? `${item.propertyName} as ${item.name}` : item.propertyName\n }\n return item\n })\n\n return `import ${typePrefix}{ ${specifiers.join(', ')} } from ${from}`\n}\n\n/**\n * Renders an `export … from` declaration (named, `* as name`, or wildcard, each optionally `type`-only). `path` is used verbatim, so resolve it first.\n */\nexport function printExport({ path, name, isTypeOnly = false, asAlias = false }: Pick<ast.ExportNode, 'name' | 'path' | 'isTypeOnly' | 'asAlias'>): string {\n const typePrefix = isTypeOnly ? 'type ' : ''\n const from = quoteModulePath(path)\n\n if (Array.isArray(name)) {\n return `export ${typePrefix}{ ${name.join(', ')} } from ${from}`\n }\n\n if (asAlias && name) {\n // An identifier cannot start with a digit, so swap the digit for `_`\n const parsedName = /^\\d/.test(name) ? `_${name.slice(1)}` : name\n return `export ${typePrefix}* as ${parsedName} from ${from}`\n }\n\n if (name) {\n return `export ${typePrefix}{ ${name} } from ${from}`\n }\n\n return `export ${typePrefix}* from ${from}`\n}\n","import { ast } from '@kubb/ast'\nimport { defineExtension } from '@kubb/core'\nimport { compatibility } from '../kubb-extension.json'\nimport { version } from '../package.json'\nimport { getRelativePath, print, printExport, printImport, printSource, resolveOutputPath, splitModuleDeclarations, type TsNode } from './utils.ts'\n\nconst DEFAULT_EXTENSION: Record<ast.FileNode['extname'], ast.FileNode['extname'] | ''> = { '.ts': '' }\n\n/**\n * Options accepted by `parserTs` and `parserTsx`.\n */\nexport type ParserTsOptions = {\n /**\n * Rewrite extensions on relative `import`/`export` statements. Each key is the extension of a\n * generated file, and its value is the extension written on the relative specifiers in that\n * file. `''` drops it, and so does a generated file whose extension has no key. Package\n * specifiers stay unchanged. Also applies to relative paths in `copy` templates.\n *\n * Use `{ '.ts': '.js' }` for ESM output compiled to JavaScript, or `{ '.ts': '.ts' }` to run the\n * `.ts` files directly in Node.js or compile them with `rewriteRelativeImportExtensions`.\n *\n * @default { '.ts': '' }\n * @example\n * ```ts\n * parserTs({ extension: { '.ts': '.js' } }) // import './api.js' instead of './api'\n * parserTs({ extension: { '.ts': '.ts' } }) // import './api.ts' instead of './api'\n * ```\n */\n extension?: Record<ast.FileNode['extname'], ast.FileNode['extname'] | ''>\n}\n\n/**\n * Default Kubb parser for `.ts` and `.js` files. Takes the universal AST\n * produced by an adapter and prints it as TypeScript source. Imports and exports\n * are rewritten based on each file's metadata and the `extension` option.\n *\n * Used automatically when no `parsers` option is set on `defineConfig`. Use\n * `parserTsx` instead for React projects that emit JSX.\n *\n * @example\n * ```ts\n * import { defineConfig } from 'kubb'\n * import { adapterOas } from '@kubb/adapter-oas'\n * import { parserTs } from '@kubb/parser-ts'\n *\n * export default defineConfig({\n * input: './petStore.yaml',\n * output: { path: './src/gen' },\n * adapter: adapterOas(),\n * parsers: [parserTs()],\n * plugins: [],\n * })\n * ```\n */\nexport const parserTs = defineExtension<ParserTsOptions, object, string | TsNode>({\n kind: 'parser',\n meta: { name: 'typescript', version, compatibility, issues: 'https://github.com/kubb-labs/kubb/issues' },\n build({ extension = DEFAULT_EXTENSION }) {\n return {\n extNames: ['.ts', '.js'],\n print,\n parse(file) {\n const extname = extension[file.extname] || undefined\n\n const source = file.sources\n .map((item) => printSource(item))\n .filter(Boolean)\n .map((text) => text.trimEnd())\n .join('\\n\\n')\n\n const importLines = file.imports.map((item) =>\n printImport({\n ...item,\n path: resolveOutputPath(item.root ? getRelativePath(item.root, item.path) : item.path, extname, Boolean(item.root)),\n }),\n )\n\n const exportLines = file.exports.map((item) => printExport({ ...item, path: resolveOutputPath(item.path, extname, item.path.startsWith('.')) }))\n\n const importExportBlock = [...importLines, ...exportLines].join('\\n')\n\n const parts = [file.banner, importExportBlock, source, file.footer].filter((segment): segment is string => Boolean(segment)).map((s) => s.trimEnd())\n\n return parts.join('\\n\\n')\n },\n copy(file, source) {\n const { header, imports, exports, body } = splitModuleDeclarations(source, file.path)\n\n return {\n ...file,\n banner: [header, file.banner].filter(Boolean).join('\\n') || undefined,\n imports: [...file.imports, ...imports],\n exports: [...file.exports, ...exports],\n sources: [ast.factory.createSource({ nodes: [ast.factory.createText(body)] })],\n }\n },\n }\n },\n})\n","import { defineExtension } from '@kubb/core'\nimport { parserTs, type ParserTsOptions } from './parserTs.ts'\nimport type { TsNode } from './utils.ts'\n\n/**\n * Kubb parser for `.tsx` and `.jsx` files. Delegates to `parserTs`, since JSX\n * prints as text the same way, so it shares the same `extension` option.\n *\n * Add to the `parsers` array on `defineConfig` when generating components for\n * React (or any framework that emits JSX).\n *\n * @example\n * ```ts\n * import { defineConfig } from 'kubb'\n * import { adapterOas } from '@kubb/adapter-oas'\n * import { parserTsx } from '@kubb/parser-ts'\n *\n * export default defineConfig({\n * input: './petStore.yaml',\n * output: { path: './src/gen' },\n * adapter: adapterOas(),\n * parsers: [parserTsx()],\n * plugins: [],\n * })\n * ```\n */\nexport const parserTsx = defineExtension<ParserTsOptions, object, string | TsNode>({\n kind: 'parser',\n meta: { name: 'tsx', issues: 'https://github.com/kubb-labs/kubb/issues' },\n build: (options) => ({ ...parserTs(options), extNames: ['.tsx', '.jsx'] }),\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;AEiBA,IAAI;;;;;;;AAqBJ,SAAS,eAAyB;CAChC,IAAI,UAAU,OAAO;CAErB,MAAMA,aAAAA,GAAUC,YAAAA,cAAAA,CAAAA,QAAAA,KAAAA,CAAAA,CAAAA,cAAAA,UAAAA,CAAAA,CAAAA,IAA6B;CAE7C,MAAM,QAAQ,CAAC,QAAQ,IAAI,IAAA,GAAGC,UAAAA,QAAAA,EAAAA,GAAQC,SAAAA,cAAAA,CAAAA,QAAAA,KAAAA,CAAAA,CAAAA,cAAAA,UAAAA,CAAAA,CAAAA,IAA6B,CAAC,CAAC;CACrE,IAAI;CAEJ,KAAK,MAAM,QAAQ,CAAC,cAAc,yBAAyB,GACzD,IAAI;EACF,MAAM,YAAYH,UAAQA,UAAQ,QAAQ,MAAM,EAAE,MAAM,CAAC,CAAC;EAC1D,IAAI,OAAO,UAAU,kBAAkB,YAAY;GACjD,aAAa;GACb;EACF;CACF,QAAQ,CAAC;CAEX,IAAI,CAAC,YACH,MAAM,IAAI,MACR,uJACF;CAIF,MAAM,UAAU,WAAW,cAAc;EACvC,uBAAuB;EACvB,SAAS,WAAW,YAAY;EAChC,gBAAgB;EAChB,eAAe;CACjB,CAAC;CACD,MAAM,aAAa,WAAW,iBAAiB,aAAa,IAAI,WAAW,aAAa,QAAQ,MAAM,WAAW,WAAW,GAAG;CAE/H,WAAW,EACT,aAAa,UAAU,QAAQ,UAAU,WAAW,WAAW,WAAW,WAAW,QAAQ,gBAAgB,KAAK,GAAG,UAAU,EACjI;CAEA,OAAO;AACT;;;;AAKA,SAAgB,gBAAgB,MAAc,UAA0B;CACtE,MAAM,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AAoB,CAAC,GAAG,aAAa,GAAG,WAAW,CAAC,CAAC,KAAK,IAAI;IAIpE,OAFc;KAAC,KAAK;KAAQ;KAAmB;KAAQ,KAAK;IAAM,CAAC,CAAC,QAAQ,YAA+B,QAAQ,OAAO,CAAC,CAAC,CAAC,KAAK,MAAM,EAAE,QAAQ,CAEvI,CAAC,CAAC,KAAK,MAAM;GAC1B;GACA,KAAK,MAAM,QAAQ;IACjB,MAAM,EAAE,QAAQ,SAAS,SAAS,SAAS,wBAAwB,QAAQ,KAAK,IAAI;IAEpF,OAAO;KACL,GAAG;KACH,QAAQ,CAAC,QAAQ,KAAK,MAAM,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,IAAI,KAAK,KAAA;KAC5D,SAAS,CAAC,GAAG,KAAK,SAAS,GAAG,OAAO;KACrC,SAAS,CAAC,GAAG,KAAK,SAAS,GAAG,OAAO;KACrC,SAAS,CAACC,UAAAA,IAAI,QAAQ,aAAa,EAAE,OAAO,CAACA,UAAAA,IAAI,QAAQ,WAAW,IAAI,CAAC,EAAE,CAAC,CAAC;IAC/E;GACF;EACF;CACF;AACF,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;ACxED,MAAa,aAAA,GAAYC,WAAAA,gBAAAA,CAA0D;CACjF,MAAM;CACN,MAAM;EAAE,MAAM;EAAO,QAAQ;CAA2C;CACxE,QAAQ,aAAa;EAAE,GAAG,SAAS,OAAO;EAAG,UAAU,CAAC,QAAQ,MAAM;CAAE;AAC1E,CAAC"}
package/dist/index.d.cts CHANGED
@@ -1,5 +1,14 @@
1
1
  import { ast } from "@kubb/ast";
2
- import * as ts from "@typescript/typescript6";
2
+ //#region src/utils.d.ts
3
+ /**
4
+ * A TypeScript compiler node, typed structurally so `@kubb/parser-ts` does not depend on `@typescript/typescript6`.
5
+ *
6
+ * @deprecated Pass printed strings to `print` instead. Support for compiler nodes is removed in the next major.
7
+ */
8
+ type TsNode = {
9
+ readonly kind: number;
10
+ };
11
+ //#endregion
3
12
  //#region src/parserTs.d.ts
4
13
  /**
5
14
  * Options accepted by `parserTs` and `parserTsx`.
@@ -26,8 +35,7 @@ type ParserTsOptions = {
26
35
  /**
27
36
  * Default Kubb parser for `.ts` and `.js` files. Takes the universal AST
28
37
  * produced by an adapter and prints it as TypeScript source. Imports and exports
29
- * are rewritten based on each file's metadata and the `extension` option. The
30
- * `print` helper renders TypeScript compiler nodes with the TypeScript printer.
38
+ * are rewritten based on each file's metadata and the `extension` option.
31
39
  *
32
40
  * Used automatically when no `parsers` option is set on `defineConfig`. Use
33
41
  * `parserTsx` instead for React projects that emit JSX.
@@ -47,13 +55,12 @@ type ParserTsOptions = {
47
55
  * })
48
56
  * ```
49
57
  */
50
- export declare const parserTs: import("@kubb/core").ParserFactory<ParserTsOptions, object, ts.Node>;
58
+ export declare const parserTs: import("@kubb/core").ParserFactory<ParserTsOptions, object, string | TsNode>;
51
59
  //#endregion
52
60
  //#region src/parserTsx.d.ts
53
61
  /**
54
- * Kubb parser for `.tsx` and `.jsx` files. Delegates to `parserTs` because the
55
- * TypeScript compiler handles JSX natively via `ScriptKind.TSX`, so it shares the
56
- * same `extension` option.
62
+ * Kubb parser for `.tsx` and `.jsx` files. Delegates to `parserTs`, since JSX
63
+ * prints as text the same way, so it shares the same `extension` option.
57
64
  *
58
65
  * Add to the `parsers` array on `defineConfig` when generating components for
59
66
  * React (or any framework that emits JSX).
@@ -73,7 +80,7 @@ export declare const parserTs: import("@kubb/core").ParserFactory<ParserTsOption
73
80
  * })
74
81
  * ```
75
82
  */
76
- export declare const parserTsx: import("@kubb/core").ParserFactory<ParserTsOptions, object, ts.Node>;
83
+ export declare const parserTsx: import("@kubb/core").ParserFactory<ParserTsOptions, object, string | TsNode>;
77
84
  //#endregion
78
- export type { ParserTsOptions };
85
+ export type { ParserTsOptions, TsNode };
79
86
  //# sourceMappingURL=index.d.cts.map
package/dist/index.d.ts CHANGED
@@ -1,5 +1,14 @@
1
1
  import { ast } from "@kubb/ast";
2
- import * as ts from "@typescript/typescript6";
2
+ //#region src/utils.d.ts
3
+ /**
4
+ * A TypeScript compiler node, typed structurally so `@kubb/parser-ts` does not depend on `@typescript/typescript6`.
5
+ *
6
+ * @deprecated Pass printed strings to `print` instead. Support for compiler nodes is removed in the next major.
7
+ */
8
+ type TsNode = {
9
+ readonly kind: number;
10
+ };
11
+ //#endregion
3
12
  //#region src/parserTs.d.ts
4
13
  /**
5
14
  * Options accepted by `parserTs` and `parserTsx`.
@@ -26,8 +35,7 @@ type ParserTsOptions = {
26
35
  /**
27
36
  * Default Kubb parser for `.ts` and `.js` files. Takes the universal AST
28
37
  * produced by an adapter and prints it as TypeScript source. Imports and exports
29
- * are rewritten based on each file's metadata and the `extension` option. The
30
- * `print` helper renders TypeScript compiler nodes with the TypeScript printer.
38
+ * are rewritten based on each file's metadata and the `extension` option.
31
39
  *
32
40
  * Used automatically when no `parsers` option is set on `defineConfig`. Use
33
41
  * `parserTsx` instead for React projects that emit JSX.
@@ -47,13 +55,12 @@ type ParserTsOptions = {
47
55
  * })
48
56
  * ```
49
57
  */
50
- export declare const parserTs: import("@kubb/core").ParserFactory<ParserTsOptions, object, ts.Node>;
58
+ export declare const parserTs: import("@kubb/core").ParserFactory<ParserTsOptions, object, string | TsNode>;
51
59
  //#endregion
52
60
  //#region src/parserTsx.d.ts
53
61
  /**
54
- * Kubb parser for `.tsx` and `.jsx` files. Delegates to `parserTs` because the
55
- * TypeScript compiler handles JSX natively via `ScriptKind.TSX`, so it shares the
56
- * same `extension` option.
62
+ * Kubb parser for `.tsx` and `.jsx` files. Delegates to `parserTs`, since JSX
63
+ * prints as text the same way, so it shares the same `extension` option.
57
64
  *
58
65
  * Add to the `parsers` array on `defineConfig` when generating components for
59
66
  * React (or any framework that emits JSX).
@@ -73,7 +80,7 @@ export declare const parserTs: import("@kubb/core").ParserFactory<ParserTsOption
73
80
  * })
74
81
  * ```
75
82
  */
76
- export declare const parserTsx: import("@kubb/core").ParserFactory<ParserTsOptions, object, ts.Node>;
83
+ export declare const parserTsx: import("@kubb/core").ParserFactory<ParserTsOptions, object, string | TsNode>;
77
84
  //#endregion
78
- export type { ParserTsOptions };
85
+ export type { ParserTsOptions, TsNode };
79
86
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -2,37 +2,47 @@ import { createRequire } from "node:module";
2
2
  import { ast } from "@kubb/ast";
3
3
  import { defineExtension } from "@kubb/core";
4
4
  import { dirname, extname, relative, resolve } from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+ import { parse } from "yuku-parser";
5
7
  //#endregion
6
8
  //#region kubb-extension.json
7
9
  var compatibility = {
8
10
  "kubb": ">=5.8.3",
9
- "node": ">=22.12"
11
+ "node": ">=22.22"
10
12
  };
11
13
  //#endregion
12
14
  //#region package.json
13
- var version = "5.12.7";
15
+ var version = "5.13.0";
14
16
  //#endregion
15
17
  //#region src/utils.ts
16
18
  let compiler;
17
19
  /**
18
- * Loads TypeScript on the first `print` or `copy`; `parse` is string templating and never needs it.
20
+ * Loads TypeScript the first time `print` gets a compiler node. Strings never need it, so bundles for edge runtimes such as Cloudflare Workers leave it out.
19
21
  *
20
22
  * Loaded with `require`, not `import`: when ESM imports a CommonJS package, Node keeps a second copy of its source
21
23
  * to detect named exports, and for TypeScript that copy is about 9 MB.
22
24
  */
23
25
  function loadCompiler() {
24
26
  if (compiler) return compiler;
25
- const typescript = createRequire(import.meta.url)("@typescript/typescript6");
26
- compiler = {
27
- typescript,
28
- printer: typescript.createPrinter({
29
- omitTrailingSemicolon: true,
30
- newLine: typescript.NewLineKind.LineFeed,
31
- removeComments: false,
32
- noEmitHelpers: true
33
- }),
34
- sourceFile: typescript.createSourceFile("print.tsx", "", typescript.ScriptTarget.ES2022, true, typescript.ScriptKind.TSX)
35
- };
27
+ const require = createRequire(import.meta.url);
28
+ const paths = [process.cwd(), dirname(fileURLToPath(import.meta.url))];
29
+ let typescript;
30
+ for (const name of ["typescript", "@typescript/typescript6"]) try {
31
+ const candidate = require(require.resolve(name, { paths }));
32
+ if (typeof candidate.createPrinter === "function") {
33
+ typescript = candidate;
34
+ break;
35
+ }
36
+ } catch {}
37
+ if (!typescript) throw new Error("`print` received a TypeScript compiler node, which needs `typescript` 5 or 6, or `@typescript/typescript6`, installed. Pass a printed string instead.");
38
+ const printer = typescript.createPrinter({
39
+ omitTrailingSemicolon: true,
40
+ newLine: typescript.NewLineKind.LineFeed,
41
+ removeComments: false,
42
+ noEmitHelpers: true
43
+ });
44
+ const sourceFile = typescript.createSourceFile("print.tsx", "", typescript.ScriptTarget.ES2022, true, typescript.ScriptKind.TSX);
45
+ compiler = { printNodes: (nodes) => printer.printList(typescript.ListFormat.MultiLine, typescript.factory.createNodeArray(nodes), sourceFile) };
36
46
  return compiler;
37
47
  }
38
48
  /**
@@ -51,79 +61,95 @@ function resolveOutputPath(path, extname$1, rootAware) {
51
61
  return current ? `${path.slice(0, -current.length)}${extname$1 ?? ""}` : path;
52
62
  }
53
63
  /**
64
+ * Node types this module reads from the yuku AST.
65
+ */
66
+ const nodeTypes = {
67
+ identifier: "Identifier",
68
+ literal: "Literal",
69
+ importDeclaration: "ImportDeclaration",
70
+ importSpecifier: "ImportSpecifier",
71
+ importDefaultSpecifier: "ImportDefaultSpecifier",
72
+ importNamespaceSpecifier: "ImportNamespaceSpecifier",
73
+ exportAllDeclaration: "ExportAllDeclaration",
74
+ exportNamedDeclaration: "ExportNamedDeclaration"
75
+ };
76
+ /**
77
+ * `importKind` and `exportKind` values this module reads from the yuku AST.
78
+ */
79
+ const declarationKinds = { type: "type" };
80
+ function nameOf(node) {
81
+ return node.type === nodeTypes.literal ? node.value : node.name;
82
+ }
83
+ /**
54
84
  * Converts an import specifier into an `ImportNode` name, keeping the quotes of a string-literal name (`{ 'a-b' as ab }`).
55
85
  */
56
- function toImportName(element) {
57
- if (!element.propertyName) return element.name.text;
58
- const { typescript } = loadCompiler();
59
- const { propertyName } = element;
86
+ function toImportName({ imported, local }) {
87
+ if (imported.type === nodeTypes.identifier && imported.name === local.name) return local.name;
60
88
  return {
61
- propertyName: typescript.isStringLiteral(propertyName) ? quoteModulePath(propertyName.text) : propertyName.text,
62
- name: element.name.text
89
+ propertyName: imported.type === nodeTypes.literal ? quoteModulePath(imported.value) : imported.name,
90
+ name: local.name
63
91
  };
64
92
  }
65
93
  /**
66
- * Converts an `import` declaration into `ImportNode`s. Side-effect imports and imports with attributes stay as written.
94
+ * Converts an `import` declaration into `ImportNode`s. Side-effect imports and imports with attributes or a phase stay as written.
67
95
  */
68
96
  function toImportNodes(statement, filePath) {
69
- const { typescript } = loadCompiler();
70
- if (!typescript.isImportDeclaration(statement) || !statement.importClause || !typescript.isStringLiteral(statement.moduleSpecifier) || statement.attributes) return [];
71
- const { name, namedBindings, phaseModifier } = statement.importClause;
72
- const specifier = statement.moduleSpecifier.text;
97
+ if (statement.type !== nodeTypes.importDeclaration || !statement.specifiers.length || statement.attributes.length || statement.phase) return [];
98
+ const specifier = statement.source.value;
73
99
  const target = specifier.startsWith(".") ? {
74
100
  path: resolve(dirname(filePath), specifier),
75
101
  root: filePath
76
102
  } : { path: specifier };
77
- const isTypeOnly = phaseModifier === typescript.SyntaxKind.TypeKeyword;
103
+ const isTypeOnly = statement.importKind === declarationKinds.type;
78
104
  const nodes = [];
79
- if (name) nodes.push(ast.factory.createImport({
80
- name: name.text,
81
- ...target,
82
- isTypeOnly
83
- }));
84
- if (namedBindings && typescript.isNamespaceImport(namedBindings)) nodes.push(ast.factory.createImport({
85
- name: namedBindings.name.text,
86
- ...target,
87
- isTypeOnly,
88
- isNameSpace: true
89
- }));
90
- if (namedBindings && typescript.isNamedImports(namedBindings)) {
91
- const values = namedBindings.elements.filter((element) => !element.isTypeOnly);
92
- const types = namedBindings.elements.filter((element) => element.isTypeOnly);
93
- if (values.length) nodes.push(ast.factory.createImport({
94
- name: values.map(toImportName),
105
+ const named = statement.specifiers.filter((element) => element.type === nodeTypes.importSpecifier);
106
+ for (const element of statement.specifiers) {
107
+ if (element.type === nodeTypes.importDefaultSpecifier) nodes.push(ast.factory.createImport({
108
+ name: element.local.name,
95
109
  ...target,
96
110
  isTypeOnly
97
111
  }));
98
- if (types.length) nodes.push(ast.factory.createImport({
99
- name: types.map(toImportName),
112
+ if (element.type === nodeTypes.importNamespaceSpecifier) nodes.push(ast.factory.createImport({
113
+ name: element.local.name,
100
114
  ...target,
101
- isTypeOnly: true
115
+ isTypeOnly,
116
+ isNameSpace: true
102
117
  }));
103
118
  }
119
+ const values = named.filter((element) => element.importKind !== declarationKinds.type);
120
+ const types = named.filter((element) => element.importKind === declarationKinds.type);
121
+ if (values.length) nodes.push(ast.factory.createImport({
122
+ name: values.map(toImportName),
123
+ ...target,
124
+ isTypeOnly
125
+ }));
126
+ if (types.length) nodes.push(ast.factory.createImport({
127
+ name: types.map(toImportName),
128
+ ...target,
129
+ isTypeOnly: true
130
+ }));
104
131
  return nodes;
105
132
  }
106
133
  /**
107
134
  * Converts an `export … from` declaration into `ExportNode`s. Forms `printExport` cannot print stay as written.
108
135
  */
109
136
  function toExportNodes(statement) {
110
- const { typescript } = loadCompiler();
111
- if (!typescript.isExportDeclaration(statement) || !statement.moduleSpecifier || !typescript.isStringLiteral(statement.moduleSpecifier) || statement.attributes) return [];
112
- const { exportClause, isTypeOnly } = statement;
113
- const path = statement.moduleSpecifier.text;
114
- if (!exportClause) return [ast.factory.createExport({
115
- path,
116
- isTypeOnly
117
- })];
118
- if (typescript.isNamespaceExport(exportClause)) return [ast.factory.createExport({
119
- name: exportClause.name.text,
137
+ if (statement.type !== nodeTypes.exportAllDeclaration && statement.type !== nodeTypes.exportNamedDeclaration) return [];
138
+ if (!statement.source || statement.attributes.length) return [];
139
+ const path = statement.source.value;
140
+ const isTypeOnly = statement.exportKind === declarationKinds.type;
141
+ if (statement.type === nodeTypes.exportAllDeclaration) return [statement.exported ? ast.factory.createExport({
142
+ name: nameOf(statement.exported),
120
143
  path,
121
144
  isTypeOnly,
122
145
  asAlias: true
146
+ }) : ast.factory.createExport({
147
+ path,
148
+ isTypeOnly
123
149
  })];
124
- if (exportClause.elements.some((element) => element.propertyName || element.isTypeOnly || typescript.isStringLiteral(element.name))) return [];
150
+ if (statement.specifiers.some((element) => element.exportKind === declarationKinds.type || element.exported.type === nodeTypes.literal || nameOf(element.exported) !== nameOf(element.local))) return [];
125
151
  return [ast.factory.createExport({
126
- name: exportClause.elements.map((element) => element.name.text),
152
+ name: statement.specifiers.map((element) => nameOf(element.local)),
127
153
  path,
128
154
  isTypeOnly
129
155
  })];
@@ -132,26 +158,28 @@ function toExportNodes(statement) {
132
158
  * Splits `source` into its lifted `import`/`export … from` nodes, the `header` above the first one (shebang, directives, comments) and the rest as `body`.
133
159
  */
134
160
  function splitModuleDeclarations(source, filePath) {
135
- const { typescript } = loadCompiler();
136
- const sourceFile = typescript.createSourceFile(filePath, source, typescript.ScriptTarget.Latest);
161
+ const { program } = parse(source, {
162
+ lang: "ts",
163
+ sourceType: "module"
164
+ });
137
165
  const imports = [];
138
166
  const exports = [];
139
167
  let header = "";
140
168
  let body = "";
141
169
  let cursor = 0;
142
- for (const statement of sourceFile.statements) {
170
+ for (const statement of program.body) {
143
171
  const importNodes = toImportNodes(statement, filePath);
144
172
  const exportNodes = toExportNodes(statement);
145
173
  if (!importNodes.length && !exportNodes.length) {
146
- if (typescript.isImportDeclaration(statement) || typescript.isExportDeclaration(statement) && statement.moduleSpecifier) break;
174
+ if (statement.type === nodeTypes.importDeclaration || (statement.type === nodeTypes.exportNamedDeclaration || statement.type === nodeTypes.exportAllDeclaration) && statement.source) break;
147
175
  continue;
148
176
  }
149
- const text = source.slice(cursor, statement.getStart(sourceFile));
177
+ const text = source.slice(cursor, statement.start);
150
178
  if (imports.length || exports.length) body += text;
151
179
  else header = text;
152
180
  imports.push(...importNodes);
153
181
  exports.push(...exportNodes);
154
- cursor = statement.getEnd();
182
+ cursor = statement.end;
155
183
  }
156
184
  return {
157
185
  header: header.trim(),
@@ -193,14 +221,15 @@ function indentLines(text) {
193
221
  */
194
222
  function dedent(text) {
195
223
  if (!text) return "";
224
+ if (!text.includes("\n")) return text.trim() ? text.trimStart() : "";
196
225
  const lines = text.split("\n");
197
226
  const isBlank = (line) => line.trim() === "";
198
227
  const start = lines.findIndex((line) => !isBlank(line));
199
228
  if (start === -1) return "";
200
229
  const end = lines.findLastIndex((line) => !isBlank(line));
201
230
  const trimmed = lines.slice(start, end + 1);
202
- const indents = trimmed.filter((line) => !isBlank(line)).map((line) => line.match(/^\s*/)?.[0].length ?? 0);
203
- const min = indents.length ? Math.min(...indents) : 0;
231
+ let min = Infinity;
232
+ for (const line of trimmed) if (!isBlank(line)) min = Math.min(min, line.length - line.trimStart().length);
204
233
  return trimmed.map((line) => isBlank(line) ? "" : line.slice(min)).join("\n");
205
234
  }
206
235
  /**
@@ -220,13 +249,17 @@ function withJSDoc({ jsDoc, declaration }) {
220
249
  return jsDocStr ? `${jsDocStr}\n${declaration}` : declaration;
221
250
  }
222
251
  /**
223
- * Converts TypeScript/TSX AST nodes to a string using the TypeScript printer.
252
+ * Joins printed code fragments with a newline.
253
+ *
254
+ * Passing TypeScript compiler nodes still works but is deprecated and needs `typescript` 5 or 6, or `@typescript/typescript6`, installed.
255
+ * Support for compiler nodes is removed in the next major.
224
256
  */
225
257
  function print(...elements) {
226
258
  const filtered = elements.filter(Boolean);
227
259
  if (filtered.length === 0) return "";
228
- const { typescript, printer, sourceFile } = loadCompiler();
229
- return printer.printList(typescript.ListFormat.MultiLine, typescript.factory.createNodeArray(filtered), sourceFile);
260
+ if (filtered.every((element) => typeof element === "string")) return filtered.join("\n");
261
+ if (filtered.every((element) => typeof element !== "string")) return loadCompiler().printNodes(filtered);
262
+ return filtered.map((element) => typeof element === "string" ? element : loadCompiler().printNodes([element]).trimEnd()).join("\n");
230
263
  }
231
264
  /**
232
265
  * Converts a {@link ast.JSDocNode} to a `/** … *\/` block, dropping blank comments.
@@ -368,8 +401,7 @@ const DEFAULT_EXTENSION = { ".ts": "" };
368
401
  /**
369
402
  * Default Kubb parser for `.ts` and `.js` files. Takes the universal AST
370
403
  * produced by an adapter and prints it as TypeScript source. Imports and exports
371
- * are rewritten based on each file's metadata and the `extension` option. The
372
- * `print` helper renders TypeScript compiler nodes with the TypeScript printer.
404
+ * are rewritten based on each file's metadata and the `extension` option.
373
405
  *
374
406
  * Used automatically when no `parsers` option is set on `defineConfig`. Use
375
407
  * `parserTsx` instead for React projects that emit JSX.
@@ -436,9 +468,8 @@ const parserTs = defineExtension({
436
468
  //#endregion
437
469
  //#region src/parserTsx.ts
438
470
  /**
439
- * Kubb parser for `.tsx` and `.jsx` files. Delegates to `parserTs` because the
440
- * TypeScript compiler handles JSX natively via `ScriptKind.TSX`, so it shares the
441
- * same `extension` option.
471
+ * Kubb parser for `.tsx` and `.jsx` files. Delegates to `parserTs`, since JSX
472
+ * prints as text the same way, so it shares the same `extension` option.
442
473
  *
443
474
  * Add to the `parsers` array on `defineConfig` when generating components for
444
475
  * React (or any framework that emits JSX).
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["getExtname","extname"],"sources":["../kubb-extension.json","../package.json","../src/utils.ts","../src/parserTs.ts","../src/parserTsx.ts"],"sourcesContent":["","","import { createRequire } from 'node:module'\nimport { dirname, extname as getExtname, relative, resolve } from 'node:path'\nimport { ast } from '@kubb/ast'\nimport type * as ts from '@typescript/typescript6'\n\ntype Compiler = {\n typescript: typeof ts\n printer: ts.Printer\n sourceFile: ts.SourceFile\n}\n\nlet compiler: Compiler | undefined\n\n/**\n * Loads TypeScript on the first `print` or `copy`; `parse` is string templating and never needs it.\n *\n * Loaded with `require`, not `import`: when ESM imports a CommonJS package, Node keeps a second copy of its source\n * to detect named exports, and for TypeScript that copy is about 9 MB.\n */\nfunction loadCompiler(): Compiler {\n if (compiler) return compiler\n\n const typescript: typeof ts = createRequire(import.meta.url)('@typescript/typescript6')\n\n compiler = {\n typescript,\n // One printer serves every call; printing does not mutate the source file, which only lends its compiler options\n printer: typescript.createPrinter({\n omitTrailingSemicolon: true,\n newLine: typescript.NewLineKind.LineFeed,\n removeComments: false,\n noEmitHelpers: true,\n }),\n sourceFile: typescript.createSourceFile('print.tsx', '', typescript.ScriptTarget.ES2022, true, typescript.ScriptKind.TSX),\n }\n\n return compiler\n}\n\n/**\n * Module specifier that imports `filePath` from the file at `root`: POSIX, relative to that file's directory, `./`-prefixed unless it climbs with `../`.\n */\nexport function getRelativePath(root: string, filePath: string): string {\n const slashed = relative(dirname(root), filePath).replaceAll('\\\\', '/')\n return slashed.startsWith('../') ? slashed : `./${slashed}`\n}\n\n/**\n * Swaps the extension of a relative import/export path for `extname`. Package specifiers and extension-less paths stay as-is.\n */\nexport function resolveOutputPath(path: string, extname: string | undefined, rootAware: boolean): string {\n if (!rootAware) return path\n const current = getExtname(path)\n return current ? `${path.slice(0, -current.length)}${extname ?? ''}` : path\n}\n\n/**\n * Converts an import specifier into an `ImportNode` name, keeping the quotes of a string-literal name (`{ 'a-b' as ab }`).\n */\nfunction toImportName(element: ts.ImportSpecifier): string | { propertyName: string; name: string } {\n if (!element.propertyName) return element.name.text\n\n const { typescript } = loadCompiler()\n const { propertyName } = element\n return { propertyName: typescript.isStringLiteral(propertyName) ? quoteModulePath(propertyName.text) : propertyName.text, name: element.name.text }\n}\n\n/**\n * Converts an `import` declaration into `ImportNode`s. Side-effect imports and imports with attributes stay as written.\n */\nfunction toImportNodes(statement: ts.Statement, filePath: string): Array<ast.ImportNode> {\n const { typescript } = loadCompiler()\n if (!typescript.isImportDeclaration(statement) || !statement.importClause || !typescript.isStringLiteral(statement.moduleSpecifier) || statement.attributes)\n return []\n\n const { name, namedBindings, phaseModifier } = statement.importClause\n const specifier = statement.moduleSpecifier.text\n const target = specifier.startsWith('.') ? { path: resolve(dirname(filePath), specifier), root: filePath } : { path: specifier }\n const isTypeOnly = phaseModifier === typescript.SyntaxKind.TypeKeyword\n const nodes: Array<ast.ImportNode> = []\n\n if (name) nodes.push(ast.factory.createImport({ name: name.text, ...target, isTypeOnly }))\n if (namedBindings && typescript.isNamespaceImport(namedBindings)) {\n nodes.push(ast.factory.createImport({ name: namedBindings.name.text, ...target, isTypeOnly, isNameSpace: true }))\n }\n if (namedBindings && typescript.isNamedImports(namedBindings)) {\n const values = namedBindings.elements.filter((element) => !element.isTypeOnly)\n const types = namedBindings.elements.filter((element) => element.isTypeOnly)\n if (values.length) nodes.push(ast.factory.createImport({ name: values.map(toImportName), ...target, isTypeOnly }))\n if (types.length) nodes.push(ast.factory.createImport({ name: types.map(toImportName), ...target, isTypeOnly: true }))\n }\n\n return nodes\n}\n\n/**\n * Converts an `export … from` declaration into `ExportNode`s. Forms `printExport` cannot print stay as written.\n */\nfunction toExportNodes(statement: ts.Statement): Array<ast.ExportNode> {\n const { typescript } = loadCompiler()\n if (\n !typescript.isExportDeclaration(statement) ||\n !statement.moduleSpecifier ||\n !typescript.isStringLiteral(statement.moduleSpecifier) ||\n statement.attributes\n )\n return []\n\n const { exportClause, isTypeOnly } = statement\n const path = statement.moduleSpecifier.text\n\n if (!exportClause) return [ast.factory.createExport({ path, isTypeOnly })]\n if (typescript.isNamespaceExport(exportClause)) return [ast.factory.createExport({ name: exportClause.name.text, path, isTypeOnly, asAlias: true })]\n if (exportClause.elements.some((element) => element.propertyName || element.isTypeOnly || typescript.isStringLiteral(element.name))) return []\n\n return [ast.factory.createExport({ name: exportClause.elements.map((element) => element.name.text), path, isTypeOnly })]\n}\n\n/**\n * Splits `source` into its lifted `import`/`export … from` nodes, the `header` above the first one (shebang, directives, comments) and the rest as `body`.\n */\nexport function splitModuleDeclarations(\n source: string,\n filePath: string,\n): { header: string; imports: Array<ast.ImportNode>; exports: Array<ast.ExportNode>; body: string } {\n const { typescript } = loadCompiler()\n const sourceFile = typescript.createSourceFile(filePath, source, typescript.ScriptTarget.Latest)\n const imports: Array<ast.ImportNode> = []\n const exports: Array<ast.ExportNode> = []\n let header = ''\n let body = ''\n let cursor = 0\n\n for (const statement of sourceFile.statements) {\n const importNodes = toImportNodes(statement, filePath)\n const exportNodes = toExportNodes(statement)\n if (!importNodes.length && !exportNodes.length) {\n // Lifted declarations print above the body, so stop at the first one that stays in place to keep the evaluation order.\n if (typescript.isImportDeclaration(statement) || (typescript.isExportDeclaration(statement) && statement.moduleSpecifier)) break\n continue\n }\n\n const text = source.slice(cursor, statement.getStart(sourceFile))\n if (imports.length || exports.length) body += text\n else header = text\n imports.push(...importNodes)\n exports.push(...exportNodes)\n cursor = statement.getEnd()\n }\n\n return { header: header.trim(), imports, exports, body: `${body}${source.slice(cursor)}`.trim() }\n}\n\n/**\n * Joins the printed `nodes` with `separator`; a `Break` widens the next separator to a blank line, and leading, trailing and repeated breaks fold into one.\n *\n * Imperative on purpose: this runs once per source fragment and `map().filter().join()` showed up in deopt traces.\n */\nfunction printNodes({ nodes, separator }: { nodes: Array<ast.CodeNode> | undefined; separator: '\\n' | '\\n\\n' }): string {\n let result = ''\n let pendingBreak = false\n\n for (const node of nodes ?? []) {\n if (node.kind === 'Break') {\n pendingBreak = result !== ''\n continue\n }\n\n const text = printCodeNode(node)\n if (!text) continue\n\n if (result) result += pendingBreak ? '\\n\\n' : separator\n result += text\n pendingBreak = false\n }\n\n return result\n}\n\n/**\n * Indents every non-empty line of `text` by two spaces.\n */\nfunction indentLines(text: string): string {\n if (!text) return ''\n return text\n .split('\\n')\n .map((line) => (line.trim() ? ` ${line}` : ''))\n .join('\\n')\n}\n\n/**\n * Strips the common leading whitespace and the surrounding blank lines, counting tabs and spaces alike, so indented template literals start at column zero.\n */\nfunction dedent(text: string): string {\n if (!text) return ''\n\n const lines = text.split('\\n')\n const isBlank = (line: string) => line.trim() === ''\n\n const start = lines.findIndex((line) => !isBlank(line))\n if (start === -1) return ''\n const end = lines.findLastIndex((line) => !isBlank(line))\n\n const trimmed = lines.slice(start, end + 1)\n const indents = trimmed.filter((line) => !isBlank(line)).map((line) => line.match(/^\\s*/)?.[0].length ?? 0)\n const min = indents.length ? Math.min(...indents) : 0\n\n return trimmed.map((line) => (isBlank(line) ? '' : line.slice(min))).join('\\n')\n}\n\n/**\n * Renders `<T>(params): ReturnType`; an async function wraps its return type in `Promise<>`.\n */\nfunction signature({ async: isAsync, generics, params, returnType }: Pick<ast.FunctionNode, 'async' | 'generics' | 'params' | 'returnType'>): string {\n const genericsStr = generics ? `<${Array.isArray(generics) ? generics.join(', ') : generics}>` : ''\n const wrapped = isAsync ? `Promise<${returnType}>` : returnType\n const returnTypeStr = returnType ? `: ${wrapped}` : ''\n\n return `${genericsStr}(${params ?? ''})${returnTypeStr}`\n}\n\n/**\n * Puts the JSDoc block, when it renders to something, above `declaration`.\n */\nfunction withJSDoc({ jsDoc, declaration }: { jsDoc?: ast.JSDocNode | null; declaration: string }): string {\n const jsDocStr = jsDoc ? printJSDoc(jsDoc) : ''\n\n return jsDocStr ? `${jsDocStr}\\n${declaration}` : declaration\n}\n\n/**\n * Converts TypeScript/TSX AST nodes to a string using the TypeScript printer.\n */\nexport function print(...elements: Array<ts.Node>): string {\n const filtered = elements.filter(Boolean)\n if (filtered.length === 0) return ''\n\n const { typescript, printer, sourceFile } = loadCompiler()\n return printer.printList(typescript.ListFormat.MultiLine, typescript.factory.createNodeArray(filtered), sourceFile)\n}\n\n/**\n * Converts a {@link ast.JSDocNode} to a `/** … *\\/` block, dropping blank comments.\n */\nfunction printJSDoc(jsDoc: ast.JSDocNode): string {\n const comments = (jsDoc.comments ?? []).filter((c) => c != null)\n if (comments.length === 0) return ''\n\n const lines = comments\n .flatMap((c) => c.split(/\\r?\\n/))\n .map((l) => l.replace(/\\*\\//g, '* /').replace(/\\r/g, ''))\n .filter((l) => l.trim().length > 0)\n\n if (lines.length === 0) return ''\n\n return ['/**', ...lines.map((l) => ` * ${l}`), ' */'].join('\\n')\n}\n\n/**\n * Converts a {@link ast.ConstNode} to a `const` declaration, mirroring the `Const` component from `@kubb/renderer-jsx`.\n */\nfunction printConst(node: ast.ConstNode): string {\n const { name, export: canExport, type, JSDoc, asConst, nodes } = node\n\n const declaration = `${canExport ? 'export ' : ''}const ${name}${type ? `: ${type}` : ''} = ${printNodes({ nodes, separator: '\\n' })}${asConst ? ' as const' : ''}`\n\n return withJSDoc({ jsDoc: JSDoc, declaration })\n}\n\n/**\n * Converts a {@link ast.TypeNode} to a `type` alias, mirroring the `Type` component from `@kubb/renderer-jsx`.\n */\nfunction printType(node: ast.TypeNode): string {\n const { name, export: canExport, JSDoc, nodes } = node\n\n const declaration = `${canExport ? 'export ' : ''}type ${name} = ${printNodes({ nodes, separator: '\\n' })}`\n\n return withJSDoc({ jsDoc: JSDoc, declaration })\n}\n\n/**\n * Converts a {@link ast.FunctionNode} to a `function` declaration, mirroring the `Function` component from `@kubb/renderer-jsx`.\n */\nfunction printFunction(node: ast.FunctionNode): string {\n const { name, default: isDefault, export: canExport, async: isAsync, generics, params, returnType, JSDoc, nodes } = node\n\n const body = indentLines(printNodes({ nodes, separator: '\\n' }))\n const prefix = `${canExport ? 'export ' : ''}${isDefault ? 'default ' : ''}${isAsync ? 'async ' : ''}`\n const declaration = `${prefix}function ${name}${signature({ async: isAsync, generics, params, returnType })} {${body ? `\\n${body}\\n` : ''}}`\n\n return withJSDoc({ jsDoc: JSDoc, declaration })\n}\n\n/**\n * Converts an {@link ast.ArrowFunctionNode} to a `const` arrow function, mirroring the `Function.Arrow` component from `@kubb/renderer-jsx`.\n */\nfunction printArrowFunction(node: ast.ArrowFunctionNode): string {\n const { name, default: isDefault, export: canExport, async: isAsync, generics, params, returnType, JSDoc, nodes, singleLine } = node\n\n const body = printNodes({ nodes, separator: '\\n' })\n const arrowBody = singleLine ? ` => ${body}` : body ? ` => {\\n${indentLines(body)}\\n}` : ' => {}'\n const prefix = `${canExport ? 'export ' : ''}${isDefault ? 'default ' : ''}`\n const declaration = `${prefix}const ${name} = ${isAsync ? 'async ' : ''}${signature({ async: isAsync, generics, params, returnType })}${arrowBody}`\n\n return withJSDoc({ jsDoc: JSDoc, declaration })\n}\n\n/**\n * Dispatches a {@link ast.CodeNode} to the printer for its `kind`.\n */\nfunction printCodeNode(node: ast.CodeNode): string {\n switch (node.kind) {\n case 'Break':\n return ''\n case 'Text':\n case 'Jsx':\n return dedent(node.value)\n case 'Const':\n return printConst(node)\n case 'Type':\n return printType(node)\n case 'Function':\n return printFunction(node)\n case 'ArrowFunction':\n return printArrowFunction(node)\n }\n}\n\n/**\n * Prints a {@link ast.SourceNode} with a blank line between its top-level nodes.\n */\nexport function printSource(node: ast.SourceNode): string {\n return printNodes({ nodes: node.nodes, separator: '\\n\\n' })\n}\n\n/**\n * Wraps a module specifier in single quotes, escaping embedded backslashes and quotes.\n */\nfunction quoteModulePath(path: string): string {\n return `'${path.replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\")}'`\n}\n\n/**\n * Renders an `import` declaration (default, `* as`, or named with `{ a as b }`, each optionally `type`-only). `path` is used verbatim, so resolve it first.\n */\nexport function printImport({\n name,\n path,\n isTypeOnly = false,\n isNameSpace = false,\n}: Pick<ast.ImportNode, 'name' | 'path' | 'isTypeOnly' | 'isNameSpace'>): string {\n const typePrefix = isTypeOnly ? 'type ' : ''\n const from = quoteModulePath(path)\n\n if (!Array.isArray(name)) {\n if (isNameSpace) return `import ${typePrefix}* as ${name} from ${from}`\n return `import ${typePrefix}${name} from ${from}`\n }\n\n const specifiers = name.map((item) => {\n if (typeof item === 'object') {\n return item.name ? `${item.propertyName} as ${item.name}` : item.propertyName\n }\n return item\n })\n\n return `import ${typePrefix}{ ${specifiers.join(', ')} } from ${from}`\n}\n\n/**\n * Renders an `export … from` declaration (named, `* as name`, or wildcard, each optionally `type`-only). `path` is used verbatim, so resolve it first.\n */\nexport function printExport({ path, name, isTypeOnly = false, asAlias = false }: Pick<ast.ExportNode, 'name' | 'path' | 'isTypeOnly' | 'asAlias'>): string {\n const typePrefix = isTypeOnly ? 'type ' : ''\n const from = quoteModulePath(path)\n\n if (Array.isArray(name)) {\n return `export ${typePrefix}{ ${name.join(', ')} } from ${from}`\n }\n\n if (asAlias && name) {\n // An identifier cannot start with a digit, so swap the digit for `_`\n const parsedName = /^\\d/.test(name) ? `_${name.slice(1)}` : name\n return `export ${typePrefix}* as ${parsedName} from ${from}`\n }\n\n if (name) {\n return `export ${typePrefix}{ ${name} } from ${from}`\n }\n\n return `export ${typePrefix}* from ${from}`\n}\n","import { ast } from '@kubb/ast'\nimport { defineExtension } from '@kubb/core'\nimport type * as ts from '@typescript/typescript6'\nimport { compatibility } from '../kubb-extension.json'\nimport { version } from '../package.json'\nimport { getRelativePath, print, printExport, printImport, printSource, resolveOutputPath, splitModuleDeclarations } from './utils.ts'\n\nconst DEFAULT_EXTENSION: Record<ast.FileNode['extname'], ast.FileNode['extname'] | ''> = { '.ts': '' }\n\n/**\n * Options accepted by `parserTs` and `parserTsx`.\n */\nexport type ParserTsOptions = {\n /**\n * Rewrite extensions on relative `import`/`export` statements. Each key is the extension of a\n * generated file, and its value is the extension written on the relative specifiers in that\n * file. `''` drops it, and so does a generated file whose extension has no key. Package\n * specifiers stay unchanged. Also applies to relative paths in `copy` templates.\n *\n * Use `{ '.ts': '.js' }` for ESM output compiled to JavaScript, or `{ '.ts': '.ts' }` to run the\n * `.ts` files directly in Node.js or compile them with `rewriteRelativeImportExtensions`.\n *\n * @default { '.ts': '' }\n * @example\n * ```ts\n * parserTs({ extension: { '.ts': '.js' } }) // import './api.js' instead of './api'\n * parserTs({ extension: { '.ts': '.ts' } }) // import './api.ts' instead of './api'\n * ```\n */\n extension?: Record<ast.FileNode['extname'], ast.FileNode['extname'] | ''>\n}\n\n/**\n * Default Kubb parser for `.ts` and `.js` files. Takes the universal AST\n * produced by an adapter and prints it as TypeScript source. Imports and exports\n * are rewritten based on each file's metadata and the `extension` option. The\n * `print` helper renders TypeScript compiler nodes with the TypeScript printer.\n *\n * Used automatically when no `parsers` option is set on `defineConfig`. Use\n * `parserTsx` instead for React projects that emit JSX.\n *\n * @example\n * ```ts\n * import { defineConfig } from 'kubb'\n * import { adapterOas } from '@kubb/adapter-oas'\n * import { parserTs } from '@kubb/parser-ts'\n *\n * export default defineConfig({\n * input: './petStore.yaml',\n * output: { path: './src/gen' },\n * adapter: adapterOas(),\n * parsers: [parserTs()],\n * plugins: [],\n * })\n * ```\n */\nexport const parserTs = defineExtension<ParserTsOptions, object, ts.Node>({\n kind: 'parser',\n meta: { name: 'typescript', version, compatibility, issues: 'https://github.com/kubb-labs/kubb/issues' },\n build({ extension = DEFAULT_EXTENSION }) {\n return {\n extNames: ['.ts', '.js'],\n print,\n parse(file) {\n const extname = extension[file.extname] || undefined\n\n const source = file.sources\n .map((item) => printSource(item))\n .filter(Boolean)\n .map((text) => text.trimEnd())\n .join('\\n\\n')\n\n const importLines = file.imports.map((item) =>\n printImport({\n ...item,\n path: resolveOutputPath(item.root ? getRelativePath(item.root, item.path) : item.path, extname, Boolean(item.root)),\n }),\n )\n\n const exportLines = file.exports.map((item) => printExport({ ...item, path: resolveOutputPath(item.path, extname, item.path.startsWith('.')) }))\n\n const importExportBlock = [...importLines, ...exportLines].join('\\n')\n\n const parts = [file.banner, importExportBlock, source, file.footer].filter((segment): segment is string => Boolean(segment)).map((s) => s.trimEnd())\n\n return parts.join('\\n\\n')\n },\n copy(file, source) {\n const { header, imports, exports, body } = splitModuleDeclarations(source, file.path)\n\n return {\n ...file,\n banner: [header, file.banner].filter(Boolean).join('\\n') || undefined,\n imports: [...file.imports, ...imports],\n exports: [...file.exports, ...exports],\n sources: [ast.factory.createSource({ nodes: [ast.factory.createText(body)] })],\n }\n },\n }\n },\n})\n","import { defineExtension } from '@kubb/core'\nimport type * as ts from '@typescript/typescript6'\nimport { parserTs, type ParserTsOptions } from './parserTs.ts'\n\n/**\n * Kubb parser for `.tsx` and `.jsx` files. Delegates to `parserTs` because the\n * TypeScript compiler handles JSX natively via `ScriptKind.TSX`, so it shares the\n * same `extension` option.\n *\n * Add to the `parsers` array on `defineConfig` when generating components for\n * React (or any framework that emits JSX).\n *\n * @example\n * ```ts\n * import { defineConfig } from 'kubb'\n * import { adapterOas } from '@kubb/adapter-oas'\n * import { parserTsx } from '@kubb/parser-ts'\n *\n * export default defineConfig({\n * input: './petStore.yaml',\n * output: { path: './src/gen' },\n * adapter: adapterOas(),\n * parsers: [parserTsx()],\n * plugins: [],\n * })\n * ```\n */\nexport const parserTsx = defineExtension<ParserTsOptions, object, ts.Node>({\n kind: 'parser',\n meta: { name: 'tsx', issues: 'https://github.com/kubb-labs/kubb/issues' },\n build: (options) => ({ ...parserTs(options), extNames: ['.tsx', '.jsx'] }),\n})\n"],"mappings":";;;;;;;;;;;;;;;AEWA,IAAI;;;;;;;AAQJ,SAAS,eAAyB;CAChC,IAAI,UAAU,OAAO;CAErB,MAAM,aAAwB,cAAc,YAAY,GAAG,CAAC,CAAC,yBAAyB;CAEtF,WAAW;EACT;EAEA,SAAS,WAAW,cAAc;GAChC,uBAAuB;GACvB,SAAS,WAAW,YAAY;GAChC,gBAAgB;GAChB,eAAe;EACjB,CAAC;EACD,YAAY,WAAW,iBAAiB,aAAa,IAAI,WAAW,aAAa,QAAQ,MAAM,WAAW,WAAW,GAAG;CAC1H;CAEA,OAAO;AACT;;;;AAKA,SAAgB,gBAAgB,MAAc,UAA0B;CACtE,MAAM,UAAU,SAAS,QAAQ,IAAI,GAAG,QAAQ,CAAC,CAAC,WAAW,MAAM,GAAG;CACtE,OAAO,QAAQ,WAAW,KAAK,IAAI,UAAU,KAAK;AACpD;;;;AAKA,SAAgB,kBAAkB,MAAc,WAA6B,WAA4B;CACvG,IAAI,CAAC,WAAW,OAAO;CACvB,MAAM,UAAUA,QAAW,IAAI;CAC/B,OAAO,UAAU,GAAG,KAAK,MAAM,GAAG,CAAC,QAAQ,MAAM,IAAIC,aAAW,OAAO;AACzE;;;;AAKA,SAAS,aAAa,SAA8E;CAClG,IAAI,CAAC,QAAQ,cAAc,OAAO,QAAQ,KAAK;CAE/C,MAAM,EAAE,eAAe,aAAa;CACpC,MAAM,EAAE,iBAAiB;CACzB,OAAO;EAAE,cAAc,WAAW,gBAAgB,YAAY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KAAK,KAAK,WAAW,GAAG,CAAC;IAAE,CAAC,CAAC;IAE/I,MAAM,oBAAoB,CAAC,GAAG,aAAa,GAAG,WAAW,CAAC,CAAC,KAAK,IAAI;IAIpE,OAFc;KAAC,KAAK;KAAQ;KAAmB;KAAQ,KAAK;IAAM,CAAC,CAAC,QAAQ,YAA+B,QAAQ,OAAO,CAAC,CAAC,CAAC,KAAK,MAAM,EAAE,QAAQ,CAEvI,CAAC,CAAC,KAAK,MAAM;GAC1B;GACA,KAAK,MAAM,QAAQ;IACjB,MAAM,EAAE,QAAQ,SAAS,SAAS,SAAS,wBAAwB,QAAQ,KAAK,IAAI;IAEpF,OAAO;KACL,GAAG;KACH,QAAQ,CAAC,QAAQ,KAAK,MAAM,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,IAAI,KAAK,KAAA;KAC5D,SAAS,CAAC,GAAG,KAAK,SAAS,GAAG,OAAO;KACrC,SAAS,CAAC,GAAG,KAAK,SAAS,GAAG,OAAO;KACrC,SAAS,CAAC,IAAI,QAAQ,aAAa,EAAE,OAAO,CAAC,IAAI,QAAQ,WAAW,IAAI,CAAC,EAAE,CAAC,CAAC;IAC/E;GACF;EACF;CACF;AACF,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;ACzED,MAAa,YAAY,gBAAkD;CACzE,MAAM;CACN,MAAM;EAAE,MAAM;EAAO,QAAQ;CAA2C;CACxE,QAAQ,aAAa;EAAE,GAAG,SAAS,OAAO;EAAG,UAAU,CAAC,QAAQ,MAAM;CAAE;AAC1E,CAAC"}
1
+ {"version":3,"file":"index.js","names":["getExtname","extname"],"sources":["../kubb-extension.json","../package.json","../src/utils.ts","../src/parserTs.ts","../src/parserTsx.ts"],"sourcesContent":["","","import { createRequire } from 'node:module'\nimport { dirname, extname as getExtname, relative, resolve } from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport { ast } from '@kubb/ast'\nimport { type ImportSpecifier, type ModuleExportName, parse, type ProgramStatement } from 'yuku-parser'\n\n/**\n * A TypeScript compiler node, typed structurally so `@kubb/parser-ts` does not depend on `@typescript/typescript6`.\n *\n * @deprecated Pass printed strings to `print` instead. Support for compiler nodes is removed in the next major.\n */\nexport type TsNode = { readonly kind: number }\n\ntype Compiler = {\n printNodes: (nodes: Array<TsNode>) => string\n}\n\nlet compiler: Compiler | undefined\n\n// The parts of the TypeScript 6 API that printing compiler nodes uses, typed here so no package depends on it\ntype TypeScript = {\n createPrinter(options: { omitTrailingSemicolon: boolean; newLine: number; removeComments: boolean; noEmitHelpers: boolean }): {\n printList(format: number, list: unknown, sourceFile: unknown): string\n }\n createSourceFile(fileName: string, text: string, target: number, setParentNodes: boolean, kind: number): unknown\n factory: { createNodeArray(nodes: Array<TsNode>): unknown }\n NewLineKind: { LineFeed: number }\n ScriptTarget: { ES2022: number }\n ScriptKind: { TSX: number }\n ListFormat: { MultiLine: number }\n}\n\n/**\n * Loads TypeScript the first time `print` gets a compiler node. Strings never need it, so bundles for edge runtimes such as Cloudflare Workers leave it out.\n *\n * Loaded with `require`, not `import`: when ESM imports a CommonJS package, Node keeps a second copy of its source\n * to detect named exports, and for TypeScript that copy is about 9 MB.\n */\nfunction loadCompiler(): Compiler {\n if (compiler) return compiler\n\n const require = createRequire(import.meta.url)\n // Look in the user's project first: a strict package manager such as pnpm does not link it next to this package\n const paths = [process.cwd(), dirname(fileURLToPath(import.meta.url))]\n let typescript: TypeScript | undefined\n // `typescript` 5 and 6 ship the compiler API; next to TypeScript 7 it comes from `@typescript/typescript6`\n for (const name of ['typescript', '@typescript/typescript6']) {\n try {\n const candidate = require(require.resolve(name, { paths }))\n if (typeof candidate.createPrinter === 'function') {\n typescript = candidate as TypeScript\n break\n }\n } catch {}\n }\n if (!typescript) {\n throw new Error(\n '`print` received a TypeScript compiler node, which needs `typescript` 5 or 6, or `@typescript/typescript6`, installed. Pass a printed string instead.',\n )\n }\n\n // One printer serves every call; printing does not mutate the source file, which only lends its compiler options\n const printer = typescript.createPrinter({\n omitTrailingSemicolon: true,\n newLine: typescript.NewLineKind.LineFeed,\n removeComments: false,\n noEmitHelpers: true,\n })\n const sourceFile = typescript.createSourceFile('print.tsx', '', typescript.ScriptTarget.ES2022, true, typescript.ScriptKind.TSX)\n\n compiler = {\n printNodes: (nodes) => printer.printList(typescript.ListFormat.MultiLine, typescript.factory.createNodeArray(nodes), sourceFile),\n }\n\n return compiler\n}\n\n/**\n * Module specifier that imports `filePath` from the file at `root`: POSIX, relative to that file's directory, `./`-prefixed unless it climbs with `../`.\n */\nexport function getRelativePath(root: string, filePath: string): string {\n const slashed = relative(dirname(root), filePath).replaceAll('\\\\', '/')\n return slashed.startsWith('../') ? slashed : `./${slashed}`\n}\n\n/**\n * Swaps the extension of a relative import/export path for `extname`. Package specifiers and extension-less paths stay as-is.\n */\nexport function resolveOutputPath(path: string, extname: string | undefined, rootAware: boolean): string {\n if (!rootAware) return path\n const current = getExtname(path)\n return current ? `${path.slice(0, -current.length)}${extname ?? ''}` : path\n}\n\n/**\n * Node types this module reads from the yuku AST.\n */\nconst nodeTypes = {\n identifier: 'Identifier',\n literal: 'Literal',\n importDeclaration: 'ImportDeclaration',\n importSpecifier: 'ImportSpecifier',\n importDefaultSpecifier: 'ImportDefaultSpecifier',\n importNamespaceSpecifier: 'ImportNamespaceSpecifier',\n exportAllDeclaration: 'ExportAllDeclaration',\n exportNamedDeclaration: 'ExportNamedDeclaration',\n} as const\n\n/**\n * `importKind` and `exportKind` values this module reads from the yuku AST.\n */\nconst declarationKinds = {\n type: 'type',\n} as const\n\nfunction nameOf(node: ModuleExportName): string {\n return node.type === nodeTypes.literal ? node.value : node.name\n}\n\n/**\n * Converts an import specifier into an `ImportNode` name, keeping the quotes of a string-literal name (`{ 'a-b' as ab }`).\n */\nfunction toImportName({ imported, local }: ImportSpecifier): string | { propertyName: string; name: string } {\n if (imported.type === nodeTypes.identifier && imported.name === local.name) return local.name\n\n return { propertyName: imported.type === nodeTypes.literal ? quoteModulePath(imported.value) : imported.name, name: local.name }\n}\n\n/**\n * Converts an `import` declaration into `ImportNode`s. Side-effect imports and imports with attributes or a phase stay as written.\n */\nfunction toImportNodes(statement: ProgramStatement, filePath: string): Array<ast.ImportNode> {\n if (statement.type !== nodeTypes.importDeclaration || !statement.specifiers.length || statement.attributes.length || statement.phase) return []\n\n const specifier = statement.source.value\n const target = specifier.startsWith('.') ? { path: resolve(dirname(filePath), specifier), root: filePath } : { path: specifier }\n const isTypeOnly = statement.importKind === declarationKinds.type\n const nodes: Array<ast.ImportNode> = []\n const named = statement.specifiers.filter((element) => element.type === nodeTypes.importSpecifier)\n\n for (const element of statement.specifiers) {\n if (element.type === nodeTypes.importDefaultSpecifier) nodes.push(ast.factory.createImport({ name: element.local.name, ...target, isTypeOnly }))\n if (element.type === nodeTypes.importNamespaceSpecifier)\n nodes.push(ast.factory.createImport({ name: element.local.name, ...target, isTypeOnly, isNameSpace: true }))\n }\n const values = named.filter((element) => element.importKind !== declarationKinds.type)\n const types = named.filter((element) => element.importKind === declarationKinds.type)\n if (values.length) nodes.push(ast.factory.createImport({ name: values.map(toImportName), ...target, isTypeOnly }))\n if (types.length) nodes.push(ast.factory.createImport({ name: types.map(toImportName), ...target, isTypeOnly: true }))\n\n return nodes\n}\n\n/**\n * Converts an `export … from` declaration into `ExportNode`s. Forms `printExport` cannot print stay as written.\n */\nfunction toExportNodes(statement: ProgramStatement): Array<ast.ExportNode> {\n if (statement.type !== nodeTypes.exportAllDeclaration && statement.type !== nodeTypes.exportNamedDeclaration) return []\n if (!statement.source || statement.attributes.length) return []\n\n const path = statement.source.value\n const isTypeOnly = statement.exportKind === declarationKinds.type\n\n if (statement.type === nodeTypes.exportAllDeclaration) {\n return [\n statement.exported\n ? ast.factory.createExport({ name: nameOf(statement.exported), path, isTypeOnly, asAlias: true })\n : ast.factory.createExport({ path, isTypeOnly }),\n ]\n }\n if (\n statement.specifiers.some(\n (element) =>\n element.exportKind === declarationKinds.type || element.exported.type === nodeTypes.literal || nameOf(element.exported) !== nameOf(element.local),\n )\n )\n return []\n\n return [ast.factory.createExport({ name: statement.specifiers.map((element) => nameOf(element.local)), path, isTypeOnly })]\n}\n\n/**\n * Splits `source` into its lifted `import`/`export … from` nodes, the `header` above the first one (shebang, directives, comments) and the rest as `body`.\n */\nexport function splitModuleDeclarations(\n source: string,\n filePath: string,\n): { header: string; imports: Array<ast.ImportNode>; exports: Array<ast.ExportNode>; body: string } {\n const { program } = parse(source, { lang: 'ts', sourceType: 'module' })\n const imports: Array<ast.ImportNode> = []\n const exports: Array<ast.ExportNode> = []\n let header = ''\n let body = ''\n let cursor = 0\n\n for (const statement of program.body) {\n const importNodes = toImportNodes(statement, filePath)\n const exportNodes = toExportNodes(statement)\n if (!importNodes.length && !exportNodes.length) {\n // Lifted declarations print above the body, so stop at the first one that stays in place to keep the evaluation order.\n if (\n statement.type === nodeTypes.importDeclaration ||\n ((statement.type === nodeTypes.exportNamedDeclaration || statement.type === nodeTypes.exportAllDeclaration) && statement.source)\n )\n break\n continue\n }\n\n const text = source.slice(cursor, statement.start)\n if (imports.length || exports.length) body += text\n else header = text\n imports.push(...importNodes)\n exports.push(...exportNodes)\n cursor = statement.end\n }\n\n return { header: header.trim(), imports, exports, body: `${body}${source.slice(cursor)}`.trim() }\n}\n\n/**\n * Joins the printed `nodes` with `separator`; a `Break` widens the next separator to a blank line, and leading, trailing and repeated breaks fold into one.\n *\n * Imperative on purpose: this runs once per source fragment and `map().filter().join()` showed up in deopt traces.\n */\nfunction printNodes({ nodes, separator }: { nodes: Array<ast.CodeNode> | undefined; separator: '\\n' | '\\n\\n' }): string {\n let result = ''\n let pendingBreak = false\n\n for (const node of nodes ?? []) {\n if (node.kind === 'Break') {\n pendingBreak = result !== ''\n continue\n }\n\n const text = printCodeNode(node)\n if (!text) continue\n\n if (result) result += pendingBreak ? '\\n\\n' : separator\n result += text\n pendingBreak = false\n }\n\n return result\n}\n\n/**\n * Indents every non-empty line of `text` by two spaces.\n */\nfunction indentLines(text: string): string {\n if (!text) return ''\n return text\n .split('\\n')\n .map((line) => (line.trim() ? ` ${line}` : ''))\n .join('\\n')\n}\n\n/**\n * Strips the common leading whitespace and the surrounding blank lines, counting tabs and spaces alike, so indented template literals start at column zero.\n */\nfunction dedent(text: string): string {\n if (!text) return ''\n // Most text nodes are one line, so the common indent is its leading whitespace.\n if (!text.includes('\\n')) return text.trim() ? text.trimStart() : ''\n\n const lines = text.split('\\n')\n const isBlank = (line: string) => line.trim() === ''\n\n const start = lines.findIndex((line) => !isBlank(line))\n if (start === -1) return ''\n const end = lines.findLastIndex((line) => !isBlank(line))\n\n const trimmed = lines.slice(start, end + 1)\n // A loop, not `Math.min(...indents)`, which overflows the stack on very long text.\n let min = Infinity\n for (const line of trimmed) {\n if (!isBlank(line)) min = Math.min(min, line.length - line.trimStart().length)\n }\n\n return trimmed.map((line) => (isBlank(line) ? '' : line.slice(min))).join('\\n')\n}\n\n/**\n * Renders `<T>(params): ReturnType`; an async function wraps its return type in `Promise<>`.\n */\nfunction signature({ async: isAsync, generics, params, returnType }: Pick<ast.FunctionNode, 'async' | 'generics' | 'params' | 'returnType'>): string {\n const genericsStr = generics ? `<${Array.isArray(generics) ? generics.join(', ') : generics}>` : ''\n const wrapped = isAsync ? `Promise<${returnType}>` : returnType\n const returnTypeStr = returnType ? `: ${wrapped}` : ''\n\n return `${genericsStr}(${params ?? ''})${returnTypeStr}`\n}\n\n/**\n * Puts the JSDoc block, when it renders to something, above `declaration`.\n */\nfunction withJSDoc({ jsDoc, declaration }: { jsDoc?: ast.JSDocNode | null; declaration: string }): string {\n const jsDocStr = jsDoc ? printJSDoc(jsDoc) : ''\n\n return jsDocStr ? `${jsDocStr}\\n${declaration}` : declaration\n}\n\n/**\n * Joins printed code fragments with a newline.\n *\n * Passing TypeScript compiler nodes still works but is deprecated and needs `typescript` 5 or 6, or `@typescript/typescript6`, installed.\n * Support for compiler nodes is removed in the next major.\n */\nexport function print(...elements: Array<string | TsNode>): string {\n const filtered = elements.filter(Boolean)\n if (filtered.length === 0) return ''\n if (filtered.every((element) => typeof element === 'string')) return filtered.join('\\n')\n // Printing compiler nodes as one list keeps the output byte-for-byte the same as before strings were accepted\n if (filtered.every((element) => typeof element !== 'string')) return loadCompiler().printNodes(filtered)\n\n return filtered.map((element) => (typeof element === 'string' ? element : loadCompiler().printNodes([element]).trimEnd())).join('\\n')\n}\n\n/**\n * Converts a {@link ast.JSDocNode} to a `/** … *\\/` block, dropping blank comments.\n */\nfunction printJSDoc(jsDoc: ast.JSDocNode): string {\n const comments = (jsDoc.comments ?? []).filter((c) => c != null)\n if (comments.length === 0) return ''\n\n const lines = comments\n .flatMap((c) => c.split(/\\r?\\n/))\n .map((l) => l.replace(/\\*\\//g, '* /').replace(/\\r/g, ''))\n .filter((l) => l.trim().length > 0)\n\n if (lines.length === 0) return ''\n\n return ['/**', ...lines.map((l) => ` * ${l}`), ' */'].join('\\n')\n}\n\n/**\n * Converts a {@link ast.ConstNode} to a `const` declaration, mirroring the `Const` component from `@kubb/renderer-jsx`.\n */\nfunction printConst(node: ast.ConstNode): string {\n const { name, export: canExport, type, JSDoc, asConst, nodes } = node\n\n const declaration = `${canExport ? 'export ' : ''}const ${name}${type ? `: ${type}` : ''} = ${printNodes({ nodes, separator: '\\n' })}${asConst ? ' as const' : ''}`\n\n return withJSDoc({ jsDoc: JSDoc, declaration })\n}\n\n/**\n * Converts a {@link ast.TypeNode} to a `type` alias, mirroring the `Type` component from `@kubb/renderer-jsx`.\n */\nfunction printType(node: ast.TypeNode): string {\n const { name, export: canExport, JSDoc, nodes } = node\n\n const declaration = `${canExport ? 'export ' : ''}type ${name} = ${printNodes({ nodes, separator: '\\n' })}`\n\n return withJSDoc({ jsDoc: JSDoc, declaration })\n}\n\n/**\n * Converts a {@link ast.FunctionNode} to a `function` declaration, mirroring the `Function` component from `@kubb/renderer-jsx`.\n */\nfunction printFunction(node: ast.FunctionNode): string {\n const { name, default: isDefault, export: canExport, async: isAsync, generics, params, returnType, JSDoc, nodes } = node\n\n const body = indentLines(printNodes({ nodes, separator: '\\n' }))\n const prefix = `${canExport ? 'export ' : ''}${isDefault ? 'default ' : ''}${isAsync ? 'async ' : ''}`\n const declaration = `${prefix}function ${name}${signature({ async: isAsync, generics, params, returnType })} {${body ? `\\n${body}\\n` : ''}}`\n\n return withJSDoc({ jsDoc: JSDoc, declaration })\n}\n\n/**\n * Converts an {@link ast.ArrowFunctionNode} to a `const` arrow function, mirroring the `Function.Arrow` component from `@kubb/renderer-jsx`.\n */\nfunction printArrowFunction(node: ast.ArrowFunctionNode): string {\n const { name, default: isDefault, export: canExport, async: isAsync, generics, params, returnType, JSDoc, nodes, singleLine } = node\n\n const body = printNodes({ nodes, separator: '\\n' })\n const arrowBody = singleLine ? ` => ${body}` : body ? ` => {\\n${indentLines(body)}\\n}` : ' => {}'\n const prefix = `${canExport ? 'export ' : ''}${isDefault ? 'default ' : ''}`\n const declaration = `${prefix}const ${name} = ${isAsync ? 'async ' : ''}${signature({ async: isAsync, generics, params, returnType })}${arrowBody}`\n\n return withJSDoc({ jsDoc: JSDoc, declaration })\n}\n\n/**\n * Dispatches a {@link ast.CodeNode} to the printer for its `kind`.\n */\nfunction printCodeNode(node: ast.CodeNode): string {\n switch (node.kind) {\n case 'Break':\n return ''\n case 'Text':\n case 'Jsx':\n return dedent(node.value)\n case 'Const':\n return printConst(node)\n case 'Type':\n return printType(node)\n case 'Function':\n return printFunction(node)\n case 'ArrowFunction':\n return printArrowFunction(node)\n }\n}\n\n/**\n * Prints a {@link ast.SourceNode} with a blank line between its top-level nodes.\n */\nexport function printSource(node: ast.SourceNode): string {\n return printNodes({ nodes: node.nodes, separator: '\\n\\n' })\n}\n\n/**\n * Wraps a module specifier in single quotes, escaping embedded backslashes and quotes.\n */\nfunction quoteModulePath(path: string): string {\n return `'${path.replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\")}'`\n}\n\n/**\n * Renders an `import` declaration (default, `* as`, or named with `{ a as b }`, each optionally `type`-only). `path` is used verbatim, so resolve it first.\n */\nexport function printImport({\n name,\n path,\n isTypeOnly = false,\n isNameSpace = false,\n}: Pick<ast.ImportNode, 'name' | 'path' | 'isTypeOnly' | 'isNameSpace'>): string {\n const typePrefix = isTypeOnly ? 'type ' : ''\n const from = quoteModulePath(path)\n\n if (!Array.isArray(name)) {\n if (isNameSpace) return `import ${typePrefix}* as ${name} from ${from}`\n return `import ${typePrefix}${name} from ${from}`\n }\n\n const specifiers = name.map((item) => {\n if (typeof item === 'object') {\n return item.name ? `${item.propertyName} as ${item.name}` : item.propertyName\n }\n return item\n })\n\n return `import ${typePrefix}{ ${specifiers.join(', ')} } from ${from}`\n}\n\n/**\n * Renders an `export … from` declaration (named, `* as name`, or wildcard, each optionally `type`-only). `path` is used verbatim, so resolve it first.\n */\nexport function printExport({ path, name, isTypeOnly = false, asAlias = false }: Pick<ast.ExportNode, 'name' | 'path' | 'isTypeOnly' | 'asAlias'>): string {\n const typePrefix = isTypeOnly ? 'type ' : ''\n const from = quoteModulePath(path)\n\n if (Array.isArray(name)) {\n return `export ${typePrefix}{ ${name.join(', ')} } from ${from}`\n }\n\n if (asAlias && name) {\n // An identifier cannot start with a digit, so swap the digit for `_`\n const parsedName = /^\\d/.test(name) ? `_${name.slice(1)}` : name\n return `export ${typePrefix}* as ${parsedName} from ${from}`\n }\n\n if (name) {\n return `export ${typePrefix}{ ${name} } from ${from}`\n }\n\n return `export ${typePrefix}* from ${from}`\n}\n","import { ast } from '@kubb/ast'\nimport { defineExtension } from '@kubb/core'\nimport { compatibility } from '../kubb-extension.json'\nimport { version } from '../package.json'\nimport { getRelativePath, print, printExport, printImport, printSource, resolveOutputPath, splitModuleDeclarations, type TsNode } from './utils.ts'\n\nconst DEFAULT_EXTENSION: Record<ast.FileNode['extname'], ast.FileNode['extname'] | ''> = { '.ts': '' }\n\n/**\n * Options accepted by `parserTs` and `parserTsx`.\n */\nexport type ParserTsOptions = {\n /**\n * Rewrite extensions on relative `import`/`export` statements. Each key is the extension of a\n * generated file, and its value is the extension written on the relative specifiers in that\n * file. `''` drops it, and so does a generated file whose extension has no key. Package\n * specifiers stay unchanged. Also applies to relative paths in `copy` templates.\n *\n * Use `{ '.ts': '.js' }` for ESM output compiled to JavaScript, or `{ '.ts': '.ts' }` to run the\n * `.ts` files directly in Node.js or compile them with `rewriteRelativeImportExtensions`.\n *\n * @default { '.ts': '' }\n * @example\n * ```ts\n * parserTs({ extension: { '.ts': '.js' } }) // import './api.js' instead of './api'\n * parserTs({ extension: { '.ts': '.ts' } }) // import './api.ts' instead of './api'\n * ```\n */\n extension?: Record<ast.FileNode['extname'], ast.FileNode['extname'] | ''>\n}\n\n/**\n * Default Kubb parser for `.ts` and `.js` files. Takes the universal AST\n * produced by an adapter and prints it as TypeScript source. Imports and exports\n * are rewritten based on each file's metadata and the `extension` option.\n *\n * Used automatically when no `parsers` option is set on `defineConfig`. Use\n * `parserTsx` instead for React projects that emit JSX.\n *\n * @example\n * ```ts\n * import { defineConfig } from 'kubb'\n * import { adapterOas } from '@kubb/adapter-oas'\n * import { parserTs } from '@kubb/parser-ts'\n *\n * export default defineConfig({\n * input: './petStore.yaml',\n * output: { path: './src/gen' },\n * adapter: adapterOas(),\n * parsers: [parserTs()],\n * plugins: [],\n * })\n * ```\n */\nexport const parserTs = defineExtension<ParserTsOptions, object, string | TsNode>({\n kind: 'parser',\n meta: { name: 'typescript', version, compatibility, issues: 'https://github.com/kubb-labs/kubb/issues' },\n build({ extension = DEFAULT_EXTENSION }) {\n return {\n extNames: ['.ts', '.js'],\n print,\n parse(file) {\n const extname = extension[file.extname] || undefined\n\n const source = file.sources\n .map((item) => printSource(item))\n .filter(Boolean)\n .map((text) => text.trimEnd())\n .join('\\n\\n')\n\n const importLines = file.imports.map((item) =>\n printImport({\n ...item,\n path: resolveOutputPath(item.root ? getRelativePath(item.root, item.path) : item.path, extname, Boolean(item.root)),\n }),\n )\n\n const exportLines = file.exports.map((item) => printExport({ ...item, path: resolveOutputPath(item.path, extname, item.path.startsWith('.')) }))\n\n const importExportBlock = [...importLines, ...exportLines].join('\\n')\n\n const parts = [file.banner, importExportBlock, source, file.footer].filter((segment): segment is string => Boolean(segment)).map((s) => s.trimEnd())\n\n return parts.join('\\n\\n')\n },\n copy(file, source) {\n const { header, imports, exports, body } = splitModuleDeclarations(source, file.path)\n\n return {\n ...file,\n banner: [header, file.banner].filter(Boolean).join('\\n') || undefined,\n imports: [...file.imports, ...imports],\n exports: [...file.exports, ...exports],\n sources: [ast.factory.createSource({ nodes: [ast.factory.createText(body)] })],\n }\n },\n }\n },\n})\n","import { defineExtension } from '@kubb/core'\nimport { parserTs, type ParserTsOptions } from './parserTs.ts'\nimport type { TsNode } from './utils.ts'\n\n/**\n * Kubb parser for `.tsx` and `.jsx` files. Delegates to `parserTs`, since JSX\n * prints as text the same way, so it shares the same `extension` option.\n *\n * Add to the `parsers` array on `defineConfig` when generating components for\n * React (or any framework that emits JSX).\n *\n * @example\n * ```ts\n * import { defineConfig } from 'kubb'\n * import { adapterOas } from '@kubb/adapter-oas'\n * import { parserTsx } from '@kubb/parser-ts'\n *\n * export default defineConfig({\n * input: './petStore.yaml',\n * output: { path: './src/gen' },\n * adapter: adapterOas(),\n * parsers: [parserTsx()],\n * plugins: [],\n * })\n * ```\n */\nexport const parserTsx = defineExtension<ParserTsOptions, object, string | TsNode>({\n kind: 'parser',\n meta: { name: 'tsx', issues: 'https://github.com/kubb-labs/kubb/issues' },\n build: (options) => ({ ...parserTs(options), extNames: ['.tsx', '.jsx'] }),\n})\n"],"mappings":";;;;;;;;;;;;;;;;;AEiBA,IAAI;;;;;;;AAqBJ,SAAS,eAAyB;CAChC,IAAI,UAAU,OAAO;CAErB,MAAM,UAAU,cAAc,YAAY,GAAG;CAE7C,MAAM,QAAQ,CAAC,QAAQ,IAAI,GAAG,QAAQ,cAAc,YAAY,GAAG,CAAC,CAAC;CACrE,IAAI;CAEJ,KAAK,MAAM,QAAQ,CAAC,cAAc,yBAAyB,GACzD,IAAI;EACF,MAAM,YAA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AC"}
package/docs/overview.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # TypeScript
2
2
 
3
- The TypeScript parser writes `.ts` and `.js` files. It turns each file's AST into source text with imports, exports, declarations, and JSDoc, and resolves relative import paths. Plugins such as `@kubb/plugin-ts` print TypeScript nodes with its `print` helper, which uses the official TypeScript printer.
3
+ The TypeScript parser writes `.ts` and `.js` files. It turns each file's AST into source text with imports, exports, declarations, and JSDoc, and resolves relative import paths.
4
4
 
5
5
  The package also exports `parserTsx`, which writes `.tsx` and `.jsx` files with the same options.
6
6
 
@@ -14,6 +14,6 @@
14
14
  "maintainers": [{ "name": "Stijn Van Hulle", "github": "stijnvanhulle" }],
15
15
  "compatibility": {
16
16
  "kubb": ">=5.8.3",
17
- "node": ">=22.12"
17
+ "node": ">=22.22"
18
18
  }
19
19
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kubb/parser-ts",
3
- "version": "5.12.7",
4
- "description": "TypeScript and TSX source file parser for Kubb. Converts AST nodes into formatted source strings using the TypeScript compiler API.",
3
+ "version": "5.13.0",
4
+ "description": "TypeScript and TSX parser for Kubb. Prints AST nodes as TypeScript and TSX source, with imports, exports and JSDoc.",
5
5
  "keywords": [
6
6
  "codegen",
7
7
  "kubb",
@@ -64,12 +64,12 @@
64
64
  "registry": "https://registry.npmjs.org/"
65
65
  },
66
66
  "dependencies": {
67
- "@kubb/ast": "5.12.7",
68
- "@kubb/core": "5.12.7",
69
- "@typescript/typescript6": "^6.0.2"
67
+ "@kubb/ast": "5.13.0",
68
+ "@kubb/core": "5.13.0",
69
+ "yuku-parser": "^0.19.0"
70
70
  },
71
71
  "engines": {
72
- "node": ">=22.12"
72
+ "node": ">=22.22"
73
73
  },
74
74
  "scripts": {
75
75
  "build": "tsdown",