@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 +105 -103
- package/dist/index.js +105 -103
- package/package.json +2 -2
- package/src/SyncRuntime.tsx +38 -18
- package/src/utils.ts +81 -76
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
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
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
|
-
|
|
17913
|
-
|
|
17914
|
-
|
|
17915
|
-
|
|
17916
|
-
|
|
17917
|
-
|
|
17918
|
-
|
|
17919
|
-
|
|
17920
|
-
|
|
17921
|
-
|
|
17922
|
-
|
|
17923
|
-
|
|
17924
|
-
|
|
17925
|
-
|
|
17926
|
-
|
|
17927
|
-
|
|
17928
|
-
|
|
17929
|
-
|
|
17930
|
-
|
|
17931
|
-
|
|
17932
|
-
|
|
17933
|
-
|
|
17934
|
-
|
|
17935
|
-
|
|
17936
|
-
|
|
17937
|
-
|
|
17938
|
-
|
|
17939
|
-
|
|
17940
|
-
|
|
17941
|
-
|
|
17942
|
-
|
|
17943
|
-
|
|
17944
|
-
|
|
17945
|
-
|
|
17946
|
-
|
|
17947
|
-
|
|
17948
|
-
|
|
17949
|
-
|
|
17950
|
-
|
|
17951
|
-
|
|
17952
|
-
|
|
17953
|
-
|
|
17954
|
-
|
|
17955
|
-
|
|
17956
|
-
|
|
17957
|
-
|
|
17958
|
-
|
|
17959
|
-
|
|
17960
|
-
|
|
17961
|
-
|
|
17962
|
-
|
|
17963
|
-
|
|
17964
|
-
|
|
17965
|
-
|
|
17966
|
-
|
|
17967
|
-
|
|
17968
|
-
|
|
17969
|
-
|
|
17970
|
-
|
|
17971
|
-
|
|
17972
|
-
|
|
17973
|
-
|
|
17974
|
-
|
|
17975
|
-
|
|
17976
|
-
|
|
17977
|
-
|
|
17978
|
-
|
|
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
|
-
|
|
18322
|
-
|
|
18323
|
-
|
|
18324
|
-
|
|
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
|
-
|
|
18328
|
-
|
|
18329
|
-
|
|
18330
|
-
|
|
18331
|
-
|
|
18332
|
-
|
|
18333
|
-
|
|
18334
|
-
|
|
18335
|
-
|
|
18336
|
-
|
|
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
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
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
|
-
|
|
17910
|
-
|
|
17911
|
-
|
|
17912
|
-
|
|
17913
|
-
|
|
17914
|
-
|
|
17915
|
-
|
|
17916
|
-
|
|
17917
|
-
|
|
17918
|
-
|
|
17919
|
-
|
|
17920
|
-
|
|
17921
|
-
|
|
17922
|
-
|
|
17923
|
-
|
|
17924
|
-
|
|
17925
|
-
|
|
17926
|
-
|
|
17927
|
-
|
|
17928
|
-
|
|
17929
|
-
|
|
17930
|
-
|
|
17931
|
-
|
|
17932
|
-
|
|
17933
|
-
|
|
17934
|
-
|
|
17935
|
-
|
|
17936
|
-
|
|
17937
|
-
|
|
17938
|
-
|
|
17939
|
-
|
|
17940
|
-
|
|
17941
|
-
|
|
17942
|
-
|
|
17943
|
-
|
|
17944
|
-
|
|
17945
|
-
|
|
17946
|
-
|
|
17947
|
-
|
|
17948
|
-
|
|
17949
|
-
|
|
17950
|
-
|
|
17951
|
-
|
|
17952
|
-
|
|
17953
|
-
|
|
17954
|
-
|
|
17955
|
-
|
|
17956
|
-
|
|
17957
|
-
|
|
17958
|
-
|
|
17959
|
-
|
|
17960
|
-
|
|
17961
|
-
|
|
17962
|
-
|
|
17963
|
-
|
|
17964
|
-
|
|
17965
|
-
|
|
17966
|
-
|
|
17967
|
-
|
|
17968
|
-
|
|
17969
|
-
|
|
17970
|
-
|
|
17971
|
-
|
|
17972
|
-
|
|
17973
|
-
|
|
17974
|
-
|
|
17975
|
-
|
|
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
|
-
|
|
18319
|
-
|
|
18320
|
-
|
|
18321
|
-
|
|
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
|
-
|
|
18325
|
-
|
|
18326
|
-
|
|
18327
|
-
|
|
18328
|
-
|
|
18329
|
-
|
|
18330
|
-
|
|
18331
|
-
|
|
18332
|
-
|
|
18333
|
-
|
|
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.
|
|
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.
|
|
78
|
+
"@kubb/ast": "5.0.0-beta.20"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
81
81
|
"@types/react": "^19.2.14",
|
package/src/SyncRuntime.tsx
CHANGED
|
@@ -221,28 +221,48 @@ function collectFileChildren(element: unknown): FileChildren {
|
|
|
221
221
|
}
|
|
222
222
|
|
|
223
223
|
function* walkFiles(element: unknown): Generator<FileNode> {
|
|
224
|
-
|
|
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
|
-
|
|
227
|
-
|
|
228
|
-
|
|
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
|
-
|
|
245
|
-
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
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
|
|