@kubb/renderer-jsx 5.0.0-beta.18 → 5.0.0-beta.19

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
@@ -18035,9 +18035,17 @@ function createFileNode(child) {
18035
18035
  const sources = [];
18036
18036
  const exports = [];
18037
18037
  const imports = [];
18038
- for (const node of collectFileEntries(child)) if (node.kind === "Source") sources.push(node);
18039
- else if (node.kind === "Export") exports.push(node);
18040
- else imports.push(node);
18038
+ for (const node of collectFileEntries(child)) {
18039
+ if (node.kind === "Source") {
18040
+ sources.push(node);
18041
+ continue;
18042
+ }
18043
+ if (node.kind === "Export") {
18044
+ exports.push(node);
18045
+ continue;
18046
+ }
18047
+ imports.push(node);
18048
+ }
18041
18049
  return {
18042
18050
  baseName: child.attributes["baseName"],
18043
18051
  path: child.attributes["path"],
@@ -18175,9 +18183,15 @@ function walkElement(element, onText, onHost) {
18175
18183
  const el = element;
18176
18184
  const { type } = el;
18177
18185
  const props = el.props;
18178
- if (type === import_react.Fragment) walkElement(props["children"], onText, onHost);
18179
- else if (typeof type === "function") walkElement(type(props), onText, onHost);
18180
- else if (typeof type === "string") onHost(type, props);
18186
+ if (type === import_react.Fragment) {
18187
+ walkElement(props["children"], onText, onHost);
18188
+ return;
18189
+ }
18190
+ if (typeof type === "function") {
18191
+ walkElement(type(props), onText, onHost);
18192
+ return;
18193
+ }
18194
+ if (typeof type === "string") onHost(type, props);
18181
18195
  }
18182
18196
  }
18183
18197
  function toBool(val) {
@@ -18306,19 +18320,21 @@ function collectFileChildren(element) {
18306
18320
  function* walkFiles(element) {
18307
18321
  const files = [];
18308
18322
  function onHost(type, props) {
18309
- if (type === "kubb-file" && props["baseName"] !== void 0 && props["path"] !== void 0) {
18310
- const { sources, exports, imports } = collectFileChildren(props["children"]);
18311
- files.push({
18312
- baseName: props["baseName"],
18313
- path: props["path"],
18314
- meta: props["meta"] || {},
18315
- footer: props["footer"],
18316
- banner: props["banner"],
18317
- sources,
18318
- exports,
18319
- imports
18320
- });
18321
- } else walkElement(props["children"], () => {}, onHost);
18323
+ if (!(type === "kubb-file" && props["baseName"] !== void 0 && props["path"] !== void 0)) {
18324
+ walkElement(props["children"], () => {}, onHost);
18325
+ return;
18326
+ }
18327
+ const { sources, exports, imports } = collectFileChildren(props["children"]);
18328
+ files.push({
18329
+ baseName: props["baseName"],
18330
+ path: props["path"],
18331
+ meta: props["meta"] || {},
18332
+ footer: props["footer"],
18333
+ banner: props["banner"],
18334
+ sources,
18335
+ exports,
18336
+ imports
18337
+ });
18322
18338
  }
18323
18339
  walkElement(element, () => {}, onHost);
18324
18340
  yield* files;
@@ -18430,8 +18446,8 @@ const jsxRendererSync = () => {
18430
18446
  get files() {
18431
18447
  return runtime.nodes;
18432
18448
  },
18433
- async *stream(element) {
18434
- yield* runtime.stream(element);
18449
+ stream(element) {
18450
+ return runtime.stream(element);
18435
18451
  },
18436
18452
  unmount(_error) {}
18437
18453
  };
package/dist/index.d.ts CHANGED
@@ -571,7 +571,7 @@ declare const jsxRenderer: () => {
571
571
  declare const jsxRendererSync: () => {
572
572
  render(element: KubbReactElement): Promise<void>;
573
573
  readonly files: FileNode[];
574
- stream(element: KubbReactElement): AsyncGenerator<FileNode>;
574
+ stream(element: KubbReactElement): Generator<FileNode>;
575
575
  unmount(_error?: Error | number | null): void;
576
576
  };
577
577
  //#endregion
package/dist/index.js CHANGED
@@ -18032,9 +18032,17 @@ function createFileNode(child) {
18032
18032
  const sources = [];
18033
18033
  const exports = [];
18034
18034
  const imports = [];
18035
- for (const node of collectFileEntries(child)) if (node.kind === "Source") sources.push(node);
18036
- else if (node.kind === "Export") exports.push(node);
18037
- else imports.push(node);
18035
+ for (const node of collectFileEntries(child)) {
18036
+ if (node.kind === "Source") {
18037
+ sources.push(node);
18038
+ continue;
18039
+ }
18040
+ if (node.kind === "Export") {
18041
+ exports.push(node);
18042
+ continue;
18043
+ }
18044
+ imports.push(node);
18045
+ }
18038
18046
  return {
18039
18047
  baseName: child.attributes["baseName"],
18040
18048
  path: child.attributes["path"],
@@ -18172,9 +18180,15 @@ function walkElement(element, onText, onHost) {
18172
18180
  const el = element;
18173
18181
  const { type } = el;
18174
18182
  const props = el.props;
18175
- if (type === import_react.Fragment) walkElement(props["children"], onText, onHost);
18176
- else if (typeof type === "function") walkElement(type(props), onText, onHost);
18177
- else if (typeof type === "string") onHost(type, props);
18183
+ if (type === import_react.Fragment) {
18184
+ walkElement(props["children"], onText, onHost);
18185
+ return;
18186
+ }
18187
+ if (typeof type === "function") {
18188
+ walkElement(type(props), onText, onHost);
18189
+ return;
18190
+ }
18191
+ if (typeof type === "string") onHost(type, props);
18178
18192
  }
18179
18193
  }
18180
18194
  function toBool(val) {
@@ -18303,19 +18317,21 @@ function collectFileChildren(element) {
18303
18317
  function* walkFiles(element) {
18304
18318
  const files = [];
18305
18319
  function onHost(type, props) {
18306
- if (type === "kubb-file" && props["baseName"] !== void 0 && props["path"] !== void 0) {
18307
- const { sources, exports, imports } = collectFileChildren(props["children"]);
18308
- files.push({
18309
- baseName: props["baseName"],
18310
- path: props["path"],
18311
- meta: props["meta"] || {},
18312
- footer: props["footer"],
18313
- banner: props["banner"],
18314
- sources,
18315
- exports,
18316
- imports
18317
- });
18318
- } else walkElement(props["children"], () => {}, onHost);
18320
+ if (!(type === "kubb-file" && props["baseName"] !== void 0 && props["path"] !== void 0)) {
18321
+ walkElement(props["children"], () => {}, onHost);
18322
+ return;
18323
+ }
18324
+ const { sources, exports, imports } = collectFileChildren(props["children"]);
18325
+ files.push({
18326
+ baseName: props["baseName"],
18327
+ path: props["path"],
18328
+ meta: props["meta"] || {},
18329
+ footer: props["footer"],
18330
+ banner: props["banner"],
18331
+ sources,
18332
+ exports,
18333
+ imports
18334
+ });
18319
18335
  }
18320
18336
  walkElement(element, () => {}, onHost);
18321
18337
  yield* files;
@@ -18427,8 +18443,8 @@ const jsxRendererSync = () => {
18427
18443
  get files() {
18428
18444
  return runtime.nodes;
18429
18445
  },
18430
- async *stream(element) {
18431
- yield* runtime.stream(element);
18446
+ stream(element) {
18447
+ return runtime.stream(element);
18432
18448
  },
18433
18449
  unmount(_error) {}
18434
18450
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/renderer-jsx",
3
- "version": "5.0.0-beta.18",
3
+ "version": "5.0.0-beta.19",
4
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.",
5
5
  "keywords": [
6
6
  "codegen",
@@ -75,7 +75,7 @@
75
75
  "registry": "https://registry.npmjs.org/"
76
76
  },
77
77
  "dependencies": {
78
- "@kubb/ast": "5.0.0-beta.18"
78
+ "@kubb/ast": "5.0.0-beta.19"
79
79
  },
80
80
  "devDependencies": {
81
81
  "@types/react": "^19.2.14",
@@ -44,9 +44,13 @@ function walkElement(element: unknown, onText: OnText, onHost: OnHost): void {
44
44
 
45
45
  if (type === React.Fragment) {
46
46
  walkElement(props['children'], onText, onHost)
47
- } else if (typeof type === 'function') {
47
+ return
48
+ }
49
+ if (typeof type === 'function') {
48
50
  walkElement((type as (p: unknown) => unknown)(props), onText, onHost)
49
- } else if (typeof type === 'string') {
51
+ return
52
+ }
53
+ if (typeof type === 'string') {
50
54
  onHost(type, props)
51
55
  }
52
56
  }
@@ -220,21 +224,21 @@ function* walkFiles(element: unknown): Generator<FileNode> {
220
224
  const files: FileNode[] = []
221
225
 
222
226
  function onHost(type: string, props: Record<string, unknown>): void {
223
- if (type === KUBB_FILE && props['baseName'] !== undefined && props['path'] !== undefined) {
224
- const { sources, exports, imports } = collectFileChildren(props['children'])
225
- files.push({
226
- baseName: props['baseName'],
227
- path: props['path'],
228
- meta: props['meta'] || {},
229
- footer: props['footer'],
230
- banner: props['banner'],
231
- sources,
232
- exports,
233
- imports,
234
- } as FileNode)
235
- } else {
227
+ if (!(type === KUBB_FILE && props['baseName'] !== undefined && props['path'] !== undefined)) {
236
228
  walkElement(props['children'], () => {}, onHost)
229
+ return
237
230
  }
231
+ const { sources, exports, imports } = collectFileChildren(props['children'])
232
+ files.push({
233
+ baseName: props['baseName'],
234
+ path: props['path'],
235
+ meta: props['meta'] || {},
236
+ footer: props['footer'],
237
+ banner: props['banner'],
238
+ sources,
239
+ exports,
240
+ imports,
241
+ } as FileNode)
238
242
  }
239
243
 
240
244
  walkElement(element, () => {}, onHost)
@@ -64,6 +64,7 @@ export const jsxRenderer = () => {
64
64
  */
65
65
  export const jsxRendererSync = () => {
66
66
  const runtime = new SyncRuntime()
67
+
67
68
  return {
68
69
  async render(element: KubbReactElement): Promise<void> {
69
70
  runtime.render(element)
@@ -71,8 +72,8 @@ export const jsxRendererSync = () => {
71
72
  get files() {
72
73
  return runtime.nodes
73
74
  },
74
- async *stream(element: KubbReactElement): AsyncGenerator<FileNode> {
75
- yield* runtime.stream(element)
75
+ stream(element: KubbReactElement): Generator<FileNode> {
76
+ return runtime.stream(element)
76
77
  },
77
78
  unmount(_error?: Error | number | null) {},
78
79
  }
package/src/utils.ts CHANGED
@@ -187,9 +187,15 @@ function createFileNode(child: DOMElement): FileNode {
187
187
  const imports: ImportNode[] = []
188
188
 
189
189
  for (const node of collectFileEntries(child)) {
190
- if (node.kind === 'Source') sources.push(node)
191
- else if (node.kind === 'Export') exports.push(node)
192
- else imports.push(node)
190
+ if (node.kind === 'Source') {
191
+ sources.push(node)
192
+ continue
193
+ }
194
+ if (node.kind === 'Export') {
195
+ exports.push(node)
196
+ continue
197
+ }
198
+ imports.push(node)
193
199
  }
194
200
 
195
201
  return {