Skip to content

Commit

Permalink
feat(compile): add support for pre rendering React components
Browse files Browse the repository at this point in the history
  • Loading branch information
lc-soft committed Sep 2, 2023
1 parent 9e4d41a commit 7e71b3a
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/compiler/react-tsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function replaceCSSImportStatments(code, files) {
}

function transformReactElement(el) {
const node = {
let node = {
type: "element",
name: "",
text: "",
Expand All @@ -124,14 +124,21 @@ function transformReactElement(el) {
break;
}
} else if (typeof el.type === "function") {
if (el.type.shouldPreRender) {
const newNode = transformReactElement(el.type(el.props));
if (el.props.$ref) {
newNode.attributes.ref = el.props.$ref;
}
return newNode;
}
node.name = el.type.constructor.name;
} else {
return;
}

const attrMap = {
className: 'class',
$ref: "ref"
className: "class",
$ref: "ref",
};
Object.keys(el.props).forEach((propKey) => {
let key = propKey;
Expand All @@ -149,7 +156,9 @@ function transformReactElement(el) {
if (key in attrMap) {
key = attrMap[key];
}
node.attributes[key] = el.props[propKey];
if (typeof el.props[propKey] !== 'undefined') {
node.attributes[key] = el.props[propKey];
}
});
return node;
}
Expand Down

0 comments on commit 7e71b3a

Please sign in to comment.