@kubb/parser-ts 5.18.7 → 5.19.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/dist/index.cjs CHANGED
@@ -11,7 +11,7 @@ var compatibility = {
11
11
  "node": ">=22.22"
12
12
  };
13
13
  // package.json
14
- var version = "5.18.7";
14
+ var version = "5.19.0";
15
15
  // src/inline.ts
16
16
  const keyStarts = /* @__PURE__ */ new Set([
17
17
  yuku_parser.TokenKind.LeftBrace,
@@ -57,6 +57,47 @@ const inlineTs = createInline("ts");
57
57
  * {@link inlineTs} for `.tsx` and `.jsx` files, where JSX text and attribute names are not identifiers.
58
58
  */
59
59
  const inlineTsx = createInline("tsx");
60
+ // ../../internals/utils/src/promise.ts
61
+ /**
62
+ * Returns the value cached under `key` in `store`, computing and storing it on the first call.
63
+ * Pass a `WeakMap` for object keys, so an entry goes away with its key, or a `Map` for primitive
64
+ * keys. A cached `null` or `undefined` counts as a hit, so `compute` runs once per key.
65
+ *
66
+ * @example
67
+ * `const refs = memo(refCache, node, () => collectRefs(node))`
68
+ */
69
+ function memo(store, key, compute) {
70
+ const cached = store.get(key);
71
+ if (cached !== void 0 || store.has(key)) return cached;
72
+ const value = compute();
73
+ store.set(key, value);
74
+ return value;
75
+ }
76
+ function createStore({ weak, max } = {}) {
77
+ if (weak) return /* @__PURE__ */ new WeakMap();
78
+ const entry = /* @__PURE__ */ new Map();
79
+ if (max === void 0) return entry;
80
+ const set = (key, value) => {
81
+ if (entry.size >= max) entry.clear();
82
+ entry.set(key, value);
83
+ };
84
+ if (max !== 1) return {
85
+ has: (key) => entry.has(key),
86
+ get: (key) => entry.get(key),
87
+ set
88
+ };
89
+ const touch = (key) => {
90
+ if (!entry.has(key)) return false;
91
+ set(key, entry.get(key));
92
+ return true;
93
+ };
94
+ return {
95
+ has: touch,
96
+ get: (key) => touch(key) ? entry.get(key) : void 0,
97
+ set
98
+ };
99
+ }
100
+ memo.create = createStore;
60
101
  // ../../internals/utils/src/text.ts
61
102
  /**
62
103
  * Indents every non-empty line of `text` by `unit`, leaving blank lines empty.
@@ -124,16 +165,12 @@ function loadCompiler() {
124
165
  */
125
166
  function getRelativePath(root, filePath) {
126
167
  const key = (0, node_path.isAbsolute)(root) && (0, node_path.isAbsolute)(filePath) ? `${root}\u0000${filePath}` : `${process.cwd()}\u0000${root}\u0000${filePath}`;
127
- const cached = relativePaths.get(key);
128
- if (cached !== void 0) return cached;
129
- const slashed = (0, node_path.relative)((0, node_path.dirname)(root), filePath).replaceAll("\\", "/");
130
- const result = slashed.startsWith("../") ? slashed : `./${slashed}`;
131
- if (relativePaths.size >= memoLimit) relativePaths.clear();
132
- relativePaths.set(key, result);
133
- return result;
168
+ return memo(relativePaths, key, () => {
169
+ const slashed = (0, node_path.relative)((0, node_path.dirname)(root), filePath).replaceAll("\\", "/");
170
+ return slashed.startsWith("../") ? slashed : `./${slashed}`;
171
+ });
134
172
  }
135
- const relativePaths = /* @__PURE__ */ new Map();
136
- const memoLimit = 1e5;
173
+ const relativePaths = memo.create({ max: 1e5 });
137
174
  /**
138
175
  * Swaps the extension of a relative import/export path for `extname`. Package specifiers and extension-less paths stay as-is.
139
176
  */
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["TokenKind","parse","createRequire","dirname","fileURLToPath","isAbsolute","relative","getExtname","resolve","ast","parse","defineExtension","ast","defineExtension"],"sources":["../kubb-extension.json","../package.json","../src/inline.ts","../../../internals/utils/src/text.ts","../src/utils.ts","../src/parserTs.ts","../src/parserTsx.ts"],"sourcesContent":["","","import type { ast } from '@kubb/ast'\nimport { parse, TokenKind } from 'yuku-parser'\n\n// A name followed by `:` or `?:` right after one of these is a key or parameter name (`{ Name: x }`, `(Name: x)`).\nconst keyStarts = new Set<number>([TokenKind.LeftBrace, TokenKind.Comma, TokenKind.Semicolon, TokenKind.LeftParen])\n\n/**\n * Calls `replace` for every identifier that references something, and swaps in what it returns.\n * yuku's tokens leave out strings, comments and template text; member access (`x.Name`) and keys are skipped here.\n */\nexport function replaceIdentifiers(text: string, replace: (name: string) => string | undefined, lang: 'ts' | 'tsx' = 'ts'): string {\n // Generated fragments such as `options: Options<Pet>` are not whole programs; yuku still tokenizes them.\n const tokens = parse(text, { lang, sourceType: 'module', tokens: true }).tokens!\n\n // `TokenList` is indexed, not iterable; a plain array also makes the neighbours of a token `undefined` at the ends.\n const kinds = Array.from({ length: tokens.length }, (_, i) => tokens.kind(i))\n\n let out = ''\n let last = 0\n\n for (const [i, kind] of kinds.entries()) {\n if (kind !== TokenKind.Identifier || kinds[i - 1] === TokenKind.Dot || kinds[i - 1] === TokenKind.OptionalChaining) continue\n const isKey = kinds[i + 1] === TokenKind.Colon || (kinds[i + 1] === TokenKind.Question && kinds[i + 2] === TokenKind.Colon)\n // `? Name :` in a conditional type is a reference.\n if (isKey && (i === 0 || tokens.newlineBefore(i) || keyStarts.has(kinds[i - 1]!))) continue\n\n const replacement = replace(tokens.text(i))\n if (replacement === undefined) continue\n out += text.slice(last, tokens.start(i)) + replacement\n last = tokens.end(i)\n }\n\n return out + text.slice(last)\n}\n\nfunction createInline(lang: 'ts' | 'tsx'): ast.InlineLanguage {\n return {\n replaceIdentifiers: (text, replace) => replaceIdentifiers(text, replace, lang),\n wrap: (expression) => (/^[\\w$.]+$/.test(expression) ? expression : `(${expression})`),\n }\n}\n\n/**\n * Inline support for TypeScript and JavaScript files: identifiers are found with {@link replaceIdentifiers},\n * and a definition that is more than a name or a dotted path goes in parentheses.\n */\nexport const inlineTs = createInline('ts')\n\n/**\n * {@link inlineTs} for `.tsx` and `.jsx` files, where JSX text and attribute names are not identifiers.\n */\nexport const inlineTsx = createInline('tsx')\n","/**\n * Indents every non-empty line of `text` by `unit`, leaving blank lines empty.\n * @example\n * `indent({ text: 'a\\n\\nb' }) // ' a\\n\\n b'`\n */\nexport function indent({ text, unit = ' ' }: { text: string; unit?: string }): string {\n if (!text) return ''\n return text\n .split('\\n')\n .map((line) => (line.trim() ? `${unit}${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 */\nexport function 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 indents = lines.map((line) => {\n const indent = line.length - line.trimStart().length\n return indent === line.length ? -1 : indent\n })\n const start = indents.findIndex((indent) => indent !== -1)\n if (start === -1) return ''\n const end = indents.findLastIndex((indent) => indent !== -1)\n // `-1` marks a blank line. `reduce`, not `Math.min(...indents)`, which overflows the stack on very long text.\n const min = indents.reduce((lowest, indent) => (indent !== -1 && indent < lowest ? indent : lowest), Infinity)\n\n return lines\n .slice(start, end + 1)\n .map((line, i) => (indents[start + i] === -1 ? '' : line.slice(min)))\n .join('\\n')\n}\n\n/**\n * Strips one matching pair of `\"`, `'` or `` ` `` from both ends of `text`. Returns `text` unchanged without a matching pair.\n * @example\n * `unquote('\"hello\"') // 'hello'`\n */\nexport function unquote(text: string): string {\n if (text.length < 2) return text\n const first = text[0]\n return (first === '\"' || first === \"'\" || first === '`') && text.at(-1) === first ? text.slice(1, -1) : text\n}\n","import { dedent, indent } from '@internals/utils'\nimport { createRequire } from 'node:module'\nimport { dirname, extname as getExtname, isAbsolute, 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 process.emitWarning(\n 'Printing TypeScript compiler nodes with `print` from `@kubb/parser-ts` is deprecated and is removed in the next major. Return printed strings from printer handlers instead.',\n { type: 'DeprecationWarning', code: 'KUBB_PRINT_TS_NODE' },\n )\n\n const requireModule = 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 = requireModule(requireModule.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 // A relative input resolves against the working directory, so that directory is part of its key.\n const key = isAbsolute(root) && isAbsolute(filePath) ? `${root}\\u0000${filePath}` : `${process.cwd()}\\u0000${root}\\u0000${filePath}`\n const cached = relativePaths.get(key)\n if (cached !== undefined) return cached\n\n const slashed = relative(dirname(root), filePath).replaceAll('\\\\', '/')\n const result = slashed.startsWith('../') ? slashed : `./${slashed}`\n if (relativePaths.size >= memoLimit) relativePaths.clear()\n relativePaths.set(key, result)\n return result\n}\n\n// The limit bounds what a long-running host keeps across builds into fresh roots; one build stays well under it.\nconst relativePaths = new Map<string, string>()\nconst memoLimit = 100_000\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 === ast.node.kinds.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 * 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 = indent({ text: 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${indent({ text: 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 ast.node.kinds.break:\n return ''\n case ast.node.kinds.text:\n case ast.node.kinds.jsx:\n return dedent(node.value)\n case ast.node.kinds.const:\n return printConst(node)\n case ast.node.kinds.type:\n return printType(node)\n case ast.node.kinds.function:\n return printFunction(node)\n case ast.node.kinds.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 { inlineTs } from './inline.ts'\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 inline: inlineTs,\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 { inlineTsx } from './inline.ts'\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'], inline: inlineTsx }),\n})\n"],"mappings":";;;;;;;;;;;;;;;AEIA,MAAM,4BAAY,IAAI,IAAY;CAACA,YAAAA,UAAU;CAAWA,YAAAA,UAAU;CAAOA,YAAAA,UAAU;CAAWA,YAAAA,UAAU;AAAS,CAAC;;;;;AAMlH,SAAgB,mBAAmB,MAAc,SAA+C,OAAqB,MAAc;CAEjI,MAAM,UAAA,GAASC,YAAAA,MAAAA,CAAM,MAAM;EAAE;EAAM,YAAY;EAAU,QAAQ;CAAK,CAAC,CAAC,CAAC;CAGzE,MAAM,QAAQ,MAAM,KAAK,EAAE,QAAQ,OAAO,OAAO,IAAI,GAAG,MAAM,OAAO,KAAK,CAAC,CAAC;CAE5E,IAAI,MAAM;CACV,IAAI,OAAO;CAEX,KAAK,MAAM,CAAC,GAAG,SAAS,MAAM,QAAQ,GAAG;EACvC,IAAI,SAASD,YAAAA,UAAU,cAAc,MAAM,IAAI,OAAOA,YAAAA,UAAU,OAAO,MAAM,IAAI,OAAOA,YAAAA,UAAU,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AC,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;;;;;;;;;;;;;;;;;;;;;;;;ACzED,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;EAAG,QAAQ;CAAU;AAC7F,CAAC"}
1
+ {"version":3,"file":"index.cjs","names":["TokenKind","parse","createRequire","dirname","fileURLToPath","isAbsolute","relative","getExtname","resolve","ast","parse","defineExtension","ast","defineExtension"],"sources":["../kubb-extension.json","../package.json","../src/inline.ts","../../../internals/utils/src/promise.ts","../../../internals/utils/src/text.ts","../src/utils.ts","../src/parserTs.ts","../src/parserTsx.ts"],"sourcesContent":["","","import type { ast } from '@kubb/ast'\nimport { parse, TokenKind } from 'yuku-parser'\n\n// A name followed by `:` or `?:` right after one of these is a key or parameter name (`{ Name: x }`, `(Name: x)`).\nconst keyStarts = new Set<number>([TokenKind.LeftBrace, TokenKind.Comma, TokenKind.Semicolon, TokenKind.LeftParen])\n\n/**\n * Calls `replace` for every identifier that references something, and swaps in what it returns.\n * yuku's tokens leave out strings, comments and template text; member access (`x.Name`) and keys are skipped here.\n */\nexport function replaceIdentifiers(text: string, replace: (name: string) => string | undefined, lang: 'ts' | 'tsx' = 'ts'): string {\n // Generated fragments such as `options: Options<Pet>` are not whole programs; yuku still tokenizes them.\n const tokens = parse(text, { lang, sourceType: 'module', tokens: true }).tokens!\n\n // `TokenList` is indexed, not iterable; a plain array also makes the neighbours of a token `undefined` at the ends.\n const kinds = Array.from({ length: tokens.length }, (_, i) => tokens.kind(i))\n\n let out = ''\n let last = 0\n\n for (const [i, kind] of kinds.entries()) {\n if (kind !== TokenKind.Identifier || kinds[i - 1] === TokenKind.Dot || kinds[i - 1] === TokenKind.OptionalChaining) continue\n const isKey = kinds[i + 1] === TokenKind.Colon || (kinds[i + 1] === TokenKind.Question && kinds[i + 2] === TokenKind.Colon)\n // `? Name :` in a conditional type is a reference.\n if (isKey && (i === 0 || tokens.newlineBefore(i) || keyStarts.has(kinds[i - 1]!))) continue\n\n const replacement = replace(tokens.text(i))\n if (replacement === undefined) continue\n out += text.slice(last, tokens.start(i)) + replacement\n last = tokens.end(i)\n }\n\n return out + text.slice(last)\n}\n\nfunction createInline(lang: 'ts' | 'tsx'): ast.InlineLanguage {\n return {\n replaceIdentifiers: (text, replace) => replaceIdentifiers(text, replace, lang),\n wrap: (expression) => (/^[\\w$.]+$/.test(expression) ? expression : `(${expression})`),\n }\n}\n\n/**\n * Inline support for TypeScript and JavaScript files: identifiers are found with {@link replaceIdentifiers},\n * and a definition that is more than a name or a dotted path goes in parentheses.\n */\nexport const inlineTs = createInline('ts')\n\n/**\n * {@link inlineTs} for `.tsx` and `.jsx` files, where JSX text and attribute names are not identifiers.\n */\nexport const inlineTsx = createInline('tsx')\n","/** A value that may already be resolved or still pending.\n *\n * @example\n * ```ts\n * function load(id: string): PossiblePromise<string> {\n * return cache.get(id) ?? fetchRemote(id)\n * }\n * ```\n */\nexport type PossiblePromise<T> = Promise<T> | T\n\ntype Store<TKey, TValue> = {\n has(key: TKey): boolean\n get(key: TKey): TValue | undefined\n set(key: TKey, value: TValue): unknown\n}\n\n/**\n * Returns the value cached under `key` in `store`, computing and storing it on the first call.\n * Pass a `WeakMap` for object keys, so an entry goes away with its key, or a `Map` for primitive\n * keys. A cached `null` or `undefined` counts as a hit, so `compute` runs once per key.\n *\n * @example\n * `const refs = memo(refCache, node, () => collectRefs(node))`\n */\nexport function memo<TKey, TValue>(store: Store<TKey, TValue>, key: TKey, compute: () => TValue): TValue {\n const cached = store.get(key)\n if (cached !== undefined || store.has(key)) return cached as TValue\n const value = compute()\n store.set(key, value)\n return value\n}\n\n/**\n * Creates a store for `memo`. With no options it is a `Map`. Each option changes one thing:\n *\n * - `weak` holds the keys weakly, in a `WeakMap`, so an entry goes away with its key.\n * - `max` bounds the store: it empties itself before the entry that would pass `max`, which keeps a\n * cache in a long-running process from growing without end. `max: 1` keeps only the last entry.\n *\n * @example\n * `const patterns = memo.create<string, RegExp>()`\n *\n * @example Freed with its key\n * `const refs = memo.create<SchemaNode, Array<string>>({ weak: true })`\n *\n * @example Bounded\n * `const names = memo.create<string, string>({ max: 100_000 })`\n *\n * @example Many values per key\n * ```ts\n * const filesByPlugin = memo.create<string, Array<string>>()\n * memo(filesByPlugin, 'plugin-ts', () => []).push('models.ts')\n * ```\n */\nfunction createStore<TKey, TValue>(options?: { weak?: false; max?: undefined }): Map<TKey, TValue>\nfunction createStore<TKey extends WeakKey, TValue>(options: { weak: true; max?: undefined }): WeakMap<TKey, TValue>\nfunction createStore<TKey, TValue>(options: { max: number; weak?: false }): Store<TKey, TValue>\nfunction createStore<TKey, TValue>({ weak, max }: { weak?: boolean; max?: number } = {}): Store<TKey, TValue> {\n if (weak) return new WeakMap<WeakKey, TValue>() as Store<TKey, TValue>\n const entry = new Map<TKey, TValue>()\n if (max === undefined) return entry\n const set = (key: TKey, value: TValue) => {\n if (entry.size >= max) entry.clear()\n entry.set(key, value)\n }\n if (max !== 1) return { has: (key) => entry.has(key), get: (key) => entry.get(key), set }\n // A key equal to the stored one but a different object, such as a copy of a string, replaces the\n // stored key, so the next lookup is an identity hit instead of a full comparison.\n const touch = (key: TKey) => {\n if (!entry.has(key)) return false\n set(key, entry.get(key) as TValue)\n return true\n }\n return { has: touch, get: (key) => (touch(key) ? entry.get(key) : undefined), set }\n}\n\nmemo.create = createStore\n\ntype ParallelOptions<TItem> = {\n /**\n * Items to work through, handed out in order.\n */\n items: ReadonlyArray<TItem>\n /**\n * How many items may be in flight at once.\n */\n limit: number\n /**\n * Runs once per item, with the item's position so a caller can report progress.\n */\n run(item: TItem, index: number): Promise<void>\n}\n\n/**\n * Runs `run` over every item with at most `limit` in flight. Workers share one iterator, so each\n * takes the next item the moment it frees up instead of waiting for a batch to drain.\n *\n * @example\n * ```ts\n * await inParallel({ items: files, limit: 50, run: (file) => storage.writeItem(file.path, file.source) })\n * ```\n */\nexport async function inParallel<TItem>({ items, limit, run }: ParallelOptions<TItem>): Promise<void> {\n const queue = items.entries()\n\n const worker = async (): Promise<void> => {\n for (const [index, item] of queue) await run(item, index)\n }\n\n await Promise.all(Array.from({ length: Math.min(limit, items.length) }, () => worker()))\n}\n","/**\n * Indents every non-empty line of `text` by `unit`, leaving blank lines empty.\n * @example\n * `indent({ text: 'a\\n\\nb' }) // ' a\\n\\n b'`\n */\nexport function indent({ text, unit = ' ' }: { text: string; unit?: string }): string {\n if (!text) return ''\n return text\n .split('\\n')\n .map((line) => (line.trim() ? `${unit}${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 */\nexport function 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 indents = lines.map((line) => {\n const indent = line.length - line.trimStart().length\n return indent === line.length ? -1 : indent\n })\n const start = indents.findIndex((indent) => indent !== -1)\n if (start === -1) return ''\n const end = indents.findLastIndex((indent) => indent !== -1)\n // `-1` marks a blank line. `reduce`, not `Math.min(...indents)`, which overflows the stack on very long text.\n const min = indents.reduce((lowest, indent) => (indent !== -1 && indent < lowest ? indent : lowest), Infinity)\n\n return lines\n .slice(start, end + 1)\n .map((line, i) => (indents[start + i] === -1 ? '' : line.slice(min)))\n .join('\\n')\n}\n\n/**\n * Strips one matching pair of `\"`, `'` or `` ` `` from both ends of `text`. Returns `text` unchanged without a matching pair.\n * @example\n * `unquote('\"hello\"') // 'hello'`\n */\nexport function unquote(text: string): string {\n if (text.length < 2) return text\n const first = text[0]\n return (first === '\"' || first === \"'\" || first === '`') && text.at(-1) === first ? text.slice(1, -1) : text\n}\n","import { dedent, indent, memo } from '@internals/utils'\nimport { createRequire } from 'node:module'\nimport { dirname, extname as getExtname, isAbsolute, 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 process.emitWarning(\n 'Printing TypeScript compiler nodes with `print` from `@kubb/parser-ts` is deprecated and is removed in the next major. Return printed strings from printer handlers instead.',\n { type: 'DeprecationWarning', code: 'KUBB_PRINT_TS_NODE' },\n )\n\n const requireModule = 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 = requireModule(requireModule.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 // A relative input resolves against the working directory, so that directory is part of its key.\n const key = isAbsolute(root) && isAbsolute(filePath) ? `${root}\\u0000${filePath}` : `${process.cwd()}\\u0000${root}\\u0000${filePath}`\n return memo(relativePaths, key, () => {\n const slashed = relative(dirname(root), filePath).replaceAll('\\\\', '/')\n return slashed.startsWith('../') ? slashed : `./${slashed}`\n })\n}\n\n// The limit bounds what a long-running host keeps across builds into fresh roots; one build stays well under it.\nconst relativePaths = memo.create<string, string>({ max: 100_000 })\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 === ast.node.kinds.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 * 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 = indent({ text: 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${indent({ text: 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 ast.node.kinds.break:\n return ''\n case ast.node.kinds.text:\n case ast.node.kinds.jsx:\n return dedent(node.value)\n case ast.node.kinds.const:\n return printConst(node)\n case ast.node.kinds.type:\n return printType(node)\n case ast.node.kinds.function:\n return printFunction(node)\n case ast.node.kinds.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 { inlineTs } from './inline.ts'\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 inline: inlineTs,\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 { inlineTsx } from './inline.ts'\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'], inline: inlineTsx }),\n})\n"],"mappings":";;;;;;;;;;;;;;;AEIA,MAAM,4BAAY,IAAI,IAAY;CAACA,YAAAA,UAAU;CAAWA,YAAAA,UAAU;CAAOA,YAAAA,UAAU;CAAWA,YAAAA,UAAU;AAAS,CAAC;;;;;AAMlH,SAAgB,mBAAmB,MAAc,SAA+C,OAAqB,MAAc;CAEjI,MAAM,UAAA,GAASC,YAAAA,MAAAA,CAAM,MAAM;EAAE;EAAM,YAAY;EAAU,QAAQ;CAAK,CAAC,CAAC,CAAC;CAGzE,MAAM,QAAQ,MAAM,KAAK,EAAE,QAAQ,OAAO,OAAO,IAAI,GAAG,MAAM,OAAO,KAAK,CAAC,CAAC;CAE5E,IAAI,MAAM;CACV,IAAI,OAAO;CAEX,KAAK,MAAM,CAAC,GAAG,SAAS,MAAM,QAAQ,GAAG;EACvC,IAAI,SAASD,YAAAA,UAAU,cAAc,MAAM,IAAI,OAAOA,YAAAA,UAAU,OAAO,MAAM,IAAI,OAAOA,YAAAA,UAAU,kBAAkB;EAGpH,KAFc,MAAM,IAAI,OAAOA,YAAAA,UAAU,SAAU,MAAM,IAAI,OAAOA,YAAAA,UAAU,YAAY,MAAM,IAAI,OAAOA,YAAAA,UAAU,WAEvG,MAAM,KAAK,OAAO,cAAc,CAAC,KAAK,UAAU,IAAI,MAAM,IAAI,EAAG,IAAI;EAEnF,MAAM,cAAc,QAAQ,OAAO,KAAK,CAAC,CAAC;EAC1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0D;CACjF,MAAM;CACN,MAAM;EAAE,MAAM;EAAO,QAAQ;CAA2C;CACxE,QAAQ,aAAa;EAAE,GAAG,SAAS,OAAO;EAAG,UAAU,CAAC,QAAQ,MAAM;EAAG,QAAQ;CAAU;AAC7F,CAAC"}
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@ var compatibility = {
10
10
  "node": ">=22.22"
11
11
  };
12
12
  // package.json
13
- var version = "5.18.7";
13
+ var version = "5.19.0";
14
14
  // src/inline.ts
15
15
  const keyStarts = /* @__PURE__ */ new Set([
16
16
  TokenKind.LeftBrace,
@@ -56,6 +56,47 @@ const inlineTs = createInline("ts");
56
56
  * {@link inlineTs} for `.tsx` and `.jsx` files, where JSX text and attribute names are not identifiers.
57
57
  */
58
58
  const inlineTsx = createInline("tsx");
59
+ // ../../internals/utils/src/promise.ts
60
+ /**
61
+ * Returns the value cached under `key` in `store`, computing and storing it on the first call.
62
+ * Pass a `WeakMap` for object keys, so an entry goes away with its key, or a `Map` for primitive
63
+ * keys. A cached `null` or `undefined` counts as a hit, so `compute` runs once per key.
64
+ *
65
+ * @example
66
+ * `const refs = memo(refCache, node, () => collectRefs(node))`
67
+ */
68
+ function memo(store, key, compute) {
69
+ const cached = store.get(key);
70
+ if (cached !== void 0 || store.has(key)) return cached;
71
+ const value = compute();
72
+ store.set(key, value);
73
+ return value;
74
+ }
75
+ function createStore({ weak, max } = {}) {
76
+ if (weak) return /* @__PURE__ */ new WeakMap();
77
+ const entry = /* @__PURE__ */ new Map();
78
+ if (max === void 0) return entry;
79
+ const set = (key, value) => {
80
+ if (entry.size >= max) entry.clear();
81
+ entry.set(key, value);
82
+ };
83
+ if (max !== 1) return {
84
+ has: (key) => entry.has(key),
85
+ get: (key) => entry.get(key),
86
+ set
87
+ };
88
+ const touch = (key) => {
89
+ if (!entry.has(key)) return false;
90
+ set(key, entry.get(key));
91
+ return true;
92
+ };
93
+ return {
94
+ has: touch,
95
+ get: (key) => touch(key) ? entry.get(key) : void 0,
96
+ set
97
+ };
98
+ }
99
+ memo.create = createStore;
59
100
  // ../../internals/utils/src/text.ts
60
101
  /**
61
102
  * Indents every non-empty line of `text` by `unit`, leaving blank lines empty.
@@ -123,16 +164,12 @@ function loadCompiler() {
123
164
  */
124
165
  function getRelativePath(root, filePath) {
125
166
  const key = isAbsolute(root) && isAbsolute(filePath) ? `${root}\u0000${filePath}` : `${process.cwd()}\u0000${root}\u0000${filePath}`;
126
- const cached = relativePaths.get(key);
127
- if (cached !== void 0) return cached;
128
- const slashed = relative(dirname(root), filePath).replaceAll("\\", "/");
129
- const result = slashed.startsWith("../") ? slashed : `./${slashed}`;
130
- if (relativePaths.size >= memoLimit) relativePaths.clear();
131
- relativePaths.set(key, result);
132
- return result;
167
+ return memo(relativePaths, key, () => {
168
+ const slashed = relative(dirname(root), filePath).replaceAll("\\", "/");
169
+ return slashed.startsWith("../") ? slashed : `./${slashed}`;
170
+ });
133
171
  }
134
- const relativePaths = /* @__PURE__ */ new Map();
135
- const memoLimit = 1e5;
172
+ const relativePaths = memo.create({ max: 1e5 });
136
173
  /**
137
174
  * Swaps the extension of a relative import/export path for `extname`. Package specifiers and extension-less paths stay as-is.
138
175
  */
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["getExtname","extname"],"sources":["../kubb-extension.json","../package.json","../src/inline.ts","../../../internals/utils/src/text.ts","../src/utils.ts","../src/parserTs.ts","../src/parserTsx.ts"],"sourcesContent":["","","import type { ast } from '@kubb/ast'\nimport { parse, TokenKind } from 'yuku-parser'\n\n// A name followed by `:` or `?:` right after one of these is a key or parameter name (`{ Name: x }`, `(Name: x)`).\nconst keyStarts = new Set<number>([TokenKind.LeftBrace, TokenKind.Comma, TokenKind.Semicolon, TokenKind.LeftParen])\n\n/**\n * Calls `replace` for every identifier that references something, and swaps in what it returns.\n * yuku's tokens leave out strings, comments and template text; member access (`x.Name`) and keys are skipped here.\n */\nexport function replaceIdentifiers(text: string, replace: (name: string) => string | undefined, lang: 'ts' | 'tsx' = 'ts'): string {\n // Generated fragments such as `options: Options<Pet>` are not whole programs; yuku still tokenizes them.\n const tokens = parse(text, { lang, sourceType: 'module', tokens: true }).tokens!\n\n // `TokenList` is indexed, not iterable; a plain array also makes the neighbours of a token `undefined` at the ends.\n const kinds = Array.from({ length: tokens.length }, (_, i) => tokens.kind(i))\n\n let out = ''\n let last = 0\n\n for (const [i, kind] of kinds.entries()) {\n if (kind !== TokenKind.Identifier || kinds[i - 1] === TokenKind.Dot || kinds[i - 1] === TokenKind.OptionalChaining) continue\n const isKey = kinds[i + 1] === TokenKind.Colon || (kinds[i + 1] === TokenKind.Question && kinds[i + 2] === TokenKind.Colon)\n // `? Name :` in a conditional type is a reference.\n if (isKey && (i === 0 || tokens.newlineBefore(i) || keyStarts.has(kinds[i - 1]!))) continue\n\n const replacement = replace(tokens.text(i))\n if (replacement === undefined) continue\n out += text.slice(last, tokens.start(i)) + replacement\n last = tokens.end(i)\n }\n\n return out + text.slice(last)\n}\n\nfunction createInline(lang: 'ts' | 'tsx'): ast.InlineLanguage {\n return {\n replaceIdentifiers: (text, replace) => replaceIdentifiers(text, replace, lang),\n wrap: (expression) => (/^[\\w$.]+$/.test(expression) ? expression : `(${expression})`),\n }\n}\n\n/**\n * Inline support for TypeScript and JavaScript files: identifiers are found with {@link replaceIdentifiers},\n * and a definition that is more than a name or a dotted path goes in parentheses.\n */\nexport const inlineTs = createInline('ts')\n\n/**\n * {@link inlineTs} for `.tsx` and `.jsx` files, where JSX text and attribute names are not identifiers.\n */\nexport const inlineTsx = createInline('tsx')\n","/**\n * Indents every non-empty line of `text` by `unit`, leaving blank lines empty.\n * @example\n * `indent({ text: 'a\\n\\nb' }) // ' a\\n\\n b'`\n */\nexport function indent({ text, unit = ' ' }: { text: string; unit?: string }): string {\n if (!text) return ''\n return text\n .split('\\n')\n .map((line) => (line.trim() ? `${unit}${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 */\nexport function 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 indents = lines.map((line) => {\n const indent = line.length - line.trimStart().length\n return indent === line.length ? -1 : indent\n })\n const start = indents.findIndex((indent) => indent !== -1)\n if (start === -1) return ''\n const end = indents.findLastIndex((indent) => indent !== -1)\n // `-1` marks a blank line. `reduce`, not `Math.min(...indents)`, which overflows the stack on very long text.\n const min = indents.reduce((lowest, indent) => (indent !== -1 && indent < lowest ? indent : lowest), Infinity)\n\n return lines\n .slice(start, end + 1)\n .map((line, i) => (indents[start + i] === -1 ? '' : line.slice(min)))\n .join('\\n')\n}\n\n/**\n * Strips one matching pair of `\"`, `'` or `` ` `` from both ends of `text`. Returns `text` unchanged without a matching pair.\n * @example\n * `unquote('\"hello\"') // 'hello'`\n */\nexport function unquote(text: string): string {\n if (text.length < 2) return text\n const first = text[0]\n return (first === '\"' || first === \"'\" || first === '`') && text.at(-1) === first ? text.slice(1, -1) : text\n}\n","import { dedent, indent } from '@internals/utils'\nimport { createRequire } from 'node:module'\nimport { dirname, extname as getExtname, isAbsolute, 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 process.emitWarning(\n 'Printing TypeScript compiler nodes with `print` from `@kubb/parser-ts` is deprecated and is removed in the next major. Return printed strings from printer handlers instead.',\n { type: 'DeprecationWarning', code: 'KUBB_PRINT_TS_NODE' },\n )\n\n const requireModule = 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 = requireModule(requireModule.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 // A relative input resolves against the working directory, so that directory is part of its key.\n const key = isAbsolute(root) && isAbsolute(filePath) ? `${root}\\u0000${filePath}` : `${process.cwd()}\\u0000${root}\\u0000${filePath}`\n const cached = relativePaths.get(key)\n if (cached !== undefined) return cached\n\n const slashed = relative(dirname(root), filePath).replaceAll('\\\\', '/')\n const result = slashed.startsWith('../') ? slashed : `./${slashed}`\n if (relativePaths.size >= memoLimit) relativePaths.clear()\n relativePaths.set(key, result)\n return result\n}\n\n// The limit bounds what a long-running host keeps across builds into fresh roots; one build stays well under it.\nconst relativePaths = new Map<string, string>()\nconst memoLimit = 100_000\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 === ast.node.kinds.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 * 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 = indent({ text: 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${indent({ text: 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 ast.node.kinds.break:\n return ''\n case ast.node.kinds.text:\n case ast.node.kinds.jsx:\n return dedent(node.value)\n case ast.node.kinds.const:\n return printConst(node)\n case ast.node.kinds.type:\n return printType(node)\n case ast.node.kinds.function:\n return printFunction(node)\n case ast.node.kinds.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 { inlineTs } from './inline.ts'\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 inline: inlineTs,\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 { inlineTsx } from './inline.ts'\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'], inline: inlineTsx }),\n})\n"],"mappings":";;;;;;;;;;;;;;AEIA,MAAM,4BAAY,IAAI,IAAY;CAAC,UAAU;CAAW,UAAU;CAAO,UAAU;CAAW,UAAU;AAAS,CAAC;;;;;AAMlH,SAAgB,mBAAmB,MAAc,SAA+C,OAAqB,MAAc;CAEjI,MAAM,SAAS,MAAM,MAAM;EAAE;EAAM,YAAY;EAAU,QAAQ;CAAK,CAAC,CAAC,CAAC;CAGzE,MAAM,QAAQ,MAAM,KAAK,EAAE,QAAQ,OAAO,OAAO,IAAI,GAAG,MAAM,OAAO,KAAK,CAAC,CAAC;CAE5E,IAAI,MAAM;CACV,IAAI,OAAO;CAEX,KAAK,MAAM,CAAC,GAAG,SAAS,MAAM,QAAQ,GAAG;EACvC,IAAI,SAAS,UAAU,cAAc,MAAM,IAAI,OAAO,UAAU,OAAO,MAAM,IAAI,OAAO,UAAU,kBAAkB;EAGpH,KAFc,MAAM,IAAI,OAAO,UAAU,SAAU,MAAM,IAAI,OAAO,UAAU,YAAY,MAAM,IAAI,OAAO,UAAU,WAEvG,MAAM,KAAK,OAAO,cAAc,CAAC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;;;;;;;;;;;;;;;;;;;;ACzED,MAAa,YAAY,gBAA0D;CACjF,MAAM;CACN,MAAM;EAAE,MAAM;EAAO,QAAQ;CAA2C;CACxE,QAAQ,aAAa;EAAE,GAAG,SAAS,OAAO;EAAG,UAAU,CAAC,QAAQ,MAAM;EAAG,QAAQ;CAAU;AAC7F,CAAC"}
1
+ {"version":3,"file":"index.js","names":["getExtname","extname"],"sources":["../kubb-extension.json","../package.json","../src/inline.ts","../../../internals/utils/src/promise.ts","../../../internals/utils/src/text.ts","../src/utils.ts","../src/parserTs.ts","../src/parserTsx.ts"],"sourcesContent":["","","import type { ast } from '@kubb/ast'\nimport { parse, TokenKind } from 'yuku-parser'\n\n// A name followed by `:` or `?:` right after one of these is a key or parameter name (`{ Name: x }`, `(Name: x)`).\nconst keyStarts = new Set<number>([TokenKind.LeftBrace, TokenKind.Comma, TokenKind.Semicolon, TokenKind.LeftParen])\n\n/**\n * Calls `replace` for every identifier that references something, and swaps in what it returns.\n * yuku's tokens leave out strings, comments and template text; member access (`x.Name`) and keys are skipped here.\n */\nexport function replaceIdentifiers(text: string, replace: (name: string) => string | undefined, lang: 'ts' | 'tsx' = 'ts'): string {\n // Generated fragments such as `options: Options<Pet>` are not whole programs; yuku still tokenizes them.\n const tokens = parse(text, { lang, sourceType: 'module', tokens: true }).tokens!\n\n // `TokenList` is indexed, not iterable; a plain array also makes the neighbours of a token `undefined` at the ends.\n const kinds = Array.from({ length: tokens.length }, (_, i) => tokens.kind(i))\n\n let out = ''\n let last = 0\n\n for (const [i, kind] of kinds.entries()) {\n if (kind !== TokenKind.Identifier || kinds[i - 1] === TokenKind.Dot || kinds[i - 1] === TokenKind.OptionalChaining) continue\n const isKey = kinds[i + 1] === TokenKind.Colon || (kinds[i + 1] === TokenKind.Question && kinds[i + 2] === TokenKind.Colon)\n // `? Name :` in a conditional type is a reference.\n if (isKey && (i === 0 || tokens.newlineBefore(i) || keyStarts.has(kinds[i - 1]!))) continue\n\n const replacement = replace(tokens.text(i))\n if (replacement === undefined) continue\n out += text.slice(last, tokens.start(i)) + replacement\n last = tokens.end(i)\n }\n\n return out + text.slice(last)\n}\n\nfunction createInline(lang: 'ts' | 'tsx'): ast.InlineLanguage {\n return {\n replaceIdentifiers: (text, replace) => replaceIdentifiers(text, replace, lang),\n wrap: (expression) => (/^[\\w$.]+$/.test(expression) ? expression : `(${expression})`),\n }\n}\n\n/**\n * Inline support for TypeScript and JavaScript files: identifiers are found with {@link replaceIdentifiers},\n * and a definition that is more than a name or a dotted path goes in parentheses.\n */\nexport const inlineTs = createInline('ts')\n\n/**\n * {@link inlineTs} for `.tsx` and `.jsx` files, where JSX text and attribute names are not identifiers.\n */\nexport const inlineTsx = createInline('tsx')\n","/** A value that may already be resolved or still pending.\n *\n * @example\n * ```ts\n * function load(id: string): PossiblePromise<string> {\n * return cache.get(id) ?? fetchRemote(id)\n * }\n * ```\n */\nexport type PossiblePromise<T> = Promise<T> | T\n\ntype Store<TKey, TValue> = {\n has(key: TKey): boolean\n get(key: TKey): TValue | undefined\n set(key: TKey, value: TValue): unknown\n}\n\n/**\n * Returns the value cached under `key` in `store`, computing and storing it on the first call.\n * Pass a `WeakMap` for object keys, so an entry goes away with its key, or a `Map` for primitive\n * keys. A cached `null` or `undefined` counts as a hit, so `compute` runs once per key.\n *\n * @example\n * `const refs = memo(refCache, node, () => collectRefs(node))`\n */\nexport function memo<TKey, TValue>(store: Store<TKey, TValue>, key: TKey, compute: () => TValue): TValue {\n const cached = store.get(key)\n if (cached !== undefined || store.has(key)) return cached as TValue\n const value = compute()\n store.set(key, value)\n return value\n}\n\n/**\n * Creates a store for `memo`. With no options it is a `Map`. Each option changes one thing:\n *\n * - `weak` holds the keys weakly, in a `WeakMap`, so an entry goes away with its key.\n * - `max` bounds the store: it empties itself before the entry that would pass `max`, which keeps a\n * cache in a long-running process from growing without end. `max: 1` keeps only the last entry.\n *\n * @example\n * `const patterns = memo.create<string, RegExp>()`\n *\n * @example Freed with its key\n * `const refs = memo.create<SchemaNode, Array<string>>({ weak: true })`\n *\n * @example Bounded\n * `const names = memo.create<string, string>({ max: 100_000 })`\n *\n * @example Many values per key\n * ```ts\n * const filesByPlugin = memo.create<string, Array<string>>()\n * memo(filesByPlugin, 'plugin-ts', () => []).push('models.ts')\n * ```\n */\nfunction createStore<TKey, TValue>(options?: { weak?: false; max?: undefined }): Map<TKey, TValue>\nfunction createStore<TKey extends WeakKey, TValue>(options: { weak: true; max?: undefined }): WeakMap<TKey, TValue>\nfunction createStore<TKey, TValue>(options: { max: number; weak?: false }): Store<TKey, TValue>\nfunction createStore<TKey, TValue>({ weak, max }: { weak?: boolean; max?: number } = {}): Store<TKey, TValue> {\n if (weak) return new WeakMap<WeakKey, TValue>() as Store<TKey, TValue>\n const entry = new Map<TKey, TValue>()\n if (max === undefined) return entry\n const set = (key: TKey, value: TValue) => {\n if (entry.size >= max) entry.clear()\n entry.set(key, value)\n }\n if (max !== 1) return { has: (key) => entry.has(key), get: (key) => entry.get(key), set }\n // A key equal to the stored one but a different object, such as a copy of a string, replaces the\n // stored key, so the next lookup is an identity hit instead of a full comparison.\n const touch = (key: TKey) => {\n if (!entry.has(key)) return false\n set(key, entry.get(key) as TValue)\n return true\n }\n return { has: touch, get: (key) => (touch(key) ? entry.get(key) : undefined), set }\n}\n\nmemo.create = createStore\n\ntype ParallelOptions<TItem> = {\n /**\n * Items to work through, handed out in order.\n */\n items: ReadonlyArray<TItem>\n /**\n * How many items may be in flight at once.\n */\n limit: number\n /**\n * Runs once per item, with the item's position so a caller can report progress.\n */\n run(item: TItem, index: number): Promise<void>\n}\n\n/**\n * Runs `run` over every item with at most `limit` in flight. Workers share one iterator, so each\n * takes the next item the moment it frees up instead of waiting for a batch to drain.\n *\n * @example\n * ```ts\n * await inParallel({ items: files, limit: 50, run: (file) => storage.writeItem(file.path, file.source) })\n * ```\n */\nexport async function inParallel<TItem>({ items, limit, run }: ParallelOptions<TItem>): Promise<void> {\n const queue = items.entries()\n\n const worker = async (): Promise<void> => {\n for (const [index, item] of queue) await run(item, index)\n }\n\n await Promise.all(Array.from({ length: Math.min(limit, items.length) }, () => worker()))\n}\n","/**\n * Indents every non-empty line of `text` by `unit`, leaving blank lines empty.\n * @example\n * `indent({ text: 'a\\n\\nb' }) // ' a\\n\\n b'`\n */\nexport function indent({ text, unit = ' ' }: { text: string; unit?: string }): string {\n if (!text) return ''\n return text\n .split('\\n')\n .map((line) => (line.trim() ? `${unit}${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 */\nexport function 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 indents = lines.map((line) => {\n const indent = line.length - line.trimStart().length\n return indent === line.length ? -1 : indent\n })\n const start = indents.findIndex((indent) => indent !== -1)\n if (start === -1) return ''\n const end = indents.findLastIndex((indent) => indent !== -1)\n // `-1` marks a blank line. `reduce`, not `Math.min(...indents)`, which overflows the stack on very long text.\n const min = indents.reduce((lowest, indent) => (indent !== -1 && indent < lowest ? indent : lowest), Infinity)\n\n return lines\n .slice(start, end + 1)\n .map((line, i) => (indents[start + i] === -1 ? '' : line.slice(min)))\n .join('\\n')\n}\n\n/**\n * Strips one matching pair of `\"`, `'` or `` ` `` from both ends of `text`. Returns `text` unchanged without a matching pair.\n * @example\n * `unquote('\"hello\"') // 'hello'`\n */\nexport function unquote(text: string): string {\n if (text.length < 2) return text\n const first = text[0]\n return (first === '\"' || first === \"'\" || first === '`') && text.at(-1) === first ? text.slice(1, -1) : text\n}\n","import { dedent, indent, memo } from '@internals/utils'\nimport { createRequire } from 'node:module'\nimport { dirname, extname as getExtname, isAbsolute, 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 process.emitWarning(\n 'Printing TypeScript compiler nodes with `print` from `@kubb/parser-ts` is deprecated and is removed in the next major. Return printed strings from printer handlers instead.',\n { type: 'DeprecationWarning', code: 'KUBB_PRINT_TS_NODE' },\n )\n\n const requireModule = 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 = requireModule(requireModule.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 // A relative input resolves against the working directory, so that directory is part of its key.\n const key = isAbsolute(root) && isAbsolute(filePath) ? `${root}\\u0000${filePath}` : `${process.cwd()}\\u0000${root}\\u0000${filePath}`\n return memo(relativePaths, key, () => {\n const slashed = relative(dirname(root), filePath).replaceAll('\\\\', '/')\n return slashed.startsWith('../') ? slashed : `./${slashed}`\n })\n}\n\n// The limit bounds what a long-running host keeps across builds into fresh roots; one build stays well under it.\nconst relativePaths = memo.create<string, string>({ max: 100_000 })\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 === ast.node.kinds.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 * 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 = indent({ text: 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${indent({ text: 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 ast.node.kinds.break:\n return ''\n case ast.node.kinds.text:\n case ast.node.kinds.jsx:\n return dedent(node.value)\n case ast.node.kinds.const:\n return printConst(node)\n case ast.node.kinds.type:\n return printType(node)\n case ast.node.kinds.function:\n return printFunction(node)\n case ast.node.kinds.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 { inlineTs } from './inline.ts'\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 inline: inlineTs,\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 { inlineTsx } from './inline.ts'\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'], inline: inlineTsx }),\n})\n"],"mappings":";;;;;;;;;;;;;;AEIA,MAAM,4BAAY,IAAI,IAAY;CAAC,UAAU;CAAW,UAAU;CAAO,UAAU;CAAW,UAAU;AAAS,CAAC;;;;;AAMlH,SAAgB,mBAAmB,MAAc,SAA+C,OAAqB,MAAc;CAEjI,MAAM,SAAS,MAAM,MAAM;EAAE;EAAM,YAAY;EAAU,QAAQ;CAAK,CAAC,CAAC,CAAC;CAGzE,MAAM,QAAQ,MAAM,KAAK,EAAE,QAAQ,OAAO,OAAO,IAAI,GAAG,MAAM,OAAO,KAAK,CAAC,CAAC;CAE5E,IAAI,MAAM;CACV,IAAI,OAAO;CAEX,KAAK,MAAM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AC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/parser-ts",
3
- "version": "5.18.7",
3
+ "version": "5.19.0",
4
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",
@@ -64,8 +64,8 @@
64
64
  "registry": "https://registry.npmjs.org/"
65
65
  },
66
66
  "dependencies": {
67
- "@kubb/ast": "^5.18.7",
68
- "@kubb/core": "^5.18.7",
67
+ "@kubb/ast": "^5.19.0",
68
+ "@kubb/core": "^5.19.0",
69
69
  "yuku-parser": "^0.19.0"
70
70
  },
71
71
  "devDependencies": {