@kubb/plugin-ts 5.0.14 → 5.0.15

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.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Exclude, Group, Include, Output, OutputOptions, Override, PluginType, Resolver, ResolverPatch, ast } from "kubb/kit";
2
2
  import { KubbReactNode } from "kubb/jsx";
3
- import ts from "typescript";
3
+ import ts from "@typescript/typescript6";
4
4
  //#region src/printers/printerTs.d.ts
5
5
  /**
6
6
  * Partial map of node-type overrides for the TypeScript printer.
@@ -388,7 +388,7 @@ type Options = OutputOptions & {
388
388
  *
389
389
  * @example Use the JavaScript `Date` object for date schemas
390
390
  * ```ts
391
- * import ts from 'typescript'
391
+ * import ts from '@typescript/typescript6'
392
392
  * pluginTs({
393
393
  * printer: {
394
394
  * nodes: {
@@ -762,7 +762,7 @@ type FunctionPrinterOptions = {
762
762
  * ```
763
763
  */
764
764
  export declare function functionPrinter(options: FunctionPrinterOptions): {
765
- name: "functionParameters";
765
+ name: 'functionParameters';
766
766
  options: FunctionPrinterOptions;
767
767
  print(node: FunctionParametersNode): string;
768
768
  };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Exclude, Group, Include, Output, OutputOptions, Override, PluginType, Resolver, ResolverPatch, ast } from "kubb/kit";
2
2
  import { KubbReactNode } from "kubb/jsx";
3
- import ts from "typescript";
3
+ import ts from "@typescript/typescript6";
4
4
  //#region src/printers/printerTs.d.ts
5
5
  /**
6
6
  * Partial map of node-type overrides for the TypeScript printer.
@@ -388,7 +388,7 @@ type Options = OutputOptions & {
388
388
  *
389
389
  * @example Use the JavaScript `Date` object for date schemas
390
390
  * ```ts
391
- * import ts from 'typescript'
391
+ * import ts from '@typescript/typescript6'
392
392
  * pluginTs({
393
393
  * printer: {
394
394
  * nodes: {
@@ -762,7 +762,7 @@ type FunctionPrinterOptions = {
762
762
  * ```
763
763
  */
764
764
  export declare function functionPrinter(options: FunctionPrinterOptions): {
765
- name: "functionParameters";
765
+ name: 'functionParameters';
766
766
  options: FunctionPrinterOptions;
767
767
  print(node: FunctionParametersNode): string;
768
768
  };
package/dist/index.js CHANGED
@@ -27,12 +27,23 @@ var __exportAll = (all, no_symbols) => {
27
27
  *
28
28
  * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
29
29
  */
30
- function toCamelOrPascal(text, pascal) {
30
+ function convert(text, pascal) {
31
31
  return text.trim().replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/(\d)([a-z])/g, "$1 $2").split(/[\s\-_./\\:]+/).filter(Boolean).map((word, i) => {
32
32
  if (word.length > 1 && word === word.toUpperCase()) return word;
33
33
  return (i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1);
34
34
  }).join("").replace(/[^a-zA-Z0-9]/g, "");
35
35
  }
36
+ const cache = /* @__PURE__ */ new Map();
37
+ const cacheLimit = 1e4;
38
+ function toCamelOrPascal(text, pascal) {
39
+ const key = `${pascal ? "P" : "c"}${text}`;
40
+ const cached = cache.get(key);
41
+ if (cached !== void 0) return cached;
42
+ const result = convert(text, pascal);
43
+ if (cache.size >= cacheLimit) cache.clear();
44
+ cache.set(key, result);
45
+ return result;
46
+ }
36
47
  /**
37
48
  * Converts `text` to camelCase.
38
49
  *
@@ -257,29 +268,16 @@ function stringify(value) {
257
268
  return `'${JSON.stringify(trimQuotes(value.toString())).slice(1, -1).replace(/\\"/g, "\"").replace(/'/g, "\\'")}'`;
258
269
  }
259
270
  /**
260
- * Escapes characters that are not allowed inside JS string literals, covering quotes, backslashes,
261
- * and the Unicode line terminators U+2028 and U+2029.
262
- *
263
- * @see http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4
271
+ * Escapes an `@` at the start of a line, so a multi-line description can't start a new JSDoc tag.
272
+ * Editors render `\@` as `@` in hovers.
264
273
  *
265
274
  * @example
266
275
  * ```ts
267
- * jsStringEscape('say "hi"\nbye') // 'say \\"hi\\"\\nbye'
276
+ * jsDocEscape('intro\n@example value') // 'intro\n\\@example value'
268
277
  * ```
269
278
  */
270
- function jsStringEscape(input) {
271
- return `${input}`.replace(/["'\\\n\r\u2028\u2029]/g, (character) => {
272
- switch (character) {
273
- case "\"":
274
- case "'":
275
- case "\\": return `\\${character}`;
276
- case "\n": return "\\n";
277
- case "\r": return "\\r";
278
- case "\u2028": return "\\u2028";
279
- case "\u2029": return "\\u2029";
280
- default: return "";
281
- }
282
- });
279
+ function jsDocEscape(input) {
280
+ return `${input}`.replace(/^(\s*)@/gm, "$1\\@");
283
281
  }
284
282
  //#endregion
285
283
  //#region ../../internals/utils/src/fs.ts
@@ -336,7 +334,7 @@ var factory_exports = /* @__PURE__ */ __exportAll({
336
334
  * Loaded with `require`, not `import`. When ESM imports a CommonJS package, Node keeps a second
337
335
  * copy of its source to detect named exports, and for TypeScript that copy is about 9 MB.
338
336
  */
339
- const typescript = createRequire(import.meta.url)("typescript");
337
+ const typescript = createRequire(import.meta.url)("@typescript/typescript6");
340
338
  const { SyntaxKind, factory } = typescript;
341
339
  function isNumber(value) {
342
340
  return typeof value === "number" && !Number.isNaN(value);
@@ -434,7 +432,7 @@ function createPropertySignature({ readOnly, modifiers = [], name, questionToken
434
432
  function appendJSDocToNode({ node, comments }) {
435
433
  const filteredComments = comments.filter(Boolean);
436
434
  if (!filteredComments.length) return node;
437
- const text = filteredComments.reduce((acc = "", comment = "") => {
435
+ const text = filteredComments.flatMap((comment = "") => comment.split(/\r?\n/)).reduce((acc = "", comment = "") => {
438
436
  return `${acc}\n * ${comment.replaceAll("*/", "*\\/")}`;
439
437
  }, "*");
440
438
  return typescript.addSyntheticLeadingComment(node, typescript.SyntaxKind.MultiLineCommentTrivia, `${text || "*"}\n`, true);
@@ -1115,7 +1113,7 @@ function buildPropertyJSDocComments(schema, optional) {
1115
1113
  const formatComment = meta && "format" in meta && meta.format ? hasDescription ? [" ", `Format: \`${meta.format}\``] : ["@description", `Format: \`${meta.format}\``] : [];
1116
1114
  const exampleValues = meta?.examples ?? [];
1117
1115
  const comments = [
1118
- hasDescription ? `@description ${jsStringEscape(meta.description)}` : null,
1116
+ hasDescription ? `@description ${jsDocEscape(meta.description)}` : null,
1119
1117
  ...formatComment,
1120
1118
  meta && "deprecated" in meta && meta.deprecated ? "@deprecated" : null,
1121
1119
  !isArray && meta && "min" in meta && meta.min !== void 0 ? `@minLength ${meta.min}` : null,
@@ -1640,7 +1638,7 @@ var compatibility = {
1640
1638
  };
1641
1639
  //#endregion
1642
1640
  //#region package.json
1643
- var version = "5.0.14";
1641
+ var version = "5.0.15";
1644
1642
  //#endregion
1645
1643
  //#region src/resolvers/resolverTs.ts
1646
1644
  /**