Skip to content

Instantly share code, notes, and snippets.

@stephencookdev
Created April 24, 2020 16:23
Show Gist options
  • Save stephencookdev/7e51982cf10b5261dd812ba1a4f6bf4d to your computer and use it in GitHub Desktop.
Save stephencookdev/7e51982cf10b5261dd812ba1a4f6bf4d to your computer and use it in GitHub Desktop.
A look at the genTypeExpression function of grandma-visitor-jsx
module.exports = function ({ types: t }) {
const genTypeExpression = (node) => {
return t.callExpression(
t.memberExpression(t.identifier("React"), t.identifier("createElement")),
[
/^[A-Z]/.test(node.type[0])
? t.identifier(node.type)
: t.stringLiteral(node.type),
t.objectExpression(node.args),
...node.children.map(genTypeExpression),
]
);
};
const GrandmaVisitor = { /* ... */ };
const GrandmaVisitorInitiator = { /* ... */ };
return { visitor: GrandmaVisitorInitiator };
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment