Created
April 24, 2020 16:23
-
-
Save stephencookdev/7e51982cf10b5261dd812ba1a4f6bf4d to your computer and use it in GitHub Desktop.
A look at the genTypeExpression function of grandma-visitor-jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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