@kubb/renderer-jsx 5.0.0-beta.42 → 5.0.0-beta.44

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.
@@ -1,11 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_jsx_runtime$1 = require("./jsx-runtime-4M1bV6ub.cjs");
3
- //#region src/jsx-dev-runtime.ts
4
- var import_jsx_runtime = /* @__PURE__ */ require_jsx_runtime$1.__toESM(require_jsx_runtime$1.require_jsx_runtime(), 1);
5
- const Fragment = import_jsx_runtime.Fragment;
6
- const jsxDEV = import_jsx_runtime.jsx;
7
- //#endregion
8
- exports.Fragment = Fragment;
9
- exports.jsxDEV = jsxDEV;
10
-
11
- //# sourceMappingURL=jsx-dev-runtime.cjs.map
2
+ const require_jsx_runtime = require("./jsx-runtime-CzH00oSR.cjs");
3
+ exports.Fragment = require_jsx_runtime.Fragment;
4
+ exports.jsxDEV = require_jsx_runtime.jsxDEV;
@@ -1,11 +1,8 @@
1
- import { n as __name } from "./chunk-DoukXa0m.js";
2
- import { h as KubbReactNode, m as KubbReactElement } from "./types-B5VGpHs0.js";
3
- import { t as JSX } from "./jsx-namespace-dmStM1a2.js";
4
- import * as React from "react/jsx-runtime";
1
+ import { t as __name } from "./chunk-C0LytTxp.js";
2
+ import { d as KubbReactNode, u as KubbReactElement } from "./types-DBdp_5qR.js";
3
+ import { Fragment, JSX, jsxDEV } from "./jsx-runtime.js";
5
4
 
6
5
  //#region src/jsx-dev-runtime.d.ts
7
- declare const Fragment: import("react").ExoticComponent<import("react").FragmentProps>;
8
- declare const jsxDEV: typeof React.jsx;
9
6
  type JSXElement = KubbReactElement;
10
7
  type ReactNode = KubbReactNode;
11
8
  //#endregion
@@ -1,10 +1,2 @@
1
- import { r as __toESM } from "./chunk-DoukXa0m.js";
2
- import { t as require_jsx_runtime } from "./jsx-runtime-CQ6-_gue.js";
3
- //#region src/jsx-dev-runtime.ts
4
- var import_jsx_runtime = /* @__PURE__ */ __toESM(require_jsx_runtime(), 1);
5
- const Fragment = import_jsx_runtime.Fragment;
6
- const jsxDEV = import_jsx_runtime.jsx;
7
- //#endregion
1
+ import { Fragment, jsxDEV } from "./jsx-runtime.js";
8
2
  export { Fragment, jsxDEV };
9
-
10
- //# sourceMappingURL=jsx-dev-runtime.js.map
@@ -0,0 +1,64 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __defProp = Object.defineProperty;
3
+ var __name = (target, value) => __defProp(target, "name", {
4
+ value,
5
+ configurable: true
6
+ });
7
+ //#endregion
8
+ //#region src/jsx-runtime.ts
9
+ const KUBB_ELEMENT = Symbol.for("kubb.element");
10
+ /**
11
+ * Fragment marker. A `<>…</>` compiles to `jsx(Fragment, …)`, and the renderer
12
+ * unwraps it while walking the tree.
13
+ */
14
+ const Fragment = Symbol.for("kubb.fragment");
15
+ /**
16
+ * Create a Kubb JSX element. The automatic JSX runtime calls this for every tag,
17
+ * so the renderer never depends on React at runtime. The element carries a
18
+ * `$$typeof` marker, its `type` (a host string, a function component, or
19
+ * `Fragment`), and its `props`, with children included.
20
+ */
21
+ function createElement(type, props, key) {
22
+ return {
23
+ $$typeof: KUBB_ELEMENT,
24
+ type,
25
+ key: key ?? null,
26
+ props: props ?? {}
27
+ };
28
+ }
29
+ const jsx = createElement;
30
+ const jsxs = createElement;
31
+ const jsxDEV = createElement;
32
+ //#endregion
33
+ Object.defineProperty(exports, "Fragment", {
34
+ enumerable: true,
35
+ get: function() {
36
+ return Fragment;
37
+ }
38
+ });
39
+ Object.defineProperty(exports, "__name", {
40
+ enumerable: true,
41
+ get: function() {
42
+ return __name;
43
+ }
44
+ });
45
+ Object.defineProperty(exports, "jsx", {
46
+ enumerable: true,
47
+ get: function() {
48
+ return jsx;
49
+ }
50
+ });
51
+ Object.defineProperty(exports, "jsxDEV", {
52
+ enumerable: true,
53
+ get: function() {
54
+ return jsxDEV;
55
+ }
56
+ });
57
+ Object.defineProperty(exports, "jsxs", {
58
+ enumerable: true,
59
+ get: function() {
60
+ return jsxs;
61
+ }
62
+ });
63
+
64
+ //# sourceMappingURL=jsx-runtime-CzH00oSR.cjs.map
@@ -1,15 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_jsx_runtime$1 = require("./jsx-runtime-4M1bV6ub.cjs");
3
- //#region src/jsx-runtime.ts
4
- var import_jsx_runtime = /* @__PURE__ */ require_jsx_runtime$1.__toESM(require_jsx_runtime$1.require_jsx_runtime(), 1);
5
- const Fragment = import_jsx_runtime.Fragment;
6
- const jsx = import_jsx_runtime.jsx;
7
- const jsxDEV = import_jsx_runtime.jsx;
8
- const jsxs = import_jsx_runtime.jsxs;
9
- //#endregion
10
- exports.Fragment = Fragment;
11
- exports.jsx = jsx;
12
- exports.jsxDEV = jsxDEV;
13
- exports.jsxs = jsxs;
14
-
15
- //# sourceMappingURL=jsx-runtime.cjs.map
2
+ const require_jsx_runtime = require("./jsx-runtime-CzH00oSR.cjs");
3
+ exports.Fragment = require_jsx_runtime.Fragment;
4
+ exports.jsx = require_jsx_runtime.jsx;
5
+ exports.jsxDEV = require_jsx_runtime.jsxDEV;
6
+ exports.jsxs = require_jsx_runtime.jsxs;
@@ -1,13 +1,64 @@
1
- import { n as __name } from "./chunk-DoukXa0m.js";
2
- import { h as KubbReactNode, m as KubbReactElement } from "./types-B5VGpHs0.js";
3
- import { t as JSX } from "./jsx-namespace-dmStM1a2.js";
4
- import * as React from "react/jsx-runtime";
1
+ import { t as __name } from "./chunk-C0LytTxp.js";
2
+ import { a as KubbExportProps, c as KubbImportProps, d as KubbReactNode, f as KubbSourceProps, i as KubbConstProps, l as KubbJsxProps, m as LineBreakProps, n as Key, o as KubbFileProps, p as KubbTypeProps, r as KubbArrowFunctionProps, s as KubbFunctionProps, u as KubbReactElement } from "./types-DBdp_5qR.js";
5
3
 
4
+ //#region src/jsx-namespace.d.ts
5
+ /**
6
+ * JSX contract for `@kubb/renderer-jsx`, resolved through `jsxImportSource`.
7
+ *
8
+ * It is self-contained and does not extend `React.JSX`: the renderer only emits
9
+ * the custom `kubb-*` hosts plus `br`, `indent`, and `dedent`, and supports
10
+ * pure function components, so the HTML element and class-component machinery
11
+ * from `@types/react` is not needed.
12
+ */
13
+ declare namespace JSX {
14
+ type ElementType = string | ((props: any) => KubbReactNode);
15
+ type Element = KubbReactElement;
16
+ interface ElementClass {
17
+ render(): KubbReactNode;
18
+ }
19
+ interface ElementAttributesProperty {
20
+ props: {};
21
+ }
22
+ interface ElementChildrenAttribute {
23
+ children: {};
24
+ }
25
+ interface IntrinsicAttributes {
26
+ key?: Key | null;
27
+ }
28
+ interface IntrinsicClassAttributes<T> {
29
+ key?: Key | null;
30
+ }
31
+ interface IntrinsicElements {
32
+ 'kubb-jsx': KubbJsxProps;
33
+ 'kubb-file': KubbFileProps;
34
+ 'kubb-source': KubbSourceProps;
35
+ 'kubb-import': KubbImportProps;
36
+ 'kubb-export': KubbExportProps;
37
+ 'kubb-function': KubbFunctionProps;
38
+ 'kubb-arrow-function': KubbArrowFunctionProps;
39
+ 'kubb-const': KubbConstProps;
40
+ 'kubb-type': KubbTypeProps;
41
+ br: LineBreakProps;
42
+ }
43
+ type LibraryManagedAttributes<C, P> = P;
44
+ }
45
+ //#endregion
6
46
  //#region src/jsx-runtime.d.ts
7
- declare const Fragment: import("react").ExoticComponent<import("react").FragmentProps>;
8
- declare const jsx: typeof React.jsx;
9
- declare const jsxDEV: typeof React.jsx;
10
- declare const jsxs: typeof React.jsxs;
47
+ /**
48
+ * Fragment marker. A `<>…</>` compiles to `jsx(Fragment, …)`, and the renderer
49
+ * unwraps it while walking the tree.
50
+ */
51
+ declare const Fragment: unique symbol;
52
+ /**
53
+ * Create a Kubb JSX element. The automatic JSX runtime calls this for every tag,
54
+ * so the renderer never depends on React at runtime. The element carries a
55
+ * `$$typeof` marker, its `type` (a host string, a function component, or
56
+ * `Fragment`), and its `props`, with children included.
57
+ */
58
+ declare function createElement(type: unknown, props: Record<string, unknown> | null, key?: Key | null): KubbReactElement;
59
+ declare const jsx: typeof createElement;
60
+ declare const jsxs: typeof createElement;
61
+ declare const jsxDEV: typeof createElement;
11
62
  type JSXElement = KubbReactElement;
12
63
  type ReactNode = KubbReactNode;
13
64
  //#endregion
@@ -1,11 +1,28 @@
1
- import { r as __toESM } from "./chunk-DoukXa0m.js";
2
- import { t as require_jsx_runtime } from "./jsx-runtime-CQ6-_gue.js";
1
+ import "./chunk-C0LytTxp.js";
3
2
  //#region src/jsx-runtime.ts
4
- var import_jsx_runtime = /* @__PURE__ */ __toESM(require_jsx_runtime(), 1);
5
- const Fragment = import_jsx_runtime.Fragment;
6
- const jsx = import_jsx_runtime.jsx;
7
- const jsxDEV = import_jsx_runtime.jsx;
8
- const jsxs = import_jsx_runtime.jsxs;
3
+ const KUBB_ELEMENT = Symbol.for("kubb.element");
4
+ /**
5
+ * Fragment marker. A `<>…</>` compiles to `jsx(Fragment, …)`, and the renderer
6
+ * unwraps it while walking the tree.
7
+ */
8
+ const Fragment = Symbol.for("kubb.fragment");
9
+ /**
10
+ * Create a Kubb JSX element. The automatic JSX runtime calls this for every tag,
11
+ * so the renderer never depends on React at runtime. The element carries a
12
+ * `$$typeof` marker, its `type` (a host string, a function component, or
13
+ * `Fragment`), and its `props`, with children included.
14
+ */
15
+ function createElement(type, props, key) {
16
+ return {
17
+ $$typeof: KUBB_ELEMENT,
18
+ type,
19
+ key: key ?? null,
20
+ props: props ?? {}
21
+ };
22
+ }
23
+ const jsx = createElement;
24
+ const jsxs = createElement;
25
+ const jsxDEV = createElement;
9
26
  //#endregion
10
27
  export { Fragment, jsx, jsxDEV, jsxs };
11
28
 
@@ -0,0 +1,116 @@
1
+ import { t as __name } from "./chunk-C0LytTxp.js";
2
+ import { ArrowFunctionNode, ConstNode, ExportNode, FileNode, FunctionNode, ImportNode, SourceNode, TypeNode } from "@kubb/ast";
3
+
4
+ //#region src/types.d.ts
5
+ /**
6
+ * Unique key for a Kubb JSX element in lists or conditional renders.
7
+ */
8
+ type Key = string | number | bigint;
9
+ /**
10
+ * Element produced by a Kubb JSX component. It carries the host or component
11
+ * `type`, its `props`, and an optional list `key`. The renderer walks these at
12
+ * runtime, so the fields stay opaque to type-checking.
13
+ */
14
+ type KubbReactElement = {
15
+ type: unknown;
16
+ props: unknown;
17
+ key: Key | null;
18
+ };
19
+ /**
20
+ * Anything a Kubb JSX component accepts as children: an element, a primitive
21
+ * rendered as text, a nullish value that is skipped, or an iterable of nodes.
22
+ */
23
+ type KubbReactNode = KubbReactElement | string | number | bigint | boolean | null | undefined | Iterable<KubbReactNode>;
24
+ /**
25
+ * Props for the `<kubb-jsx>` element.
26
+ * Embeds a raw JSX string verbatim in generated output.
27
+ */
28
+ type KubbJsxProps = {
29
+ children?: string;
30
+ };
31
+ /**
32
+ * Props for the `<kubb-file>` element.
33
+ * Represents a generated file.
34
+ */
35
+ type KubbFileProps = {
36
+ id?: string | null;
37
+ children?: KubbReactNode;
38
+ baseName: string;
39
+ path: string;
40
+ override?: boolean | null;
41
+ meta?: FileNode['meta'] | null;
42
+ };
43
+ /**
44
+ * Props for the `<kubb-source>` element.
45
+ * Marks a block of source text associated with a file.
46
+ */
47
+ type KubbSourceProps = Omit<SourceNode, 'kind'> & {
48
+ children?: KubbReactNode;
49
+ };
50
+ /**
51
+ * Props for the `<kubb-import>` element.
52
+ * Declares an import statement in the generated file.
53
+ */
54
+ type KubbImportProps = Omit<ImportNode, 'kind'> & {};
55
+ /**
56
+ * Props for the `<kubb-export>` element.
57
+ * Declares an export statement in the generated file.
58
+ */
59
+ type KubbExportProps = Omit<ExportNode, 'kind'> & {};
60
+ /**
61
+ * Props for the `<kubb-function>` element.
62
+ * Generates a function declaration.
63
+ */
64
+ type KubbFunctionProps = Omit<FunctionNode, 'kind'> & {
65
+ children?: KubbReactNode;
66
+ };
67
+ /**
68
+ * Props for the `<kubb-arrow-function>` element.
69
+ * Generates an arrow function declaration.
70
+ */
71
+ type KubbArrowFunctionProps = Omit<ArrowFunctionNode, 'kind'> & {
72
+ children?: KubbReactNode;
73
+ };
74
+ /**
75
+ * Props for the `<kubb-const>` element.
76
+ * Generates a constant declaration.
77
+ */
78
+ type KubbConstProps = Omit<ConstNode, 'kind'> & {
79
+ children?: KubbReactNode;
80
+ };
81
+ /**
82
+ * Props for the `<kubb-type>` element.
83
+ * Generates a TypeScript type alias declaration.
84
+ */
85
+ type KubbTypeProps = Omit<TypeNode, 'kind'> & {
86
+ children?: KubbReactNode;
87
+ };
88
+ /**
89
+ * Props for the `<br>` element. It emits a single line break and takes no
90
+ * attributes of its own.
91
+ */
92
+ type LineBreakProps = {};
93
+ /**
94
+ * JSDoc comment block to attach to a generated declaration.
95
+ * Each string in `comments` becomes one line inside the `/** … *\/` block.
96
+ *
97
+ * @example
98
+ * ```ts
99
+ * { comments: ['@description A pet object.', '@deprecated Use PetV2 instead.'] }
100
+ * // Emits:
101
+ * // /**
102
+ * // * @description A pet object.
103
+ * // * @deprecated Use PetV2 instead.
104
+ * // *\/
105
+ * ```
106
+ */
107
+ type JSDoc = {
108
+ /**
109
+ * Lines to emit inside the JSDoc block, in source order.
110
+ * Use standard JSDoc tags such as `@description`, `@deprecated`, `@see`, etc.
111
+ */
112
+ comments: Array<string>;
113
+ };
114
+ //#endregion
115
+ export { KubbExportProps as a, KubbImportProps as c, KubbReactNode as d, KubbSourceProps as f, KubbConstProps as i, KubbJsxProps as l, LineBreakProps as m, Key as n, KubbFileProps as o, KubbTypeProps as p, KubbArrowFunctionProps as r, KubbFunctionProps as s, JSDoc as t, KubbReactElement as u };
116
+ //# sourceMappingURL=types-DBdp_5qR.d.ts.map
package/dist/types.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { _ as KubbTextProps, a as JSDoc, b as TextNode, c as KubbConstProps, d as KubbFunctionProps, f as KubbImportProps, g as KubbSourceProps, h as KubbReactNode, i as ElementNames, l as KubbExportProps, m as KubbReactElement, n as DOMNode, o as Key, p as KubbJsxProps, r as DOMNodeAttribute, s as KubbArrowFunctionProps, t as DOMElement, u as KubbFileProps, v as KubbTypeProps, y as LineBreakProps } from "./types-B5VGpHs0.js";
2
- export { DOMElement, DOMNode, DOMNodeAttribute, ElementNames, JSDoc, Key, KubbArrowFunctionProps, KubbConstProps, KubbExportProps, KubbFileProps, KubbFunctionProps, KubbImportProps, KubbJsxProps, KubbReactElement, KubbReactNode, KubbSourceProps, KubbTextProps, KubbTypeProps, LineBreakProps, TextNode };
1
+ import { a as KubbExportProps, c as KubbImportProps, d as KubbReactNode, f as KubbSourceProps, i as KubbConstProps, l as KubbJsxProps, m as LineBreakProps, n as Key, o as KubbFileProps, p as KubbTypeProps, r as KubbArrowFunctionProps, s as KubbFunctionProps, t as JSDoc, u as KubbReactElement } from "./types-DBdp_5qR.js";
2
+ export { JSDoc, Key, KubbArrowFunctionProps, KubbConstProps, KubbExportProps, KubbFileProps, KubbFunctionProps, KubbImportProps, KubbJsxProps, KubbReactElement, KubbReactNode, KubbSourceProps, KubbTypeProps, LineBreakProps };
package/package.json CHANGED
@@ -1,13 +1,12 @@
1
1
  {
2
2
  "name": "@kubb/renderer-jsx",
3
- "version": "5.0.0-beta.42",
4
- "description": "JSX-based renderer for Kubb. Provides a custom React runtime, reconciler, and built-in components (File, Function, Type, Const) for component-based, type-safe code generation.",
3
+ "version": "5.0.0-beta.44",
4
+ "description": "Self-contained synchronous JSX renderer for Kubb. Turns JSX into FileNodes with built-in components (File, Function, Type, Const) for component-based, type-safe code generation. No React dependency.",
5
5
  "keywords": [
6
6
  "codegen",
7
7
  "jsx",
8
8
  "jsx-runtime",
9
9
  "kubb",
10
- "react",
11
10
  "typescript"
12
11
  ],
13
12
  "license": "MIT",
@@ -76,32 +75,16 @@
76
75
  },
77
76
  "dependencies": {
78
77
  "yaml": "^2.9.0",
79
- "@kubb/ast": "5.0.0-beta.42"
78
+ "@kubb/ast": "5.0.0-beta.44"
80
79
  },
81
80
  "devDependencies": {
82
- "@types/react": "^19.2.16",
83
- "@types/react-reconciler": "0.33.0",
84
- "react": "19.2.6",
85
- "react-reconciler": "0.33.0",
86
81
  "@internals/utils": "0.0.0"
87
82
  },
88
- "size-limit": [
89
- {
90
- "path": "./dist/*.js",
91
- "limit": "510 KiB",
92
- "gzip": true
93
- }
94
- ],
95
83
  "engines": {
96
84
  "node": ">=22"
97
85
  },
98
- "inlinedDependencies": {
99
- "react": "19.2.6",
100
- "react-reconciler": "0.33.0",
101
- "scheduler": "0.27.0"
102
- },
103
86
  "scripts": {
104
- "build": "tsdown && size-limit",
87
+ "build": "tsdown",
105
88
  "clean": "node -e \"require('fs').rmSync('./dist', {recursive:true,force:true})\"",
106
89
  "lint": "oxlint .",
107
90
  "lint:fix": "oxlint --fix .",
@@ -109,9 +92,7 @@
109
92
  "release:canary": "bash ../../.github/canary.sh && node ../../scripts/build.js canary && pnpm publish --no-git-check -tag canary",
110
93
  "release:stage": "pnpm stage publish --no-git-check",
111
94
  "start": "tsdown --watch ./src",
112
- "start:devtools": "npx react-devtools",
113
95
  "test": "vitest --passWithNoTests",
114
- "test:devtools": "node ./dist/runner.cjs",
115
96
  "typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false"
116
97
  }
117
98
  }
@@ -11,8 +11,8 @@ import {
11
11
  createText,
12
12
  createType,
13
13
  } from '@kubb/ast'
14
- import React from 'react'
15
14
  import { KUBB_ARROW_FUNCTION, KUBB_CONST, KUBB_EXPORT, KUBB_FILE, KUBB_FUNCTION, KUBB_IMPORT, KUBB_JSX, KUBB_SOURCE, KUBB_TYPE } from './constants.ts'
15
+ import { Fragment } from './jsx-runtime.ts'
16
16
  import type { KubbReactElement } from './types.ts'
17
17
 
18
18
  type OnText = (text: string) => void
@@ -38,11 +38,11 @@ function walkElement(element: unknown, onText: OnText, onHost: OnHost): void {
38
38
  }
39
39
 
40
40
  if (typeof element === 'object' && '$$typeof' in element) {
41
- const el = element as unknown as React.ReactElement
41
+ const el = element as unknown as KubbReactElement
42
42
  const { type } = el
43
43
  const props = el.props as Record<string, unknown>
44
44
 
45
- if (type === React.Fragment) {
45
+ if (type === Fragment) {
46
46
  walkElement(props['children'], onText, onHost)
47
47
  return
48
48
  }
@@ -231,11 +231,11 @@ function* walkFiles(element: unknown): Generator<FileNode> {
231
231
  }
232
232
 
233
233
  if (typeof element === 'object' && '$$typeof' in element) {
234
- const el = element as unknown as React.ReactElement
234
+ const el = element as unknown as KubbReactElement
235
235
  const { type } = el
236
236
  const props = el.props as Record<string, unknown>
237
237
 
238
- if (type === React.Fragment) {
238
+ if (type === Fragment) {
239
239
  yield* walkFiles(props['children'])
240
240
  return
241
241
  }
package/src/constants.ts CHANGED
@@ -1,10 +1,3 @@
1
- import type { ElementNames } from './types.ts'
2
-
3
- /**
4
- * Name used for text-node entries in the virtual DOM.
5
- */
6
- export const TEXT_NODE_NAME = '#text' as const
7
-
8
1
  export const KUBB_FILE = 'kubb-file' as const
9
2
  export const KUBB_SOURCE = 'kubb-source' as const
10
3
  export const KUBB_EXPORT = 'kubb-export' as const
@@ -14,25 +7,3 @@ export const KUBB_ARROW_FUNCTION = 'kubb-arrow-function' as const
14
7
  export const KUBB_CONST = 'kubb-const' as const
15
8
  export const KUBB_TYPE = 'kubb-type' as const
16
9
  export const KUBB_JSX = 'kubb-jsx' as const
17
-
18
- /**
19
- * Set of all element names recognized by the Kubb renderer.
20
- * Used to distinguish Kubb-owned elements from unrecognized or text nodes during tree traversal.
21
- */
22
- export const nodeNames = new Set<ElementNames>([
23
- KUBB_EXPORT,
24
- KUBB_FILE,
25
- KUBB_SOURCE,
26
- KUBB_IMPORT,
27
- KUBB_FUNCTION,
28
- KUBB_ARROW_FUNCTION,
29
- KUBB_CONST,
30
- KUBB_TYPE,
31
- KUBB_JSX,
32
- 'kubb-text',
33
- 'kubb-root',
34
- 'kubb-app',
35
- 'br',
36
- 'indent',
37
- 'dedent',
38
- ] as const)
@@ -1,17 +1,16 @@
1
1
  import type { FileNode } from '@kubb/ast'
2
- import { Runtime } from './Runtime.tsx'
3
2
  import { SyncRuntime } from './SyncRuntime.tsx'
4
3
  import type { KubbReactElement } from './types.ts'
5
4
 
6
5
  /**
7
- * Renderer factory that turns the JSX produced by a generator into
8
- * `FileNode`s using React's reconciler under the hood. Pass as the `renderer`
9
- * property on `defineGenerator`. Kubb core stays generic, with no hard
10
- * dependency on `@kubb/renderer-jsx`.
6
+ * Renderer that walks the JSX tree in a single recursive pass, with no React
7
+ * reconciler or scheduler. Pass as the `renderer` property on
8
+ * `defineGenerator`. Kubb core stays generic, with no hard dependency on
9
+ * `@kubb/renderer-jsx`.
11
10
  *
12
- * Use this when generators rely on React features (hooks, suspense, context).
13
- * For pure-function components, see {@link jsxRendererSync} for ~2-4× faster
14
- * rendering.
11
+ * Every component must be a pure function. Hooks, suspense, and class
12
+ * components are not supported. It also exposes `stream()` for incremental
13
+ * file emission.
15
14
  *
16
15
  * @example Wire up a JSX generator
17
16
  * ```tsx
@@ -30,67 +29,16 @@ import type { KubbReactElement } from './types.ts'
30
29
  * },
31
30
  * })
32
31
  * ```
33
- */
34
- export const jsxRenderer = () => {
35
- const runtime = new Runtime()
36
-
37
- return {
38
- async render(element: KubbReactElement) {
39
- await runtime.render(element)
40
- },
41
- get files() {
42
- return runtime.nodes
43
- },
44
- dispose() {
45
- runtime.unmount()
46
- },
47
- unmount(error?: Error | number | null) {
48
- runtime.unmount(error)
49
- },
50
- [Symbol.dispose]() {
51
- this.dispose()
52
- },
53
- }
54
- }
55
-
56
- /**
57
- * Lightweight renderer that walks the JSX tree in a single recursive pass, * no React reconciler, no scheduler. Drop-in replacement for
58
- * {@link jsxRenderer} at roughly 2, 4× the throughput.
59
- *
60
- * Constraints: every component must be a pure function. Hooks, suspense, and
61
- * class components are not supported.
62
- *
63
- * Use this for generators that produce large amounts of output and do not need
64
- * React's runtime features. It also exposes `stream()` for incremental file
65
- * emission.
66
- *
67
- * @example Drop-in faster renderer
68
- * ```tsx
69
- * import { defineGenerator } from '@kubb/core'
70
- * import { jsxRendererSync } from '@kubb/renderer-jsx'
71
- *
72
- * export const myGenerator = defineGenerator<PluginTs>({
73
- * name: 'types',
74
- * renderer: jsxRendererSync,
75
- * schema(node, ctx) {
76
- * return (
77
- * <File baseName="output.ts" path={`${ctx.root}/output.ts`}>
78
- * <Type node={node} resolver={ctx.resolver} />
79
- * </File>
80
- * )
81
- * },
82
- * })
83
- * ```
84
32
  *
85
33
  * @example Stream files as they are produced
86
34
  * ```tsx
87
- * const renderer = jsxRendererSync()
35
+ * const renderer = jsxRenderer()
88
36
  * for (const file of renderer.stream(element)) {
89
37
  * await writeFile(file.path, file.sources[0])
90
38
  * }
91
39
  * ```
92
40
  */
93
- export const jsxRendererSync = () => {
41
+ export const jsxRenderer = () => {
94
42
  const runtime = new SyncRuntime()
95
43
 
96
44
  return {
@@ -103,10 +51,6 @@ export const jsxRendererSync = () => {
103
51
  stream(element: KubbReactElement): Generator<FileNode> {
104
52
  return runtime.stream(element)
105
53
  },
106
- dispose() {},
107
- unmount(_error?: Error | number | null) {},
108
- [Symbol.dispose]() {
109
- this.dispose()
110
- },
54
+ [Symbol.dispose]() {},
111
55
  }
112
56
  }
package/src/globals.ts CHANGED
@@ -1,13 +1,16 @@
1
- import type React from 'react'
2
1
  import type {
2
+ KubbArrowFunctionProps,
3
+ KubbConstProps,
3
4
  KubbExportProps,
4
5
  KubbFileProps,
6
+ KubbFunctionProps,
5
7
  KubbImportProps,
6
8
  KubbJsxProps,
7
9
  KubbReactElement,
8
10
  KubbReactNode,
9
11
  KubbSourceProps,
10
- KubbTextProps,
12
+ KubbTypeProps,
13
+ Key,
11
14
  LineBreakProps,
12
15
  } from './types.ts'
13
16
 
@@ -15,20 +18,25 @@ declare global {
15
18
  namespace JSX {
16
19
  type Element = KubbReactElement
17
20
 
18
- interface ElementClass extends React.ComponentClass<any> {
21
+ interface ElementClass {
19
22
  render(): KubbReactNode
20
23
  }
21
24
 
25
+ interface IntrinsicAttributes {
26
+ key?: Key | null
27
+ }
28
+
22
29
  interface IntrinsicElements {
23
30
  'kubb-jsx': KubbJsxProps
24
- 'kubb-text': KubbTextProps
25
31
  'kubb-file': KubbFileProps
26
32
  'kubb-source': KubbSourceProps
27
33
  'kubb-import': KubbImportProps
28
34
  'kubb-export': KubbExportProps
35
+ 'kubb-function': KubbFunctionProps
36
+ 'kubb-arrow-function': KubbArrowFunctionProps
37
+ 'kubb-const': KubbConstProps
38
+ 'kubb-type': KubbTypeProps
29
39
  br: LineBreakProps
30
- indent: {}
31
- dedent: {}
32
40
  }
33
41
  }
34
42
  }
package/src/index.ts CHANGED
@@ -1,6 +1,4 @@
1
- export { createContext, inject, provide, unprovide } from '@internals/utils'
2
1
  export { Callout } from './components/Callout.tsx'
3
- export { CodeBlock } from './components/CodeBlock.tsx'
4
2
  export { Const } from './components/Const.tsx'
5
3
  export { File } from './components/File.tsx'
6
4
  export { Frontmatter } from './components/Frontmatter.tsx'
@@ -9,6 +7,5 @@ export { Heading } from './components/Heading.tsx'
9
7
  export { Jsx } from './components/Jsx.tsx'
10
8
  export { List } from './components/List.tsx'
11
9
  export { Paragraph } from './components/Paragraph.tsx'
12
- export { Root } from './components/Root.tsx'
13
10
  export { Type } from './components/Type.tsx'
14
- export { jsxRenderer, jsxRendererSync } from './createRenderer.tsx'
11
+ export { jsxRenderer } from './createRenderer.tsx'