Created
April 24, 2020 15:15
-
-
Save stephencookdev/98e96b711aae69864fbe1f7ceb5df6bf to your computer and use it in GitHub Desktop.
A look at the initiator visitor of grandmas-own-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 GrandmaVisitorInitiator = { | |
Program(path) { | |
const commentLineTokens = path.parent.comments.filter( | |
(token) => token.type === "CommentLine" | |
); | |
const commentBlockTokens = path.parent.comments.filter( | |
(token) => token.type === "CommentBlock" | |
); | |
if (!commentLineTokens.length || !commentBlockTokens.length) return; | |
const grandmasReference = buildGrandmasReference(commentLineTokens); | |
const grandmasRecipes = buildGrandmasRecipe(commentBlockTokens); | |
path.traverse(GrandmaVisitor, { | |
grandmasReference: grandmasReference, | |
grandmasRecipes: grandmasRecipes, | |
}); | |
}, | |
}; | |
return { visitor: GrandmaVisitorInitiator }; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment