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

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
@@ -454,29 +454,20 @@ var import_constants = (/* @__PURE__ */ require_jsx_runtime.__commonJSMin(((expo
454
454
  * Name used for text-node entries in the virtual DOM.
455
455
  */
456
456
  const TEXT_NODE_NAME = "#text";
457
- const KUBB_FILE = "kubb-file";
458
- const KUBB_SOURCE = "kubb-source";
459
- const KUBB_EXPORT = "kubb-export";
460
- const KUBB_IMPORT = "kubb-import";
461
- const KUBB_FUNCTION = "kubb-function";
462
- const KUBB_ARROW_FUNCTION = "kubb-arrow-function";
463
- const KUBB_CONST = "kubb-const";
464
- const KUBB_TYPE = "kubb-type";
465
- const KUBB_JSX = "kubb-jsx";
466
457
  /**
467
458
  * Set of all element names recognized by the Kubb renderer.
468
459
  * Used to distinguish Kubb-owned elements from unrecognized or text nodes during tree traversal.
469
460
  */
470
461
  const nodeNames = new Set([
471
- KUBB_EXPORT,
472
- KUBB_FILE,
473
- KUBB_SOURCE,
474
- KUBB_IMPORT,
475
- KUBB_FUNCTION,
476
- KUBB_ARROW_FUNCTION,
477
- KUBB_CONST,
478
- KUBB_TYPE,
479
- KUBB_JSX,
462
+ "kubb-export",
463
+ "kubb-file",
464
+ "kubb-source",
465
+ "kubb-import",
466
+ "kubb-function",
467
+ "kubb-arrow-function",
468
+ "kubb-const",
469
+ "kubb-type",
470
+ "kubb-jsx",
480
471
  "kubb-text",
481
472
  "kubb-root",
482
473
  "kubb-app",
@@ -17909,74 +17900,73 @@ function collectCodeNodes$1(element) {
17909
17900
  const result = [];
17910
17901
  for (const child of element.childNodes) {
17911
17902
  if (!child) continue;
17912
- switch (child.nodeName) {
17913
- case TEXT_NODE_NAME: {
17914
- const text = child.nodeValue;
17915
- if (text && text.trim()) result.push((0, _kubb_ast.createText)(text));
17916
- break;
17917
- }
17918
- case "br":
17919
- result.push((0, _kubb_ast.createBreak)());
17920
- break;
17921
- case KUBB_FUNCTION: {
17922
- const attrs = child.attributes;
17923
- result.push((0, _kubb_ast.createFunction)({
17924
- name: attrs["name"],
17925
- params: attrs["params"],
17926
- export: attrs["export"],
17927
- default: attrs["default"],
17928
- async: attrs["async"],
17929
- generics: attrs["generics"],
17930
- returnType: attrs["returnType"],
17931
- JSDoc: attrs["JSDoc"],
17932
- nodes: collectCodeNodes$1(child)
17933
- }));
17934
- break;
17935
- }
17936
- case KUBB_ARROW_FUNCTION: {
17937
- const attrs = child.attributes;
17938
- result.push((0, _kubb_ast.createArrowFunction)({
17939
- name: attrs["name"],
17940
- params: attrs["params"],
17941
- export: attrs["export"],
17942
- default: attrs["default"],
17943
- async: attrs["async"],
17944
- generics: attrs["generics"],
17945
- returnType: attrs["returnType"],
17946
- singleLine: attrs["singleLine"],
17947
- JSDoc: attrs["JSDoc"],
17948
- nodes: collectCodeNodes$1(child)
17949
- }));
17950
- break;
17951
- }
17952
- case KUBB_CONST: {
17953
- const attrs = child.attributes;
17954
- result.push((0, _kubb_ast.createConst)({
17955
- name: attrs["name"],
17956
- type: attrs["type"],
17957
- export: attrs["export"],
17958
- asConst: attrs["asConst"],
17959
- JSDoc: attrs["JSDoc"],
17960
- nodes: collectCodeNodes$1(child)
17961
- }));
17962
- break;
17963
- }
17964
- case KUBB_TYPE: {
17965
- const attrs = child.attributes;
17966
- result.push((0, _kubb_ast.createType)({
17967
- name: attrs["name"],
17968
- export: attrs["export"],
17969
- JSDoc: attrs["JSDoc"],
17970
- nodes: collectCodeNodes$1(child)
17971
- }));
17972
- break;
17973
- }
17974
- case KUBB_JSX: {
17975
- const textChild = child.childNodes[0];
17976
- const value = textChild?.nodeName === "#text" ? textChild.nodeValue : "";
17977
- if (value) result.push((0, _kubb_ast.createJsx)(value));
17978
- break;
17979
- }
17903
+ if (child.nodeName === "#text") {
17904
+ const text = child.nodeValue;
17905
+ if (text && text.trim()) result.push((0, _kubb_ast.createText)(text));
17906
+ continue;
17907
+ }
17908
+ if (child.nodeName === "br") {
17909
+ result.push((0, _kubb_ast.createBreak)());
17910
+ continue;
17911
+ }
17912
+ if (child.nodeName === "kubb-function") {
17913
+ const attrs = child.attributes;
17914
+ result.push((0, _kubb_ast.createFunction)({
17915
+ name: attrs["name"],
17916
+ params: attrs["params"],
17917
+ export: attrs["export"],
17918
+ default: attrs["default"],
17919
+ async: attrs["async"],
17920
+ generics: attrs["generics"],
17921
+ returnType: attrs["returnType"],
17922
+ JSDoc: attrs["JSDoc"],
17923
+ nodes: collectCodeNodes$1(child)
17924
+ }));
17925
+ continue;
17926
+ }
17927
+ if (child.nodeName === "kubb-arrow-function") {
17928
+ const attrs = child.attributes;
17929
+ result.push((0, _kubb_ast.createArrowFunction)({
17930
+ name: attrs["name"],
17931
+ params: attrs["params"],
17932
+ export: attrs["export"],
17933
+ default: attrs["default"],
17934
+ async: attrs["async"],
17935
+ generics: attrs["generics"],
17936
+ returnType: attrs["returnType"],
17937
+ singleLine: attrs["singleLine"],
17938
+ JSDoc: attrs["JSDoc"],
17939
+ nodes: collectCodeNodes$1(child)
17940
+ }));
17941
+ continue;
17942
+ }
17943
+ if (child.nodeName === "kubb-const") {
17944
+ const attrs = child.attributes;
17945
+ result.push((0, _kubb_ast.createConst)({
17946
+ name: attrs["name"],
17947
+ type: attrs["type"],
17948
+ export: attrs["export"],
17949
+ asConst: attrs["asConst"],
17950
+ JSDoc: attrs["JSDoc"],
17951
+ nodes: collectCodeNodes$1(child)
17952
+ }));
17953
+ continue;
17954
+ }
17955
+ if (child.nodeName === "kubb-type") {
17956
+ const attrs = child.attributes;
17957
+ result.push((0, _kubb_ast.createType)({
17958
+ name: attrs["name"],
17959
+ export: attrs["export"],
17960
+ JSDoc: attrs["JSDoc"],
17961
+ nodes: collectCodeNodes$1(child)
17962
+ }));
17963
+ continue;
17964
+ }
17965
+ if (child.nodeName === "kubb-jsx") {
17966
+ const textChild = child.childNodes[0];
17967
+ const value = textChild?.nodeName === "#text" ? textChild.nodeValue : "";
17968
+ if (value) result.push((0, _kubb_ast.createJsx)(value));
17969
+ continue;
17980
17970
  }
17981
17971
  }
17982
17972
  return result;
@@ -18318,26 +18308,38 @@ function collectFileChildren(element) {
18318
18308
  };
18319
18309
  }
18320
18310
  function* walkFiles(element) {
18321
- const files = [];
18322
- function onHost(type, props) {
18323
- if (!(type === "kubb-file" && props["baseName"] !== void 0 && props["path"] !== void 0)) {
18324
- walkElement(props["children"], () => {}, onHost);
18311
+ if (element == null || typeof element === "boolean") return;
18312
+ if (typeof element === "string" || typeof element === "number" || typeof element === "bigint") return;
18313
+ if (Array.isArray(element)) {
18314
+ for (const child of element) yield* walkFiles(child);
18315
+ return;
18316
+ }
18317
+ if (typeof element === "object" && "$$typeof" in element) {
18318
+ const el = element;
18319
+ const { type } = el;
18320
+ const props = el.props;
18321
+ if (type === import_react.Fragment) {
18322
+ yield* walkFiles(props["children"]);
18325
18323
  return;
18326
18324
  }
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
- });
18325
+ if (typeof type === "function") {
18326
+ yield* walkFiles(type(props));
18327
+ return;
18328
+ }
18329
+ if (typeof type === "string") if (type === "kubb-file" && props["baseName"] !== void 0 && props["path"] !== void 0) {
18330
+ const { sources, exports, imports } = collectFileChildren(props["children"]);
18331
+ yield {
18332
+ baseName: props["baseName"],
18333
+ path: props["path"],
18334
+ meta: props["meta"] || {},
18335
+ footer: props["footer"],
18336
+ banner: props["banner"],
18337
+ sources,
18338
+ exports,
18339
+ imports
18340
+ };
18341
+ } else yield* walkFiles(props["children"]);
18338
18342
  }
18339
- walkElement(element, () => {}, onHost);
18340
- yield* files;
18341
18343
  }
18342
18344
  /**
18343
18345
  * Synchronous JSX renderer that walks the element tree in a single pass,
package/dist/index.js CHANGED
@@ -454,29 +454,20 @@ var import_constants = (/* @__PURE__ */ __commonJSMin(((exports, module) => {
454
454
  * Name used for text-node entries in the virtual DOM.
455
455
  */
456
456
  const TEXT_NODE_NAME = "#text";
457
- const KUBB_FILE = "kubb-file";
458
- const KUBB_SOURCE = "kubb-source";
459
- const KUBB_EXPORT = "kubb-export";
460
- const KUBB_IMPORT = "kubb-import";
461
- const KUBB_FUNCTION = "kubb-function";
462
- const KUBB_ARROW_FUNCTION = "kubb-arrow-function";
463
- const KUBB_CONST = "kubb-const";
464
- const KUBB_TYPE = "kubb-type";
465
- const KUBB_JSX = "kubb-jsx";
466
457
  /**
467
458
  * Set of all element names recognized by the Kubb renderer.
468
459
  * Used to distinguish Kubb-owned elements from unrecognized or text nodes during tree traversal.
469
460
  */
470
461
  const nodeNames = new Set([
471
- KUBB_EXPORT,
472
- KUBB_FILE,
473
- KUBB_SOURCE,
474
- KUBB_IMPORT,
475
- KUBB_FUNCTION,
476
- KUBB_ARROW_FUNCTION,
477
- KUBB_CONST,
478
- KUBB_TYPE,
479
- KUBB_JSX,
462
+ "kubb-export",
463
+ "kubb-file",
464
+ "kubb-source",
465
+ "kubb-import",
466
+ "kubb-function",
467
+ "kubb-arrow-function",
468
+ "kubb-const",
469
+ "kubb-type",
470
+ "kubb-jsx",
480
471
  "kubb-text",
481
472
  "kubb-root",
482
473
  "kubb-app",
@@ -17906,74 +17897,73 @@ function collectCodeNodes$1(element) {
17906
17897
  const result = [];
17907
17898
  for (const child of element.childNodes) {
17908
17899
  if (!child) continue;
17909
- switch (child.nodeName) {
17910
- case TEXT_NODE_NAME: {
17911
- const text = child.nodeValue;
17912
- if (text && text.trim()) result.push(createText(text));
17913
- break;
17914
- }
17915
- case "br":
17916
- result.push(createBreak());
17917
- break;
17918
- case KUBB_FUNCTION: {
17919
- const attrs = child.attributes;
17920
- result.push(createFunction({
17921
- name: attrs["name"],
17922
- params: attrs["params"],
17923
- export: attrs["export"],
17924
- default: attrs["default"],
17925
- async: attrs["async"],
17926
- generics: attrs["generics"],
17927
- returnType: attrs["returnType"],
17928
- JSDoc: attrs["JSDoc"],
17929
- nodes: collectCodeNodes$1(child)
17930
- }));
17931
- break;
17932
- }
17933
- case KUBB_ARROW_FUNCTION: {
17934
- const attrs = child.attributes;
17935
- result.push(createArrowFunction({
17936
- name: attrs["name"],
17937
- params: attrs["params"],
17938
- export: attrs["export"],
17939
- default: attrs["default"],
17940
- async: attrs["async"],
17941
- generics: attrs["generics"],
17942
- returnType: attrs["returnType"],
17943
- singleLine: attrs["singleLine"],
17944
- JSDoc: attrs["JSDoc"],
17945
- nodes: collectCodeNodes$1(child)
17946
- }));
17947
- break;
17948
- }
17949
- case KUBB_CONST: {
17950
- const attrs = child.attributes;
17951
- result.push(createConst({
17952
- name: attrs["name"],
17953
- type: attrs["type"],
17954
- export: attrs["export"],
17955
- asConst: attrs["asConst"],
17956
- JSDoc: attrs["JSDoc"],
17957
- nodes: collectCodeNodes$1(child)
17958
- }));
17959
- break;
17960
- }
17961
- case KUBB_TYPE: {
17962
- const attrs = child.attributes;
17963
- result.push(createType({
17964
- name: attrs["name"],
17965
- export: attrs["export"],
17966
- JSDoc: attrs["JSDoc"],
17967
- nodes: collectCodeNodes$1(child)
17968
- }));
17969
- break;
17970
- }
17971
- case KUBB_JSX: {
17972
- const textChild = child.childNodes[0];
17973
- const value = textChild?.nodeName === "#text" ? textChild.nodeValue : "";
17974
- if (value) result.push(createJsx(value));
17975
- break;
17976
- }
17900
+ if (child.nodeName === "#text") {
17901
+ const text = child.nodeValue;
17902
+ if (text && text.trim()) result.push(createText(text));
17903
+ continue;
17904
+ }
17905
+ if (child.nodeName === "br") {
17906
+ result.push(createBreak());
17907
+ continue;
17908
+ }
17909
+ if (child.nodeName === "kubb-function") {
17910
+ const attrs = child.attributes;
17911
+ result.push(createFunction({
17912
+ name: attrs["name"],
17913
+ params: attrs["params"],
17914
+ export: attrs["export"],
17915
+ default: attrs["default"],
17916
+ async: attrs["async"],
17917
+ generics: attrs["generics"],
17918
+ returnType: attrs["returnType"],
17919
+ JSDoc: attrs["JSDoc"],
17920
+ nodes: collectCodeNodes$1(child)
17921
+ }));
17922
+ continue;
17923
+ }
17924
+ if (child.nodeName === "kubb-arrow-function") {
17925
+ const attrs = child.attributes;
17926
+ result.push(createArrowFunction({
17927
+ name: attrs["name"],
17928
+ params: attrs["params"],
17929
+ export: attrs["export"],
17930
+ default: attrs["default"],
17931
+ async: attrs["async"],
17932
+ generics: attrs["generics"],
17933
+ returnType: attrs["returnType"],
17934
+ singleLine: attrs["singleLine"],
17935
+ JSDoc: attrs["JSDoc"],
17936
+ nodes: collectCodeNodes$1(child)
17937
+ }));
17938
+ continue;
17939
+ }
17940
+ if (child.nodeName === "kubb-const") {
17941
+ const attrs = child.attributes;
17942
+ result.push(createConst({
17943
+ name: attrs["name"],
17944
+ type: attrs["type"],
17945
+ export: attrs["export"],
17946
+ asConst: attrs["asConst"],
17947
+ JSDoc: attrs["JSDoc"],
17948
+ nodes: collectCodeNodes$1(child)
17949
+ }));
17950
+ continue;
17951
+ }
17952
+ if (child.nodeName === "kubb-type") {
17953
+ const attrs = child.attributes;
17954
+ result.push(createType({
17955
+ name: attrs["name"],
17956
+ export: attrs["export"],
17957
+ JSDoc: attrs["JSDoc"],
17958
+ nodes: collectCodeNodes$1(child)
17959
+ }));
17960
+ continue;
17961
+ }
17962
+ if (child.nodeName === "kubb-jsx") {
17963
+ const textChild = child.childNodes[0];
17964
+ const value = textChild?.nodeName === "#text" ? textChild.nodeValue : "";
17965
+ if (value) result.push(createJsx(value));
17966
+ continue;
17977
17967
  }
17978
17968
  }
17979
17969
  return result;
@@ -18315,26 +18305,38 @@ function collectFileChildren(element) {
18315
18305
  };
18316
18306
  }
18317
18307
  function* walkFiles(element) {
18318
- const files = [];
18319
- function onHost(type, props) {
18320
- if (!(type === "kubb-file" && props["baseName"] !== void 0 && props["path"] !== void 0)) {
18321
- walkElement(props["children"], () => {}, onHost);
18308
+ if (element == null || typeof element === "boolean") return;
18309
+ if (typeof element === "string" || typeof element === "number" || typeof element === "bigint") return;
18310
+ if (Array.isArray(element)) {
18311
+ for (const child of element) yield* walkFiles(child);
18312
+ return;
18313
+ }
18314
+ if (typeof element === "object" && "$$typeof" in element) {
18315
+ const el = element;
18316
+ const { type } = el;
18317
+ const props = el.props;
18318
+ if (type === import_react.Fragment) {
18319
+ yield* walkFiles(props["children"]);
18322
18320
  return;
18323
18321
  }
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
- });
18322
+ if (typeof type === "function") {
18323
+ yield* walkFiles(type(props));
18324
+ return;
18325
+ }
18326
+ if (typeof type === "string") if (type === "kubb-file" && props["baseName"] !== void 0 && props["path"] !== void 0) {
18327
+ const { sources, exports, imports } = collectFileChildren(props["children"]);
18328
+ yield {
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
+ };
18338
+ } else yield* walkFiles(props["children"]);
18335
18339
  }
18336
- walkElement(element, () => {}, onHost);
18337
- yield* files;
18338
18340
  }
18339
18341
  /**
18340
18342
  * Synchronous JSX renderer that walks the element tree in a single pass,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/renderer-jsx",
3
- "version": "5.0.0-beta.19",
3
+ "version": "5.0.0-beta.20",
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.19"
78
+ "@kubb/ast": "5.0.0-beta.20"
79
79
  },
80
80
  "devDependencies": {
81
81
  "@types/react": "^19.2.14",
@@ -221,28 +221,48 @@ function collectFileChildren(element: unknown): FileChildren {
221
221
  }
222
222
 
223
223
  function* walkFiles(element: unknown): Generator<FileNode> {
224
- const files: FileNode[] = []
224
+ if (element == null || typeof element === 'boolean') return
225
+
226
+ if (typeof element === 'string' || typeof element === 'number' || typeof element === 'bigint') return
227
+
228
+ if (Array.isArray(element)) {
229
+ for (const child of element) yield* walkFiles(child)
230
+ return
231
+ }
232
+
233
+ if (typeof element === 'object' && '$$typeof' in element) {
234
+ const el = element as unknown as React.ReactElement
235
+ const { type } = el
236
+ const props = el.props as Record<string, unknown>
225
237
 
226
- function onHost(type: string, props: Record<string, unknown>): void {
227
- if (!(type === KUBB_FILE && props['baseName'] !== undefined && props['path'] !== undefined)) {
228
- walkElement(props['children'], () => {}, onHost)
238
+ if (type === React.Fragment) {
239
+ yield* walkFiles(props['children'])
240
+ return
241
+ }
242
+
243
+ if (typeof type === 'function') {
244
+ yield* walkFiles((type as (p: unknown) => unknown)(props))
229
245
  return
230
246
  }
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)
242
- }
243
247
 
244
- walkElement(element, () => {}, onHost)
245
- yield* files
248
+ if (typeof type === 'string') {
249
+ if (type === KUBB_FILE && props['baseName'] !== undefined && props['path'] !== undefined) {
250
+ const { sources, exports, imports } = collectFileChildren(props['children'])
251
+ yield {
252
+ baseName: props['baseName'],
253
+ path: props['path'],
254
+ meta: props['meta'] || {},
255
+ footer: props['footer'],
256
+ banner: props['banner'],
257
+ sources,
258
+ exports,
259
+ imports,
260
+ } as FileNode
261
+ } else {
262
+ yield* walkFiles(props['children'])
263
+ }
264
+ }
265
+ }
246
266
  }
247
267
 
248
268
  /**
package/src/utils.ts CHANGED
@@ -43,82 +43,87 @@ function collectCodeNodes(element: DOMElement): CodeNode[] {
43
43
  for (const child of element.childNodes) {
44
44
  if (!child) continue
45
45
 
46
- switch (child.nodeName) {
47
- case TEXT_NODE_NAME: {
48
- const text = (child as DOMNode<{ nodeName: '#text' }>).nodeValue
49
- if (text && text.trim()) result.push(createText(text))
50
- break
51
- }
52
- case 'br':
53
- result.push(createBreak())
54
- break
55
- case KUBB_FUNCTION: {
56
- const attrs = child.attributes
57
- result.push(
58
- createFunction({
59
- name: attrs['name'] as string,
60
- params: attrs['params'] as string | undefined,
61
- export: attrs['export'] as boolean | undefined,
62
- default: attrs['default'] as boolean | undefined,
63
- async: attrs['async'] as boolean | undefined,
64
- generics: attrs['generics'] as string | undefined,
65
- returnType: attrs['returnType'] as string | undefined,
66
- JSDoc: attrs['JSDoc'] as JSDocNode | undefined,
67
- nodes: collectCodeNodes(child),
68
- }),
69
- )
70
- break
71
- }
72
- case KUBB_ARROW_FUNCTION: {
73
- const attrs = child.attributes
74
- result.push(
75
- createArrowFunction({
76
- name: attrs['name'] as string,
77
- params: attrs['params'] as string | undefined,
78
- export: attrs['export'] as boolean | undefined,
79
- default: attrs['default'] as boolean | undefined,
80
- async: attrs['async'] as boolean | undefined,
81
- generics: attrs['generics'] as string | undefined,
82
- returnType: attrs['returnType'] as string | undefined,
83
- singleLine: attrs['singleLine'] as boolean | undefined,
84
- JSDoc: attrs['JSDoc'] as JSDocNode | undefined,
85
- nodes: collectCodeNodes(child),
86
- } as Omit<ArrowFunctionNode, 'kind'>),
87
- )
88
- break
89
- }
90
- case KUBB_CONST: {
91
- const attrs = child.attributes
92
- result.push(
93
- createConst({
94
- name: attrs['name'] as string,
95
- type: attrs['type'] as string | undefined,
96
- export: attrs['export'] as boolean | undefined,
97
- asConst: attrs['asConst'] as boolean | undefined,
98
- JSDoc: attrs['JSDoc'] as JSDocNode | undefined,
99
- nodes: collectCodeNodes(child),
100
- }),
101
- )
102
- break
103
- }
104
- case KUBB_TYPE: {
105
- const attrs = child.attributes
106
- result.push(
107
- createType({
108
- name: attrs['name'] as string,
109
- export: attrs['export'] as boolean | undefined,
110
- JSDoc: attrs['JSDoc'] as JSDocNode | undefined,
111
- nodes: collectCodeNodes(child),
112
- }),
113
- )
114
- break
115
- }
116
- case KUBB_JSX: {
117
- const textChild = child.childNodes[0]
118
- const value = textChild?.nodeName === TEXT_NODE_NAME ? (textChild as DOMNode<{ nodeName: '#text' }>).nodeValue : ''
119
- if (value) result.push(createJsx(value))
120
- break
121
- }
46
+ if (child.nodeName === TEXT_NODE_NAME) {
47
+ const text = (child as DOMNode<{ nodeName: '#text' }>).nodeValue
48
+ if (text && text.trim()) result.push(createText(text))
49
+ continue
50
+ }
51
+
52
+ if (child.nodeName === 'br') {
53
+ result.push(createBreak())
54
+ continue
55
+ }
56
+
57
+ if (child.nodeName === KUBB_FUNCTION) {
58
+ const attrs = child.attributes
59
+ result.push(
60
+ createFunction({
61
+ name: attrs['name'] as string,
62
+ params: attrs['params'] as string | undefined,
63
+ export: attrs['export'] as boolean | undefined,
64
+ default: attrs['default'] as boolean | undefined,
65
+ async: attrs['async'] as boolean | undefined,
66
+ generics: attrs['generics'] as string | undefined,
67
+ returnType: attrs['returnType'] as string | undefined,
68
+ JSDoc: attrs['JSDoc'] as JSDocNode | undefined,
69
+ nodes: collectCodeNodes(child),
70
+ }),
71
+ )
72
+ continue
73
+ }
74
+
75
+ if (child.nodeName === KUBB_ARROW_FUNCTION) {
76
+ const attrs = child.attributes
77
+ result.push(
78
+ createArrowFunction({
79
+ name: attrs['name'] as string,
80
+ params: attrs['params'] as string | undefined,
81
+ export: attrs['export'] as boolean | undefined,
82
+ default: attrs['default'] as boolean | undefined,
83
+ async: attrs['async'] as boolean | undefined,
84
+ generics: attrs['generics'] as string | undefined,
85
+ returnType: attrs['returnType'] as string | undefined,
86
+ singleLine: attrs['singleLine'] as boolean | undefined,
87
+ JSDoc: attrs['JSDoc'] as JSDocNode | undefined,
88
+ nodes: collectCodeNodes(child),
89
+ } as Omit<ArrowFunctionNode, 'kind'>),
90
+ )
91
+ continue
92
+ }
93
+
94
+ if (child.nodeName === KUBB_CONST) {
95
+ const attrs = child.attributes
96
+ result.push(
97
+ createConst({
98
+ name: attrs['name'] as string,
99
+ type: attrs['type'] as string | undefined,
100
+ export: attrs['export'] as boolean | undefined,
101
+ asConst: attrs['asConst'] as boolean | undefined,
102
+ JSDoc: attrs['JSDoc'] as JSDocNode | undefined,
103
+ nodes: collectCodeNodes(child),
104
+ }),
105
+ )
106
+ continue
107
+ }
108
+
109
+ if (child.nodeName === KUBB_TYPE) {
110
+ const attrs = child.attributes
111
+ result.push(
112
+ createType({
113
+ name: attrs['name'] as string,
114
+ export: attrs['export'] as boolean | undefined,
115
+ JSDoc: attrs['JSDoc'] as JSDocNode | undefined,
116
+ nodes: collectCodeNodes(child),
117
+ }),
118
+ )
119
+ continue
120
+ }
121
+
122
+ if (child.nodeName === KUBB_JSX) {
123
+ const textChild = child.childNodes[0]
124
+ const value = textChild?.nodeName === TEXT_NODE_NAME ? (textChild as DOMNode<{ nodeName: '#text' }>).nodeValue : ''
125
+ if (value) result.push(createJsx(value))
126
+ continue
122
127
  }
123
128
  }
124
129